March 16, 2015

Ffmpeg media converting guide

 

proxy?url=http%3A%2F%2F3.bp.blogspot.com

 

FFmpeg Converting Guide

 

 I noticed some people have problems with ffmpeg very basic commends so I decided to make an article that will provide with very basic information and commends that will help people use ffmpeg.

 

 First we need to get FFmpeg for our system, there are multiple ways to get it but I would recommend getting the binary files you can get it from here (Windows, Linux, Mac) This video will help you understand how we will use our ffmpeg

 

 Second understand the difference between Digital container format (.mkv, .mp4, .avi) and video compression format / Audio compression format (H.264, Vp9, AAC) Container format is a thing were you put your compression format in. Note that not every compression format can be placed in any container formats.

 

 Third lets look at very basic commends

 

-b:v  -Target video bitrate
 
-b:a  -Target Audio bitrate

 

-r    -specify frame rate of video example -r 60 (video frame rate will be 60) 

 

-vf scale=1920:1080   -change the resolution of the video (16:9 or 4:3 resolutions)
 
-aspect 16:9    -force aspect ration, even though you might have 4:3 resolution you can force aspect ration like this
 
 

 

1) Convert video file to Audio file 

example video to mp3

 

ffmpeg -i input_movie.mp4 -acodec libmp3lame -b:a 192k output.mp3

 

libmp3lame

is a audio compression format (mp3) you can change to a different one but make sure that you put it a the correct container format.

 

example:

 

AAC - Advanced Audio Coding - libvo_aacenc

 

ffmpeg -i input_movie.mp4 -acodec libvo_aacenc -b:a 192k output.aac

 

ogg - Vorbis - libvorbis

 

ffmpeg -i input_movie.mp4 -acodec libvorbis -b:a 192k output.oga

 

 

You can go on and go on like this For compression format just change lib* file to a different one and for bit rate just change 192k to what ever you want for example 128k, 256k,

 

2) Convert a video file into a different one

example to x264

 

ffmpeg -i input_movie.mp4 -c:v libx264 -b:v 2567k -c:a libmp3lame -b:a 192k output.mp4

 

libx264

Is a video compression format just like in audio compression format you can change this as well, and you can change the audio compression format as well.

make sure that you put it in a correct container format.

 

example:

 

mpeg2 - mpeg2video

 

ffmpeg -i input_movie.mp4 -c:v mpeg2video -b:v 2567k -c:a libmp3lame -b:a 192k output.mpg

 

Vp9 - libvpx-vp9

 

ffmpeg -i input_movie.mp4 -c:v libvpx-vp9 -b:v 2567k -c:a libvorbis -b:a 192k output.mkv

 

x265 - libx265

 

ffmpeg -i input_movie.mp4 -c:v libx265 -b:v 2567k -c:a libvorbis -b:a 192k output.mkv

 

xvid - libxvid

 

ffmpeg -i input_movie.mp4 -c:v libxvid -b:v 2567k -c:a libvorbis -b:a 192k output.mkv

 

You can go on and go one like this as you can see it is very simple just change lib* to what ever you want and for bit rate just change 192k to what ever you want for example 128k, 256k,

 

 

One more thing lats make one commend a bit hard to show you how easy it really is

 

ffmpeg -i input_movie.mp4 -vf scale=640:480-aspect 16:9-r 120 -c:v libx264 -b:v 13976k -c:a libmp3lame -b:a 192k output.mkv

 

 

-vf scale=640:480 

With this I resized the video resolution to 640:480

 

-aspect 16:9

Even though 640:480 is a 4:3 aspect ration resolution with -aspect 16:9 I forced the video to be 16:9

 

-r 120

I changed the video frame rate to be 120 FPS

 

 

See how easy it is.

 

 

3) Cut (Change) video length

 

 ffmpeg -i in.mp4 -ss [start] -t [duration] -c:v copy -c:a copy out.mp4
 

Example

 ffmpeg -i in.mp4 -ss 00:01:15 -t 00:00:10 -c:v copy -c:a copy out.mp4
 

Running this command will not encode your  video it will copy the video and the only difference will be the durations of the video as you specified

 

4) Extract an image out of your video

 

 

 ffmpeg -i input_movie.mp4 -ss 00:00:05 -f image2 -vframes 1 imagename.png
 
5) Create Video Thumbnails 
 
ffmpeg -ss 00:00:01 -i yourvideofile.avi -frames 1 -vf "select=not(mod(n\,240)),scale=512:288,tile=4x7" out.jpg
 
 

 - ss 00:00:01 means that it will start from first second of course you can tweak it

 

yourvideofile.avi this is where you should put your video file it can be .avi .mp4 just about any format because ffmpeg supports a lot of formats

 

240 means that it will take a screenshot every 240 frames of caures you can  adjust to your preferences. for example if your video is 30 fps and you have 240 then it means that it will take a shoot every 8 seconds.

 

512:288  now this is a scale of every individual image in the gallery you can adjust it but note that if your video is 16:9 you should select a resolution that is 16:9 see this list if your video is 4:3 look at this list make sure to select proper aspect ratio.

 

4x7 this means that it will put 4 horizontal and 7 vertical images on the final outputted imag. of course you can edit this 

 

out.jpg here you can use other image compression methods like .png etc..

 

make sure the spacing the latter cases are exactly the same

 

6)Join Video and Audio files

 

ffmpeg -i video.mp4 -i audio.mp3' -c:v copy -c:a copy -map 0:v:0 -map 1:a:0 output.mp4

 

 

 

You can see how easy it is to work with ffmpeg, all of this is not even scratching the boom of the ffmpeg capabilities and the Internet is a great place to get more information.

 

Video compression format comparison.

 

FFmpeg man page

Click Here!