ffmpeg!
Home
This Site
Windows

 

ffmpeg!

I see ffmpeg as a CLI tool allowing to perform various operations upon video and audio files.
It supports many formats, I haven't yet encountered a single one ffmpeg doesn't support.
You can install it by just downloading and adding to your PATH from the official site.
It's plain nature of just reading files, processing the streams and writing files allows it to have maximum portability.

Why would someone need such a thing in every day life?
In my case it's like a couple of times a month. Still, I don't see a pleasant way I would live without it.
Considering that I'm not interested in professional video editing at the moment.
After all, a CLI tool today is the simplest imaginable approach to interaction between a human and a computer.
That makes CLI tools the most lightweight software pieces available, maximising the power/size quotient.
Here I'm gonna pull together a list of things keeping me in love with this tool.

Convert GIFs into MP4s

ffmpeg -i darn-gif.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" not-a-gif.mp4
A video presentation of a GUI usage case can be very helpful in many situations. That's predominantly the reason I'm getting to see some big GIFs sometimes. Apart from the memes, that is.
However, exporting that presentation as a GIF may bring a lot of pain to the viewer. Surely so, when the video is longer than 5-10 seconds!
The above command I've found in a stackoverflow answer allows to convert that GIF into something a fine player would be able to pause and rewind. So one doesn't have to wait for the whole video to roll through just to see that very fast click on some very important piece of GUI.
Here:
  • -i darn-gif.gif
    is how we point ffmpeg onto the file we want to work with;
  • -movflags faststart
    according to the docs I don't understand what it does, but the author of that SO tells that the option should help the performance of loading the resulting video in a browser;
  • -pix_fmt yuv420p
    is said to use the most popular format of pixels, in the same answer;
  • -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"
    this makes sure the resulting output has even width and height, because mp4 requires that, for some reason;
  • not-a-gif.mp4
    is the output file name in that command.
  • Convert a bunch of videos into MP4

    I sometimes, somewhat regularly, have fun with video games and my friends.
    And I'm used to record parts of our sessions using OBS' relatively fresh feature of "replay buffer".
    It just saves the last N seconds into a file. And I sometimes end up with quite a bunch of videos.
    The formats OBS writes in are optimized for streaming, not for storing. And MP4 is for storing, and is much more broadly supported by various communicating clients.
    So I need to recode all the videos I get from my replay buffers into mp4.
    For that, I've written a simple script to recode a bunch of videofiles, putting recoded versions into a subdirectory.
    recode_all_to_mp4.sh '<FileNameOrWildcardFileNames>' <OutputDir>
    Note that to feed it a wildcard, the first argument must be enclosed in quotes, so that bash itself doesn't start calling the command for every file.