How to save raw h264 raspberry pi stream to .h264 file

3.6k Views Asked by At

How do we save h264 udp stream from raspberry pi to raw .h264 file?

Tried saving raspivid directly to raw video and it works. But after streaming to the computer the .h264 doesn't show anything when played with VLC.

Raspberry pi script:

raspivid -t 0 -w 800 -h 600 -fps 16 -g 5 -b 1000000 -vf -o - | gst-launch-1.0  --gst-debug=3 fdsrc ! h264parse ! rtph264pay ! udpsink host=<<IP>> port=5000

On the receiving side:

gst-launch-1.0 -e -v udpsrc port=5000 ! application/x-rtp, clock-rate=90000, encoding-name=H264, payload=96 ! rtpjitterbuffer ! rtph264depay ! filesink location=test.h264

Can this be done?

1

There are 1 best solutions below

0
On BEST ANSWER

If you are getting raw h264 (avc format) it might not be playable as a file. You can either force it to be converted to byte-stream which can be saved directly to file or use a container with the avc.

gst-launch-1.0 -e -v udpsrc port=5000 ! application/x-rtp, clock-rate=90000, encoding-name=H264, payload=96 ! rtpjitterbuffer ! rtph264depay ! h264parse ! "video/x-h264, format=byte-stream" ! filesink location=test.h264

gst-launch-1.0 -e -v udpsrc port=5000 ! application/x-rtp, clock-rate=90000, encoding-name=H264, payload=96 ! rtpjitterbuffer ! rtph264depay ! h264parse ! mp4mux ! filesink location=test.mp4

You can also force byte-stream format on the sender:

raspivid -t 0 -w 800 -h 600 -fps 16 -g 5 -b 1000000 -vf -o - | gst-launch-1.0 --gst-debug=3 fdsrc ! h264parse ! "video/x-h264, format=byte-stream" ! rtph264pay ! udpsink host=<> port=5000