gpt4 book ai didi

python - 在子进程中重定向ffmpeg的输出

转载 作者:行者123 更新时间:2023-12-04 23:24:44 25 4
gpt4 key购买 nike

我有一个名为 video_files 的文件夹我在哪里存储了一堆视频文件,例如100.mp4, 101.mp4... .我编写了一个迭代每个视频文件的 python 脚本。使用 subprocess调用ffmpeg提取帧,然后将帧保存到名为 frames 的输出目录中.这是我的示例代码:

def frame_extractor(video_files_path):
video_files = sorted(glob.glob(video_files_path + "**/*.mp4", recursive=True))
print("Number of video files found: ", len(video_files))
for i, video in enumerate(video_files):
subprocess.call(["ffmpeg", "-i", video, "%04d.png"]
print("Extracted frames from all the videos")

问题是它提取了当前目录中的帧,我从这里运行这个脚本,但我希望在 frames 中提取帧。文件夹。

PS: frames/%04d.png不起作用。

谁能告诉我该怎么做?

最佳答案

您可以在函数完成后添加调用以移动所有输出文件。

import os
import glob

for img in glob.glob(video_files_path + '**/*.png', recursive=True):
img_out = os.path.join('frames', os.path.split(img)[-1])
os.rename(img, img_out)

关于python - 在子进程中重定向ffmpeg的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52777211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com