Php-ffmpeg

From DreamHost

Jump to: navigation, search
This article or section may require a cleanup.
We are hoping to create articles that meet certain standards. Please discuss this issue on the talk page. Editing help is available.


The instructions provided in this article or section are considered advanced.

You are expected to be knowledgeable in the UNIX shell.
Support for these instructions is not available from DreamHost tech support.


Contents

Php-ffmpeg

php-ffmpeg is a component that can be used in a php script. Here are some details:

  • php-ffmpeg is free
  • php-ffmpeg installation is similar to installing a perl module
  • php-ffmpeg is used for many youtube clones
  • unlike other scripts, php-ffmpeg supports all video types

install

login to unix shell and type:

wget http://superb-west.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.5.0.tbz2

bunzip2 ffmpeg-php-0.5.0.tbz2; tar xvf ffmpeg-php-0.5.0.tar

cd ~/ffmpeg/ffmpeg-php-0.5.0
phpize
./configure
make
make install

echo 'extension=/usr/local/lib/php/extensions/ no-debug-non-zts-20020429/ffmpeg.so' >> /usr/local/Zend/etc/php.ini

verify it is working...

php -r 'phpinfo();' | grep ffmpeg

if it returns something like this:

ffmpeg
ffmpeg support (ffmpeg-php) => enabled
ffmpeg-php version => 0.5.0
ffmpeg.allow_persistent => 0 => 0

then you are all set!

The php script

Full Code

<?php
	// Set our source file
	$srcFile = "/path/to/clock.avi";
	$destFile = "/path/to/clock.flv";
	$ffmpegPath = "/path/to/ffmpeg";
	$flvtool2Path = "/path/to/flvtool2";
	
	// Create our FFMPEG-PHP class
	$ffmpegObj = new ffmpeg_movie($srcFile);
	
	// Save our needed variables
	$srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
	$srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
	$srcFPS = $ffmpegObj->getFrameRate();
	$srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
	$srcAR = $ffmpegObj->getAudioSampleRate();
	
	// Call our convert using exec()
	exec($ffmpegPath . " -i " . $srcFile . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile . " | " . $flvtool2Path . " -U stdin " . $destFile);
	
	function makeMultipleTwo ($value) {
		if ($value % 2)
			return $value - 1;
		else
			return $value;
	}
?>
Personal tools