Capture RTSP Video Streams to Linux with FFmpeg

This article provides a practical guide on how to capture a live Real-Time Streaming Protocol (RTSP) camera feed and save it directly to your Linux storage using FFmpeg. You will learn the exact command-line syntax required for efficient recording, how to handle common connectivity challenges, and methods for automating your security footage split into manageable files.

The Core Command for Basic Capture

To save an RTSP stream without re-encoding the video—which saves CPU power and preserves original quality—you should copy the audio and video codecs directly. Run the following command in your Linux terminal:

ffmpeg -rtsp_transport tcp -i "rtsp://username:password@camera_ip_address:554/stream_path" -c copy output.mp4

Breaking Down the Command Options

Advanced: Segmentation and Automatic File Splitting

Leaving a network stream recording indefinitely into a single file can lead to massive, unmanageable file sizes and potential corruption if the system crashes. You can instruct FFmpeg to automatically split the video into timed segments (e.g., every 15 minutes) using the segment muxer:

ffmpeg -rtsp_transport tcp -i "rtsp://username:password@camera_ip_address:554/stream_path" \
-c copy -map 0 -f segment -segment_time 900 -segment_format mp4 \
-reset_timestamps 1 "capture_%03d.mp4"

Key Parameters for Segmented Recording

Running the Capture in the Background

To ensure the recording continues running even after you close your terminal session, wrap the FFmpeg command using nohup or run it inside a screen or tmux session. For a quick background task, use:

nohup ffmpeg -rtsp_transport tcp -i "rtsp://username:password@camera_ip_address:554/stream_path" -c copy output.mp4 > ffmpeg.log 2>&1 &

This routes the operational logs to ffmpeg.log and frees up your terminal immediately.