在阅读了关于与 FFMPEG 和 PHP 相关的 SO 的大量问题后,我收集了一个小片段或其他什么,但它似乎没有做任何事情 - 甚至没有抛出错误。
我的PHP如下:
function get_video_thumbnail($file) {
define('ALL_PLACE_WIDTH', 250);
define('ALL_PLACE_HEIGHT', 200);
$ffmpeg = "ffmpeg"; // where ffmpeg is
$image_source_path = $file; // where the video is
$image_cmd = " -r 1 -ss 00:00:10 -t 00:00:01 -s ".ALL_PLACE_WIDTH."x".ALL_PLACE_HEIGHT." -f image2 "; // command
$dest_image_path = "cdn/thumbnails"; // destination of thumbnail
$str_command = $ffmpeg ." -i " . $image_source_path . $image_cmd .$dest_image_path;
shell_exec($str_command);
}
在根文件夹中有一个文件夹“ffmpeg”,里面有“ffmpeg.exe”、“ffplay.exe”和“pthreadGC2.dll”。所以我想知道,我有什么遗漏吗?我正在尝试从视频/mp4 文件生成缩略图。
最佳答案
cdn/thumbnails 是文件夹吗?如果是这样,您必须提供文件名。你只给了一个文件夹。因此它不起作用。由于您希望每秒一个 10 秒,因此您必须提供类似 cdn/thumbnails/images%03d.jpg 之类的内容作为输出。
所以你的命令看起来像这样:
ffmpeg -i inputfile -s widthxheight -f image2 文件夹/文件名%04d.jpg
转到命令行并首先键入命令。确保它在那里工作。然后它将在 php 中工作。
文件将被命名为 filename0000.jpg filename0001.jpg 等等。
关于php - FFMPEG 与 PHP 不执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12435245/