Your ffmpeg
has not been configured with --enable-gpl
and --enable-libx264
which are required to support encoding with libx264.
上一篇已讲将了 ffmpeg 的安装说明,接一下来讲一下我们要实现的功能,将 jpeg 转成 mp4.
参看:FFmpeg and H.264 Encoding Guide
本版本使用的是 ffmpeg-3.3.1
1、将单个 jpeg 转码生成 mp4
# ./ffmpeg -f image2 -i ../jpg/IMG_3870.jpg -vcodec libx264 -b:v 200k -r 10 -s 640x480 -acodec libfaac -y single_jpg.mp4
ffmpeg version 3.3.1 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
configuration: --enable-shared --prefix=/usr/local/ffmpeg
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
Input #0, image2, from '../jpg/IMG_3870.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 2592x1728, 25 tbr, 25 tbn, 25 tbc
Unknown encoder 'libx264'
上述出现错误信息 Unknown encoder 'libx264'
查看原因,参看:“Unknown encoder libx264” on Windows
|
一开始的配置只是简单的:(后面会在 ffmpeg再学习 -- 安装说明 更改的)
# ./configure --enable-shared --prefix=/usr/local/ffmpeg
如果按照上面的提示修改配置:
# ./configure --enable-shared --prefix=/usr/local/ffmpeg --enable-gpl --enable-libx264
ERROR: libx264 not found
If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "config.log" produced by configure as this will help
solve the problem.
又会出现错误 ERROR: libx264 not found
查看原因,参看:How to resolve “ERROR: libx264 not found”?
Make sure your $ADDI_CFLAGS variable (which you pass in |
查看config.log,详细信息如下:
check_lib stdint.h x264.h x264_encoder_encode -lx264
check_func_headers stdint.h x264.h x264_encoder_encode -lx264
check_ld cc -lx264
check_cc
BEGIN /tmp/ffconf.SkjtKMss.c
1 #include <stdint.h>
2 #include <x264.h>
3 #include <stdint.h>
4 long check_x264_encoder_encode(void) { return (long) x264_encoder_encode; }
5 int main(void) { int ret = 0;
6 ret |= ((intptr_t)check_x264_encoder_encode) & 0xFFFF;
7 return ret; }
END /tmp/ffconf.SkjtKMss.c
gcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -std=c99 -fomit-frame-pointe r -pthread -c -o /tmp/ffconf.bfZpW8gZ.o /tmp/ffconf.SkjtKMss.c
/tmp/ffconf.SkjtKMss.c:2:18: fatal error: x264.h: No such file or directory
compilation terminated.
ERROR: libx264 not found
最后结论即,只要在配制 configure 时,添加额外的 include/link 路径应该能够解决问题。
--extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib
巴特,我使用的 Ubuntu 上未安装 x264,需要下载安装:
下载:(git clone 文件下载到当前的目录下)
# git clone http://git.videolan.org/git/x264.git
进入 x264 文件,进行配置、编译
进入x264 文件
cd x264
配置:
# ./configure --enable-shared --enable-static --disable-asm
编译:
首先执行(时间比较长,需耐心等待几分钟)
# make
再执行:
# make install
查看:
# ls /usr/local/lib/
libjpeg.la libjpeg.so.62 libmp3lame.a libmp3lame.so libmp3lame.so.0.0.0 libx264.so pkgconfig site_ruby
libjpeg.so libjpeg.so.62.0.0 libmp3lame.la libmp3lame.so.0 libx264.a libx264.so.150 python2.7
# ls /usr/local/include/
jconfig.h jerror.h jmorecfg.h jpeglib.h x264_config.h x264.h
然后,不知道你有没有注意到,其实我耍懒了。音频的 mp3lame 和 faac 没有下载安装配置。
如果需要的话,其实还是有必要再重新 参看:ffmpeg x264安装 下载安装配置一下的。
趁现在有时间,还是将其安装上吧,以后可能会用到。
后续,还有一些其他需要安装的,参看:Compile FFmpeg on CentOS
(1)安装配置 facc (实际不需要安装,ffmpeg已删除它了)
下载:facc 下载
配置:
./configure --enable-shared --enable-static
编译:
首先执行:
# make
出现错误:
make[3]: 正在进入目录 `/home/tarena/project/jpg to mp4/faac-1.28/common/mp4v2'
if g++ -DHAVE_CONFIG_H -I. -I. -I../.. -I../../include -Wall -g -O2 -MT 3gp.o -MD -MP -MF ".deps/3gp.Tpo" -c -o 3gp.o 3gp.cpp; \
then mv -f ".deps/3gp.Tpo" ".deps/3gp.Po"; else rm -f ".deps/3gp.Tpo"; exit 1; fi
In file included from mp4common.h:29:0,
from 3gp.cpp:28:
mpeg4ip.h:126:58: 错误: 对‘char* strcasestr(const char*, const char*)’的新声明
/usr/include/string.h:369:28: 错误: 使旧的声明‘const char* strcasestr(const char*, const char*)’出现歧义
make[3]: *** [3gp.o] 错误 1
make[3]:正在离开目录 `/home/tarena/project/jpg to mp4/faac-1.28/common/mp4v2'
make[2]: *** [all-recursive] 错误 1
make[2]:正在离开目录 `/home/tarena/project/jpg to mp4/faac-1.28/common'
make[1]: *** [all-recursive] 错误 1
make[1]:正在离开目录 `/home/tarena/project/jpg to mp4/faac-1.28'
make: *** [all] 错误 2
解决方法:
将 faac-1.28/common/mp4v2/mpeg4ip.h 第 123行~129行,进行如下修改:
修改前:
#ifdef __cplusplus
extern "C" {
#endif
char *strcasestr(const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif
修改后:
#ifdef __cplusplus
extern "C++" {
#endif
const char *strcasestr(const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif
再执行:
# make install
(2)安装配置 mp3lame
下载:lame-3.99.5 下载
配置:
# ./configure --enable-shared --enable-static
编译:
首先执行:
# make
再执行:
# make install
出现错误:
/bin/bash: /home/tarena/project/jpg: No such file or directory
make[3]: *** [install-libLTLIBRARIES] 错误 127
make[3]:正在离开目录 `/home/tarena/project/jpg to mp4/lame-3.99.5/libmp3lame'
make[2]: *** [install-am] 错误 2
make[2]:正在离开目录 `/home/tarena/project/jpg to mp4/lame-3.99.5/libmp3lame'
make[1]: *** [install-recursive] 错误 1
make[1]:正在离开目录 `/home/tarena/project/jpg to mp4/lame-3.99.5/libmp3lame'
make: *** [install-recursive] 错误 1
原因是:/home/tarena/project/jpg 名字不一致,文件名我有空格不显示。重命名问题解决。
当配置改为:
./configure --enable-shared --prefix=/usr/local/ffmpeg --enable-gpl --enable-libx264 --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --enable-libfaac --enable-libmp3lame --disable-yasm
又会出错:
Unknown option "--enable-libfaac"
查看:./configure --help 未发现该选项,后来查看资料,显示已经删除 libfaac。
最后得出,配置应为:
./configure --enable-shared --prefix=/usr/local/ffmpeg --enable-gpl --enable-libx264 --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --enable-libmp3lame --disable-yasm
然后重新执行:
# ./ffmpeg -f image2 -i ../jpg/IMG_3870.jpg -vcodec libx264 -b:v 200k -r 10 -s 640x480 -acodec libfaac -y single_jpg.mp4
ffmpeg version 3.3.1 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
configuration: --enable-shared --prefix=/usr/local/ffmpeg --enable-gpl --enable-libx264 --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --disable-yasm
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Input #0, image2, from '../jpg/IMG_3870.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 2592x1728, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[swscaler @ 0x8b81740] deprecated pixel format used, make sure you did set range correctly
No pixel format specified, yuvj444p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x8b6ff60] using cpu capabilities: none!
[libx264 @ 0x8b6ff60] profile High 4:4:4 Predictive, level 2.2, 4:4:4 8-bit
[libx264 @ 0x8b6ff60] 264 - core 150 r2829 d1fe6fd - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=10 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=200 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'single_jpg.mp4':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuvj444p(pc), 640x480, q=-1--1, 200 kb/s, 10 fps, 10240 tbn, 10 tbc
Metadata:
encoder : Lavc57.89.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 1 fps=0.0 q=32.0 Lsize= 43kB time=00:00:00.00 bitrate=3585959.2kbits/s speed=0.000289x
video:42kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.854943%
[libx264 @ 0x8b6ff60] frame I:1 Avg QP:34.43 size: 42425
[libx264 @ 0x8b6ff60] mb I I16..4: 0.8% 75.3% 23.8%
[libx264 @ 0x8b6ff60] final ratefactor: 48.61
[libx264 @ 0x8b6ff60] 8x8 transform intra:75.3%
[libx264 @ 0x8b6ff60] coded y,u,v intra: 94.6% 73.8% 20.7%
[libx264 @ 0x8b6ff60] i16 v,h,dc,p: 10% 10% 10% 70%
[libx264 @ 0x8b6ff60] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 10% 14% 24% 8% 8% 7% 8% 9% 12%
[libx264 @ 0x8b6ff60] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 13% 18% 10% 10% 9% 8% 8% 9%
[libx264 @ 0x8b6ff60] kb/s:3394.00
生成并播放 single_jpg.mp4 文件(因为是I帧所以不会显示图像,跳帧)
2、将单个jpeg转码生成序列mp4
# ./ffmpeg -f image2 -stream_loop 500 -i ../jpg/IMG_3870.jpg -vcodec libx264 -b:v 200k -r 10 -s 640x480 -acodec libfaac -y multi_jpg.mp4
ffmpeg version 3.3.1 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
configuration: --enable-shared --prefix=/usr/local/ffmpeg --enable-gpl --enable-libx264 --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --disable-yasm
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Input #0, image2, from '../jpg/IMG_3870.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 2592x1728, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[swscaler @ 0x98336e0] deprecated pixel format used, make sure you did set range correctly
No pixel format specified, yuvj444p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x9821f80] using cpu capabilities: none!
[libx264 @ 0x9821f80] profile High 4:4:4 Predictive, level 2.2, 4:4:4 8-bit
[libx264 @ 0x9821f80] 264 - core 150 r2829 d1fe6fd - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=10 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=200 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'multi_jpg.mp4':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuvj444p(pc), 640x480, q=-1--1, 200 kb/s, 10 fps, 10240 tbn, 10 tbc
Metadata:
encoder : Lavc57.89.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame= 202 fps=2.3 q=20.0 Lsize= 344kB time=00:00:19.90 bitrate= 141.5kbits/s dup=0 drop=299 speed=0.225x
video:341kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.934512%
[libx264 @ 0x9821f80] frame I:1 Avg QP:23.69 size:133878
[libx264 @ 0x9821f80] frame P:51 Avg QP:22.63 size: 3985
[libx264 @ 0x9821f80] frame B:150 Avg QP:33.91 size: 74
[libx264 @ 0x9821f80] consecutive B-frames: 1.0% 0.0% 0.0% 99.0%
[libx264 @ 0x9821f80] mb I I16..4: 0.3% 53.3% 46.3%
[libx264 @ 0x9821f80] mb P I16..4: 0.0% 0.0% 0.0% P16..4: 27.3% 0.2% 0.6% 0.0% 0.0% skip:71.9%
[libx264 @ 0x9821f80] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 8.6% 0.0% 0.0% direct: 0.0% skip:91.4% L0: 0.4% L1:99.6% BI: 0.0%
[libx264 @ 0x9821f80] final ratefactor: 23.26
[libx264 @ 0x9821f80] 8x8 transform intra:53.3% inter:47.0%
[libx264 @ 0x9821f80] coded y,u,v intra: 99.9% 94.2% 56.7% inter: 2.1% 2.1% 1.4%
[libx264 @ 0x9821f80] i16 v,h,dc,p: 0% 0% 75% 25%
[libx264 @ 0x9821f80] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 10% 14% 20% 8% 8% 7% 9% 8% 15%
[libx264 @ 0x9821f80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 9% 10% 16% 10% 10% 10% 10% 11% 14%
[libx264 @ 0x9821f80] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x9821f80] ref P L0: 84.6% 0.2% 11.1% 4.1%
[libx264 @ 0x9821f80] ref B L0: 80.7% 19.3%
[libx264 @ 0x9821f80] ref B L1: 75.6% 24.4%
[libx264 @ 0x9821f80] kb/s:137.88
3、将多个 jpeg 转码生成序列 mp4
# ./ffmpeg -f image2 -i ../jpg/%02d.jpg -vcodec libx264 -b:v 200k -r 10 -s 640x480 -acodec libfaac -y multi_jpg2.mp4
ffmpeg version 3.3.1 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
configuration: --enable-shared --prefix=/usr/local/ffmpeg --enable-gpl --enable-libx264 --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --disable-yasm
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Input #0, image2, from '../jpg/%02d.jpg':
Duration: 00:00:01.24, start: 0.000000, bitrate: N/A
Stream #0:0: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 5184x3456, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[swscaler @ 0x85e69a0] deprecated pixel format used, make sure you did set range correctly
No pixel format specified, yuvj444p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x85d3b80] using cpu capabilities: none!
[libx264 @ 0x85d3b80] profile High 4:4:4 Predictive, level 2.2, 4:4:4 8-bit
[libx264 @ 0x85d3b80] 264 - core 150 r2829 d1fe6fd - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=10 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=200 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'multi_jpg2.mp4':
Metadata:
encoder : Lavf57.71.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuvj444p(pc), 640x480, q=-1--1, 200 kb/s, 10 fps, 10240 tbn, 10 tbc
Metadata:
encoder : Lavc57.89.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
[swscaler @ 0x85e66c0] deprecated pixel format used, make sure you did set range correctly 0x
frame= 14 fps=1.1 q=48.0 Lsize= 63kB time=00:00:01.10 bitrate= 471.5kbits/s dup=0 drop=17 speed=0.0895x
video:62kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.496486%
[libx264 @ 0x85d3b80] frame I:1 Avg QP:27.12 size: 29594
[libx264 @ 0x85d3b80] frame P:9 Avg QP:44.71 size: 3723
[libx264 @ 0x85d3b80] frame B:4 Avg QP:40.50 size: 20
[libx264 @ 0x85d3b80] consecutive B-frames: 57.1% 14.3% 0.0% 28.6%
[libx264 @ 0x85d3b80] mb I I16..4: 8.8% 69.6% 21.6%
[libx264 @ 0x85d3b80] mb P I16..4: 19.2% 52.2% 2.9% P16..4: 0.7% 0.1% 0.0% 0.0% 0.0% skip:25.0%
[libx264 @ 0x85d3b80] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.1% 0.0% 0.0% direct: 0.0% skip:99.9% L0:50.0% L1:50.0% BI: 0.0%
[libx264 @ 0x85d3b80] final ratefactor: 42.18
[libx264 @ 0x85d3b80] 8x8 transform intra:70.1% inter:90.5%
[libx264 @ 0x85d3b80] coded y,u,v intra: 33.1% 27.8% 18.6% inter: 0.3% 0.5% 0.4%
[libx264 @ 0x85d3b80] i16 v,h,dc,p: 25% 39% 18% 18%
[libx264 @ 0x85d3b80] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 15% 23% 33% 5% 5% 4% 6% 3% 5%
[libx264 @ 0x85d3b80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 22% 15% 7% 7% 6% 7% 5% 6%
[libx264 @ 0x85d3b80] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x85d3b80] ref P L0: 69.1% 17.3% 9.9% 3.7%
[libx264 @ 0x85d3b80] ref B L0: 33.3% 66.7%
[libx264 @ 0x85d3b80] kb/s:361.03
生成并播放 multi_jpg2.mp4 文件:
0.jpg 到 9.jpg, 或 00.jpg 到 99.jpg, 或 000.jpg 到 999.jpg, 或 0000.jpg, 9999.jpg
对应的参数也为"../jpg/%01~04d.jpg";
%d就是普通的输出了
%2d是将数字按宽度为2,采用右对齐方式输出,若数据位数不到2位,则左边补空格
%02d,和%2d差不多,只不过左边补0
%.2d没见过,但从执行效果来看,和%02d一样
#!/bin/sh
i=1;
for img in `ls *.jpg`;
do mv $img `printf %.2d $i`.jpg;
i=`expr $i + 1`;
done
./ffmpeg -f image2 -i ../jpg/%02d.jpg -vcodec libx264 -b:v 200k -r 10 -s 640x480 -acodec libfaac -y multi_jpg2.mp4
安装说明里都有的,参看:ffmpeg再学习 -- 安装说明-f: 格式
-i:文件
-vcodec:视频编解码器
-b:视频比特率 ( 请使用- b:v )
-r:设置帧率 ( Hz 值,分数或缩写)
-s:设置帧大小 ( WxH 或缩写)
-acodec:音频编解码器 (“复制”复制流 )
-y:覆盖输出文件
帧率是、帧大小,参看:ffmpeg-比特率,帧率和文件大小比特率和帧率是音视频基本的特性,对于音视频整体的质量有关键作用!如果知道比特率和持续时间,就可以计算输出文件的大小。
1.Frame(frequency)rate introduction
帧率就是每秒编码进视频文件的帧数目。人类的眼睛需要每秒至少15帧才能将图像连贯在一起。帧率的单位是HZ,LCD显示一般有60Hz的平率。
有2种类型的帧率-interlaced(denoted asi after FPS number) and progressive(denoted asp after FPS number)//逐行扫描和隔行扫描
逐行扫描(interlaced)的帧率一般用在电视:
-NTSC用60i fps,意思是:60 interlaced fields(30 frames)per second
-PAL and SECAM标准用50i fps,等于25帧每秒。
隔行扫描(progressive)帧率是24p,25p和30p,用在电影工业上。现在较新的帧率是50p/60p用在高档的HDTV产品上。
2.帧率设置
使用-r选项
语法是:
ffmpeg -i input -r fps output
例如:
ffmpeg -i input.avi -r 30 output.mp4
使用fps filter
另一个设置帧率是用fps filter,特别是在filterchains使用时非常有用
例如:修改输入文件的帧率到25
ffmpeg -v clip.mpg -vf fps=fps=25 clip.webm
对帧率预定义值
例如:设置帧率29.97fps
3.比特率设置
比特率也是一个决定音视频总体质量的参数。他决定每个时间单位处理的bit数。
设置比特率:
比特率决定处理1s的编码流需要多少bits,设置用-b选项。区分音视频用-b:a和-b:v
例如:设置整体1.5Mbit每秒
ffmpeg -i file.avi -b 1.5M file.mp4
ffmpeg -i input.avi -b:v 1500K output.mp4
CBR设置:
CBR设置一般用作直播流,比如视频会议。为输出设置CBR,有三个参数必须设置为同一个值。
bitrate(-b option), minimal rate(-minrate), maximal rate(-maxrate)。maximal rate需要设置-bufsize选项。例如设置CBR为0.5Mbit/s。
ffmpeg -i in.avi -b 0.5M -minrate 0.5M -maxrate 0.5M -bufsize 1M output.mkv
设置输出文件的最大size。
用-fs选项。
例如设置输出文件的最大的size为10M
ffmpeg -i input.avi -fs 10MB output.mp4
文件大小计算:
文件的大小是是音视频流大小的和。
视频流的大小的方程式是(除以8是由bits到bytes的转换):
video_size = video_bitrate * time_in_seconds / 8;
如果音频是解压缩的,计算公式是:
audio_size = smpaling_rate * bit_depth * channels * time_in_second / 8;
例如:计算10分钟的视频, 1500kbits/s 视频比特率和 128kbits/s的音频比特率,用下面的计算方法:
file_size = video_size + audio_size;
file_size = (video_bitrate + audio_bitrate) * time_in_seconds / 8;
file_size = (1500 kbits/s + 128kbits/s) * 600s
file_size = 1628kbits/s * 600s
file_size = 976800kb = 976800000 b / 8 = 122100000 B / 1024 = 119238.28125KB
file_size = 119238.28125 KB / 1024 = 116.443634033203125MB = 116.44M
./ffmpeg -f image2 -i ../jpg/%02d.jpg -vcodec libx264 -s 1920x1080 multi_jpg2.mp4
查看视频信息:
# ./mp4info multi_jpg2.mp4
/home/tarena/project/mp4v2/mp4v2-2.0.0/.libs/lt-mp4info version 2.0.0
multi_jpg2.mp4:
Track Type Info
1 video H264 Unknown Profile f4@4, 3.160 secs, 32411 kbps, 1920x1080 @ 25.000000 fps
Encoded with: Lavf57.71.100