简体   繁体   English

ffmpeg等间隔生成图像

[英]ffmpeg image generation in equal interval

I'm using ffmpeg in Ubuntu for the image creation and video conversion my problem is i want to generate image(thumbnail) at different intervals. 我在Ubuntu中使用ffmpeg进行图像创建和视频转换,我的问题是我想以不同的间隔生成图像(缩略图)。 suppose that i upload a video then it calculate the video time and generate 5 images(thumbnail) at equal intervals.(eg suppose that the time period of the video is 50 minutes then images obtains at 0,10,20,30,40,50 intervals) 假设我上传了一个视频,然后它计算了视频时间,并以相等的间隔生成了5张图像(缩略图)。(例如,假设视频的时间段为50分钟,那么在0、10、20、30、40处可获得图像, 50间隔)

please help 请帮忙

thanks 谢谢

Short version: 简洁版本:

ffmpeg -itsoffset -4 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg ffmpeg -itsoffset -4 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg

This command generates a 320×240 sized PNG thumbnail at the 4th second in the video. 此命令在视频的第4秒生成320×240尺寸的PNG缩略图。 Put this in a script that changes the time and file name and you're done . 把它放在一个可以改变时间和文件名的脚本中,就完成了。

Long version: http://blog.prashanthellina.com/2008/03/29/creating-video-thumbnails-using-ffmpeg/ 长版: http//blog.prashanthellina.com/2008/03/29/creating-video-thumbnails-using-ffmpeg/

Well if you just run: 好吧,如果您只是运行:

ffmpeg -i file.mp4 ffmpeg -i file.mp4

The output will contain the length of the video on stderr. 输出将包含stderr上视频的长度。 If you run your program and pipe its output to a file you can read it or if you'd prefer you can read the output of stderr and just write some code in whatever language you're using to find the position in that output. 如果您运行程序并将其输出通过管道传输到文件中,则可以读取该文件;或者,如果您愿意,可以读取stderr的输出,然后只用您使用的任何语言编写一些代码,即可在该输出中查找位置。 It's pretty because I believe it's actually in the string as "Duration: 00:15:00" or whatever. 这很漂亮,因为我相信它实际上在字符串中,例如“ Duration:00:15:00”或其他。

If you run: 如果您运行:

ffmpeg -ss 00:03:00 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg ffmpeg -ss 00:03:00 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg
ffmpeg -ss 00:06:00 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg ffmpeg -ss 00:06:00 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg
ffmpeg -ss 00:09:00 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg ffmpeg -ss 00:09:00 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg
ffmpeg -ss 00:12:00 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg ffmpeg -ss 00:12:00 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg
ffmpeg -ss 00:15:00 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg ffmpeg -ss 00:15:00 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg

Then you'll have frames as jpegs every 3 minutes. 然后,每3分钟将有jpeg帧。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM