5

I have problematic footage from diving due to my camera/SD card - every 4th or so frame is just black, and I want to replace all those black frames with either an interpolation between the previous and next frame or just duplicate the previous frame.

I found this question "remove black frames from vob files with ffmpeg", but I don't want to cut out the frames but instead want to interpolate between the two frames or duplicate the previous frame.

I think I might be able to get all the relevant positions with the black-frame filters etc, but what kind of actions would I use to replace those frames with an interpolation or a duplicate of the previous frame in a fully automatic way (so I only pass my movie file into the script)?

All I've found so far is the "shuffleframes" method, which I could somehow (how?) feed with the position of the black frames and then thereby duplicate the previous frame.

Demo footage detailing the probem can be found here.

1

1 Answer 1

6

It's possible to have the black frames removed and earlier frames duplicated.

ffmpeg -i in.mp4 -vf blackframe=0,metadata=select:key=lavfi.blackframe.pblack:value=50:function=less -vsync cfr -c:a copy out.mp4

The blackframe filter analyses and registers the proportion of a frame's pixels which are black. The metadata filter keeps all frames which have at most 50% of pixels black. The removed frames create a gap in the video stream. So by setting the video sync method to constant frame rate, ffmpeg duplicates earlier (non-black) frames to fill in those gaps.

You'll have to experiment with the metadata selection value 50 to get the right threshold.

8
  • This is amazing. It pretty much achieves what I wanted to (I think). I wonder though how it a) handles cases where there is multiple directly following black frames b) why the output files are consistently longer than the input files (duration wise)
    – Hug
    Commented Mar 17, 2018 at 19:05
  • why does the output have a longer duration than the input?
    – Hug
    Commented Mar 20, 2018 at 9:45
  • Share full log. How much difference are we talking about?
    – Gyan
    Commented Mar 20, 2018 at 10:29
  • Hi, I'm sorry for the delay in replying. The difference is already some seconds, eg here pastebin.com/NfTVtEC0 original file: cl.ly/qSfM ffmpeged file: cl.ly/qSMr
    – Hug
    Commented Mar 26, 2018 at 19:34
  • 1
    Don't see a difference. Mediainfo shows format duration for original: 3 s 532 ms and for new file 3 s 534 ms
    – Gyan
    Commented Mar 26, 2018 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.