Thursday, October 9, 2008
Friday, June 27, 2008
FFMPEG useful commands
FFMPEG is a very power full tool for video manipulation. Mostly developers use the different command to convert video from one format to another e.g ( avi to flv ) . Mostly developers search different type of command via search engines e.g google.com . Exert of FFMPEG use the different parameters for different scenarios. The purpose of this blog to write down common command that will be very useful while developing video sites.
1- Live Stream Conversion
In Window
ffmpeg.exe -i http://serveraddress/streamvideo.asf -target ntsc-dvd -aspect 1.3333 -s 176x108 yourvideo.flv
In Linux
exec('/user/bin/ffmpeg -i http://serveraddress/streamvideo.asf -target ntsc-dvd -aspect 1.3333 -s 176x108 yourvideo.flv');
2- Creat Movie from Images
Note: Your folder contain images with discrete unique name e.g image1, image2, image3.....
In Window
ffmpeg.exe -r 2 -i images/image%d.jpg -ar 22050 -s 320x240 -aspect 4:3 -f flv ' yourflvname.flv
In Linux
exec('/usr/local/bin/ffmpeg -r 2 -i images/image%d.jpg -ar 22050 -s 320x240 -aspect 4:3 -yourflvname. flv '.$movie_Store_Path,$output,$return);
3- Get the single Frame of Specific movie Time
$curFrameTime = "00:00:05";
exec('/usr/local/bin/ffmpeg -i yourfile.flv -an -ss '.$curFrameTime.' -an -r 1 -vframes 1 images/img%d.jpg');
4- Get multiple frames from movie
exec('/usr/local/bin/ffmpeg -i ./yourfile.wmv -an -ss 00:00:01 -t 00:01:31 -r 10 -s 550x450 -aspect 5:3 ./img/%d.png',$output,$result);
4- Avi to flv Conversion
exec('/usr/local/bin/ffmpeg -i ./youravifile.avi -pass 2 -s 448x336 -ab 56k -ar 22050 -ac 1 -vcodec flv -b 500k -g 160 -cmp 3 -subcmp 3 -mbd 2 -flags aic+cbp+mv0+mv4+trell -y yourfilename.flv',$output,$result);
5-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:
exec('/usr/local/bin/ffmpeg -i InputFile.mpg -an -b 1200 OutputFile.avi');
5-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:
exec('/usr/local/bin/ffmpeg -i InputFile.mpg -vn -ab 256 OutputFile.mp3');6-Extracting sound from a video, and save it as Mp3
This is very easy command to extract audio from video file .
ffmpeg -i inputVideo.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 outputFile.mp3
Mencoder:
7.Combine two flv using mencoder
A very simple command to combine two flv.
mencoder.exe -fps 29.97 1.flv -fps 29.97 2.flv -o combine.flv -of lavf -ovc copy -oac copy
8-Remove the video from file.
In order to remove video from file; ffmpeg allow to remove video component completely by
adding -vn in command line.
ffmpeg -i InputFile.mpg -vn -ab 256 OutputFile.mp3
9- How to get Movie Time using FFMPEG
Following is very useful PHP function to get the movie duration.
function duration($videofile)
{
ob_start();
passthru("ffmpeg.exe -i \"". $videofile . "\" 2>&1");
$duration = ob_get_contents();
ob_end_clean();
preg_match('/Duration: (.*?),/', $duration, $matches);
$duration = $matches[1];
return($duration);
}
Note: If you have recorded file using flash media server or RED5; then you have to again convert file ( flv to flv ) using FFMPEG.
Note: If some one need window version of FFMPEG and MENCODER, just to mail me .
smile110 (at) gmail (dot) com
kids cartoons
Visit Pakistan