'Use FFMPEG to record a RTSP stream to a local file

I'm looking for a snippet (C/ObjC) in which an up-to-date version of FFMPEG is used to capture a RTSP or RTP stream and save it as a .mp4 file onto the device (with a start/stop record button)

Almost all snippets are are out-dated. I would like to use FFMPEG/Libav v3.2-v3.4

I'm using IJKPlayer to display the streams, which works nicely, but there's no record functionality included.

Any suggestions? Thanks!



Solution 1:[1]

You can use a ffmpeg call from a command line. Ffmpeg syntax is very straight forward.

ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ...

So, if you don“t need to reencode or decode your RTPS video stream, you can simply run:

ffmpeg -i rtsp://your_stream_url your_file_name.format

Where format could be avi, mp4, flv or others, ffmpeg you automatic package your stream to the output file.

More information here.

https://www.ffmpeg.org/ffmpeg.html

Solution 2:[2]

my demo: ffmpeg -i "rtsp://admin:[email protected]:554/h264/ch1/main/av_stream" -f segment -segment_time 5 %d.mp4

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thadeu Antonio Ferreira Melo
Solution 2 codemaker