Showing posts with label ffmpeg. Show all posts
Showing posts with label ffmpeg. Show all posts

Monday, August 26, 2013

ffmpeg Cheat Sheet

SkyHi @ Monday, August 26, 2013

Video Size and Aspect Ratios

iPhone 3 (480x320):
Name Size Aspect
Wide 16:9 480x270 16:9
Old TV 4:3 427x320 4:3
Wide 16:9 /16 480x272 16:9
Old TV 4:3 /16 432x320 4:3
iPhone 4 (960x640):
Name Size Aspect
Wide 16:9 960x540 16:9
Old TV 4:3 853x640 4:3
Wide 16:9 /16 960x544 16:9
Old TV 4:3 /16 848x640 4:3
iPhone 5 (1136x640):
Name Size Aspect
Wide 16:9 1136x639 16:9
Old TV 4:3 856x640 4:3
Wide 16:9 /16 1136x640 16:9
Old TV 4:3 /16 864x640 4:3
DV NTSC Video
Name Size Aspect
Wide 16:9 720x480 16:9
Old TV 4:3 720x480 4:3
Youtube and Vimeo Upload
Name Size Aspect
SD 4:3 640:480 4:3
HD 16:9 1280x720 16:9
Full HD 1920x1080 (1920x1072 base 16) 16:9
HD, Blu-Ray, AVCHD
Name Size Aspect
720p 1280x720 16:9
1080p/i Anamorphic 1440x1080 16:9
1080p/i 1920x1080 16:9

Frame Rates

Name Standard Fps FFmpeg
Movies NTSC 23.976 24000/1001
TV Video NTSC 29.97 30000/1001
Movies PAL 25 25
TV Video PAL 30 30

FFmpeg Encoding

X264Presets
default fastfirstpass lossless_ultrafast lossless_slower
baseline slowfirstpass lossless_fast lossless_max
normal hq lossless_medium ipod320
main max lossless_slow ipod640
High quality 2 Pass
ffmpeg -y -i INPUT -r 30000/1001 -b 2M -bt 4M -vcodec libx264 -pass 1 -vpre fastfirstpass -an output.mp4
ffmpeg -y -i INPUT -r 30000/1001 -b 2M -bt 4M -vcodec libx264 -pass 2 -vpre hq -acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4
iPod-iPhone 320 width
ffmpeg -i INPUT -s 320x240 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 -vpre ipod320 -acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4
iPod-iPhone 640 width
ffmpeg -i INPUT -s 640x480 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 -vpre ipod640 -acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4
Hight quality, 2 pass without presset
ffmpeg -y -i input -r 24000/1001 -b 6144k -bt 8192k -vcodec libx264 -pass 1 -flags +loop -me_method dia -g 250 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -bf 16 -b_strategy 1 -i_qfactor 0.71 -cmp +chroma -subq 1 -me_range 16 -coder 1 -sc_threshold 40 -flags2 -bpyramid-wpred-mixed_refs-dct8x8+fastpskip -keyint_min 25 -refs 1 -trellis 0 -directpred 1 -partitions -parti8x8-parti4x4-partp8x8-partp4x4-partb8x8-an output.mp4
ffmpeg -y -i input -r 24000/1001 -b 6144k -bt 8192k -vcodec libx264 -pass 2 -flags +loop -me_method umh -g 250 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -bf 16 -b_strategy 1 -i_qfactor 0.71 -cmp +chroma -subq 8 -me_range 16 -coder 1 -sc_threshold 40 -flags2 +bpyramid+wpred+mixed_refs+dct8x8+fastpskip -keyint_min 25 -refs 4 -trellis 1 -directpred 3 -partitions +parti8x8+parti4x4+partp8x8+partb8x8-acodec libfaac -ac 2 -ar 44100 -ab 128k output.mp4
iPod-iPhone 320 width, without presset
ffmpeg -i INPUT -s 320x240 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 -coder 0 -bf 0 -flags2 -wpred-dct8x8 -level 13 -maxrate 768k -bufsize 3M-acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4
iPod-iPhone 640 width, without presset
ffmpeg -i INPUT -s 320x240 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 coder 0 -bf 0 -refs 1 -flags2 -wpred-dct8x8 -level 30 -maxrate 10M -bufsize 10M-acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4
iPod-iPhone, 2 pass custom
ffmpeg -y -i input -r 30000/1001 -s 480x272 -aspect 480:272 -vcodec libx264 -b 512k -bt 1024k -maxrate 4M -flags +loop -cmp +chroma -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq "blurCplx^(1-qComp)" -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -coder 0 -refs 1 -bufsize 4M -level 21 -partitions parti4x4+partp8x8+partb8x8 -subq 5 -f mp4 -pass 1 -an -title "Title" output.mp4
ffmpeg -y -i input -r 30000/1001 -s 480x272 -aspect 480:272 -vcodec libx264 -b 512k -bt 1024k -maxrate 4M -flags +loop -cmp +chroma -me_range 16 -g 300 keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq "blurCplx^(1-qComp)" -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -coder 0 -refs 1 -bufsize 4M -level 21 -partitions parti4x4+partp8x8+partb8x8 -subq 5 -f mp4 -pass 2 -acodec libfaac -ac 2 -ar 44100 -ab 128k -title "Title" output.mp4 

DV Video

To DV
ffmpeg -i input -target ntsc-dv -aspect 4:3 -y output.dv
From DV To Microsoft AVI DV
ffmpeg -i input.dv -vcodec copy -vtag dvsd -acodec pcm_s16le -f avi -aspect 4:3 -y output.avi

Audio

AAC Stereo HQ
-acodec libfaac -ac 2 -ar 48000 -ab 192k
AAC Stereo SQ
-acodec libfaac -ac 2 -ar 44100 -ab 128k
AAC 5.1 HQ
-acodec libfaac -ac 6 -ar 48000 -ab 448k
AAC 5.1 LQ
-acodec libfaac -ac 6 -ar 44100 -ab 224k

Eac3To

AC3 5.1 Channel Mapping Fix
eac3to from_true_hd.ac3 fixed_mapping.ac3 -blu-ray -448
AAC to AC3
  1. From AAC to WAV with faad2:
    faad2 -o temp_audio.wav input.aac
  2. From WAV to AC3 with eac3to
    eac3to temp_audio.wav output.ac3 -448
AC3 to AAC
  1. From AC3 to a remapped AC3 with eac3to:
    eac3to input.ac3 temp_remaped.ac3 -448 -resampleTo48000 -2,1,0,3,4,5
  2. From remapped AC3 to AAC with FFmpeg
    ffmpeg -y -i temp_remaped.ac3 -vn -acodec libfaac -ac 6 -ar 48000 -ab 384k output.m4a

Other FFmpeg Options

-threads thread count, 0 means all threads available
-y overwrite output files
-ss time_off set the start time offset
-t duration record or transcode "duration" seconds of audio/video
-ildct Interlaced

FFmpeg Information Sources

IRC
Server: irc.freenode.net
Channel: #ffmpeg

Download

The bests binaries on the web, Easy installation without compiling, just runing an install file:
FFmpeg for Windows
FFmpeg for Macintosh OS X (Intel)
FFmpeg for Linux
You can also use this extremely easy guide to install FFmpeg on your Windows, GNU Linux or Macintosh machine:
http://rodrigopolo.com/about/wp-stream-video/ffmpeg-binary-installers-for-win-mac-and-linux
Win32 Binary Builds
http://ffmpeg.arrozcru.com/autobuilds
http://sourceforge.net/project/showfiles.php?group_id=205275&package_id=248632
FFmpeg x264 encoding guide by Robert Swain
http://rob.opendot.cl/index.php/useful-stuff/ffmpeg-x264-encoding-guide

H.264 Profiles and Levels
8x8dct high
cabac+bframes main
-level #



video conversion, sound extraction, encoding file for iPod or PSP, and more.
Getting infos 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.
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 input -acodec aac -ab 128kb -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
Or:
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


REFERENCES
http://rodrigopolo.com/ffmpeg/cheats.php

Friday, May 20, 2011

Converting videos in Ubuntu using FFMPEG

SkyHi @ Friday, May 20, 2011
you are a multimedia junkie and felt it your karma to convert tons of videos and music to popular formats, then FFMPEG is the right tool for you. FFmpeg is a free video converter and so much more. It can be found in the default Ubuntu repository and also comes pre-installed in most other distro's. It's an open source project that contains an infinite number of libraries, the most noticeable among them is the libavcodec (for encoding and decoding of the audio and video data ) and libavformat( mux demux library).

ffmpeg-logo.png
Thats not all. It can also be used for more advanced functions like slowing down the frame rate, resizing the video and many more. Good news for geeks. FFmpeg is CLI based. So you don't need to struggle with those unbearable mouse clicks. The latest stable release version of FFmpeg is 0.6.
Converting a video using the command line.

Warning. Now if the word "command line" gives you a heart attack then you should probably skip this section and jump straight to the bottom of the page.
FFmpeg is mainly used for converting videos from one format to another. Duh!!. The most common syntax of using FFmpeg consists of the input of the file followed by the output file in the desired format.
Example

ffmpeg -i inputvideo outputvideo.
Sounds so simple right? Well there is a glitch. The quality of the output (bit rates, frame rate) gets degraded when we use this format.
To avoid this problem we will use a number of options along with the command . Suppose we want to convert a .avi file to .flv video. Use the following command.
ffmpeg -i input.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv final.flv 
After the execution processing takes place and you should see a screenshot like the one below:
convert video ubuntu 1.png

No doubt, the command is very long but it is also very easy to understand. Now let's get to know those cryptic options-
  • -i = input the file
  • -ab = set the audio bitrate
  • -ar = setting the audio frequency
  • -b = video bitrate
  • -r = video frame rate
  • -s = size of the video display
  • -f= format
  • -vcodec – is the video codec we want to use during the conversion
  • -acodec- It is the audio codec we want to use during the conversion
See, we told you it would be easy.

Now lets try out some more popular options.

Convert videos from .avi to divx format.

ffmpeg -i input.avi -s 320x240 -vcodec msmpeg4v2 output.avi
Convert videos from .avi to dv format

ffmpeg -i input.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 final.dv
Convert videos from .mpg to .avi format

ffmpeg -i input.mpg ouput.avi
Convert videos from wav file to mp3 format

ffmpeg -i input.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3  output.mp3
Convert videos from ogg theora to mpeg format

ffmpeg -i  input.ogm -s 720x576 -vcodec mpeg2video -acodec mp3  ouput .mpg
Changing the Frame Rate

Frame rate can be defined as the number of frames displayed per sec. Frame rate is directly proportional to the speed of the video and is mainly responsible for the animation or continuous stream of images. Phew..!! Now we do not want to sound like your math teacher.
Sometimes it's necessary for the developers to slow down the frame rate of the video , so that they can better understand about the minute changes in the video. This can be done only by including the -r option.
Syntax for the same is

ffmpeg -i inputfile -r 5 outputfile.
This will create the output video with a rate of 5 frames per second. When played, you will observe the slow processing of the video.
Extracting Audio From The Video

Sometimes you only need the audio. FFmpeg is capable of extracting the audio from the videos too .
ffmpeg -i input.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 audio.mp3
The -vn option holds the key to this command. This option is used when we want to disable the video recording. Executing the upper command will extract the audio file from the input.avi and willl save it under the name of “audio.mp3” .You can add more appropriate options in between if you want to juice the maximum from this niftly tool.
Converting Images To Videos

Now here is a neat little trick.

Suppose you have a collection of images named as say image1.jpg,image2.jpg and you want to view them in the video format. FFmpeg can do this job as well. You can do this by running this command on the shell.
ffmpeg -f image2 -i image%d.jpg output.mpg. 
You can also do this in the reverse. So there you go. Complete video converting in Ubuntu. Play with the options and you are likely to find more cool tricks.
So thats with the geek stuff. If you want a more comprehensive list of options then type the following command in the terminal.

man ffmpeg
WinFF : GUI Client of FFmpeg

Okay. I guess you jumped straight to this one.

If you are not comfortable with the cli , don't worry there is an equivalent GUI client for the FFmpeg called “WinFF” and it is so much more easier to use.
You can install it from the repository in ubuntu by typing
sudo apt-get install winff 
To open it either use type winff in the terminal or you can go to the Applications → Sound & Video → Winff . You will see the screenshot like below

convert video ubuntu.png
As you can see, the GUI makes the setup much more easier.

Input your video by clicking the “Add” button on the top. Then select the video and from the top down menu select the output options according to your need . Then click on the convert button on the top panel and that's it . You are done with the formating. To set the audio video rate you need to use the”options” button. It will display the extra settings panel at the bottom of the output settings just like
convert video ubuntu2.png
WinFF is also cross-platforrm, being an open source, GPL licensed software.



REFERENCES

http://ubuntumanual.org/posts/327/converting-videos-in-ubuntu-using-ffmpeg-the-ultimate-free-video-converter

Friday, March 18, 2011

ffmpeg Converting VOB or MP4 to FLV format

SkyHi @ Friday, March 18, 2011
Using "mencoder" to create "flv" from "VOB" DVD video format files

Many websites nowadays are using swf and flv file formats to play videos hosted on their site or sites, it's advantage is clear in that the file itself is often in comparison to regular video format files, smaller and easier to upload so the site is able to hold and run more video content with much less bandwidth than would normally be required.

#> mencoder inputfile.VOB -of lavf -ovc lavc -lavcopts vcodec=flv:vbitrate=150 -ofps 25 -oac mp3lame -lameopts abr:br=32 -srate 22050 -vf scale=720 -o outputfile.flv

In our first test video conversion format a file named VTS_01_2.VOB was successfully converted from a 776.9Mb file to a 17mb outputfile.flv although the video and audio was brilliant the file stopped short of it's actual completion target in other words outputfile.flv was considerably shorter than it should have been, we have concluded from this that the VOB file is corrupt and the conversion terminates at that point. Having obtained another dvd with which to copy from we tried again, you should not this recording was original obtained from a small video recorder and transfered to DVD which we then migrated to a flash video (flv). Below is how we archived it, please note the above mencoder script is different to the one below which did eventually work.

#> mplayer dvd://1 -dumpstream -dumpfile myvideo.vob
#> mencoder myvideo.vob -of lavf -ovc lavc -lavcopts vcodec=flv:vbitrate=150 -ofps 25 -oac mp3lame -lameopts abr:br=32 -srate 8000 -vf scale=720 -o outputfile.flv

It is important to note the above "mplayer" command it does not play the file not visibly at least but dumps or rips 1 or more VTS_01_n.VOB files into a single "vob" extension file that can then be converted into a video file format you require. The input file has been altered to reflect the file output from mplayer and "-srate" has been altered to "8000". If you think a graphical user interface is the way to go you may be right it would take a lot of the guess work and fun out of using command line, but for now command line seems much better than "gui". Ahh problems with the above it turns out with an "-srate of 8000" you might get some rapid clicking when transfered to a website or you tube, through some investigation and some trial and error we came up with the following which you might think is much better.

#> mplayer dvd://1 -dumpstream -dumpfile myvideo.vob
#> mencoder myvideo.vob -of lavf -ovc lavc -lavcopts vcodec=flv:vbitrate=150 -ofps 25 -oac mp3lame -lameopts abr:br=32 -srate 44100 -vf scale=720 -o outputfile.flv

The "flv" format files can only support 8000, 22050 and 44100 I believe for the available -srate.

Converting MP4 to FLV
ffmpeg -i myvideo.mp4 -ar 44100 myvideo.flv

Converting FLV TO SWF

ffmpeg -i input.flv -acodec copy -vcodec copy output.swf

REFERENCES
http://ubuntuforums.org/showthread.php?t=1001642

Tuesday, October 12, 2010

FFmpeg Tricks You Should Know About

SkyHi @ Tuesday, October 12, 2010
FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video. It includes libavcodec – the leading audio/video codec library. FFmpeg is free software and is licensed under the LGPL or GPL depending on your choice of configuration options.
FFmpeg supports most of the popular formats, we don’t need to worry a lot about that. Formats supported by FFmpeg include MPEG, MPEG-4 (Divx), ASF, AVI, Real Audio/Video and Quicktime. To see a list of all the codecs/formats supported by FFmpeg, run the following command:
ffmpeg -formats

1. X11 grabbing

FFmpeg can grab the X11 display.
ffmpeg -f x11grab -s cif -i :0.0 /tmp/out.mpg
0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable.
ffmpeg -f x11grab -s cif -i :0.0+10,20 /tmp/out.mpg
0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable. 10 is the x-offset and 20 the y-offset for the grabbing.
ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/outputFile.mpg

2. Convert Pictures To Movie

First, rename your pictures to follow a numerical sequence. For example, img1.jpg, img2.jpg, img3.jpg,… Then you may run:
ffmpeg -f image2 -i img%d.jpg /tmp/a.mpg
Notice that `%d’ is replaced by the image number.
`img%03d.jpg' means the sequence `img001.jpg', `img002.jpg', etc…
If you have large number of pictures to rename, you can use the following command to ease the burden. The command, using the bourne shell syntax, symbolically links all files in the current directory that match *jpg to the `/tmp' directory in the sequence of `img001.jpg', `img002.jpg' and so on.
x=1; for i in *jpg; do counter=$(printf %03d $x); ln "$i" /tmp/img"$counter".jpg; x=$(($x+1)); done
If you want to sequence them by oldest modified first, substitute $(ls -r -t *jpg) in place of *jpg.
Then run:
ffmpeg -f image2 -i /tmp/img%03d.jpg /tmp/a.mpg
The same logic is used for any image format that ffmpeg reads.

3. Video Conversions

Quick and dirty convert to flv
ffmpeg -i inputfile.mp4 outputfile.flv
This converts any media ffmpeg handles to flash. It would actually convert anything to anything, it’s based on the file extension. It doesn’t do ANY quality control, sizing, etc, it just does what it thinks is best.
Convert .flv to .3gp
ffmpeg -i file.flv -r 15 -b 128k -s qcif -acodec amr_nb -ar 8000 -ac 1 -ab 13 -f 3gp -y out.3gp
Download YouTube videos as .flv and convert them to .3gp for your mobile phone.
Convert AVI to iPhone MP4
ffmpeg -i [source].avi -f mp4 -vcodec mpeg4 -b 250000 -s 480?320 -acodec aac -ar 24000 -ab 64 -ac 2 [destination].mp4
for 4:3 aspect:
ffmpeg -i source-xvid.avi -s 480x320 -aspect 4:3 -b 768k -ab 64k -ar 22050 -r 30000/1001 OUT.mp4
for 16:9:
ffmpeg -i source-xvid.avi -s 480x320 -aspect 16:9 -b 768k -ab 64k -ar 22050 -r 30000/1001 OUT.mp4
Create a video that is supported by youtube:
ffmpeg -i mymovie.mpg -ar 22050 -acodec libmp3lame -ab 32K -r 25 -s 320x240 -vcodec flv
mytarget.flv
Takes an mpeg video and coverts it to a youtube compatible flv file.
The -r 25 sets the frame rate for PAL, for NTSC use 29.97

4. Audio Conversion

Convert RM file to mp3
ffmpeg -i input.rm -acodec libmp3lame -ab 96k output.mp3
Adjust the bitrate (-ab) as necessary. If omitted FFmpeg will use a default of 64 kb/s.
Converting WMV to MP3 using FFMPEG
ffmpeg -i audio1.wmv audio1.mp3
This will convert audio1.wmv file to audio1.mp3
Converting WMV to FLV using FFMPEG

ffmpeg -i audio1.wmv audio1.flv
This will convert audio1.wmv file to audio1.flv, this will generate only audio content
Converting AMR to MP3 using FFMPEG

ffmpeg -i audio1.amr -ar 22050 audio1.mp3
This will convert audio1.amr file to audio1.mp3 having audio rate 22.05 Khz
Converting aac to mp3 using FFMPEG

ffmpeg -i audio1.aac -ar 22050 -ab 32 audio1.mp3
This will convert audio1.aac to audio1.mp3 having audio rate 22.05 Khz and Audio BitRate 32Khz
Converting aac to mp3 using FFMPEG with MetaData

ffmpeg -i audio1.aac -ar 22050 -ab 32 -map_meta_data audio1.mp3:audio1.aac audio1.mp3
This will convert audio1.aac to audio1.mp3 having audio rate 22.05 Khz and Audio BitRate 32Khz and will copy the meta data from .aac file to .mp3 file

5. Audio Extraction

ffmpeg -i video.avi -f mp3 audio.mp3
Dumping Audio stream from flv (using ffmpeg)
ffmpeg -i input.flv -f mp3 -vn -acodec copy ouput.mp3

6. Record Audio and Video from webcam

To record video run ffmpeg with arguments such as these:
ffmpeg -f video4linux2 -s 320x240 -i /dev/video0 out.mpg
To record both audio and video run ffmpeg with arguments such as these:
ffmpeg -f oss -i /dev/dsp -f video4linux2 -s 320x240 -i /dev/video0 out.mpg

7. Copy Only A Part Of Video

Cut out a piece of film from a file. Choose an arbitrary length and starting time.
ffmpeg -vcodec copy -acodec copy -i orginalfile -ss 00:01:30 -t 0:0:20 newfile
-vcodec, you choose what video codec the new file should be encoded with. Run ffmpeg -formats E to list all available video and audio encoders and file formats.
copy, you choose the video encoder that just copies the file.
-acodec, you choose what audio codec the new file should be encoded with.
copy, you choose the audio encoder that just copies the file.
-i originalfile, you provide the filename of the original file to ffmpeg
-ss 00:01:30, you choose the starting time on the original file in this case 1 min and 30 seconds into the film
-t 0:0:20, you choose the length of the new film
newfile, you choose the name of the file created.

8. Join Multiple Video Files

A few multimedia containers (MPEG-1, MPEG-2 PS, DV) allow to join video files by merely concatenating them.
Hence you may concatenate your multimedia files by first transcoding them to these privileged formats, then using the humble cat command (or the equally humble copy under Windows), and finally transcoding back to your format of choice.
mkfifo orig1.mpg
mkfifo orig2.mpg
ffmpeg -i input1.avi -sameq -y orig1.mpg
ffmpeg -i input2.avi -sameq -y orig2.mpg
Merge files
cat orig1.mpg orig2.mpg | ffmpeg -f mpeg -i - -vcodec copy -acodec copy merged.mpg
Merge and convert to avi
cat orig1.mpg orig2.mpg | ffmpeg -f mpeg -i - -sameq -vcodec mpeg4 -acodec libmp3lame merged.avi
Notice that you should either use -sameq or set a reasonably high bitrate for your intermediate and output files, if you want to preserve video quality.
Also notice that you may avoid the huge intermediate files by taking advantage of named pipes, should your platform support it:

9. Removing Synchronization Problems Between Audio and Video

ffmpeg -i source_audio.mp3 -itsoffset 00:00:10.2 -i source_video.m2v target_video.flv
This assumes that there is a 10.2 sec delay between the video and the audio (delayed).
To extract the original video into a audio and video composites look at the command on extracting audio and video from a movie
Here is more information of how to use ffmpeg:
http://www.ffmpeg.org/ffmpeg-doc.html

REFERENCES
http://segfault.in/2010/10/ffmpeg-tricks-you-should-know-about/

Monday, May 10, 2010

How to Install FFmpeg Centos

SkyHi @ Monday, May 10, 2010

FFmpeg is so important
if you are planning to run a video website with streaming with conversion of
video files to different video formats. This tutorial is intended for Centos/Redhat
versions of Linux where any novice user can install ffmpeg without compiling
the source which is a more traditional way of installing the FFmpeg software
on linux servers. In this tutorial i will show you the easy way to install ffmpeg
and ffmpeg-php (php extension) with just yum rather than compiling ffmpeg from
source files.




 


FFmpeg (http://ffmpeg.mplayerhq.hu)

Mplayer + Mencoder (http://www.mplayerhq.hu/design7/dload.html)

Flv2tool (http://inlet-media.de/flvtool2)

Libogg + Libvorbis (http://www.xiph.org/downloads)

LAME MP3 Encoder (http://lame.sourceforge.net)


FlowPlayer - A Free Flash Video Player - http://flowplayer.org/


Installing FFMpeg


yum install ffmpeg ffmpeg-devel


If you get package not found, then you will need to add few
lines in the yum repository for dag packages installation. Create a file named
dag.repo in /etc/yum.repos.d with the following
contents on it


[dag]

name=Dag RPM Repository for Red Hat Enterprise Linux

baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag

gpgcheck=1

enabled=1


then


yum install ffmpeg ffmpeg-devel


If everything is fine, then the installation should proceed smoothly. If not
you will get something like warning GPG public key missing .


Common Errors


To fix rpmforge GPG key warning:


rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm


For more information refer to this
faq
depending on Centos version


Missing Dependency Error:


If you get missing dependency error like shown below, in the middle of ffmpeg
installation


Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed
by package ffmpeg

Error: Missing Dependency: libtheora.so.0(libtheora.so.1.0) is needed by package
ffmpeg

Error: Missing Dependency: rtld(GNU_HASH) is needed by package ffmpeg

Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package imlib2

Error: Missing Dependency: rtld(GNU_HASH) is needed by package a52dec

Error: Missing Dependency: rtld(GNU_HASH) is needed by package imlib2

Error: Missing Dependency: rtld(GNU_HASH) is needed by package gsm

Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package x264

Error: Missing Dependency: rtld(GNU_HASH) is needed by package xvidcore

Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package lame

Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package a52dec

Error: Missing Dependency: rtld(GNU_HASH) is needed by package faad2

Error: Missing Dependency: rtld(GNU_HASH) is needed by package x264

Error: Missing Dependency: rtld(GNU_HASH) is needed by package lame

Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package xvidcore

Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package faac

Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package faad2

Error: Missing Dependency: libgif.so.4 is needed by package imlib2

Error: Missing Dependency: rtld(GNU_HASH) is needed by package faac

Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package gsm

Error: Missing Dependency: libpng12.so.0(PNG12_0) is needed by package imlib2

Error: Missing Dependency: rtld(GNU_HASH) is needed by package libmp4v2

Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package libmp4v2


then most commonly you have GLIB 2.3 installed instead of GLIB 2.4 version.
To check the current GLIB version installed on your server. just use


yum list glib*


and it should list the latest GLIB package version.


The reason i was getting this error was my rpmforge packages was pointed to
centos 5 versions instead of centos 4.6.


To fix dependency error:


To fix this error, you might need to check your rpmforge packages compatible
to the release of your existing CentOS version.

Check the file /etc/yum.repos.d/rpmforge.repo and it should
look like for Centos 4.6(Final). If you have lines like http://apt.sw.be/redhat/el5/en/mirrors-rpmforge
you might need to make changes to the rpmforge.repos
like shown below


Note: Backup the original rpmforge.repo file
before you edit its content.


[rpmforge]

name = Red Hat Enterprise $releasever - RPMforge.net - dag

#baseurl = http://apt.sw.be/redhat/el4/en/$basearch/dag

mirrorlist = http://apt.sw.be/redhat/el4/en/mirrors-rpmforge

#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge

enabled = 1

protect = 0

gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag

gpgcheck = 1


To know what linux type and version you are running


cat /etc/redhat-release


Once this is done, do again yum install ffmpeg.


This trick resolved the problem in my linux box running Centos 4.6 and this
is the only way i found to install ffmpeg using yum.


To check the FFmpeg working:


Finally, check the ffmpeg whether it is working or not.


> ffmpeg

> ffmpeg -formats

> ffmpeg --help

// This lists path of mpeg, its modules and other path information




ffmpeg -i Input.file Output.file


To check what audi/video formats are supported


ffmpeg -formats > ffmpeg-format.txt


Open the ffmpeg-formats.txt to see the ooutput


D means decode

E means encode

V means video

A means audio

T = Truncated


Install FFMPEG-PHP Extension


FFmpeg-php
is a very good extension and wrapper for PHP which can pull useful information
about video through API interface. Inorder to install it you will need to download
the source file and then compile and install extension in your server. You can
download the source tarball : http://ffmpeg-php.sourceforge.net/


wget /path/to/this/file/ffmpeg-php-0.5.2.1.tbz2


tar -xjf ffmpeg-0.5.2.1.tbz2


phpize


./configure

make

make install


Common Errors


1. If you get command not found error for
phpize, then you will need to do yum install php-devel


2. If you get error like "ffmpeg headers not
found"
while configuring the source.


configure: error: ffmpeg headers not found. Make sure ffmpeg is
compiled as shared libraries using the --enable-shared option


then it means you have not installed ffmpeg-devel packages.


To Fix: Just install ffmpeg-devel using


yum install ffmpeg-devel


3. If you get an error like shared libraries not found problem
and the program halts in the middle, then you must specify the ffmpeg installed
path explicitly to the ./configure.


configure: error: ffmpeg shared libraries not found. Make sure
ffmpeg is compiled as shared libraries using the --enable-shared option


To Fix:


1. First find out the ffmpeg path with ffmpeg --help command.
The prefix default path should be like /usr/local/cpffmpeg

2. Configure the FFmpeg-php with --with-ffmpeg option


./configure --with-ffmpeg=/usr/local/cpffmpeg


That should resolve the problem!


Editing PHP.INI


Once you have done that without any problems then you will see the php extension
file /usr/local/lib/php/extensions/no-debug-non-zts-20060613/ffmpeg.so
and you will need mention that extension in php.ini file


nano /usr/local/lib/php.ini


Put the below two lines at the end of the php.ini file


[ffmpeg]

extension=ffmpeg.so


Then restart the server service httpd restart


To check whether ffmpeg enabled with php, point your browser
to test.php file. It should show the confirmation of installed
ffmpeg php extension


// #test.php



<?php


phpinfo()


?>



If any case the ffmpeg does not show in the phpinfo() test make sure that php.ini
path to ffmpeg.so is correct. Still the problem occurs, the reason could be
you might be using older versions of ffmpeg-php which is buggy. Just download
the latest version of ffmpeg-php source then compile it.


Installing Mplayer + Mencoder


Just issue the following yum commands to install the rest of the packages.


yum install mplayer mencoder


Installing FlvTool2


Flvtool2 is a flash video file manipulation tool. It can calculate metadata
and can cut and edit cue points for flv files.


If you are on Centos 5 try yum install flvtool2 with dag
repository and if you get package not found you will need to manually download
and compile the flvtool2. You can download latest version of flvtool2 here:
http://rubyforge.org/projects/flvtool2/


wget <url-link>


ruby setup.rb config

ruby setup.rb setup

sudo ruby setup.rb install


If you get command not found error, it probably means that
you dont have ruby installed.


yum install ruby


Thats it! Once ffmpeg works fine with php extension, download a sample video,
convert to .flv format in the command line and plug it to flowplayer
to see it work on your web browser. Try also to download the video file offline
and see whether the converted flv file works well with both audio and video.


Useful Links


FFmpeg (http://ffmpeg.mplayerhq.hu)

Mplayer + Mencoder (http://www.mplayerhq.hu/design7/dload.html)

Flv2tool (http://inlet-media.de/flvtool2)

Libogg + Libvorbis (http://www.xiph.org/downloads)

LAME MP3 Encoder (http://lame.sourceforge.net)


FlowPlayer - A Free Flash Video Player - http://flowplayer.org/


Install FFmpeg from Compiling Source (Tutorial
Link
)

Nice FFmpeg Installation Tutorial (click
here
)

Important Audio Codecs (http://www.mplayerhq.hu/DOCS/HTML/en/audio-codecs.html)

Common Errors & Fixes while Installing FFmpeg (click
here
)

http://www.mysql-apache-php.com/ffmpeg-install.htm

Flash Streaming vs Progressive Download

SkyHi @ Monday, May 10, 2010

This is a brief description of Streaming vs Progressive Download with Flash and how it relates to web video.


Progressive Download


This is a common way people link to videos from their own websites. They encode a video, upload it to their website then embed the video.


When someone views this video it is downloaded to their computer. The web server does not care about the quality or size of the video, it will allow them to download it like any other image or document as fast as they can. Playback will begin as soon as enough video has been downloaded, but you are not able to fast-forward to the end of the video without it being downloaded.


To get a little more technical this transfer happens over HTTP (Hypertext Transport Protocol) which operates on TCP (Transport Control Protocol). These protocols make every little bit of video that is downloaded to your computer will be a little larger than it needs to be. This is to ensure that every piece of data is guaranteed to be delivered and if it isn’t the data is sent again, using a little more bandwidth. If someones internet is interment you can end up using more bandwidth for resending information than for the video itself.


TCP (progressive download) is not designed for efficient real time delivery or careful bandwidth control. But if you need a file accurate and reliable then it will deliver every time.


When the h.264 codec was released this introduced another flaw in progressive downloads. h.264 has the information to play the video at the end of the file, so the whole file must be downloaded before the video can start to play. (This was fixed with Flash player 10)


Key Points:


  • cannot be used for live events
  • is not efficient
  • is not secure
  • can not adjust for a users connection speed
  • can not jump to video without it being downloaded
  • video is downloaded

Streaming (Flash Media Server)


Streaming is more efficient and less common because you need FMS software running on a web server to use it. It works similar to embedding a video on a website using progressive download. The videos is encoded, uploaded to a FMS then embedded on a website.


When someone views the video a well made player will detect the viewers connection speed and buffer a little video, not downloading the whole file. A viewer will be able to fast-forward to any place in the file without having to download it.


To get more technical the videos are transferred over RTMP (Real Time Messaging Protocol) or RTMPS which has little overhead compared to HTTP. Every little piece of video that is sent to your computer will be just enough to view the video. If someones connection is interment then the video will pause, re-buffer and start when the connection is better. This is a more efficient use of bandwidth.


Also if RTMP (port 1935) fails it will fall back to RTMPT which will send the packets over HTTP, but will not need to resend information as with progressive download.


Using FMS and streaming videos you can also apply security by IP viewing the video or web page the video is streaming from.


Key Points:


  • can be used for live events
  • used for advanced interactive content
  • is efficient
  • adjusts for connection speeds
  • video is not downloaded
  • better analytics (how many seconds viewed)

REFERENCES
http://www.zoomwebvideo.com/zoomlab/index.php/2010/02/flash-streaming-vs-progressive-download/

Thursday, December 31, 2009

Converting Video Formats with FFmpeg

SkyHi @ Thursday, December 31, 2009
FFmpeg allows Linux users to convert video files easily between a variety of different formats.
Today's affordable digital video cameras have placed the power of digital recording within most people's reach. Unfortunately, this has been accompanied with a corresponding increase in the variety of file formats and codecs available. Some of these formats are more efficient than others, and some are less encumbered by proprietary licensing restrictions. So, having the ability to convert from one format to another is a great help, as you can decide what format you are comfortable with and use that one instead of being restricted to a specific file format.
FFmpeg is a simple and straightforward application that allows Linux users to convert video files easily between a variety of different formats. In this article, I walk you through installing FFmpeg and provide a few instructive examples to demonstrate the range of applications for which it can be used.
FFmpeg Installation
FFmpeg is an open-source audio and video converter that supports most industry-standard codecs and can convert from one file format to another quickly and easily. It also lets you capture video and audio from a live source and process it.
The source code for FFmpeg is available for download from the project Web site (ffmpeg.sourceforge.net/index.php) and at the time of this writing, the latest version available at the site is 0.4.9-pre1.
Once you download the file, extract it using the following command:
tar -zxf ffmpeg-0.4.9-pre1.tar.gz
This creates a new directory containing the source code for FFmpeg. To install it with the default configuration options, run ./configure from within the FFmpeg source directory. Once the configuration script finishes, compile it by issuing make. Once the compile finishes without any errors, you can install FFmpeg by running make install as root.
On the other hand, if you like to have control over what is installed and prefer customizing software installs, you can pass some command-line parameters to the configure script. To see all the options available for the installer, run the following command:
./configure --help
This command gives you multiple screens of the various settings that can be modified, and you can choose any options you like. The on-screen display does a decent job of explaining what each option does, so I will not go into a lot of detail on this.
I suggest that you enable the following options, but this is not a requirement—feel free to experiment:
  • --enable-mp3lame: highly recommended—you won't be able to encode MP3s without this. Needs lame to be installed already.
  • --enable-a52: enables GPLed A52 support, needed for decoding some VOB files.
  • --enable-gpl: required for the previous component; otherwise, not needed.
As I didn't have lame installed on my system, I ran the following command to configure FFmpeg:
./configure --enable-a52 --enable-gpl
Once the configuration is complete, read through the output to make sure no errors were generated. Then, run make, and go have a drink or something as this might take a little while. Once the system finishes compiling FFmpeg, run make install as root to install FFmpeg, and you are done with the installation.
Basic Usage
Now that you have successfully installed FFmpeg, you can start experimenting with it. The first thing you have to do is choose a video file with which to experiment. As this is your first time with FFmpeg, making a backup copy of this file is highly recommended. You don't want to be responsible for ruining the only copy of a rare video.
This input file most probably has been encoded using a particular codec, but because FFmpeg supports most of the popular formats, we don't need to worry a lot about that. Formats supported by FFmpeg include MPEG, MPEG-4 (Divx), ASF, AVI, Real Audio/Video and Quicktime. To see a list of all the codecs/formats supported by FFmpeg, run the following command:
ffmpeg --formats
A detailed list of supported file formats is also available at the FFmpeg site.
FFmpeg supports a large list of command-line parameters that control various settings in FFmpeg. To get a listing of the various options available, run the following command:
ffmpeg --help
Don't let the multipage listing scare you from using FFmpeg, the basic usage is actually very simple. To convert a file with the default settings, run the following command:
ffmpeg -i InputFile OutputFile
The -i option tells FFmpeg that the filename immediately after it is the name of the file to be used as input. If this option is omitted, FFmpeg attempts to overwrite that file when it tries to create the output file. FFmpeg uses the extension of the output file to try to determine the format and codec to use, though this can be overridden using command-line parameters (more on this later).
The default settings create an output file that has radio-quality sound (64kbps bitrate) and very bad video quality (200kbps bitrate). Fortunately, these settings can be changed for each encoding, which allows you to choose the quality of each file depending on the need.
To change the audio bitrate, add -ab bitrate to the command used earlier, where bitrate is the bitrate you want to use. See www.mp3-tech.org/tests/gb for information on the sound quality the various bitrates represent. I prefer to encode files with a bitrate between 128–192kbps depending my needs, but you can put in a higher value if you so desire. Keep in mind, however, that the higher the bitrate you use, the larger the output file size will be. Also keep in mind that if your source file is encoded in a low bitrate, increasing the bitrate won't accomplish much other than increasing the output file size.
Now, getting a CD-quality audio track for the video doesn't really make sense if the video looks like it was taken using a five-year-old Webcam having a bad day. Thankfully, this problem also is easily solved by adding another parameter to the command line.
To change the video bitrate, add the -b bitrate option to the command line. The bitrate here can be any numeric value you like, and I have seen bitrates all the way up to 23,000 (DVD Rips). Although the quality of video encoded with a 23,000kbps bitrate is amazing, the resulting file size of that encoding is also very amazing (a 90-minute video is about 4GB). In my experience, most videos look pretty decent at bitrates between 1,000–1,400, but this is a personal preference, so play with the numbers until you figure out what works for you.
So, to encode a video with a 128kbps audio bitrate and 1,200kbps video stream, we would issue the following command:
ffmpeg -i InputFile.avi -ab 128 -b 1200 OutputFile.mpg
If you are creating a video CD or DVD, FFmpeg makes it even easier by letting you specify a target type. Then, it uses the target type to calculate the format options required automatically. To set a target type, add -target type; type can be vcd, svcd, dvd, dv, pal-vcd or ntsc-svcd on the command line. So, if we were creating a VCD, we would run the following command:
ffmpeg -i InputFile.mpg -target vcd vcd_file.mpg
FFmpeg also has support for encoding audio files. The command to convert audio files is the same as the command to encode video files. To convert a WAV file to a 128kbps MP3 file, issue the following command:
ffmpeg -i Input.wav -ab 128 Output.mp3
Now, the biggest selling point of FFmpeg is that you can customize it to a level that you are comfortable with. So, if all you want to do is convert from one codec to another, and you don't really care about the advanced features, you can stop reading here and still be able to encode/decode videos. On the other hand, if you like to have more control over the encoding, keep reading as we cover more of the advanced options available in FFmpeg.
There are far too many options available in FFmpeg for me to go over each of them here, so I cover some of the ones I found most interesting and leave the rest for you to explore.

Forcing the Use of a Particular Video Codec
There are a times when you will want to encode a video using a particular codec and file format. FFmpeg lets you choose the codec with which you want to encode by adding -vcodec codec to the command line, where codec is the name of the codec you want to use. So if we want to encode using the MPEG-4 codec at 1,200kbps video bitrate and 128kbps audio bitrate, the command looks like this:
ffmpeg -i InputFile.mpg -ab 128 -b 1200 -vcodec mpeg4 OutputFile.avi
Remove the Audio Stream
Let's say you have recorded a video that has a lot of background noise and undesired commentary, so you decide to remove the audio component of the video completely. To accomplish this, all you have to do is add the -an option to the command line, and FFmpeg automatically removes all audio from the output. Keep in mind that using this option negates any other option that affects the audio stream.
So, in our example, to remove the audio component, we would run the following command:
ffmpeg -i InputFile.mpg -an -b 1200 OutputFile.avi
Remove the Video Stream
Let's say you downloaded a news video from the Net that you want to listen to on your iPod on the way to work, but in order to do that, you have to remove the video component from the output file. FFmpeg allows you to remove the video component of the file completely by adding the -vn option to the command line. Using this option negates any other option that affects the video stream.
So, in our example, to remove the video component and save the audio as a 256kbps MP3 file, we would run the following command:
ffmpeg -i InputFile.mpg -vn -ab 256 OutputFile.mp3
Choose between Multiple Audio Streams to Encode the Output File
Many DVDs have multiple language tracks available, and you can choose in which language you want to watch the video. Having multiple audio tracks is cool if you speak multiple languages and want to be able to watch videos in multiple languages. However, if you don't speak multiple languages, the extra audio tracks are useless and are taking up disk space.
FFmpeg lets you choose which streams you want to keep and ignore the rest. The command-line parameter that allows you to map streams is called -map. So, if in our test file, stream 0 is the video stream, stream 1 is the Spanish audio stream and stream 2 is the English audio stream, and we want to keep the English audio in the output file, we would issue the following command:
ffmpeg -i InputFile.mpg -map 0:0 -map 2:1 -b 1200 OutputFile.avi
In my experience, stream 0 in most video files is usually the video stream, and the remaining streams are the audio streams available with the video.
Conclusion
FFmpeg provides a wide range of options for manipulating and converting video files between a variety of formats. For more information, or to download the latest version of FFmpeg for yourself, please refer to the project Web site.
Suramya Tomar is a Linux system administrator who also likes to program. Visit www.suramya.com for more information on his background.
Reference: http://www.linuxjournal.com/article/8517

Video Editing Magic with ffmpeg


Non-linear video editing tools are great, but they're not always the best tool for the job. This is where a powerful tool like ffmpeg becomes useful. This tutorial by Elliot Isaacson covers the basics of transcoding video, as well as more advanced tricks like creating animations, screen captures, and slow motion effects.
Reference: http://www.linuxjournal.com/video/linux-howto-video-editing-magic-ffmpeg


How to Install FFmpeg in Linux ~The Easy Way~

SkyHi @ Thursday, December 31, 2009

FFmpeg is so important if you are planning to run a video website with streaming with conversion of video files to different video formats. This tutorial is intended for Centos/Redhat versions of Linux where any novice user can install ffmpeg without compiling the source which is a more traditional way of installing the FFmpeg software on linux servers. In this tutorial i will show you the easy way to install ffmpeg and ffmpeg-php (php extension) with just yum rather than compiling ffmpeg from source files.

 

FFmpeg (http://ffmpeg.mplayerhq.hu)
Mplayer + Mencoder (http://www.mplayerhq.hu/design7/dload.html)
Flv2tool (http://inlet-media.de/flvtool2)
Libogg + Libvorbis (http://www.xiph.org/downloads)
LAME MP3 Encoder

(http://lame.sourceforge.net)
FlowPlayer - A Free Flash Video Player - http://flowplayer.org/

Installing FFMpeg

yum install ffmpeg ffmpeg-devel

If you get package not found, then you will need to add few lines in the yum repository for dag packages installation. Create a file named dag.repo in /etc/yum.repos.d with the following contents on it

[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1

then

yum install ffmpeg ffmpeg-devel

If everything is fine, then the installation should proceed smoothly. If not you will get something like warning GPG public key missing .

Common Errors

To fix rpmforge GPG key warning:

rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

For more information refer to this faq depending on Centos version

Missing Dependency Error:

If you get missing dependency error like shown below, in the middle of ffmpeg installation

Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package ffmpeg
Error: Missing Dependency: libtheora.so.0(libtheora.so.1.0) is needed by package ffmpeg
Error: Missing Dependency: rtld(GNU_HASH) is needed by package ffmpeg
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package imlib2
Error: Missing Dependency: rtld(GNU_HASH) is needed by package a52dec
Error: Missing Dependency: rtld(GNU_HASH) is needed by package imlib2
Error: Missing Dependency: rtld(GNU_HASH) is needed by package gsm
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package x264
Error: Missing Dependency: rtld(GNU_HASH) is needed by package xvidcore
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package lame
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package a52dec
Error: Missing Dependency: rtld(GNU_HASH) is needed by package faad2
Error: Missing Dependency: rtld(GNU_HASH) is needed by package x264
Error: Missing Dependency: rtld(GNU_HASH) is needed by package lame
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package xvidcore
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package faac
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package faad2
Error: Missing Dependency: libgif.so.4 is needed by package imlib2
Error: Missing Dependency: rtld(GNU_HASH) is needed by package faac
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package gsm
Error: Missing Dependency: libpng12.so.0(PNG12_0) is needed by package imlib2
Error: Missing Dependency: rtld(GNU_HASH) is needed by package libmp4v2
Error: Missing Dependency: libc.so.6(GLIBC_2.4) is needed by package libmp4v2

then most commonly you have GLIB 2.3 installed instead of GLIB 2.4 version. To check the current GLIB version installed on your server. just use

yum list glib*

and it should list the latest GLIB package version.

The reason i was getting this error was my rpmforge packages was pointed to centos 5 versions instead of centos 4.6.

To fix dependency error:

To fix this error, you might need to check your rpmforge packages compatible to the release of your existing CentOS version.
Check the file /etc/yum.repos.d/rpmforge.repo and it should look like for Centos 4.6(Final). If you have lines like http://apt.sw.be/redhat/el5/en/mirrors-rpmforge you might need to make changes to the rpmforge.repos like shown below

Note: Backup the original rpmforge.repo file before you edit its content.

[rpmforge]
name = Red Hat Enterprise $releasever - RPMforge.net - dag
#baseurl = http://apt.sw.be/redhat/el4/en/$basearch/dag
mirrorlist = http://apt.sw.be/redhat/el4/en/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1

To know what linux type and version you are running

cat /etc/redhat-release

Once this is done, do again yum install ffmpeg.

This trick resolved the problem in my linux box running Centos 4.6 and this is the only way i found to install ffmpeg using yum.

To check the FFmpeg working:

Finally, check the ffmpeg whether it is working or not.

> ffmpeg
> ffmpeg -formats
> ffmpeg --help
// This lists path of mpeg, its modules and other path information


ffmpeg -i Input.file Output.file

To check what audi/video formats are supported

ffmpeg -formats > ffmpeg-format.txt

Open the ffmpeg-formats.txt to see the ooutput

D means decode
E means encode
V means video
A means audio
T = Truncated

Install FFMPEG-PHP Extension

FFmpeg-php is a very good extension and wrapper for PHP which can pull useful information about video through API interface. Inorder to install it you will need to download the source file and then compile and install extension in your server. You can download the source tarball : http://ffmpeg-php.sourceforge.net/

wget /path/to/this/file/ffmpeg-php-0.5.2.1.tbz2

tar -xjf ffmpeg-0.5.2.1.tbz2

phpize

./configure
make
make install

Common Errors

1. If you get command not found error for phpize, then you will need to do yum install php-devel

2. If you get error like "ffmpeg headers not found" while configuring the source.

configure: error: ffmpeg headers not found. Make sure ffmpeg is compiled as shared libraries using the --enable-shared option

then it means you have not installed ffmpeg-devel packages.

To Fix: Just install ffmpeg-devel using

yum install ffmpeg-devel

3. If you get an error like shared libraries not found problem and the program halts in the middle, then you must specify the ffmpeg installed path explicitly to the ./configure.

configure: error: ffmpeg shared libraries not found. Make sure ffmpeg is compiled as shared libraries using the --enable-shared option

To Fix:

1. First find out the ffmpeg path with ffmpeg --help command. The prefix default path should be like /usr/local/cpffmpeg
2. Configure the FFmpeg-php with --with-ffmpeg option

./configure --with-ffmpeg=/usr/local/cpffmpeg

That should resolve the problem!

Editing PHP.INI

Once you have done that without any problems then you will see the php extension file /usr/local/lib/php/extensions/no-debug-non-zts-20060613/ffmpeg.so and you will need mention that extension in php.ini file

nano /usr/local/lib/php.ini

Put the below two lines at the end of the php.ini file

[ffmpeg]
extension=ffmpeg.so

Then restart the server service httpd restart

To check whether ffmpeg enabled with php, point your browser to test.php file. It should show the confirmation of installed ffmpeg php extension

// #test.php

<?php

phpinfo()

?>

If any case the ffmpeg does not show in the phpinfo() test make sure that php.ini path to ffmpeg.so is correct. Still the problem occurs, the reason could be you might be using older versions of ffmpeg-php which is buggy. Just download the latest version of ffmpeg-php source then compile it.

Installing Mplayer + Mencoder

Just issue the following yum commands to install the rest of the packages.

yum install mplayer mencoder

Installing FlvTool2

Flvtool2 is a flash video file manipulation tool. It can calculate metadata and can cut and edit cue points for flv files.

If you are on Centos 5 try yum install flvtool2 with dag repository and if you get package not found you will need to manually download and compile the flvtool2. You can download latest version of flvtool2 here: http://rubyforge.org/projects/flvtool2/

wget <url-link>

ruby setup.rb config
ruby setup.rb setup
sudo ruby setup.rb install

If you get command not found error, it probably means that you dont have ruby installed.

yum install ruby

Thats it! Once ffmpeg works fine with php extension, download a sample video, convert to .flv format in the command line and plug it to flowplayer to see it work on your web browser. Try also to download the video file offline and see whether the converted flv file works well with both audio and video.

Useful Links

FFmpeg (http://ffmpeg.mplayerhq.hu)
Mplayer + Mencoder (http://www.mplayerhq.hu/design7/dload.html)
Flv2tool (http://inlet-media.de/flvtool2)
Libogg + Libvorbis (http://www.xiph.org/downloads)
LAME MP3 Encoder (http://lame.sourceforge.net)
FlowPlayer - A Free Flash Video Player - http://flowplayer.org/

Install FFmpeg from Compiling Source (Tutorial Link)
Nice FFmpeg Installation Tutorial (click here)
Important Audio Codecs (http://www.mplayerhq.hu/DOCS/HTML/en/audio-codecs.html)
Common Errors & Fixes while Installing FFmpeg (click here)



Reference: http://www.mysql-apache-php.com/ffmpeg-install.htm