The user request sounds simple: "export channels 1, 3, and 4 from 12:02:10 to 12:02:30 as MP4s." The recorder side is messier. Dahua-family systems expose useful HTTP CGI and RTSP interfaces, but firmware differences, stream formats, timestamp encoding, and OEM quirks make reliable MP4 export more than a single URL.
Manual workflow
- Confirm CGI and RTSP access from the export machine. The machine running the export workflow needs HTTP or HTTPS access to the recorder for CGI calls and RTSP access for the fallback path. Use a recorder account with playback/search permission, not a shared admin account if you can avoid it.
- Map friendly camera names to Dahua channel numbers. Most failed exports start with the wrong channel. Write down the camera name, Dahua channel index, main/sub stream choice, and whether the camera is connected directly to the NVR PoE ports or added over the LAN.
- Search recordings with mediaFileFind.cgi before downloading. Use the recorder search API to find the segment that covers your requested window. Search a padded range when possible so firmware boundary quirks do not cause you to miss the actual clip.
- Try the fast CGI download path first. When loadfile.cgi returns a complete segment, it is usually faster than RTSP playback. Inspect the response, because some firmware returns DHAV, some returns a raw H.264/H.265 bitstream, and some returns an error payload that only looks like a download.
- Convert or remux into a normal MP4. Dahua-family recorders may export DHAV or raw video instead of a browser-friendly MP4. Remux DHAV when possible, rebuild timing for raw streams, and apply faststart so the clip opens cleanly for non-technical users.
- Fall back to RTSP playback and verify the result. RTSP playback is slower, but it is the safety net when CGI export is incomplete or unsupported. Always verify duration, codec, frame rate, and whether the clip covers the requested time window.
Dahua CGI endpoints to know
The usual manual route starts by searching with mediaFileFind.cgi, then downloading the matching recording with loadfile.cgi. Exact parameters vary by model and firmware, so treat this as the workflow shape rather than a universal copy-paste command.
# 1) Search recorded files for the requested channel and time window
/cgi-bin/mediaFileFind.cgi?action=factory.create
/cgi-bin/mediaFileFind.cgi?action=findFile&object=...&condition.Channel=1&condition.StartTime=YYYY-MM-DD HH:MM:SS&condition.EndTime=YYYY-MM-DD HH:MM:SS
/cgi-bin/mediaFileFind.cgi?action=findNextFile&object=...&count=100
# 2) Download a returned file path or segment
/cgi-bin/loadfile.cgi?action=startLoad&channel=1&startTime=YYYY-MM-DD HH:MM:SS&endTime=YYYY-MM-DD HH:MM:SSIf the download path returns a complete video segment, convert it to a standard MP4 and trim locally. If it returns a short or unusable file, use RTSP playback as a slower but often more compatible fallback.
Example RTSP fallback shape
ffmpeg -rtsp_transport tcp \
-i "rtsp://USER:PASSWORD@192.168.1.50:554/cam/playback?channel=1&starttime=YYYY_MM_DD_HH_MM_SS&endtime=YYYY_MM_DD_HH_MM_SS" \
-map 0:v -c copy channel-1-clip.mp4Dahua RTSP playback URL shapes vary across firmware and OEM brands. Validate the path on the actual recorder, and be careful with URL escaping when passwords contain symbols.
Failure modes to plan for
- The recorder returns a short file because the requested range spans internal recording chunks.
- The API response is XML, HTML, or an auth error even though the filename suggests video.
- The same endpoint behaves differently across Dahua, IC Realtime, Lorex, Amcrest, and other OEM firmware.
- Spaces and timestamps are encoded differently than the firmware expects, especially around `+` versus `%20` handling.
- The exported stream is DHAV or raw H.265/H.264 and needs conversion before most users can play it.
- RTSP works in VLC but fails in ffmpeg because of transport, timestamp, or credential escaping differences.
When automation is worth it
One manual export is manageable. Repeated exports for incidents, security reviews, sports clips, or multi-site support become a process problem: somebody has to remember channels, time formats, fallback behavior, conversion commands, and verification checks every time.
That is why I built the Dahua / IC Realtime NVR AI Agent skill. It wraps search, download, conversion, RTSP fallback, clipping, credential storage, and verification so a SKILL.md-compatible AI agent can handle plain-English footage requests and return a checked MP4.
