Save RTSP Stream to MP4 with FFmpeg Without Re-encoding
This article explains how to capture a live video stream from an RTSP camera and save it directly into an MP4 file using FFmpeg without re-encoding. By copying the original video and audio codecs instead of re-encoding them, you will minimize CPU usage, preserve the original video quality, and save the stream in real-time.
The Basic Command
To capture an RTSP stream and save it as an MP4 file without re-encoding, use the following FFmpeg command:
ffmpeg -rtsp_transport tcp -i "rtsp://username:password@camera_ip:port/stream_path" -c copy output.mp4Command Breakdown
-rtsp_transport tcp: This forces FFmpeg to use TCP instead of UDP. TCP is highly recommended for RTSP streams because it prevents packet loss, which can cause video corruption and artifacts in your saved file.-i "rtsp://...": This specifies the input source, which is the RTSP URL of your camera. Replace the placeholder with your camera’s actual IP address, port, credentials, and stream path.-c copy: This is the key argument. It tells FFmpeg to copy the input video and audio streams directly to the output container without decoding or re-encoding them. This process uses almost no CPU power.output.mp4: The destination path and name of the saved MP4 file.
Advanced Options
Limit the Recording Duration
If you want to record the stream for a specific amount of time (for
example, 10 minutes), add the -t parameter before the
output file name:
ffmpeg -rtsp_transport tcp -i "rtsp://camera_url" -c copy -t 00:10:00 output.mp4Split Recording into Segments
To continuously record the stream and split it into hourly files without gaps, you can use FFmpeg’s segment muxer:
ffmpeg -rtsp_transport tcp -i "rtsp://camera_url" -c copy -map 0 -f segment -segment_time 3600 -segment_format mp4 -reset_timestamps 1 capture_%03d.mp4This command splits the stream into 3600-second (1 hour) chunks,
naming them sequentially (capture_001.mp4,
capture_002.mp4, etc.).