in Debian, Linux, Video

How to record a RTSP stream with VLC and ffmpeg

1. Install ffmpeg. If you require H.264 or other codecs not available with the Debian provided ffmpeg skip this step and install ffmpeg using this guide: How to install ffmpeg with H.264/MPEG-4 AVC

apt-get install ffmpeg

2. Install VLC. We will use VLC for recording but it relys on ffmpeg for encoding.

apt-get install vlc

3. Record the stream. Here are two examples of how you can record RTSP streams. VLC and ffmpeg offer hundreds of options so you may need to look up the man pages for the tools to find options that fits your needs. Using these commands you can record any RTSP stream and save it to a local file.

cvlc rtsp://{hostname}:1935/live/camera.stream --sout "#transcode{}:duplicate{dst=std{access=file,mux=ts,dst={filename}}}"

Restrict the recording to 1 hour. This is useful when recording a part of a live stream

cvlc rtsp://{hostname}:1935/live/camera.stream --sout "#transcode{}:duplicate{dst=std{access=file,mux=ts,dst={filename}}}" --run-time 3600 --stop-time=3660

Replace {hostname} with the hostname or IP address of the streaming server and {filename} with the local file where you want to save the stream

4. (optional) When recording a part of a H.264 live stream, some meta data (ex. moov atom) may be missing to stream or play the file. Using the command below you can create the moov object in the file.

ffmpeg {input_file} -acodec copy -vcodec copy {output_file}

Write a Comment

Comment