Search code examples
gstreamervideo-capture

record camera stream from gstreamer


I have a gstreamer pipeline which works perfectly and takes a camera stream, encodes it as H.264 video, saves it to a file AND displays it on the screen as follows:

gst-launch-1.0 -v autovideosrc ! tee name = t ! queue ! omxh264enc ! 
'video/x-h264, stream-format=(string)byte-stream' ! h264parse ! qtmux ! 
filesink location=test.mp4 t. ! queue ! videoscale ! video/x-raw, 
width=480,height=270 ! xvimagesink -e sync=false

Now, I am trying to do something even simple and just record the stream to a file (without displaying on screen) and this does not seem to work! It writes a file but cannot play it. What I have tried so far is:

gst-launch-1.0 -v autovideosrc ! queue ! omxh264enc ! 'video/x-h264, 
stream-format=(string)byte-stream' ! h264parse ! qtmux ! filesink 
location=test.mp4 sync=false

I can also remove the queue element but with the same result:

gst-launch-1.0 -v autovideosrc ! omxh264enc ! 'video/x-h264, 
stream-format=(string)byte-stream' ! h264parse ! qtmux ! filesink 
location=test.mp4 sync=false

It does not give any errors but just does not write a valid stream to my filesink, it seems.


Solution

  • How do you stop the stream? Will the camera correctly inject an EOS signal? If not and you just press ctrl-c to stop the operation the .mp4 file will missing important headers which are required for proper playback.

    Add -e to your command line. In that case when you press ctrl-c the pipeline will not just stop but is being properly shut down by sending an EOS signal through the pipeline.