我想处理一个实时的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帧都进入stdout?
使用选择过滤器来保留第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)