使用 exec() 输出的 FFMPEG 必须是实时的


ffmpeg using exec() output must be realtime

嗨,我

正在起诉Windows和linux操作系统,我正在使用php上传视频,使用ffmpeg我可以将视频转换为其他文件类型。 在命令行中,我可以转换并通过 php 代码,但我在 php 中显示输出执行数据时遇到问题,无法在 echo 这是我的代码。

$webm = 'ffmpeg -i c:'xampp'htdocs'vidcon'video.mp4 -acodec libvorbis -aq 5 -ac 2 -qmax 25 -threads 2 c:'xampp'htdocs'vidcon'new'myvideo.webm';
    echo exec ($webm); 

但是当我运行它时,它没有任何显示..我想显示的是这样的......类似于转换以PHP显示的视频的进展...

ffmpeg version N-68810-g75cc57f Copyright (c) 2000-2014 the FFmpeg developers built on Jan 1 2015 22:02:35 with gcc 4.9.2 (GCC) configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca -- enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-lib modplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrw b --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinge r --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --en able-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable- libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enab le-zlib libavutil 54. 15.100 / 54. 15.100 libavcodec 56. 19.100 / 56. 19.100 libavformat 56. 16.102 / 56. 16.102 libavdevice 56. 3.100 / 56. 3.100 libavfilter 5. 6.100 / 5. 6.100 libswscale 3. 1.101 / 3. 1.101 libswresample 1. 1.100 / 1. 1.100 libpostproc 53. 3.100 / 53. 3.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'c:'xampp'htdocs'vidcon'video.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: mp42mp41isomavc1 creation_time : 2014-03-04 20:25:21 Duration: 00:02:33.09, start: 0.000000, bitrate: 2661 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709) , 1280x720 [SAR 1:1 DAR 16:9], 2499 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 t bc (default) Metadata: creation_time : 2014-03-04 20:25:21 handler_name : L-SMASH Video Handler encoder : AVC Coding Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, flt p, 160 kb/s (default) Metadata: creation_time : 2014-03-04 20:25:21 handler_name : L-SMASH Audio Handler [libvpx @ 0292c560] v1.3.0 Output #0, webm, to 'c:'xampp'htdocs'vidcon'new'myvideo2.webm': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: mp42mp41isomavc1 encoder : Lavf56.16.102 Stream #0:0(und): Video: vp8 (libvpx), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1-25, 200 kb/s, 29.97 fps, 1k tbn, 29.97 tbc (default) Metadata: creation_time : 2014-03-04 20:25:21 handler_name : L-SMASH Video Handler encoder : Lavc56.19.100 libvpx Stream #0:1(und): Audio: vorbis (libvorbis), 48000 Hz, stereo, fltp (default ) Metadata: creation_time : 2014-03-04 20:25:21 handler_name : L-SMASH Audio Handler encoder : Lavc56.19.100 libvorbis Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> vp8 (libvpx)) Stream #0:1 -> #0:1 (aac (native) -> vorbis (libvorbis)) Press [q] to stop, [?] for help frame= 12 fps=0.0 q=0.0 size= 5kB time=00:00:00.40 bitrate= 97.1kbits/s frame= 22 fps= 21 q=0.0 size= 5kB time=00:00:00.73 bitrate= 52.9kbits/s frame= 31 fps= 19 q=0.0 size= 153kB time=00:00:01.03 bitrate=1213.8kbits/s frame= 41 fps= 19 q=0.0 size= 153kB time=00:00:01.36 bitrate= 917.5kbits/s

有人知道我的案子吗? 提前感谢...

查看文档,

http://php.net/manual/en/function.exec.php

您需要传递一个数组作为第二个参数。

从文档中:

如果存在输出参数,则指定的数组将填充命令的每一行输出。尾随空格(如 ')不包括在此数组中。

$webm = 'ffmpeg -i c:'xampp'htdocs'vidcon'video.mp4 -acodec libvorbis -aq 5 -ac 2 -qmax 25 -threads 2 c:'xampp'htdocs'vidcon'new'myvideo.webm';
$array = array();
echo exec ($webm, $array);

这应该可以做到。

这是一种显示 shell 命令实时输出的方法:

<?php
header("Content-type: text/plain");
// tell php to flush after every output
// including lines of output produced by shell commands
ini_set('output_buffering', 'off');
    // Turn off PHP output compression
    ini_set('zlib.output_compression', false);
    // Implicitly flush the buffer(s)
    ini_set('implicit_flush', true);
    ob_implicit_flush(true);
    // Clear, and turn off output buffering
    while (ob_get_level() > 0) {
        // Get the curent level
        $level = ob_get_level();
        // End the buffering
        ob_end_clean();
        // If the current level has not changed, abort
        if (ob_get_level() == $level) break;
    }
    // Disable apache output buffering/compression
    if (function_exists('apache_setenv')) {
        apache_setenv('no-gzip', '1');
        apache_setenv('dont-vary', '1');
    }
$command = 'ffmpeg -i etc';
system($command);