如何在php中将音频和视频转换为mp4格式文件

时间:2015-03-13 08:32:25

标签: php video recorder

我正在使用 https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC/RecordRTC-to-PHP  制作录像机。

它有两个不同的文件,一个用于音频,一个用于视频。

我想合并两个文件并制作一个mp4文件。

他们已经给出了合并代码,但显示错误。

他们的代码是:

 'Win16',
    'Windows 95' => '(Windows 95)|(Win95)|(Windows_95)',
    'Windows 98' => '(Windows 98)|(Win98)',
    'Windows 2000' => '(Windows NT 5.0)|(Windows 2000)',
    'Windows XP' => '(Windows NT 5.1)|(Windows XP)',
    'Windows Server 2003' => '(Windows NT 5.2)',
    'Windows Vista' => '(Windows NT 6.0)',
    'Windows 7' => '(Windows NT 7.0)',
    'Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
    'Windows ME' => 'Windows ME',
    'Open BSD' => 'OpenBSD',
    'Sun OS' => 'SunOS',
    'Linux' => '(Linux)|(X11)',
    'Mac OS' => '(Mac_PowerPC)|(Macintosh)',
    'QNX' => 'QNX',
    'BeOS' => 'BeOS',
    'OS/2' => 'OS/2',
    'Search Bot'=>'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)'
    );
    // Loop through the array of user agents and matching operating systems
    foreach($OSList as $CurrOS=>$Match)
    {
        // Find a match
        if (eregi($Match, $_SERVER['HTTP_USER_AGENT']))
        {
            // We found the correct match
            break;
        }
    }
    // if it is audio-blob
    if (isset($_FILES["audio-blob"])) {
        $uploadDirectory = 'uploads/'.$_POST["filename"].'.wav';
        if (!move_uploaded_file($_FILES["audio-blob"]["tmp_name"], $uploadDirectory)) {
            echo("Problem writing audio file to disk!");
        }
        else {
            // if it is video-blob
            if (isset($_FILES["video-blob"])) {
                $uploadDirectory = 'uploads/'.$_POST["filename"].'.mp4';
                if (!move_uploaded_file($_FILES["video-blob"]["tmp_name"], $uploadDirectory)) {
                    echo("Problem writing video file to disk!");
                }
                else {
                    $audioFile = 'uploads/'.$_POST["filename"].'.wav';
                    $videoFile = 'uploads/'.$_POST["filename"].'.mp4';

                    $mergedFile = 'uploads/'.$_POST["filename"].'-merged.mp4';

                    // ffmpeg depends on yasm
                    // libvpx depends on libvorbis
                    // libvorbis depends on libogg
                    // make sure that you're using newest ffmpeg version!

                    if(!strrpos($CurrOS, "Windows")) {
                        $cmd = '-i '.$audioFile.' -i '.$videoFile.' -map 0:0 -map 1:0 '.$mergedFile;

                    }
                    else {
                        $cmd = ' -i '.$audioFile.' -i '.$videoFile.' -c:v mpeg4 -c:a vorbis -b:v 64k -b:a 12k -strict experimental '.$mergedFile;

                    }

                    exec('ffmpeg '.$cmd.' 2>&1', $out, $ret);
                    if ($ret){
                        echo "There was a problem!\n";
                        print_r($cmd.'\n');
                        print_r($out);
                    } else {
                        echo "Ffmpeg successfully merged audi/video files into single WebM container!\n";

                        unlink($audioFile);
                        unlink($videoFile);
                    }
                }
            }
        }
    }
?>

0 个答案:

没有答案