问题描述
我已经搜索到Google和StackOverFlow,但仍然没有找到解决方案。
I have searched all over the Google and StackOverFlow, but still did not find a solution for this.
我想生成所有mp4视频文件的视频缩略图一个目录并将缩略图命名为filename.mp4.jpg
I want to generate video thumbnail of all mp4 video files in a directory and name the thumbnails as "filename.mp4".jpg
我的服务器上安装了ffmpeg和ffmpeg-php。我也成功地创建了一个文件的缩略图。
I have ffmpeg and ffmpeg-php installed on my server. I also succeeded in creating thumbnails of one file at a time.
所以这是情况,我有一个名为uploads的目录,它有很多mp4视频。
现在,当我运行脚本时,自动创建大小为100x100的缩略图,并放置在另一个文件夹skrin中。例如:xxx.mp4应该有xxx.mp4.jpg有拇指名称。
So this is the situation, I have a directory named uploads which has lots of mp4 videos.Now, when I run the script, thumbnail of size 100x100 shoud be created automatically and placed in another folder "skrin". Eg: xxx.mp4 should have xxx.mp4.jpg has the thumb name.
重要信息:我的文件名在其文件名中有空格,单引号,括号等。所以脚本应该能够处理这个。
IMPORTANT: My filenames have spaces, single quotes, brackets etc in their file names. So the script should be able to handle this.
有人可以帮助我吗?我在php中使用以下shell命令,使用exec生成单个视频的缩略图。
Could some one help me ? I use the following shell command in php using exec to generate thumb of an individual video.
exec("/usr/local/bin/ffmpeg -itsoffset -105 -i 'xxx haha.mp4' -vcodec mjpeg -vframes 1 -an -f rawvideo -s 100x100 'xxx haha.mp4.jpg'");
推荐答案
这只是一个很快的一个:
It's just a quick one:
$videos_dir = 'path/to/videos';
$videos_dir = opendir($videos_dir);
$output_dir = 'path/to/output/dir/';
while (false !== ($file = readdir($videos_dir))) {
if ($file != '.' && $file != '..'){
$in = $videos_dir.'/'.$file;
$out = $output_dir.$file.'.jpg';
exec("/usr/local/bin/ffmpeg -itsoffset -105 -i ".$in." -vcodec mjpeg -vframes 1 -an -f rawvideo -s 100x100 ".$out);
}
}
这篇关于通过FFmpeg和PHP创建目录中所有文件的视频缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!