重定向标准错误在Python工作。
所以不是这个pipe = sp.Popen(command, stdout = sp.PIPE, stderr = sp.PIPE)
做到这一点pipe = sp.Popen(command, stdout = sp.PIPE, stderr = sp.STDOUT)
我们可以通过添加一个异步调用避免重定向到阅读的ffmpeg的这两个标准流(stdout和stderr)。这将避免视频帧和时间戳的任何混合,从而避免错误分离。 因此修改原始代码以使用threading模块应该是这样的:
# Python script to read video frames and timestamps using ffmpeg
import subprocess as sp
import threading
import matplotlib.pyplot as plt
import numpy
import cv2
ffmpeg_command = [ 'ffmpeg',
'-nostats', # do not print extra statistics
#'-debug_ts', # -debug_ts could provide timestamps avoiding showinfo filter (-vcodec copy). Need to check by providing expected fps TODO
'-r', '30', # output 30 frames per second
'-i', 'e:\sample.wmv',
'-an','-sn', #-an, -sn disables audio and sub-title processing respectively
'-pix_fmt', 'rgb24',
'-vcodec', 'rawvideo',
#'-vcodec', 'copy', # very fast!, direct copy - Note