Transcoding videos using ffmpeg

Posted By : Akash Sharma | 24-Jul-2013

In this blog I am going to discuss how to convert one type of video to another type of video using ffmpeg tool.

While using ffmpeg we should be aware of following questions:

(1)What kind of OS environment we are working

(2)What kind of libraries(codecs) are imported by ffmpeg

(3)On which version we currently working

 

If you are beginner to this, you can start with the following command to get some basic command details:

ffmpeg -help

 

While converting one video to another we have to keep three things in mind:

(1)audio codec

(2)video codec

(3)container

 

These three factors matters for both input and output video.

 

Let say I have to convert a 3GP video to mp4 video.

 

Now these video formats are known as container of a video.

So the input video has container as 3GP and the output video has container as mp4.

 

Now we should know about the audio codec and video codec of input video and we should also know audio and video codec of output video in which we want to convert video.

 

To get audio and video codecs of input video you can refer my blog

 

In my case video codec is “mpeg4” and audio codec is “aac”.

 

you should also know what audio and video codec present in a mp4 file.

Let say I want to my mp4 video in “aac” audio codec and “h264” video codec.

 

ffmpeg does simple work for video conversion.

(1)It opens the buffer of video by encoding it

(2)do some changes

(3)and then decodes the buffer in required format

 

 

But one condition should be kept in mind that our requirements should match decoders and encoders conditions.

 

To get list of capable codec(audio and video) decoders of ffmpeg,you can issue following command:

ffmpeg -decoders

 

This will give list of all audio and video codec decoders that can operate on your OS.

Remember this list is dependent on ffmpeg version and type of OS you are using.

 

The output would be like this:

Decoders:
V..... = Video
A..... = Audio
S..... = Subtitle
.F.... = Frame-level multithreading
..S... = Slice-level multithreading
...X.. = Codec is experimental
....B. = Supports draw_horiz_band
.....D = Supports direct rendering method 1
------
V....D 4xm                  4X Movie
.
.
.
A....D aac                  AAC (Advanced Audio Coding)

 

I am showing a brief list of codecs.

 

The tag “V” means it’s a decodable video codec.

That means you can convert this video codec to any kind of encodable format.

 

The tag “A” means it’s an audio codec.

 

So for my example I have to search my audio and video codec in this list.If they are found that means I can decode this video.I searched the list and I found that “mpeg4” and “aac” were in the list.

 

Now to get list codec(audio and video) encoders we can issue following command:

ffmpeg -encoders

 

This list is also dependent on ffmpeg version and type of OS you are using.

The output would be like this:

Encoders:
V..... = Video
A..... = Audio
S..... = Subtitle
.F.... = Frame-level multithreading
..S... = Slice-level multithreading
...X.. = Codec is experimental
....B. = Supports draw_horiz_band
.....D = Supports direct rendering method 1
------

 

Now I have to find codec name for audio and video codec for output video in this list.

For audio codec “aac” I found this:

A..X.. aac                  AAC (Advanced Audio Coding)
A..... libvo_aacenc         Android VisualOn AAC (Advanced Audio Coding) (codec aac)

 

since “aac” is experimental we can use “libvo_aacenc” for our conversion.

 

For video codec h264 I found this:

V..... libx264              libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)
V..... libx264rgb           libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB (codec h264)

 

I can use both codecs but I will use “libx264” library.

 

Remember these names will be important as these will be used in final video conversion command.

So finally I have a ffmpeg command for converting 3GP video to mp4 video as this:

ffmpeg -i macdonald.3GP -b:v 440k -ar 44100 -ab 128k -vcodec libx264 -acodec libvo_aacenc macdonald.mp4

 

 

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..