SmartRTSP
Languages · English

FFmpeg RTSP Commands: Play, Inspect and Record

Check RTSP video resolution, codecs and audio tracks with FFprobe. Play the camera feed with FFplay and record MP4 or numbered MKV clips with FFmpeg.

Play and check a camera stream

ffplay -rtsp_transport tcp "rtsp://CAMERA_IP:PORT/PATH"

Use the camera or recorder’s documented RTSP URL from its local network. Replace CAMERA_IP, PORT and PATH. When the camera requires credentials, use its local streaming account and keep the complete URL private.

ffprobe -v error -rtsp_transport tcp -timeout 5000000 -show_entries stream=codec_type,codec_name,width,height,sample_rate,channels -of compact=p=0 "rtsp://CAMERA_IP:PORT/PATH"
Example from the local test stream
codec_name=h264|codec_type=video|width=640|height=360 codec_name=aac|codec_type=audio|sample_rate=48000|channels=1

The video row shows H.264 at 640 × 360. The audio row shows AAC at 48 kHz with one channel. If no audio row appears, check whether the selected camera stream includes audio.

Start a local RTSP test stream

Use ffprobe to list the video and audio codecs. A listed track is only a description of the stream. Check the moving picture and listen for audio in ffplay.

Check whether the stream decodes

If ffprobe lists a video track but the screen stays black, test up to five seconds of video. FFmpeg decodes only video and discards the output.

ffmpeg -hide_banner -nostdin -xerror -abort_on empty_output -rtsp_transport tcp -timeout 5000000 -i "rtsp://CAMERA_IP:PORT/PATH" -t 5 -map 0:v:0 -an -f null -

A rising frame count shows that FFmpeg decoded video. An error stops the test. The TCP socket timeout is five seconds per operation.

Record RTSP to MKV or MP4

ffmpeg -n -rtsp_transport tcp -i "rtsp://CAMERA_IP:PORT/PATH" -map 0:v:0 -map "0:a:0?" -t 60 -c copy camera.mkv
ffmpeg -n -rtsp_transport tcp -i "rtsp://CAMERA_IP:PORT/PATH" -map 0:v:0 -map "0:a:0?" -t 60 -c:v copy -c:a aac camera.mp4

The first command saves 60 seconds without re-encoding. The second copies video and converts any audio to AAC for MP4. Use a video codec your MP4 player supports. The -n option keeps an existing output file from being overwritten.

Record an RTSP stream as numbered MKV clips

Run the command in a new, empty folder for each recording. Replace CAMERA_IP:PORT/PATH with the address, port and stream path for your camera or recorder.

ffmpeg -hide_banner -nostdin -rtsp_transport tcp -timeout 5000000 -i "rtsp://CAMERA_IP:PORT/PATH" -t 300 -map 0:v:0 -map "0:a:0?" -c copy -f segment -segment_time 60 -reset_timestamps 1 "camera-%03d.mkv"

The command records up to five minutes and aims for one minute per clip, starting with camera-000.mkv. It copies the video and any available audio. Splits occur at video keyframes, so clip lengths can vary.

Play the first and last clips after the run. To check a clip’s duration and codecs, run the command below with that clip’s filename.

ffprobe -v error -show_entries format=duration:stream=codec_type,codec_name "camera-000.mkv"
FFmpeg documentation for segment recording

Convert RTSP to HLS

ffmpeg -n -rtsp_transport tcp -i "rtsp://CAMERA_IP:PORT/PATH" -map 0:v:0 -map "0:a:0?" -c:v libx264 -pix_fmt yuv420p -flags +cgop -force_key_frames "expr:gte(t,n_forced*2)" -c:a aac -f hls -hls_time 2 -hls_list_size 4 -hls_flags delete_segments stream.m3u8

This example uses H.264 and AAC. Run it in a dedicated writable folder on a trusted network. Serve the playlist and its segments together to an HLS player. The segment duration is a target, and playback adds buffering delay.

Watch an HLS (.m3u8) stream on Apple TV

Relay one camera stream to multiple viewers

ffmpeg -rtsp_transport tcp -i "rtsp://CAMERA_IP:PORT/PATH" -map 0:v:0 -map "0:a:0?" -c copy -f rtsp -rtsp_transport tcp "rtsp://SERVER_IP:8554/relay"

Run an RTSP server such as MediaMTX that accepts publishing on the output path. The first TCP option applies to the camera input and the second applies to the server output. See the camera URL reference or the synthetic stream guide if you need a starting stream.

Download SmartRTSP

Open your camera or test stream on your device.