0

I have an avi video which is 50fps, but the camera was capturing at 25fps. Therefore, every second frame is empty. In fact, time to time the camera does not provide a frame and there are even more empty frames.

I want to remove all empty frames using ffmpeg and set fps to 25. The best I found so far is this command:

-i video.avi -c mpeg4 -qscale:v 8 -vf fps=25 -vsync drop output.avi

This would work in the ideal case when only every second frame is empty. These frames would be dropped, fps set to 25, and the video duration would remain the same without duplicite frames. But if there are more empty frames, ffmpeg makes duplicite frames to keep the duration. I need to process the video somehow and any empty or duplicite frames are unacceptable. On the other hand, I dont mind if the video will be shorter.

  • [probably related](http://superuser.com/questions/573747/drop-every-even-or-odd-frames-using-ffmpeg) – karth Jul 11 '14 at 06:25
  • Thank you for the tip. Unfortunately, these empty frames don't have specific position and thus I dont know how to select them. Btw, I asked for a solution using ffmpeg, but I actually don't know generally how to achieve the goal even using VirtualDub or Avidemux... I guess I would welcome any solution right now. – Dexter.JBC Jul 11 '14 at 09:28

1 Answers1

0

There's a simple, but space-intensive way to do what you wish. It's not ffmpeg-specific, however - but you can use ffmpeg to do it. Here's how.

Simply export the frames, use your fav image browser to remove the empty ones, and then re-import to a video file.

To export the entire video as separate image files, use:

ffmpeg -i yourvideofile.avi -f image2 "./to-remove-empty/%5d.png"

To reimport the pruned files back into something that you can use:

ffmpeg -r 25 -i "./empty-removed/*.png" -c:v mpeg4 -qscale:v 8 output.avi

(the asterisk in *.png should cause it to read the frames w/o having to renumber the entire set beforehand)

If you need to edit the file in an NLE afterwards, I would suggest either loading the frames separately (ie. from files), or encoding the resulting video into an intermediate codec like ProRes HQ (422). To do that (even in Windows), specify codec as:

        -c:v prores_ks -profile:v 2 -pix_fmt yuv422p10le output.mov

Alternatively, if you need to use it as-is later, I would recommend using x264 (an open version of h264) instead of direct mpeg4 as per your example - to do that, use this format spec:

        -c:v libx264 -crf 23 -pix_fmt yuv420p output.mp4

Most modern video playback devices (and computers) recognize this file format.

(matching sound formats/codecs to use: pcm_s16le for ProRes (aif) and aac for libx264 (m4a))


I would also like to point out that empty (ie. all black) frames can also be removed from the folder programmatically: using scripting languages (like PHP's GD2 library) or image packages (like ImageMagick). Run a command to determine if the frame is all black, and remove file if yes.