Skip to content

Instantly share code, notes, and snippets.

@mowings
Last active April 9, 2024 20:51
Show Gist options
  • Star 46 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save mowings/6960b8058daf44be1b4e to your computer and use it in GitHub Desktop.
Save mowings/6960b8058daf44be1b4e to your computer and use it in GitHub Desktop.
ffmpeg stream and save video from Dahua 4300s IP Camera

Use ffmpeg to stream video from a dahua 4300s to a file or files

You can use ffmpeg to directly pull frames off of a dahua 4300s at full resolution. May be a good alternative to pricey dvrs which likely cannot record at full resolution, may not work with the camera, or are prohibitevly expensive

Simple Stream to file

Simple stream to file. Full resolution

ffmpeg -loglevel debug -rtsp_transport tcp -i "rtsp://admin:admin@198.175.207.61:554/live" \
-c copy -map 0 foo.mp4

Break streamed file into time segments

ffmpeg can save file in arbitrary segments at fixed intervals. In this example, we save a new file at 10 second intervals, but the value for segment_time can be any positive integer

ffmpeg  -rtsp_transport tcp -i "rtsp://admin:admin@198.175.207.61:554/live"  \
-f segment -segment_time 10 -segment_format mp4 -reset_timestamps 1 \
-c copy -map 0 test%d.mp4

Timestamped output

Output files can be timestamped as well.

ffmpeg  -rtsp_transport tcp -i "rtsp://admin:admin@198.175.207.135:554/live" \
-f segment -segment_time 10 -segment_format mp4  -reset_timestamps 1 \
-strftime 1 -c copy -map 0 dauphine-%Y%m%d-%H%M%S.mp4

Select stream to read from.

A different url is used to select the substream. Set subtype to 0 for main hi-res stream, or 1 for low res substream. Channel looks to always be set to 1

ffmpeg  -rtsp_transport tcp -i "rtsp://admin:admin@198.175.207.135:554/cam/realmonitor?channel=1&subtype=1" \ 
-f segment -segment_time 10 -segment_format mp4  -reset_timestamps 1 \ 
-strftime 1 -c copy -map 0 test-%Y%m%d-%H%M%S.mp4
@a2ron
Copy link

a2ron commented Apr 9, 2017

Nice! It works also with IP 3G Cam V380e aka 360eye, handling properly credential, port and URI to connect through RTSP.

@codegastudio
Copy link

rtsp port is 554 so no need to write it in your input url

@mengzhangjian
Copy link

save my life!!! thanks

@willstare
Copy link

I am using a variation of this command combined with a bash script+cron. I run ffmpeg with the -t flag to only run for 310 seconds. Then I have cron call the script every 5 minutes. This way I end up with a new file every 5 minutes with a ~10 second overlap. This makes it resilient if the ipcam goes offline for a few minutes due to reboot, cron will start a new ffmpeg process within 5 minutes.

Not as elegant as an NVR but it's functional.

@goodkiller
Copy link

@willstare How are you using -t flag with strftime? I'm not able to cope with those parameters. My goal is not using segments.

@pppaulpeter
Copy link

great, thanks for sharing. may i know how to save the recording by ffmpeg command?

@goldsoft8888
Copy link

goldsoft8888 commented Oct 27, 2023

Is there any way to directly save IPC video streams to cloud storage as files? Can the uploading be done through webdav for streaming transmission?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment