在处理大型视频文件时,可能会出现视频持续时间的问题。为了解决这个问题,可以使用以下代码示例:
import os import subprocess
video_dir = "path/to/directory/"
output_file = "path/to/output/file.mp4"
video_files = [f for f in os.listdir(video_dir) if f.endswith(".mp4")]
command = "ffmpeg -i concat:" for video_file in video_files: video_path = os.path.join(video_dir, video_file) duration = subprocess.check_output(["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", video_path]).decode("utf-8").strip() command += video_path + "|" command = command[:-1] + " -c copy " + output_file
subprocess.call(command, shell=True)
以上代码示例使用FFmpeg将多个视频文件合并成一个大的视频文件,并确保保持正确的视频持续时间。
上一篇:Backblaze上传速度慢