FFMPEG+Python跳过FFMPEG端不需要的帧

2024-06-26 09:59:25 发布

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

我试图处理一个实时的hlsv流,从中提取每100帧,并使用openCV进行处理

目前,我的代码如下所示:

pipe = subprocess.Popen([FFMPEG_BIN, "-i", src, 
                    "-loglevel", "quiet",
                    "-an", 
                    "-f", "image2pipe",
                    "-pix_fmt", "bgr24",
                    "-vcodec", "rawvideo", "-"],
                    stdin=subprocess.PIPE, 
                    stdout=subprocess.PIPE, 
                    stderr=subprocess.DEVNULL)

while True:
    raw_image = pipe.stdout.read(WIDTH * HEIGHT * 3)
    if frame_counter > 100:
        frame_counter = 0
        process_frame(raw_image)
    frame_counter += 1

读取所有帧并转储99%的帧似乎效率低下,并导致了管道缓冲区问题(至少我怀疑是这样)

是否可以跳过FFMPEG中的帧,以便每100帧都将转到标准输出


Tags: 代码imagesrcrawbinstdoutcounterframe
1条回答
网友
1楼 · 发布于 2024-06-26 09:59:25

使用“选择”过滤器保留每100帧一次

pipe = subprocess.Popen([FFMPEG_BIN, "-i", src, 
                    "-loglevel", "quiet",
                    "-vf", "select=not(mod(n\,100))",
                    "-vsync", "0",
                    "-an", 
                    "-f", "image2pipe",
                    "-pix_fmt", "bgr24",
                    "-vcodec", "rawvideo", "-"],
                    stdin=subprocess.PIPE, 
                    stdout=subprocess.PIPE, 
                    stderr=subprocess.DEVNULL)

相关问题 更多 >