[FFmpeg-user] Issues with concatenating specific MP4s from a Unifi camera

Davison Long dlong at nextgentech.net
Wed Mar 8 10:46:54 EET 2023


I have a Unifi Video server storing video data from a UVC G3 Pro camera (in the form of 2 second MP4 files).  I've been creating time-lapses of each day using ffmpeg and the vast majority of days work perfectly fine.  However, some days the source MP4s must get malformed somehow such that the concatenation phase doesn't work well at all and produces a broken file that freezes after the first couple seconds.

My procedure is to first concatenate and speed up all the video for a given day and then transcode the resultant H264 MP4 into a H265 MKV file.  To simplify things for diagnostics I've boiled the problematic command down to just the first step without any speedup or transcoding.  I've uploaded to Dropbox eight files for each set (bad source files and good source files).  The expected result (which occurs for the good source files) is a 16 second video.  The bad source files produce a video that MPC-HC or VLC show as a 2 second duration.  In MPC-HC the video portion freezes after 2 seconds and then the audio continues for the remainder of the 16 seconds.  In VLC both the video and audio cut out after 2 seconds.

The two sets of source files along with my resulting good and bad resultant files are on Dropbox here:
https://www.dropbox.com/sh/zr1kk6dtz4lx52u/AACM6y-VV6pjVaBiD2AznhY2a?dl=0

Here are the commands I've used to generate the good and bad resultant videos from the files:
# Run the concatenation on the bad source files
ffmpeg -safe 0 -f concat -i <(find /mnt/input/bad_source_files -type f -name '*.mp4' -printf "file '%p'\n" | sort) -vcodec copy -acodec copy /mnt/output/bad_video.mp4

# Run the concatenation on the good source files
ffmpeg -safe 0 -f concat -i <(find /mnt/input/good_source_files -type f -name '*.mp4' -printf "file '%p'\n" | sort) -vcodec copy -acodec copy /mnt/output/good_video.mp4

When the command is used on the bad set of files I get hundreds of notices like this:
[mp4 @ 0x560b694b4700] Packet duration: 2223883790 / dts: 2223981070 is out of range
[mp4 @ 0x560b694b4700] pts has no value

When the command is run on the good set of files I also get a bunch of different notices like these:
DTS 35273693825, next:2041445 st:0 invalid dropping
PTS 35273693825, next:2041445 invalid dropping st:0

However, even with those messages the "good" source files end up producing a resultant file that works perfectly fine.

I've used a bunch of different versions of ffmpeg.  Currently I'm using version 6.0 on Ubuntu 22.04.

I've tried literally dozens of variations of options to try to get good output from the "bad" source files (all sorts of fflags like genpts, igndts, ignidx, discardcorrupt and options like use_wallclock_as_timestamps, avoid_negative_ts, etc) and I just can't seem to get anywhere.  I figured I'd just post the data here and see if anyone has suggestions or a solution.  Any help would be greatly appreciated.

-Davison Long


More information about the ffmpeg-user mailing list