How to use ffmpeg in Windows?

Programming | 04 May 2017

ffmpeg is the coolest application when it comes to playing with a video file. Instead of downloading so many useless converters to convert from one file format to another, ffmpeg completes any task using simple commands given to it. In this tutorial, I will list out the most useful commands one needs for video conversion and video-specific operations.

Installation

You can easily install ffmpeg for Windows from this website.

  • Choose the correct architecture (64-bit/32-bit) and click on Download FFmpeg.
  • After downloading, unzip the file and rename it to ffmpeg.
  • Go into the folder where you will find a bin folder.
  • Copy the path of the bin folder (For me it was, C:\Users\gogul\Downloads\ffmpeg\bin).
  • Right-click Computer and click on Properties.
  • Then, click on Advanced System Settings and then, click the Environmental Variables button.
  • You will find two sections - User variables and System variables. Under User variables, there will be a variable named path. Click that and click on the Edit button. Add the bin path to the variable value after a “;”.
  • Now, click Ok and close all the windows.
  • Open up the command prompt and type FFMPEG. You should get the following output. It means that you have successfully installed ffmpeg.

Convert .avi to .mp4

1
ffmpeg -i input.avi -c:v libx264 -crf 19 -preset slow -c:a libfdk_aac -b:a 192k -ac 2 output.mp4

If libfdk_aac is not available, then use the following.

1
ffmpeg -i input.avi -c:v libx264 -crf 19 -preset slow -c:a aac -b:a 192k -ac 2 out.mp4

Convert .mp4 to .gif

The below two commands skips first 11 seconds of the video (.mp4) and outputs a 10 second “.gif” which is 640 pixels wide with aspect ratio preserved.

1
2
3
ffmpeg -y -ss 11 -t 10 -i input.mp4 -vf fps=10,scale=640:-1:flags=lanczos,palettegen out.png

ffmpeg -ss 11 -t 10 -i input.mp4 -i out.png -filter_complex "fps=10,scale=640:-1:flags=lanczos[x];[x][1:v]paletteuse" out.gif

In case if you found something useful to add to this article or you found a bug in the code or would like to improve some points mentioned, feel free to write it down in the comments. Hope you found something useful here.