項目地址:https://github.com/BPing/ffmpeg-pushphp
ffprobe
命令composer require bping/ffmpeg-push
ffprobe
命令require __DIR__ . '/trunk/vendor/autoload.php'; use FFMpegPush\PushFormat; use FFMpegPush\PushInput; use FFMpegPush\PushOutput; use FFMpegPush\PushVideo; ///** @var $ffprobe FFProbeCommand */ //$ffprobe = FFProbeCommand::create(); //var_dump($ffprobe->format('test.mp4')); // 推流 // ffmpeg -re -i \"test/test.mp4\" -c:v copy -c:a copy -f flv rtmp://pili-publish.heliwebs.com $pushUrl = 'rtmp://pili-publish.heliwebs.com'; $pushCmd = PushVideo::create(); // 監聽推流進度 $pushCmd->onProgress(function ($percent, $remaining, $rate) { // var_dump(func_get_args()); echo "progress:$percent% remaining:$remaining(s) rate:$rate(kb/s)\n"; }); $pushCmd->setInput( PushInput::create() ->setStartTime(0) ->setInputVideo('res/test.mp4') ) ->setFormat( PushFormat::create() ->setVideoCodec(PushFormat::CODE_V_COPY) ) ->setOutput( PushOutput::create() ->setPushUrl($pushUrl) ); echo $pushCmd->getCommandLine(); // 開始推流 $pushCmd->push(); echo $pushCmd->getErrorOutput(); echo "\n"; echo "Exit Code: " . $pushCmd->getExitCode(); // 中止推流,須要異步調用 // $pushCmd->stop();
PushInfo
//是否成功 $pushinfo->isSuccessful() //輸出 $pushinfo->getOutput() //錯誤輸出 $pushinfo->getErrOutput() //執行返回碼 $pushinfo->getExitCode() //目前推流時間,能夠用中途斷流重推起點時間 $pushinfo->getCurrentTime() //更多請看 PushInfo類
PushInput
PushInput::create() ->setStartTime(10) ->setInputVideo('test/test.mp4')
PushFormat
PushFormat::create() ->setVideoCodec(PushFormat::CODE_V_COPY) ->setAudioCodec(PushFormat::CODE_A_COPY) ->setAudioKiloBitrate(125) ->setVideoKiloBitrate(500) ->setAdditionalParamaters( array( '--preset', 'ultrafast', ' --tune', 'zerolatency', ) );
PushOutput
PushOutput::create()->setPushUrl($pushUrl)
///** @var $ffprobe FFProbeCommand */ $ffprobe = FFProbeCommand::create(); var_dump($ffprobe->format('test/test.mp4')); var_dump($ffprobe->stream('test/test.mp4'));
ffmpeg.binaries
:ffmpeg命令名稱或者路徑。若是想使用簡單名稱,記得把ffmpeg加入環境變量
PATH
中。 默認值:ffmpeghtml
ffprobe.binaries
:ffprobe命令名稱或者路徑。若是想使用簡單名稱,記得把ffprobe加入環境變量
PATH
中。 默認值:ffprobegit
timeout
:命令執行的超時時長,單位(s).考慮到推流時長通常較長,因此默認值爲一天github
$pushCmd = PushVideo::create(Configuration::create( array( 'ffmpeg.binaries'=>array('ffmpeg'), 'ffprobe.binaries'=>array('ffprobe'), 'timeout'=>10800, ) ));