Capture IP Camera Video over HTTP with FFmpeg

Capturing video from an IP camera over HTTP and saving it to local storage is a highly efficient way to manage security footage or archive live streams. This article provides a straightforward guide on how to use FFmpeg, a powerful open-source multimedia framework, to connect to an HTTP-based camera stream, handle authentication, and save the video file directly to your system.

Step 1: Locate the IP Camera HTTP Stream URL

Before running FFmpeg, you need the exact HTTP URL of your IP camera’s video stream. This stream is often delivered in MJPEG (Motion JPEG) or H.264 format over HTTP.

Common stream URL formats include: * MJPEG: http://<CAMERA_IP>:<PORT>/video.mjpg * H.264/MPEG-4: http://<CAMERA_IP>:<PORT>/live/ch0.m3u8

Consult your IP camera’s user manual or administrative portal to find the specific streaming path.

Step 2: Run the Basic FFmpeg Command

To capture the stream and save it to a local file, open your terminal or command prompt and run the following command:

ffmpeg -i "http://192.168.1.100:8080/video.mjpg" -c:v copy output.mp4

Here is a breakdown of the parameters used: * -i "http://...": Specifies the input source, which is your IP camera’s HTTP stream URL. * -c:v copy: Instructs FFmpeg to copy the video stream directly without re-encoding. This saves CPU usage and preserves the original video quality. * output.mp4: The name and format of the output file where the video will be saved.

Step 3: Handling Username and Password

Most IP cameras require authentication to access the video stream. You can pass your credentials directly inside the HTTP URL:

ffmpeg -i "http://username:password@192.168.1.100:8080/video.mjpg" -c:v copy output.mp4

Replace username and password with your camera’s login credentials.

Step 4: Splitting the Video into Segments (Optional)

If you plan to run the capture continuously, saving a single, massive file is impractical. You can instruct FFmpeg to split the recording into smaller, time-based segments (e.g., every 15 minutes) using the segment muxer:

ffmpeg -i "http://192.168.1.100:8080/video.mjpg" -c:v copy -f segment -segment_time 900 -reset_timestamps 1 capture_%03d.mp4

Key arguments for segmentation: * -f segment: Enables the segment muxer. * -segment_time 900: Splits the video every 900 seconds (15 minutes). * -reset_timestamps 1: Resets the timestamps at the beginning of each segment to ensure the output files play back correctly. * capture_%03d.mp4: Names the output files sequentially (e.g., capture_001.mp4, capture_002.mp4).