Few Important ffmpeg commands for video transcoding

Posted By : Akash Sharma | 24-Jul-2013

In this blog I am going to share some important ffmpeg commands that can help you to convert video to some customised settings.I am also going to share the commands for creating thumbnails by ffmpeg.

 

First of all I am going to share the command for converting video.

ffmpeg is OS dependent.So the command for converting a video can vary from OS to OS.

I have worked on windows and ubuntu, so I have commands for these two OS.

In general both commands are same, the only difference that arises is their audio and video codec libraries.

 

I have a command that convert a video to mp4 format.

For Windows:

ffmpeg -i <inputfile> -profile:v main -level 3.1 -b:v 440k -ar 44100 -ab 128k -s 720x400 -vcodec h264 -acodec libvo_aacenc -y -r 30 -g 0 <outputfile>

 

For Ubuntu

ffmpeg -i <inputFile> -profile:v main -level 3.1 -b:v 440k -ar 44100 -ab 128k -s 720x400 -vcodec h264 -acodec libfaac -y -r 30 -g 0 <outputFile>

 

Now I am going to describe the parameters.

 

-profile:v main -level 3.1

 

I am converting the video to h264 video codec.h264 supports various profiles and corresponding levels for a video.Each profile and level combination has a specified range of resolution, bitrate, bandwidth and various other parameters.These parameters are helpful when you have various kinds of required platforms for playing the video.For more help you can use this link .

 

For my output video I have set profile as main and level as 3.1

You can also get profile and level information of a video from here .

 

-b:v 440k

This is required video bitrate of output video.440k means 440*1000 bits/sec

 

-ar 44100

This is required Sampling frequency of output video.

 

-ab 128k

This is required audio bitrate of output video.128k means 128*1000 bits/sec

 

-s 720x400

This is required resolution of a output video.720 is width in pixels and 400 is height in pixels.

 

-vcodec h264

This specifies the type of video codec library used to decode the video in mp4 format.

 

-acodec libfaac

This specifies the type of audio codec library used.

libvo_aacenc is for windows and libfaac is for ubuntu.

 

“-y”

By applying this option output video will overwrite if a file already exists with same name.

 

“-r 30”

This option sets frame rate of a video to 30 fps.It duplicate input frames if less or drop input frames if more to achieve constant output frame rate fps.

 

“-g 0”

By this command you can set number of frames in a keyframe of output video.

By setting value of this option as zero, ffmpeg will choose keyframes based on the video shots and bitrate.So keyframes should be inserted only when they needed, but not consistently after N frames.

 

Now I will share details of creating thumbnails from a video.

This is the command for creating thumbnail.

ffmpeg -ss <hr>:<min>:<sec>.<milliSec> -i <inputFile> -f image2 -vframes 1 -s 360x240 <outputFile.png>

 

In this command you can use -ss option to specify time at which you want the thumbnails to be created.

You can also specify the dimensions of thumbnail.

ffmpeg -ss 0:0:2.0 -i macdonald.3GP -f image2 -vframes 1 -s 360x240 outputFile.png

 

You can directly specify the time in seconds as:

ffmpeg -ss 2 -i macdonald.3GP -f image2 -vframes 1 -s 360x240 outputFile.png

 

 

Akash Sharma

About Author

Author Image
Akash Sharma

Akash is a bright Groovy and Grails developer and have worked on development of various SaaS applications using Grails technologies. Akash loves playing Cricket and Tennis

Request for Proposal

Name is required

Comment is required

Sending message..