Now the latest FFMPEG has its own library for audio and video decoding, probably because of some copyright issues, it does not have its own library for encoding audio and video. In addition, if you need to use ffplay for video playback, you need to install SDL. The following introduces the installation under linux, taking H264 and MP3 video and audio encoding SDL display as an example.
1. Download the latest installation code.
LAME audio encoding: http://lame.sourceforge.net/download.php
X264 video encoding: http://www.videolan.org/developers/x264.html
SDL Display Library: http://www.libsdl.org/download-2.0.php
FFMPEG : http://www.ffmpeg.org/download.html
2. Install MP3 encoding library
./configure
make
make install
3. Install the X264 video encoding library
./configure --enable-shared
make
make install
If the yasm version is too low during the installation process, you can use ./configure --enable-shared --disable-asm to close yasm, and then install it again. You can also upgrade yasm first and then install it.
4. SDL display installation
./configure
make
make install
5. Install FFMPEG
./configure --enable-libmp3lame --enable-libx264 --enable-gpl
make
make install
Installation test:
You can use the following command to test the codec:
ffmpeg -i Forrest_Gump_IMAX.mp4 -vcodec libx264 -b:v 1200k -r 25 -acodec mp3 -ab 128k -ar 44100 output.mp4
Codec information:
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
Show test:
The effect of executing ffplay output.mp4 is as follows: