FFmpeg: The good parts (part 1)

FFMpeg the good parts

Every company doing any kind of video processing uses FFmpeg.

FFmpeg is so powerful that it can be used on production pipelines (we're using it!), but also can be used on your personal notebook if you want to do any kind of video processing.

The problem is that FFmpeg is SO big that people are often overwhelmed by its documentation and end up using another alternative or even getting a GUI to run on top of FFmpeg.

The idea of this article is to show you how easy it is to use FFmpeg on your computer and what kind of operations you can do.

Convert audio to mp3 or ogg#

One of the most basics things you can do with FFmpeg is to convert media between different formats.

Let's say you have a .wav file (probably a rip from an old CD or an even older cassette), and you want to convert it to a .mp3 (which you prefer because its reduced sized and nice bitrate).

What you need to do is:

ffmpeg -i input.wav output.mp3

The options we are using here are:

  • -i <INPUT_AUDIO>: Defines the input file, in this example input.wav. It can be any audio file format.
  • output.mp3: Name of the output file, based on the extension FFMpeg will re-encode the audio.

Convert video to mp4#

Another thing you might want to do is convert between different video formats.

Lets say you have a .webm video (that you download from the internet) and you want to play it on QuickTime Player, but you found that it does not support .webm format. So you have two options:

  • Download VLC Player (We encourage you to download it, it's the best open source video player out there).
  • Convert the file from .webm to a format QuickTime Supports (.mp4).

We're going to focus on the second option, converting the file to another format.

Doing this is super easy. You only need to do:

ffmpeg -i input.webm output.mp4

The options we are using here are:

  • -i <INPUT_VIDEO>: Defines the input file, in this example input.web. It can be any video file format.
  • output.mp4: Name of the output file, based on the extension FFMpeg will re-encode the video.

Extract audio from a video#

There are times when you have a video, but you only want the audio. In these cases, FFMpeg is also helpful.

Doing so is as easy as:

ffmpeg -i input.mp4 -vn -c:a mp3 -b:a 128k -ac 2 -ar 48000 output.mp3

The options we are using here are:

  • -i <INPUT_VIDEO>: Defines the input file, in this example input.mp4. It can be any video extension.
  • -vn: Stands for "no video".
  • -c:a mp3: Extract the audio channel as an mp3.
  • -b:a 128k: Set the bitrate of the mp3 to 128k.
  • -ac 2: extract 2 audio channels.
  • -ar 48000: Set the audio rate to 48000.
  • output.mp3: Name of the output file.

Or, if you don't want to download and install FFMpeg locally, you can use our MultiMedia Tool to extract audio from video.

Trim video#

There are times when you have a video, but you want just a portion of it.

You can use some of the professional tools out there to do the job, or you can impress your friends with your FFMpeg knowledge.

The only thing you need for this is the time when you want to start trimming and the duration of the output clip, then you run:

ffmpeg -ss 00:00:20.000 -i input.mp4 -t 00:00:05.000 -c copy output.mp4

The options we are using here are:

  • -ss <START_TIME>: This option seeks that specific time in the video input. It needs to be placed before the -i' option. The format it hh:mm:ss.ms`.
  • -i <INPUT_VIDEO>: Defines the input file, in this example input.mp4. It can be any video extension.
  • -t <DURATION>: duration of the output. You need to specify it with the format hh:mm:ss.ms.
  • -c copy: This option makes FFMpeg to copy both audio and video channels without re-encoding them.

Create a gif from a video file#

Have you ever wondered how people make those funny gifs? You can build yours, too!

FFmpeg makes it super easy to get a gif from a video. You can run:

ffmpeg -i input.mp4 output.gif

The options we are using here are:

  • -i <INPUT_VIDEO>: Defines the input file, in this example input.mp4. It can be any video extension.
  • output.gif: The important part here is the extension. You need to specify the .gif to allow ffmpeg to do the translation.

If you mix this with the power of trim, you can make a gif from a specific clip of a video. Let's imagine we have a long video, and we want to make a gif from second 20 to second 25. We can do that super easily by running.

ffmpeg -ss 00:00:20.000 -i input.mp4 -t 00:00:05.000 -an output.gif

The options we are using here are:

  • -ss <START_TIME>: This option seeks that specific time in the video input. It needs to be placed before the -i' option. The format it hh:mm:ss.ms`.
  • -i <INPUT_VIDEO>: Defines the input file, in this example input.mp4. It can be any video extension.
  • -t <DURATION>: duration of the output. You need to specify it with the format hh:mm:ss.ms.
  • `an': Stands for "no audio".
  • output.gif: The important part here is the extension. You need to specify the .gif to allow ffmpeg to do the translation.

If you don't want to install FFMpeg or want an easier way of doing this, we have a GIF Creator you can use for free.

Extra: make your video looks like an old-school video#

Let's take a video with high resolution and >30 fps.

you can use two FFMpeg filters to make it looks like an old-school video:

  • fps filter: Reduce the fps of the video (something below 15 fps will do the trick).
  • curves filter: Apply color adjustments to your video.

FFMpeg allows us to concatenate filter, that is, process the video through a pipeline of filters. What we want is to first reduce the number of fps and then apply the curves filter to the output of the first filter.

To do this we should write in our terminal:

ffmpeg -i input.mp4 -filter:v "fps=fps=10 [intermediate]; [intermediate] curves=vintage [out]" output.mp4

where the options are:

  • -i <INPUT_VIDEO>: Defines the input file, in this example input.mp4. It can be any video extension.
  • -filter:v <FILTER>: Define the filters we want to use. More on this in a second.
  • output.m4: Output file name.

The interesting part here are the filters we're applying, in this case:

  • fps=fps=10 [intermediate]: Reduce the number of fps of the video to 10. Reference the output of this filter stage with the keyword [intermediate].
  • ;: Filter delimiter.
  • [intermediate] curves=vintage [out]: As the second stage, take the [intermediate] reference, process with the curves=vintage filter and send the video to [out].

The result of this process looks like:

Conclusion#

We're only scratching the surface of all we can do with FFMpeg. For more complex recipes, stay tuned for part 2.

Simplify your video pipelineTry MediaMachine today!

  • Get access to one of the cheapest Cloud-Transcode pipelines

  • Engage users early with great Thumbnails and NLP-Like Video summaries

  • No credit card required

Get started for free →