pipe video frame and frame info from FFMPEG [closed]
Hi All,
I'm trying to pipe a video in from FFMPEG to opencv, i would like to pass the image and info for each frame in an attempt to get the most accurate frame time stamps when i am processing the images.
i was able to get the image only and run through the whole video when only using stdout. But when i try to integrate stderr to allow info to be read; it will display the first frame, print the first info dump, then freeze and crash.
Could anybody point me in the right direction?
import cv2
import subprocess as sp
import numpy
import time
FFMPEG_BIN = "ffmpeg"
command = [ FFMPEG_BIN,
'-i', 'C:\Users\Hayden\PycharmProjects\apexvod\Apex.mp4',
'-an', '-sn',
'-pix_fmt', 'bgr24',
'-vcodec', 'rawvideo',
'-vf', 'showinfo',
'-f', 'image2pipe', 'pipe:1']
pipe = sp.Popen(command, stdout=sp.PIPE, stderr=sp.PIPE, bufsize=1920 * 1080 * 3+3357)
while pipe.poll() is None:
if cv2.waitKey(0) & 0xFF == ord('q'):
break
raw_image = pipe.stdout.read(1920 * 1080 * 3)
info = pipe.stderr.read(3357)
image1 = numpy.frombuffer(raw_image, dtype='uint8')
image2 = image1.reshape((1080, 1920, 3))
cv2.imshow('Video', image2)
print(info)
pipe.stdout.flush()
pipe.stderr.flush()
pipe.terminate()
cv2.destroyAllWindows()
sorry, but this is NOT an opencv problem