gpt4 book ai didi

php - ffmpeg 使用 exec() 输出必须是实时的

转载 作者:行者123 更新时间:2023-12-04 23:29:03 27 4
gpt4 key购买 nike

嗨,我正在起诉 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

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

从文档:

如果存在输出参数,则指定的数组将填充命令的每一行输出。此数组中不包含尾随空格,例如\n。

$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);

关于php - ffmpeg 使用 exec() 输出必须是实时的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27776358/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com