Skip to content

Instantly share code, notes, and snippets.

@dannykopping
Created August 2, 2011 23:35
Show Gist options
  • Select an option

  • Save dannykopping/1121508 to your computer and use it in GitHub Desktop.

Select an option

Save dannykopping/1121508 to your computer and use it in GitHub Desktop.
Merge audio and video FLV scripts with PHP and FFMPEG
<?php
$streamsPath = realpath("/usr/share/red5/webapps/vod/streams");
$videoFile = "$streamsPath/356a192b7913b04c54574d18c28d46e6395428ab-1312327917237_Video.flv";
$audioFile = "$streamsPath/356a192b7913b04c54574d18c28d46e6395428ab-1312327917237_Audio.flv";
// convert audio FLV to mp3
$targetAudio = dirname(realpath($audioFile))."/audio.mp3";
system("ffmpeg -y -i $audioFile -ac 2 -ab 128kb $targetAudio");
if(!realpath($targetAudio))
throw new Exception("Audio conversion failed");
$basename = basename($videoFile);
$filename = substr($basename, 0, strrpos($basename, "_Video."));
$targetVideo = dirname(realpath($videoFile))."/$filename.flv";
system("ffmpeg -itsoffset 00:00:0.75 -i $videoFile -itsoffset 00:00:0 -i $targetAudio -acodec copy -vcodec copy $targetVideo");
if(!realpath($targetVideo))
throw new Exception("Merge process failed");
?>
@testchik
Copy link

I used same code in localhost, It is done well. But i upload on my shared server it is not working.....

@martinnaj
Copy link

I used same code in localhost, It is done well. But i upload on my shared server it is not working.....

You have asked this question everywhere, here's your answer.

You do not have it installed on your shared server, you need to contact the support for your shared server or upgrade to a virtual server. You cannot execute FFMPEG if it isn't installed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment