我有一个简单的应用正在尝试: 1)旋转具有旋转值的视频 2)重新编码HEVC视频,以便它们在Chrome中播放(直到Chrome支持HEVC) 3)将几个结果缝合在一起。
我目前正在本地开发和测试中,我正在尝试扫描当前目录以查找其中存在的一些mp4示例。它在第一个上就kes住了。这是代码:
<?PHP
$files1 = scandir('./');
foreach ($files1 as $file) {
$fileinfo = new SplFileInfo($file);
$extn = $fileinfo->getExtension();
if ($extn == 'mp4'){
fixVideo($file);
}
}
// FUNCTIONS
function fixVideo($file) {
$config = array(
'ffmpeg.binaries' => '/usr/local/bin/ffmpeg',
'ffprobe.binaries' => '/usr/local/bin/ffprobe',
'timeout' => 3600, // The timeout for the underlying process
'ffmpeg.threads' => 12, // The number of threads that FFMpeg should use
);
$resultFile = 'FIXED_'.$file;
// create the ffmpeg object
$ffmpeg = FFMpeg\FFMpeg::create($config, null);
// open video file
$video = $ffmpeg->open($file);
// get the first video stream
$videostream = $ffmpeg->getFFProbe()
->streams($file)
->videos()
->first();
//echo "<pre>";print_r($videostream);
if (!$videostream instanceof FFMpeg\FFProbe\DataMapping\Stream) {
throw new \Exception('No stream given');
} else {
echo "<video src='$file' width='100'></video><br>";
echo "$file<br>";
if ($videostream->has('tags')) {
//echo "has tags<BR>";
// MUST WE ROTATE?
$tags = $videostream->get('tags');
if (isset($tags['rotate'])) {
echo "has rotate" . $tags['rotate'] . "<BR>" ;
if ($tags['rotate'] != 0) {
echo "rotate not 0<BR>";
switch($tags['rotate']) {
case 270:
$angle = FFMpeg\Filters\Video\RotateFilter::ROTATE_270;
break;
case 180:
$angle = FFMpeg\Filters\Video\RotateFilter::ROTATE_180;
break;
case 90:
$angle = FFMpeg\Filters\Video\RotateFilter::ROTATE_90;
break;
}
$video->filters()
->rotate($angle); echo "rotating<br>";
} // if ($tags['rotate']
// MUST WE REENCODE TO H.264?
if (isset($tags['encoder'])) {
echo "encoding: " . $tags['encoder'];
}
$format = new FFMpeg\Format\Video\X264();
$format->setAudioCodec("aac");
$video->save($format,$resultFile );
} // if (isset($tags['rotate']
} // if ($videostream->has('tags')
echo "<BR><BR>";
} // if $videostream instanceof
}//function
?>
在浏览器中运行它时,我得到:
appL.mp4
已旋转0
编码:HEVC
致命错误:炼金术\ BinaryDriver \ Exception \ ExecutionFailureException:ffmpeg无法执行命令'/ usr / local / bin / ffmpeg''-y''-i''appL.mp4''-threads''12' '-vcodec''libx264''-acodec''libmp3lame''-b:v''1000k''-refs''6''编码器''1''-sc_threshold''40''-flags''+循环'''-me_range''16''-subq''7''-i_qfactor''0.71''-qcomp''0.6''-qdiff''4''网格''1''-b:a' '128k''-pass''1''-passlogfile''/ var / tmp / ffmpeg-passes5ba267bb96d0abvdgk / pass-5ba267bb96e01'/ Users / [redacted] / test3 / vendor / alchemy / binary-driver中的'FIXED_appL.mp4' /src/Alchemy/BinaryDriver/ProcessRunner.php:100堆栈跟踪:#0 / Users / [已编辑] /test3/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php(72):Alchemy \ BinaryDriver \ ProcessRunner-> doExecutionFailure(''/ usr / local / bin ...')#1 /用户/ [已编辑] /test3/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/AbstractBinary.php(209) :/ Users / [已编辑] / test3 / vendor / php-ffmpeg / php-ffmpeg / src / FFMpeg / Media / Abs中的Alchemy \ Bi第106行的tractVideo.php
在终端中运行它时,我得到:
MacBook-Pro:视频[已编辑] $'/ usr / local / bin / ffmpeg''-y''-i'appL.mp4''-threads''12''-vcodec''libx264'' -acodec''libmp3lame''-b:v''1000k''-refs''6''-coder''1''-sc_threshold''40''-flags''+ loop''-me_range''16 ''-subq''7''-i_qfactor''0.71''-qcomp''0.6''-qdiff''4''-格子''1''-b:a''128k''-pass'' 1''-passlogfile''/ var / tmp / ffmpeg-passes5ba267bb96d0abvdgk / pass-5ba267bb96e01''FIXED_appL.mp4' ffmpeg版本4.0.2版权所有(c)2000-2018 FFmpeg开发人员 使用Apple LLVM版本9.1.0(clang-902.0.39.2)构建 配置:--prefix = / usr / local / Cellar / ffmpeg / 4.0.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc = clang --host-cflags = -I / System / Library / Frameworks / JavaVM.framework / Versions / Current / Headers / --host-ldflags = --enable-gpl --enable-chromaprint --enable-ffplay --enable- frei0r --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libgme --enable-libgsm- enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopus --enable-librsvg --enable-librtmp --enable-librubberband --enable -libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtesseract --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable -libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --enable-libzmq --enabl e-opencl --enable-videotoolbox --enable-openssl --enable-libsrt --enable-lzma --enable-libopenjpeg --disable-decoder = jpeg2000 --extra-cflags = -I / usr / local / Cellar / openjpeg / 2.3.0 / include / openjpeg-2.3-启用非自由 libavutil 56. 14.100 / 56. 14.100 libavcodec 58. 18.100 / 58. 18.100 libavformat 58. 12.100 / 58. 12.100 libavdevice 58. 3.100 / 58. 3.100 libavfilter 7. 16.100 / 7. 16.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 1.100 / 5. 1.100 libswresample 3. 1.100 / 3. 1.100 libpostproc 55. 1.100 / 55. 1.100 从'appL.mp4'输入#0,mov,mp4,m4a,3gp,3g2,mj2: 元数据: major_brand:qt
minor_version:0 compatible_brands:qt
creation_time:2018-09-17T16:01:54.000000Z 持续时间:00:00:03.30,开始:0.000000,比特率:4574 kb / s 流#0:0(und):视频:hevc(主)(hvc1 / 0x31637668),yuv420p(tv,bt709),960x540,4459 kb / s,29.97 fps,29.97 tbr,600 tbn,600 tbc(默认) 元数据: 旋转:0 creation_time:2018-09-17T16:01:54.000000Z handler_name:核心媒体数据处理程序 编码器:HEVC 辅助数据: displaymatrix:旋转-0.00度 流#0:1(und):音频:aac(LC)(mp4a / 0x6134706D),44100 Hz,单声道,fltp,98 kb / s(默认) 元数据: creation_time:2018-09-17T16:01:54.000000Z handler_name:核心媒体数据处理程序 流映射: 流#0:0->#0:0(hevc(本机)-> h264(libx264)) 流#0:1->#0:1(AAC(本机)-> mp3(libmp3lame)) 按[q]停止,按[?]寻求帮助 [libx264 @ 0x7f89e0018600]使用cpu功能:MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 [libx264 @ 0x7f89e0018600] ratecontrol_init:无法打开统计信息文件 初始化输出流0:0时出错-打开输出流#0:0的编码器时出错-可能是不正确的参数,例如bit_rate,rate,width或height [libmp3lame @ 0x7f89e0019e00]关闭时队列中还剩4帧 转换失败!
答案 0 :(得分:0)
尝试一下。更改:
$format = new FFMpeg\Format\Video\X264();
收件人:
$format = new FFMpeg\Format\Video\X264('libmp3lame');