现在最新的FFMPEG 他自带有音频和视频解码的库,可能是因为版权的一些问题,它没有自带编码音频和视频的库,另外,如果需要使用ffplay 进行视频播放,还需要安装SDL。下面介绍在linux 下,以H264 和 MP3 视音频编码 SDL显示为例的安装。
1、下载最新的安装代码。
LAME 音频编码:http://lame.sourceforge.net/download.php
X264 视频编码 :http://www.videolan.org/developers/x264.html
SDL 显示库: http://www.libsdl.org/download-2.0.php
FFMPEG : http://www.ffmpeg.org/download.html
2、 安装MP3编码库
./configure
make
make install
3、安装X264视频编码库
./configure --enable-shared
make
make install
如果安装过程中提示yasm版本过低,可以使用 ./configure --enable-shared --disable-asm 关闭yasm,然后再安装。也可以自己先升级yasm后再安装。
4、SDL显示安装
./configure
make
make install
5、安装FFMPEG
./configure --enable-libmp3lame --enable-libx264 --enable-gpl
make
make install
安装测试:
可以使用下面命令进行测试编解码:
ffmpeg -i Forrest_Gump_IMAX.mp4 -vcodec libx264 -b:v 1200k -r 25 -acodec mp3 -ab 128k -ar 44100 output.mp4
编解码信息:
Forrest_Gump_IMAX.mp4 Makefile test test.avi transcoding.c transcoding.o Warcraft3_End.avi
licaibiao@ubuntu:~/test/FFMPEG/examples$ ffmpeg -i Forrest_Gump_IMAX.mp4 -vcodec libx264 -b:v 1200k -r 25 -acodec mp3 -ab 128k -ar 44100 output.mp4
ffmpeg version 3.2.4 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
configuration: --enable-libmp3lame --enable-libx264 --enable-gpl --enable-shared --disable-yasm
libavutil 55. 34.101 / 55. 34.101
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.101 / 57. 56.101
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Forrest_Gump_IMAX.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.19.100
Duration: 00:00:31.21, start: -0.013061, bitrate: 878 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x352, 748 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
[libx264 @ 0xdb7040] using cpu capabilities: none!
[libx264 @ 0xdb7040] profile High, level 3.0
[libx264 @ 0xdb7040] 264 - core 148 r2762 90a61ec - 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=-2 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=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=1200 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.56.101
Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x352, q=-1--1, 1200 kb/s, 25 fps, 12800 tbn, 25 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc57.64.101 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/1200000 buffer size: 0 vbv_delay: -1
Stream #0:1(und): Audio: mp3 (libmp3lame) (i[0][0][0] / 0x0069), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc57.64.101 libmp3lame
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
frame= 776 fps= 15 q=21.0 Lsize= 4966kB time=00:00:31.21 bitrate=1303.1kbits/s dup=32 drop=0 speed=0.597x
video:4448kB audio:488kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.592174%
[libx264 @ 0xdb7040] frame I:20 Avg QP:12.04 size: 31577
[libx264 @ 0xdb7040] frame P:249 Avg QP:16.40 size: 10618
[libx264 @ 0xdb7040] frame B:507 Avg QP:19.30 size: 2523
[libx264 @ 0xdb7040] consecutive B-frames: 6.2% 14.9% 15.5% 63.4%
[libx264 @ 0xdb7040] mb I I16..4: 35.2% 18.1% 46.7%
[libx264 @ 0xdb7040] mb P I16..4: 5.6% 8.1% 4.2% P16..4: 29.1% 14.9% 9.8% 0.0% 0.0% skip:28.3%
[libx264 @ 0xdb7040] mb B I16..4: 0.5% 0.7% 0.5% B16..8: 30.5% 6.3% 2.7% direct: 3.6% skip:55.0% L0:46.7% L1:39.4% BI:13.9%
[libx264 @ 0xdb7040] final ratefactor: 16.45
[libx264 @ 0xdb7040] 8x8 transform intra:37.3% inter:44.7%
[libx264 @ 0xdb7040] coded y,uvDC,uvAC intra: 53.5% 56.6% 26.9% inter: 17.0% 15.4% 1.8%
[libx264 @ 0xdb7040] i16 v,h,dc,p: 44% 33% 11% 11%
[libx264 @ 0xdb7040] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 13% 32% 21% 4% 6% 5% 7% 5% 7%
[libx264 @ 0xdb7040] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 32% 14% 5% 7% 7% 8% 6% 8%
[libx264 @ 0xdb7040] i8c dc,h,v,p: 50% 32% 11% 6%
[libx264 @ 0xdb7040] Weighted P-Frames: Y:24.1% UV:20.1%
[libx264 @ 0xdb7040] ref P L0: 60.8% 20.7% 14.7% 3.5% 0.3%
[libx264 @ 0xdb7040] ref B L0: 88.1% 10.3% 1.6%
[libx264 @ 0xdb7040] ref B L1: 98.3% 1.7%
[libx264 @ 0xdb7040] kb/s:1173.84
显示测试:
执行 ffplay output.mp4 效果如下:
====================2016.06.12日更新===========================
SDL2 安装后,运行程序当调用SDL_OpenAudio出现SDL_OpenAudio: No such audio device 的错误
需要进行下面的操作:
sudo apt-get install xorg-dev
sudo apt-get build-dep xscreensaver vlc totem
sudo apt-get source xscreensaver totem -b
./configure
make
sudo make install
cd test
./configure
make
./testmultiaudio
正常时,运行SDL2自带的测试程序testmultiaudio 可以听到声音,表示设备和SDL2安装成功。