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

2024-04-26 23:47:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个名为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文件夹中提取帧。你知道吗

附言:frames/%04d.png不起作用。你知道吗

谁能告诉我怎么做吗?你知道吗


Tags: path目录脚本文件夹示例framespngvideo
1条回答
网友
1楼 · 发布于 2024-04-26 23:47:05

您可以在函数完成后添加一个调用来移动所有输出文件。你知道吗

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)

相关问题 更多 >