Showing posts with label PHP Video. Show all posts
Showing posts with label PHP Video. Show all posts

11 December, 2010

How to extract segment of video using FFMPEG

Once i had a situation where i had to extract a part (segment) of a video lets say from 3rd second to 8thd second. So after searching through FFMPEG documentation
i came to know how this could be done.
Following code snippet can be used to extract a segment of video.

$inputFile = "melt.mpg";
$outputFile = "melted.flv";
//-ss is the start time in HH:mm:ss
//-t is the end time in HH:mm:ss
system("path-to-ffmpeg/ffmpeg -i $inputFile -ss 00:00:03 -t 00:00:08 $outputFile");

And that's it.

11 May, 2010

Get total length of Video in PHP


//Total Length of video can be userful at many cases. Following code sample shows
// how to get the total length or duration of any video file

//get the filename of video
$uploadVideoFile = $_FILE["fleVideo"]["name"];

//turn on the output buffering
ob_start();

//execute the the ffmpef command, where -i is the input
//the 2>&1 is done to redirect standard error (stderr) to standard output(stdout)
system("/path/to/ffmpeg -i $uploadVideoFile 2>&1");
//now get the contents
$totalDuration = ob_get_contents();

//clear the output buffer and turn off the output buffering done by ob_start()
ob_end_clean();

//perform a regular expression match
//check for the pattern Duration: ... in $duration and return matches
preg_match('/Duration: (.*?),/', $duration, $matches);

//found the matches
//this is the total length of video
$totalLength = $matches[1];
echo "Total Length of the video is:".$totalLength;
?>

04 May, 2010

PHP Video Conversion & Thumbnail -- FFMPEG

To convert video to flv format add the following code:
$source = "path/somesource.mpg";
$destination = "path/somefilename.flv";
exec("/path/to/ffmpeg -i $source -ab 128 -ar 22050 -b 300000 -r 25 -s 320×240 $destination");

And to generate video first-frame thumbnail, add the following code:
exec("/path/to/ffmpeg -i $source -ss 1.4 -vframes 1 -f image2 $screenshotImg");