gstreamergstreamer-1.0

Gstreamer x-raw to h264 mp4


The documentation for some software I'm using says to use this gstreamer pipeline to stream video from a camera:

gst-launch-1.0 v4l2src device=/dev/video5 ! video/x-raw ! videoconvert ! v4l2h264enc ! h264parse config-interval=3 ! rtph264pay mtu=1024 ! udpsink host=127.0.0.1 port=5600

If I wanted to adapted this to pipe to a .mp4, I thought something like this would work:

gst-launch-1.0 v4l2src device=/dev/video5 ! video/x-raw ! videoconvert ! v4l2h264enc ! h264parse config-interval=3 ! filesink location=test.mp4

but the resulting file is not playable in vlc.

What am I missing?

Thanks in advance.


Solution

  • You would use a container (such as qtmux here) :

    # For recording 100 frames:
    gst-launch-1.0 v4l2src device=/dev/video5 num-buffers=100 ! video/x-raw ! videoconvert ! v4l2h264enc ! h264parse config-interval=3 ! qtmux ! filesink location=test.mp4
    
    # If you want to manually stop with Ctrl-C, add EOS support:
    gst-launch-1.0 -e v4l2src device=/dev/video5 ! video/x-raw ! videoconvert ! v4l2h264enc ! h264parse config-interval=3 ! qtmux ! filesink location=test.mp4