在阅读了关于用PHP进行FFMPEG的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"answers"pthreadGC2.dll"。所以我想知道,我缺少什么吗?我正在尝试从视频/mp4文件生成缩略图。
cdn/thumbus是文件夹吗?如果是,您必须提供文件名。您只提供了一个文件夹。因此,它不起作用。由于您想要在10秒内每秒一个,因此必须提供类似cdn/thumbna/images%03.jpg的内容作为输出。
所以你的命令看起来像这样:
ffmpeg-i输入文件-s宽度xheight-f image2文件夹/文件名%04.jpg
转到命令行,然后首先键入命令。确保它在那里工作。然后它将在php中工作。
文件将命名为filename0000.jpg filename0001.jpg,依此类推。