簡體   English   中英

FFMPEG + Python - 在 ffmpeg 側跳過不需要的幀

[英]FFMPEG + Python - skipping unneeded frames on ffmpeg side

我正在嘗試處理實時 hlsv stream,從中提取每 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% 似乎效率低下,並導致我遇到 pipe 緩沖區問題(至少我懷疑)。

是否可以跳過 FFMPEG 中的幀,以便每 100 幀將 go 到標准輸出?

使用 select 過濾器保留每 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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM