Sunday, 7 March 2021

How to use FFMPEG to stream RTSP into a video?

A Simple Way:

ffmpeg -i rtsp://192.168.80.112 -r 30 -vcodec copy -an -t 60 temp.mp4

ffmpeg -i rtsp://192.168.80.112 -b 900k -vcodec copy -r 60 -y MyVdeoFFmpeg.avi

ffmpeg -i rtsp://192.168.80.112 -acodec copy -vcodec copy ./abc.mp4


Simple Stream to file

Simple stream to file. Full resolution

ffmpeg -loglevel debug -rtsp_transport tcp -i "rtsp://admin:admin@198.175.207.61:554/live" \
-c copy -map 0 foo.mp4

Break streamed file into time segments

ffmpeg can save file in arbitrary segments at fixed intervals. In this example, we save a new file at 10 second intervals, but the value for segment_time can be any positive integer

ffmpeg  -rtsp_transport tcp -i "rtsp://admin:admin@198.175.207.61:554/live"  \
-f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 \
-c copy -map 0 test%d.mp4

Timestamped output

Output files can be timestamped as well.

ffmpeg  -rtsp_transport tcp -i "rtsp://admin:admin@198.175.207.135:554/live" \
-f segment -segment_time 10 -segment_format mp4  -reset_timestamps 1 \
-strftime 1 -c copy -map 0 dauphine-%Y%m%d-%H%M%S.mp4

Select stream to read from.

A different url is used to select the substream. Set subtype to 0 for main hi-res stream, or 1 for low res substream. Channel looks to always be set to 1

ffmpeg  -rtsp_transport tcp -i "rtsp://admin:admin@198.175.207.135:554/cam/realmonitor?channel=1&subtype=1" \ 
-f segment -segment_time 10 -segment_format mp4  -reset_timestamps 1 \ 
-strftime 1 -c copy -map 0 test-%Y%m%d-%H%M%S.mp4 
 
p/s: copied from https://gist.github.com/mowings/6960b8058daf44be1b4e 

No comments:

Post a Comment