PHPology is a collective of highly skilled, award winning, web gurus.
Contact Raj on 07985 467 213 or email [email protected]

FFMpeg losing duration when converting to FLV

Recently hit an issue where when I was converting a video file to a FLV format via FFMpeg (PHP) the duration of the video was lost during the export.

Searching the t'internet, various options were found i.e. using FLVTool (which needed to be installed on the server) or by spitting out the raw data using PHP passthru().

I went for the passthru() option and although the duration was not actually part of the metadata, I was at least able to tell Flash (in my case) that this video was x:x:x long.

I did end up using this example code from LongTailVideo.com and then saved the duration value to the database:

ob_start();
passthru("ffmpeg-10141.exe -i \"". $videofile . "\" 2>&1");
$duration = ob_get_contents();
ob_end_clean();

preg_match('/Duration: (.*?),/', $duration, $matches);
$duration = $matches[1];