sudo apt-get update
sudo apt-get install ffmpeg
1. 将mkv转mp4
a. h264格式的mkv:
ffmpeg -i example.mkv -acodec copy -vcodec copy example.mp4
b. vp8格式的mkv:
ffmpeg -i test.mkv -b 800k -acodec libfaac -vcodec libx264 out.mp4
如果失败可以使用:
ffmpeg -i test.mkv -b 800k -c:a aac -strict experimental -c:v libx264 out.mp4
log:
ffmpeg version 2.7.2-1~trusty Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
configuration: --prefix=/usr --extra-version='1~trusty' --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --enable-shared --disable-stripping --enable-avresample --enable-avisynth --enable-frei0r --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-openal --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libxvid --enable-libzvbi --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-libssh --enable-libsoxr --enable-libx264 --enable-libopencv --enable-libx265
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, matroska,webm, from 'test.mkv':
Metadata:
ENCODER : Lavf56.1.0
Duration: 00:00:30.57, start: 0.000000, bitrate: 898 kb/s
Stream #0:0: Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 29.92 tbr, 1k tbn, 1k tbc
Stream #0:1: Audio: pcm_mulaw ([7][0][0][0] / 0x0007), 8000 Hz, 1 channels, s16, 64 kb/s
Please use -b:a or -b:v, -b is ambiguous
[libx264 @ 0x1324d20] using SAR=1/1
[libx264 @ 0x1324d20] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0x1324d20] profile High, level 3.0
[libx264 @ 0x1324d20] 264 - core 142 r2389 956c8d8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - 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=6 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=800 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[aac @ 0x12bf960] Too many bits per frame requested, clamping to max
Output #0, mp4, to 'out.mp4':
Metadata:
encoder : Lavf56.36.100
Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x480 [SAR 1:1 DAR 4:3], q=-1--1, 800 kb/s, 29.92 fps, 11488 tbn, 29.92 tbc
Metadata:
encoder : Lavc56.41.100 libx264
Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 8000 Hz, mono, fltp, 48 kb/s
Metadata:
encoder : Lavc56.41.100 aac
Stream mapping:
Stream #0:0 -> #0:0 (vp8 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (pcm_mulaw (native) -> aac (native))
Press [q] to stop, [?] for help
Input stream #0:0 frame changed from size:640x480 fmt:yuv420p to size:600x800 fmt:yuv420p
Input stream #0:0 frame changed from size:600x800 fmt:yuv420p to size:450x600 fmt:yuv420p drop=0
frame= 916 fps=125 q=-1.0 Lsize= 3012kB time=00:00:30.59 bitrate= 806.5kbits/s dup=244 drop=0
video:2840kB audio:156kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.509654%
[libx264 @ 0x1324d20] frame I:4 Avg QP:20.77 size: 28864
[libx264 @ 0x1324d20] frame P:365 Avg QP:23.97 size: 6587
[libx264 @ 0x1324d20] frame B:547 Avg QP:29.28 size: 709
[libx264 @ 0x1324d20] consecutive B-frames: 13.4% 8.5% 37.0% 41.0%
[libx264 @ 0x1324d20] mb I I16..4: 9.4% 57.9% 32.7%
[libx264 @ 0x1324d20] mb P I16..4: 1.2% 4.5% 0.5% P16..4: 31.1% 13.9% 7.6% 0.0% 0.0% skip:41.2%
[libx264 @ 0x1324d20] mb B I16..4: 0.1% 0.2% 0.0% B16..8: 29.8% 2.1% 0.3% direct: 0.6% skip:66.9% L0:42.4% L1:52.0% BI: 5.6%
[libx264 @ 0x1324d20] final ratefactor: 22.77
[libx264 @ 0x1324d20] 8x8 transform intra:70.2% inter:56.3%
[libx264 @ 0x1324d20] coded y,uvDC,uvAC intra: 55.7% 57.9% 18.6% inter: 11.4% 5.5% 0.2%
[libx264 @ 0x1324d20] i16 v,h,dc,p: 6% 42% 5% 47%
[libx264 @ 0x1324d20] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 12% 37% 15% 3% 7% 5% 10% 3% 7%
[libx264 @ 0x1324d20] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 15% 40% 13% 2% 6% 7% 7% 2% 7%
[libx264 @ 0x1324d20] i8c dc,h,v,p: 52% 35% 9% 5%
[libx264 @ 0x1324d20] Weighted P-Frames: Y:1.4% UV:0.3%
[libx264 @ 0x1324d20] ref P L0: 62.5% 15.3% 14.9% 7.3% 0.0%
[libx264 @ 0x1324d20] ref B L0: 86.6% 11.5% 1.9%
[libx264 @ 0x1324d20] ref B L1: 93.0% 7.0%
[libx264 @ 0x1324d20] kb/s:759.70
2.推流测试
ffmpeg -re -i xxx.mpeg -vcodec libx264 -acodec libfaac -f flv rtmp://xx.xx.xx.xx/live/test
控制码率加 -b 800k
控制分辨率加 -s 1280x720