6

I've got a Reolink security camera, which saved .mp4 files via FTP to a local server. I've then got my own Python-based application processing those videos. It's been working fine for the past year or so, although I often noticed warnings in the Python console (from OpenCV) about "error reading header", but it worked anyway so ignored it.

Since getting a new server and reinstalling all of the software, which happens to mean updated versions of Debian Linux, Python and OpenCV, it no longer tolerates the errors and fails to load those videos. Worryingly, around 1 in 4 of the videos saved via FTP give this error in my Python app, and if I try to load them via FFMPEG on either my server or on my (Mac) laptop, I get the error [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7ff492000400] error reading header [path]: Operation not permitted

I've put one of the videos on Dropbox so you can see: https://www.dropbox.com/s/tu4ddegh6yn05nu/ErrorReadingHeader.mp4?dl=0

Anyone have any ideas what's causing this, or how to fix it? I think I've got a few options, but don't have enough info to progress any of them:

  • Fix the videos so they're not corrupt. I have asked Reolink, the manufacturer, if they can shed any light...
  • Make FFMPEG etc tolerate the errors. Not sure how... also not sure which codec OpenCV is using (I know it's definitely not FFMPEG, so there's more than one codec not happy with these headers!)
  • Try to 'repair' the videos before processing. There may be some mileage in this as a solution, but feels very inefficient so would rather avoid if possible... but it's there as a final resort!

Thanks a lot!

1 Answers1

6

The sample MP4 is fragmented and so instead of having a global index for samples i.e. frames, the metadata is per fragment. Within each fragment's metadata, there is a track run box trun which has data for all samples within the fragment. There was a change made in Oct 2017 (ffmpeg 4.0+) where ffmpeg would bail if the trun box indicated that 0 samples were stored within the fragment.

mp4box or older versions of ffmpeg do not fail, so you may use them to remux the file to regular MP4s.

ffmpeg-3.4 -i in.mp4 -c copy out.mp4

or

mp4box -add in.mp4 -new out.mp4
Gyan
  • 38,955