2015-11-29

Fast Forward ... Using Ffmpeg

In my screencast videos about technical things I regularly face this situation: showing slides is boring, so watching an illustration develop is more interesting. Yet developing an illustration in real-time is boring, similar to watching paint dry. Just using a swipe transition from beginning to end looks again like Powerpoint presentations, yuk. Luckily, speeding up the drawing process works much better. And Kdenlive does come with a speed effect, right...?

Kdenlive Speed Ticket


Don't worry, digital video post processing gives us so many toys, such as speeding up a video clip. Unfortunately, while Kdenlive and MLT bring in such a speed effect, I often got bitten by many peculiarities. So I better keep off now. There are many issues, related to video footage formats, and Kdenlive itself.

To the Rescue: Ffmpeg Does It Again


Once more, Ffmpeg comes to our rescue when dealing with digital video. Ffmpeg is incredibly versatile, yet its documentation is incredibly ... demanding. Its command line options are similar to TECO commands (well, just joking, as TECO is easier to understand.)

Luckily, searching around (throw some keywords at Aunt Google) reveals some useful hints at what can be done with Ffmpeg. In particular, Ffmpeg's wiki contains useful video visdom, erm, wisdom (wiki article). However, the Ffmpeg wiki articles like to be on the encyclopedic side of things, trying to explain everything.

So, let's boil this down to what I actually need. Whenever I have raw footage (without audio) to be sped up to triple speed, this simple command will do the trick:
ffmpeg -i video.mp4 -filter:v "setpts=(1/3)*PTS" video-x3.mp4
Double speed is (1/2), and so on...
 
Please note that this will keep the original number of frames per second. In consequence, Ffmpeg will thus drop frames if needs to do so, so don't worry about the final statistics showing a lot of dropped frames.

In a similar way, you can als use Ffmpeg to slow down video footage ... but this is usually only yielding good visual results when your raw footage is, say, 50 frames per second, and you want to get a 25 fps slow-mo from it. Otherwise, results will be really bad and you should consider using other, better suited tools for such tasks. That is, specialized tools that can predict intermediate frames instead of simple linear interpolation.