Easily transcode any media to any format using FFmpeg

If you’re working with video or audio, you probably often have to convert/transcode your medias, and the problem is that it’s hard to find a tool which handles all formats, and which is fast, either on Windows, Mac OS or even Linux. You may have tried a lot of them, and you may even use different tools for different formats. One solution could be the use of FFmpeg.

October, 9th 2017 update: some readers asked for the commands to convert image sequences, I’ve just added them, including some of them about sound streams.

FFmpeg is a free software, which handles all formats you may need – H.264, H.265, Apple ProRes, Avid DnxHD and a lot more, even image sequences like PNG and others – whatever platform you’re on! The only difficulty is that it’s a command-line tool, and I think this is the reason there are just few people using it. Now I’m going to show you it’s not so difficult to use, and it can actually be a lot quicker than using some other tools like Adobe Media Encoder, and it’s way faster when encoding than all the other tools I tried. Plus, it’s free!

If you’ve never used a command line before, I can help you get started, on Windows here, or Mac there (coming soon).

First, you’ll need to download the binaries (the compiled and executable files of the application), go to the official website: ffmpeg.org. You can download the files for your system in the Downloads section, in the frame Get the packages.

Basic use and getting help

To quickly convert a media, the basic use of FFmpeg is this:

ffmpeg -i "example video.mov" "transoded video.mp4"

Once the transcoding process is launched, you can simply press q if you want to stop it. FFmpeg may ask you to write over any existing file, you’ll have to input either Y or n to accept or reject.
Of course, you have a lot of options, if you want to display the most common use:

ffmpeg -h

And if you want to go into more details you can type:

ffmpeg -h long

You may need to display the list of the supported codecs and their names for use with ffmpeg:

ffmpeg -codecs

Or more probably you may want to see only the encoders (the ones you can use for your transcoding job):

ffmpeg -encoders

You may also want to display the options for a specific encoder:

ffmpeg -h encoder=name for instance: ffmpeg -h encoder=h264

Example cases

The best way to learn the most useful options is just to show you some examples.

The quickest way to convert any media to a standard H.264 mp4 is:

ffmpeg -i "example video.mov" "transcoded video.mp4"

But you should at least be a bit more precise and set the bitrate of file:

ffmpeg -i "example video.mov" -vcodec h264 -b:v 10485760 "transcoded video.mp4"
The -vcodec option specifies the encoder to use for the video, -b:v the bitrate for the video. The bitrate is given in bits per second, the value in this example is 10Mbps (10 x 1024 x 1024 bits per second)

You can even be more precise and state also how you want the audio encoded:

ffmpeg -i "example video.mov" -vcodec h264 -b:v 10485760 -acodec aac -b:a 327680 "transcoded video.mp4"
The -acodec is for the audio encoder, -b:a is the audio bitrate in bits per second, 320kbps in this example.

You can transcode just a part of the video:

ffmpeg -i "example video.mov" -ss 00:03:05 -t 00:00:45.0 "transcoded video.mp4"
The-ss is the starting timecode, hh:mm:ss.xxx, -t the duration to transcode after the starting timecode. If omitted, will encode to the end.

You may want to force ffmpeg to overwrite existing files without confirmation, just add the -y option at the beginning:

ffmpeg -y -i "example video.mov" -vcodec h264 -b:v 10485760 -acodec aac -b:a 327680 "transcoded video.mp4"

Sometimes, you just need to transcode only the audio or only the video, this can be very quick as FFmpeg is able to just copy the existing stream:

To transcode only the audio and copy the original video without transcoding: ffmpeg -i "example video.mov" -vcodec copy -acodec aac -b:a 327680 "transcoded video.mp4"
To transcode only the video: ffmpeg -i "example video.mov" -vcodec h264 -b:v 10485760 -acodec copy "transcoded video.mp4"

Of course, you can extract audio or video to an audio-only or video-only file:

To extract the audio: ffmpeg -i "example video.mov" -vn -acodec pcm_16le "transcoded video.wav"
Here, pcm_16le is a very standard PCM audio codec used in .wav files. Notice that the file extension of the output has to match the codec used. The -vn option tells ffmpeg to ignore video.
To remove the audio from a video file: ffmpeg -i "example video.mov" -vcodec copy -an "transcoded video.mov"
Here, the -anoption removes the audio, and the video is just copied to the new file.

If you need to change some parameters of the video, you can input a new size, change the framerate, change the audio sampling

ffmpeg -i "example video.mov" -vcodec h264 -b:v 10485760 -s 1998x1080 -r 24 -acodec aac -b:a 327680 -ar 96000 "transcoded video.mp4"
The size is changed to a standard 2K Flat DCP  of 1998 pixels width by 1080 pixels height with the -s option, the framerate to 24fps with the -r option, and the sound is resampled to 96KHz thanks to the -aroption.

Another very useful encoder in FFmpeg is the ProRes encoder, especially for Windows users:

ffmpeg -i "example video.mp4" -vcodec prores -profile 3 "transcoded video.mov"
The -profileoption is specific to the prores encoder, it specifies the ProRes profile quality: 0 is Proxy, 1 is LT, 2 is Normal, and 3 is HQ.

In the animation industry, we often use image sequences
To encode an image sequence to a video file :

ffmpeg -framerate 24 -i "image_%03d.png" -vcodec h264 -b:v 10485760 "transccoded video.mp4"
In the input filename, %03d means that the sequence is numbered there with three digits (001, 002, etc.). Don’t forget to specify the framerate with -framerate(or else 25fps will be used by default).

FFmpeg uses sequences starting with frame #0 by default. If your sequence starts with another frame :

ffmpeg -framerate 24 -start_number 12 -i "image_%03d.png" -vcodec h264 -b:v 10485760 "transcoded video.mp4"
Ici l’encodage commencera à l’image numéro 12 grâce à l’option -start_number.

If you need to add sound in the video too:

ffmpeg -framerate 24 -i "sound.wav" -i "image_%03d.png" -vcodec h264 -b:v 10485760 -acodec aac -b:a 327680 "transcoded video.mp4"

Finally, you can also transcode a video to an image sequence:

ffmpeg -i "example video.mp4" -vcodec png -an "image_%03d.png"

And you can extract the sound stream in the same time (see the next chapter about multiple outputs):

ffmpeg -i "example video.mp4" -vcodec png -an "image_%03d.png"-vn -acodec pcm_16le "transcoded video.wav"

Using multiple outputs and a queue

What’s really awesome is that you can easily have multiple outputs for a single file and build a queue for transcoding multiple input files.

To add two (or more) outputs:

ffmpeg -i "example video.mov" -vcodec h264 -b:v 10485760 "transcoded video.mp4" -vcodec prores -profile 3 "transcoded video.mov"
This will output both an H.264 and a ProRes file from the same source.

To build a queue:

ffmpeg -i "example video1.mov" -vcodec h264 -b:v 10485760 "transcoded video1.mp4" && ffmpeg -i "example video2.mov" -vcodec h264 -b:v 10485760 "transcoded video2.mp4"
This will transcode “example video2.mov” as soon as the first one is finished, thanks to&& ffmpeg in the middle which launches the next command.

And you can even combine all of this to build a queue with multiple outputs:

ffmpeg -i "example video1.mov" -vcodec h264 -b:v 10485760 "transcoded video1.mp4" -vcodec prores -profile 3 "transcoded video1.mov" && ffmpeg -i "example video2.mov" -vcodec h264 -b:v 10485760 "transcoded video2.mp4" -vcodec prores -profile 3 "transcoded video2.mov"

If the encoder supports it, you can use this technique to transcode with up to 3 passes to enhance the video.

ffmpeg -y -i "example video.mov" -vcodec h264 -b:v 10485760 -an -pass 1 -f mp4 NUL && ffmpeg -i "example video.mov" -vcodec h264 -b:v 10485760 -pass 2 "transcoded video.mp4"
The -passoption is used to specify which pass is run. The first pass does not create any file, data is sent to NUL. Note: on Mac or Linux, replaceNUL by /dev/nul. On the first pass,  -f mp4 specifies you want an mp4 at the end of the process.

Conclusion and UI

Et voilà! I think all of this is very useful, FFmpeg is really a very fast and versatile application for all your transcoding processes. I hope this will help you use it, and that you’ll find it’s actually quite easy to handle it.

As I use it a lot myself and I know using the command line is not the most handy way of using applications, I’ve begun to build a simple yet comprehensive user interface for FFmpeg, which will, of course, be free. This is a screenshot of the current version, still very early in its development, but which I hope will be available soon!

I’m already using it and it works well, making my transcoding processes very quicker and easier. I just want to improve it a little, and add some features like a render queue and more easy options before releasing it for free. Stay in touch!

I could not do and share what I do for free without your support. Help me on Patreon! Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.