I have a video from a security camera that was originally recorded at a low frame rate, maybe 15 fps, maybe 10 fps, maybe even less. It has since been converted by someone else to 25 fps (without changing the duration). I assume that extra, duplicate frames have been added, and possibly this has also slightly distorted the exact time at which the original frames are displayed.
I want to re-encode the video with ffmpeg to its original frame rate, without dropping any of the useful frames of actual motion. If I just use the fps
filter it won't be selective about which frames it keeps, and I assume that due to rounding errors it could end up keeping some of the duplicate frames and permanently losing useful frames, making things worse. In any case, I don't know what number to tell the filter because I don't know exactly what the original frame rate was!
How can I proceed to repair this video with ffmpeg?
ffmpeg -i "orig.mp4" -an -vcodec h264 -vf "fps=???" "fixed.mp4"
Best Answer
I managed to fix my file. I found the
mpdecimate
filter, which drops duplicate or near duplicate frames from a video stream. First I tried:I added
-loglevel debug
to get more info during transcoding. The info showed whatmpdecimate
was doing with the frames, which was lots and lots of this pattern:I.e., it was consistently dropping 4 frames in a row as duplicates and keeping every 5th. This showed that the original frame rate was 1/5th of what it was now. I was lucky! Since the video's current 25 fps was a multiple of the original frame rate, there shouldn't be a problem with temporal misalignment of the kept and dropped frames. Therefore I retranscoded the original video with nothing more complex than
-vf "fps=5"
, and the output seemed to be fine. Just to be sure, I piped the output through thempdecimate
filter, and it detected all remaining frames as a "keep". So the original file was not so messed up as I thought.