How to transcode a video using FFmpeg?

Video transcoding is a process of transforming video from one format to other.

There are several steps involved in transcoding a video.

The first step is to make sure that FFmpeg is installed on your system.

  1. Install FFmpeg on Windows
  2. Install FFmpeg on Ubuntu
  3. Install FFmpeg on Mac

Follow the below-given steps to transcode a video using FFmpeg:

  1. On your PC, open a terminal window or command prompt.

  2. Use the ‘cd’ command to move to the directory containing the input video file.

  3. For your video to be transcoded, type the FFmpeg command.

  4. ffmpeg -i input_file -c:v codec -b:v bitrate -c:a audio_codec -b:a audio_bitrate output_file


  • ‘input_file’ is the name and path of your input video file.
  • ‘codec’ is the video codec you wish to use for transcoding (e.g. H.264, VP9, etc.)
  • ‘bitrate’ is the target bitrate for the video (e.g. 1M for 1 megabit per second)
  • ‘audio_codec’ is the audio codec you can use for transcoding (e.g. AAC, MP3, etc.)
  • ‘audio_bitrate’ is the target bitrate for the audio (e.g. 128k for 128 kilobits per second)
  • output_file’ is the name and path of the output transcoded video file.

For example, we are transcoding an input video file named ‘input.mp4’ to an output file called ‘output.webm’ and using the VP9 video codec and the Opus audio codec, along with a video bitrate of 1M and an audio bitrate of 128k, then, the command will be:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 1M -c:a libopus -b:a 128k output.webm

  1. Once you’ve entered the command, FFmpeg will begin transcoding your video. You may check the status of the process in the terminal or command prompt window.

  2. Your output file can be found in the same directory as your input file once the transcoding is finished.


Working on this, just let to know what considerations should I take into account when selecting the -crf (Constant Rate Factor) option for video transcoding in FFmpeg, and how does it impact the video quality?

1 Like

Reena, when transcoding with the libx264 or libx265 codecs, the video quality can be adjusted with the -crf option in FFmpeg. Higher values, like -crf 28, reduce file size but may result in quality loss, whereas lower values, like -crf 18, produce larger files but higher quality.

The target platform or device requirements, the available storage or bandwidth, and the intended balance between file size and quality are all taken into account when choosing the right -crf setting. It is advised to experiment with various -crf options in order to get the best balance for a given use case.

Got it! then, how can FFmpeg is used to extract specific segments or clips from a video during the transcoding process, and what options are involved in this operation?

For that, Fmpeg provides the -ss (start time) and -t (duration) options for extracting specific segments or clips from a video during transcoding that you can use. The -ss option denotes the starting point, and -t specifies the duration of the extracted segment.

For example, using -ss 00:01:30 -t 00:00:30 would extract a 30-second clip starting from the 1-minute and 30-second mark. This capability is valuable for creating highlights, trimming videos, or extracting specific portions for further processing, contributing to the flexibility and versatility of FFmpeg in video transcoding workflows.