How to create thumbnails of WebM videos using Libav and the avconv tool

I’m using Debian. First we need to install the libav-tools. Open a terminal and type in aptitude install libav-tools. Now open the Libav documentation. At first sight it looks like a huge pile of command line options with little to no meaning at all. If you copy the site’s content over to a Word document, you’ll end up with 183 pages. Don’t waste your time reading all of it. Just scan and skim and then move on to try-and-error. After I did that for a while, I had found out all the options that we need.

We will

Here is the command to do the job:

avconv -ss 00:00:02 -i /some/dir/foo.webm -vsync 1 -r 1 -an -y -vframes 1 -timelimit 1 -vf scale='-1':'128',crop=128:128 /some/dir/bar.jpg

Parameters before -i are input parameters, parameters before the output file name are output parameters. Here is an explanation of the options I used:

-ss <position>    When used as an input option (before -i)
                  seeks in this input file to position.
-i <file>         Input file name.
-vsync 1          Video sync method.
-r <fps>          Set frame rate (Hz value, fraction or abbreviation).
                  As an output option, duplicate or drop input frames
                  to achieve constant output frame rate <fps>.
-an               Disable audio recording.
-y                Overwrite output files without asking.
-vframes <n>      Set the number <n> of video frames to record.
-timelimit <d>    Exit after avconv has been running for <d> seconds.
-vf <fgraph>      <fgraph> is a description of the filter graph
                  to apply to the input video. A filterchain is
                  represented by a list of ","-separated
                  filter descriptions.

scale and crop are two of the many filters that can be chained together. scale='-1':'128' uses a height of 128 pixels while maintaining the video’s aspect ratio. crop=128:128 will crop the central area of the image that we got after applying the scale filter. You can easily adjust this command to your own needs. Libav even supports more complex expressions that allow you to calculate the output image dimensions depending on the input dimensions.

/images/camera.jpg