I have a number of videos that contain sound sequences that repeat with a corresponding video freeze. I have an example clip that contains a sound sequence from 51.194s -- 60.133s that repeats again from 60.157s--69.096s with a corresponding video freeze that consists of a single frame at 61.144s with next frame coming nearly 9 seconds later at 70.149s.

I've managed to cobble together a perl script that will find and repair the erroes in this particular sample. The repair was to simply delete the second sound sequence (51.194s -- 60.133s) and reduce the following audio time stamps by ~8.9s and to reduce the video timestamps after 61.144s by the same 8.9s.

As I said my script is simply cobbled toghether and before putting more work into it, I would like to explore options with ffmpeg.

I've had luck using freezedetect to find the frozen video:

ffmpeg -i input.flv -vf "freezedetect=n=0:d=2"  -f null -
[freezedetect @ 0x5632dc441f00] lavfi.freezedetect.freeze_start: 61.14421.5x    
[freezedetect @ 0x5632dc441f00] lavfi.freezedetect.freeze_duration: 9.005
[freezedetect @ 0x5632dc441f00] lavfi.freezedetect.freeze_end: 70.149
[freezedetect @ 0x5632dc441f00] lavfi.freezedetect.freeze_start: 116.1112.2x

And I've attempted to use trim/atrim to repair the file -- with no luck:

ffmpeg -i input.flv -filter_complex
'[0:v] trim=end=61.115,trim=start=70.107, setpts=PTS-STARTPTS [v0];
 [0:a] atrim=end=60.158,atrim=start=69.121,asetpts=PTS-STARTPTS [a0]'
 -map [v0] -map [a0] output.flv

This produced a short, unplayable file. But even if this had worked, I'd need some way to detect the duplicated audio first.

So is there a filter that will detect and repair the problems I've described above? Something like this:

ffmpeg -i broken.mp4 -vf {dup remove filter} fixed.mp4
  • is there any reasons the end is smaller than the start in the trim filter? – xer-rex Dec 10 '20 at 0:30
  • I can't seem to edit the question but my understanding is this acts as 2 trims the first will include segments in 0--61.115s and the second will include segments between 70.107 and the end of the video. – nilram Dec 10 '20 at 22:40
  • You are simply not understanding how trim filters work at all. – Paul B. Mahol Dec 19 '20 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.