ffmpeg -framerate 1/5 -i images2\%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4
-framerate 1/5: 输入帧率为5秒,也就说一张图片,在压缩后的out.mp4中要显示5秒。
-i image\%03d.png: 表示输入图片的位置
-c:v libx264: 压缩算法
-r 30:表示输出图片的帧速率为 30帧/秒
-pix_fmt yuv420p:表示像素格式
out.mp4:输出的文件名(当前文件夹)
下面是我测试的过程:
我输入了8张jpg图片,可以在这里下载。
压缩后生成的out.mp4文件格式为:
播放时间正好为40秒 = 8张图片 × 5秒/张
帧速率为: 30帧/秒
然后我又播放了一下这个out.mp4,测验的结果为:
Index: 1, packet's size: 176396 Index: 2, packet's size: 556 Index: 3, packet's size: 115 Index: 4, packet's size: 107 Index: 5, packet's size: 116 //... Index: 1198, packet's size: 31 Index: 1199, packet's size: 31 Index: 1200, packet's size: 39说明一共有1200个Frame。计算一下,30帧/秒 × 40秒 = 1200帧,验证了。
参考:https://trac.ffmpeg.org/wiki/Create%20a%20video%20slideshow%20from%20images
hwh@Mountain:~/ffmpeg/ffmpeg-2.1.4/doc/examples$ ffprobe wavinflag.aac ffprobe version 2.1.4 Copyright (c) 2007-2014 the FFmpeg developers built on Mar 7 2014 15:39:45 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1) configuration: libavutil 52. 48.101 / 52. 48.101 libavcodec 55. 39.101 / 55. 39.101 libavformat 55. 19.104 / 55. 19.104 libavdevice 55. 5.100 / 55. 5.100 libavfilter 3. 90.100 / 3. 90.100 libswscale 2. 5.101 / 2. 5.101 libswresample 0. 17.104 / 0. 17.104 [aac @ 0xa55c820] Estimating duration from bitrate, this may be inaccurate Input #0, aac, from 'wavinflag.aac': Duration: 00:03:51.27, bitrate: 122 kb/s Stream #0:0: Audio: aac, 44100 Hz, stereo, fltp, 122 kb/s
hwh@Mountain:~/ffmpeg/ffmpeg-2.1.4/doc/examples$ ffprobe start.avi ffprobe version 2.1.4 Copyright (c) 2007-2014 the FFmpeg developers built on Mar 7 2014 15:39:45 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1) configuration: libavutil 52. 48.101 / 52. 48.101 libavcodec 55. 39.101 / 55. 39.101 libavformat 55. 19.104 / 55. 19.104 libavdevice 55. 5.100 / 55. 5.100 libavfilter 3. 90.100 / 3. 90.100 libswscale 2. 5.101 / 2. 5.101 libswresample 0. 17.104 / 0. 17.104 [avi @ 0x9877820] non-interleaved AVI Input #0, avi, from 'start.avi': Duration: 00:00:10.55, start: 0.000000, bitrate: 1838 kb/s Stream #0:0: Video: msvideo1 (CRAM / 0x4D415243), rgb555le, 352x288, 20 tbr, 20 tbn, 20 tbc Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 44100 Hz, stereo, s16p, 320 kb/s