操作系统:ubuntu 11.10
网络服务器: Apache
代码:PHP
我正在尝试使用 php 在网页上显示命令“ffmpeg -i”的输出。
必填:网页应显示有关视频(文本)的信息。
发生了什么:网页在运行 php 代码时没有显示文本输出。
但是,如果我在做 system("ls") 代码运行良好并输出文件列表。
这是我的代码
<?php
echo "Details of video file:";
system('ffmpeg -i /home/atish/Videos/T2V0040006_Angled_ride_720x576i_FLDCMB.avi');
?>
相同的命令在我的 shell 上运行良好,并且我的系统安装了 ffmpeg。这是直接在 shell 上执行此命令的快照:
ThinkPad-T420:~/Videos$ ffmpeg -i /home/xx/Videos/T2V0040006_Angled_ride_720x576i_FLDCMB.avi
ffmpeg version git-2012-01-10-7e2ba2d Copyright (c) 2000-2012 the FFmpeg developers
built on Jan 10 2012 12:01:19 with gcc 4.6.1
configuration: --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore- amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
libavutil 51. 34.100 / 51. 34.100
libavcodec 53. 54.100 / 53. 54.100
libavformat 53. 29.100 / 53. 29.100
libavdevice 53. 4.100 / 53. 4.100
libavfilter 2. 58.100 / 2. 58.100
libswscale 2. 1.100 / 2. 1.100
libswresample 0. 6.100 / 0. 6.100
libpostproc 51. 2.100 / 51. 2.100
Input #0, avi, from '/home/atish/Videos/T2V0040006_Angled_ride_720x576i_FLDCMB.avi':
Metadata:
encoder : Lavf52.23.1
Duration: 00:00:29.00, start: 0.000000, bitrate: 124422 kb/s
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 720x576, 25 tbr, 25 tbn, 25 tbc
At least one output file must be specified
我曾尝试将“DISPLAY=:0”附加到我的命令中,并在运行 php 代码之前完成了“xhost +”,但没有任何帮助。
谢谢。
最佳答案
这个link解释如何和为什么。感谢各位的回复。
这是获得所需输出的方法:
echo exec('/usr/local/bin/ffmpeg -i input.mp4 2>&1', $output);
var_dump($output);
关于php - 无法通过 PHP 执行 CLI 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8834210/