Missing first 30 frames when encoding videos with gstreamer/opencv in python

Hello there,

I want to build an application that will read from a camera, process the frames and save all frames in a video.

I wrote a simple python script to do this but I am always missing the first 30 frames in the video.

Any idea why this is? I have uploaded my script.

pihd_gstreamer.py (4.3 KB) This is my pipeline that is use to create an cv2.VideoWriter.

def gstreamer_video_encoding_pipeline(fileName):
return ("appsrc ! "
"video/x-raw, format=BGR ! "
"queue ! "
"videoconvert ! "
"video/x-raw, format=RGBA ! "
"nvvidconv ! "
"omxh264enc ! "
"video/x-h264, stream-format=byte-stream ! "
"h264parse ! "
"qtmux ! "
“filesink location=%s” % (fileName))


This may be related to OMX encoder plugin. You may try nvv4l2h264enc instead.

Please try Honey Patouceul’s suggestion. And also suggest try pure gstreamer pipeline:

$ gst-launch-1.0 nvarguscamerasrc num-buffers=200 ! nvv4l2h264enc ! h264parse ! qtmux ! filesink location=a.mp4

To check if the issue is specific to using OpenCV.

Great, no more missing frames after switching to nvv4l2h264enc.

1 Like