【问题标题】:FFMPEG + Python - skipping unneeded frames on ffmpeg sideFFMPEG + Python - 在 ffmpeg 端跳过不需要的帧
【发布时间】:2020-05-11 11:03:40
【问题描述】:

我正在尝试处理实时 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 帧将进入标准输出?

【问题讨论】:

    标签: python ffmpeg subprocess


    【解决方案1】:

    使用选择过滤器保留每 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)
    

    【讨论】:

      猜你喜欢
      • 2019-01-13
      • 2017-11-27
      • 2018-09-25
      • 1970-01-01
      • 2015-05-06
      • 1970-01-01
      • 2014-05-29
      • 2021-11-10
      • 2019-03-11
      相关资源
      最近更新 更多