Wednesday, June 30, 2010

FFMPEG - Transcoding Commands

Getting information from a video file
ffmpeg -i video.avi

Turn X images to a video sequence
ffmpeg -f image2 -i image%d.jpg video.mpg
This command will transform all the images from the current directory (named image1.jpg, image2.jpg, etc…) to a video file named video.mpg.

So, if your image name is image-100 - image 199, your command will be 

ffmpeg -f image2 -i image-1%02d.jpg mp4

%02 means use 2 digit starting from 00 for the input file name

Turn a video to X images
ffmpeg -i video.mpg image%d.jpg
This command will generate the files named image1.jpg, image2.jpg, …
The following image formats are also availables : PGM, PPM, PAM, PGMYUV, JPEG, GIF, PNG, TIFF, SGI.

Encode a video sequence for the iPpod/iPhone
ffmpeg -i source_video.avi -acodec aac -ab 128 -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X final_video.mp4
Explanations :
Source : source_video.avi
Audio codec : aac
Audio bitrate : 128kb/s
Video codec : mpeg4
Video bitrate : 1200kb/s
Video size : 320px par 180px
Generated video : final_video.mp4

Encode video for the PSP
ffmpeg -i source_video.avi -b 300 -s 320x240 -vcodec xvid -ab 32 -ar 24000 -acodec aac final_video.mp4
Explanations :
Source : source_video.avi
Audio codec : aac
Audio bitrate : 32kb/s
Video codec : xvid
Video bitrate : 1200kb/s
Video size : 320px par 180px
Generated video : final_video.mp4

Extracting sound from a video, and save it as Mp3
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3
Explanations :
Source video : source_video.avi
Audio bitrate : 192kb/s
output format : mp3
Generated sound : sound.mp3

Convert a wav file to Mp3
ffmpeg -i son_origine.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 son_final.mp3

Convert .avi video to .mpg
ffmpeg -i video_origine.avi video_finale.mpg

Convert .mpg to .avi
ffmpeg -i video_origine.mpg video_finale.avi

Convert .avi to animated gif(uncompressed)
ffmpeg -i video_origine.avi gif_anime.gif

Mix a video with a sound file
ffmpeg -i son.wav -i video_origine.avi video_finale.mpg

Convert .avi to .flv
ffmpeg -i video_origine.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv video_finale.flv

Convert .avi to dv
ffmpeg -i video_origine.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 video_finale.dv
ffmpeg -i video_origine.avi -target pal-dv video_finale.dv

Convert .avi to mpeg for dvd players
ffmpeg -i source_video.avi -target pal-dvd -ps 2000000000 -aspect 16:9 finale_video.mpeg
Explanations :
target pal-dvd : Output format
ps 2000000000 maximum size for the output file, in bits (here, 2 Gb)
aspect 16:9 : Widescreen

Compress .avi to divx
ffmpeg -i video_origine.avi -s 320x240 -vcodec msmpeg4v2 video_finale.avi

Compress Ogg Theora to Mpeg dvd
ffmpeg -i film_sortie_cinelerra.ogm -s 720x576 -vcodec mpeg2video -acodec mp3 film_terminée.mpg

Compress .avi to SVCD mpeg2
NTSC format:
ffmpeg -i video_origine.avi -target ntsc-svcd video_finale.mpg
PAL format:
ffmpeg -i video_origine.avi -target pal-svcd video_finale.mpg

Compress .avi to VCD mpeg2
NTSC format:
ffmpeg -i video_origine.avi -target ntsc-vcd video_finale.mpg
PAL format:
ffmpeg -i video_origine.avi -target pal-vcd video_finale.mpg

Multi-pass encoding with ffmpeg
ffmpeg -i fichierentree -pass 2 -passlogfile ffmpeg2pass fichiersortie-2

Copy AV stream without re-encoding
ffmpeg -i video.mp4 -vcodec copy -acodec copy output.mp4
copy attribute will tell the multiplexer that the stream does not need to re-encode.
If the stream is not compatible for the output format, the stream will be ignore

Copy only video stream to output file
ffmpeg -i video.mp4 -vcodec copy -an output.mp4
-an tells ffmpeg not to include audio stream. You can use -vn for not including video stream

Rescale input video 

ffmpeg -i input.mp4 -vcodec libx264 -s 160x120 output.mp4

This will convert input.mp4 to H.264 with rescaling to 160x120 image size

Convert mp4 to MPEG-TS

ffmpeg -i input.mp4 -vcodec copy -vbsf h264_mp4toannexb -acodec libvo_aacenc output.ts


-vbsf h264_mp4toannexb is a filter on each frame. MPEG-TS requires start code in H.264 frames and not all H.264 frames in mp4 contains a start code. This filter will look at each frame and add necessary information to the frame prior putting into the MPEG-TS container

1 comment:

  1. I was wondering if you knew a way to (I'm not sure if I am wording this correctly) extract the 'time of day' off of .AVI files. It is apparently embedded in the audio. I currently use SMPTE to monitor the time, so I know it's there, but I need to extract ​the time (and navigation), preferably in a .txt or .doc file, that is embedded in the file. All the different scripts that I use through ffmpeg only give me a start: 0.0000000 and duration: 00:01:23:83. Can this be even done? Any kind of help would be very much appreciated!


Facebook - Control privacy setting of liked page

By default, Facebook displayed your liked page to public. It is the user responsibility to adjust the privacy setting. And in my opinion, F...