其他 请教 ffmpeg 生成视频截图的速度问题

young4u_amy · 2012年02月09日 · 最后由 young4u_amy 回复于 2012年02月09日 · 9841 次阅读

想加一个为上传视频生成截图的功能 新上传的视频在保存之后就会自动生成 thumbnail, 但老的视频文件没有,所以要在用 lightbox 打开视频的时候检测/生成 thumbnail. 因为需要用 ffmpeg 先检测视频的宽和高,然后在生成 thumbnail。刚才测试了下一个 1280x720 的视频 60 多 M,需要用 2s 的时间 有没有办法能提速啊?

延迟处理吧

#1 楼 @huacnlee 还是想让用户一点就能看见缩略图啊

刚发现不必特意指定图片 size。。。 之前用 ffmpeg -itsoffset -10 -i "#{file_name}" -vcodec mjpeg -vframes 1 -an -f rawvideo -s #{dimensions} "#{image_name}"

现在省去取 size 那步,换个参数顺序,70M 的视频可以 0.5s 搞定。 ffmpeg -ss 10 -i "#{file_name}" "#{image_name}" -r 1 -vframes 1 -an -vcodec mjpeg

如果各位有更优方案,欢迎指点。

参考 http://stackoverflow.com/questions/2206785/create-thumbnails-from-big-movies-with-ffmpeg-takes-too-long

耗时的处理还是用异步任务好

推荐 resque

老数据后台处理跑一遍

补充下用到的参数:

-an: Disable audio recording. 
-i : Input file name on which ffmpeg commands operates.
-r : Frame per second, Set frame rate (Hz value, fraction or abbreviation), (default = 25).
-s: Set frame size. The format is `wxh' (ffserver default = 160x128, ffmpeg default = same as source). The following abbreviations are recognized: sqcif=128x96, qcif =176x144, cif =352x288, 4cif=704x576.
-ss: Seek to given time position in seconds. hh:mm:ss.
-vcodec: Force video codec to codec. 
-vframes: Set the number of video frames to record.
需要 登录 后方可回复, 如果你还没有账号请 注册新账号