以下是一个利用 FFmpeg 剪辑视频并选择目录下视频的 Python3 代码:

import os

# 安装 ffmpeg 和 ffprobe
os.system('sudo apt-get install ffmpeg')
os.system('sudo apt-get install ffprobe')

# 输入视频目录和输出目录
input_dir = input('Enter the input directory: ')
output_dir = input('Enter the output directory: ')

# 输入剪辑开始和结束时间
start_time = input('Enter the start time in hh:mm:ss format: ')
end_time = input('Enter the end time in hh:mm:ss format: ')

# 遍历目录下的视频文件
for file in os.listdir(input_dir):
    if file.endswith('.mp4'):
        input_file = os.path.join(input_dir, file)
        output_file = os.path.join(output_dir, file)
        # 使用 ffmpeg 剪辑视频
        os.system(f'ffmpeg -i {input_file} -ss {start_time} -to {end_time} -c copy {output_file}')
        print(f'{file} has been clipped.')

这个代码首先安装了 ffmpeg 和 ffprobe,然后提示用户输入视频目录和输出目录以及剪辑的开始和结束时间。然后遍历输入目录下的所有 .mp4 文件,并使用 ffmpeg 剪辑每个视频,输出到输出目录中。

Python3 使用 FFmpeg 剪辑视频 - 自定义时间和批量处理

原文地址: https://www.cveoy.top/t/topic/nzDO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录