小智 8
它不起作用,因为你永远不会执行$cmd
.实际执行$cmd
您可能需要使用popen()
,proc_open()
或exec()
.
试试这个功能.只要ffmpeg可访问,它就应该生成一个图像.要使其可访问,请将其添加到$path
Linux中,将其放入windows/system32
Windows中的文件夹中.或者将其添加到Windows控制面板中的环境变量中.
/** * ExtractThumb, extracts a thumbnail from a video * * This function loads a video and extracts an image from a frame 4 * seconds into the clip * @param $in string the input path to the video being processed * @param $out string the path where the output image is saved */ function ExtractThumb($in, $out) { $thumb_stdout; $errors; $retval = 0; // Delete the file if it already exists if (file_exists($out)) { unlink($out); } // Use ffmpeg to generate a thumbnail from the movie $cmd = "ffmpeg -itsoffset -4 -i $in -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 $out 2>&1"; exec($cmd, $thumb_stdout, $retval); // Queue up the error for processing if ($retval != 0) { $errors[] = "FFMPEG thumbnail generation failed"; } if (!empty($thumb_stdout)) { foreach ($thumb_stdout as $line) { echo $line . "
\n"; } } if (!empty($errors)) { foreach ($errors as $error) { echo $error . "
\n"; } } }
$thumb_stdout
- 显示与CLI中相同的输出.这有助于查看ffmpeg正在执行的操作的详细信息,以及查看ffmpeg无法正常工作时崩溃的位置.
$errors
- 如果CLI退出并显示错误代码(IE,如果ffmpeg崩溃),则会显示错误.