Search code examples
phplinuxencodeffmpeg-php

how to install ffmpeg-PHP for newbies to linux?


I'm trying to convert an .avi video file I have in my server folder to `.flv' format using ffmpeg-PHP. My attempt to "install" ffmpeg-PHP was to extract the contents of the "ffmpeg-php-0.6.0.tbz2" archive into a separate folder. The video conversion script I'm using references the directory location of the files extracted from "ffmpeg-php-0.6.0.tbz2"

this is the conversion script:

<?php

// Set our source file
$srcFile = "/videos/clip.avi";
$destFile = "/videos/clip.flv";
$ffmpegPath = "/install"; //where I extracted "ffmpeg-php-0.6.0.tbz2"

// 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();

function makeMultipleTwo ($value)
{
    $sType = gettype($value/2);

    if($sType == "integer")
    {
    return $value;
    } else {
    return ($value-1);
    }
}

// Call our convert using exec()
exec($ffmpegPath . " -i " . $srcFile . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile);

?>

After running the conversion script, I get the output, "Fatal error: Class 'ffmpeg_movie' not found in [conversion script location]"

I've read instructions on the ffmpeg-PHP page but it doesn't make sense to me. How do I execute these lines of linux code to install ffmpeg-PHP?

tar -xjf ffmpeg-php-X.x.x.tbz2

cd ffmpeg-php-X.x.x/
phpize

./configure && make

sudo make install

I think I'm using a shared hosting service by Inmotion with linux installed.


Solution

  • If you are on shared hosting, you will need to have shell access to be able to build the php extension. Since the hosting is shared, you will not be able to modify the php configuration (php.ini) to load the ffmpeg extension automatically.

    If you have shell access and the ability to compile scripts (not always common on shared hosting), you will need to build the extension and place the .so file in your home directory somewhere, and use the dl() function to load the library on demand in your scripts.

    Some hosts may disable dl(), or your ability to compile scripts. If you don't have shell access then you are out of luck and only the host can install this for you.