1. 程式人生 > >Android 音視頻深入 二十 FFmpeg視頻壓縮

Android 音視頻深入 二十 FFmpeg視頻壓縮

FFmpeg 視頻壓縮

項目源碼
https://github.com/979451341/FFmpegCompress

   這個視頻壓縮是通過類似在mac終端上輸入FFmpeg命令來完成,意思是我們需要在Android上達到能夠執行FFmpeg命令。其實做到這一點還比較容易,這一次重在說說這壓縮過程,不是看代碼運行過程,通過log來觀察代碼運行的結果。

1.首先普及一下相關專業名詞

  視頻尺寸:指的就是視頻的分辨率,常見的分辨率有4096*2304,1920*1080,720*576等。

  視頻編碼:視頻編碼方式就是指通過特定的壓縮技術,將某個視頻格式的文件轉換成另一種視頻格式文件的方式。視頻編碼格式常見到的有:MPEG-2 TS、Divx、Xvid、H.264、WMV-HD和VC-1。

  音頻編碼:音頻編碼方式指通過特定的壓縮技術對音頻數據進行處理的方法。

  幀率:幀率(即視頻更新率)是用於測量顯示幀數的量度。測量單位為“每秒顯示幀數”(Frame Per Second,FPS,幀率)或“赫茲”,單位用FPS用來描述視頻每秒播放多少幀,而單位用赫茲用來描述顯示器的畫面每秒更新多少次。 一般幀率越高,視頻畫面越流暢。

  比特率:指每秒傳送的比特(bit)數,即每秒傳輸的文件大小。比特率規定使用“比特每秒”(bit/s 或 bps)為單位。比特率越高,每秒傳送的數據越大。

  采樣率:采樣率的單位是Hz,表示每秒采樣的次數。單位時間內取樣率越大,精度就越高,處理過的視頻文件就越接近沒有處理過的視頻文件。

  碼率:碼率就是數據傳輸時單位時間傳送的數據位數,一般我們用的單位是kbps即千位每秒。碼率與體積成正比:碼率越大,體積越大;碼率越小,體積越小。由於文件體積與取樣率是成正比的,所以幾乎所有的編碼格式都想用最低的碼率達到最少的失真,“碼率”就是失真度,碼率越高越清晰,反之則畫面粗糙而且馬賽克多。

  視頻部分的位深度:用於指定圖像中的每個像素可以使用的顏色信息數量,用“位即bit”為單位。

  音頻部分的位深度:單個聲道的采樣數據大小

2.執行FFmpeg的壓縮命令

首先執行這個FFmpeg命令是在FFmpeg源碼fftools文件夾下的ffmpeg.c的main函數來完成的,所以我們只用把命令傳入這個main函數就可以了,然後需要註意的是他中途出現錯誤會使用exit_program(int)這個函數,如果我們直接使用main函數,調用了這個函數程序會直接被結束,所以我們需要在JNI層開啟子線程來執行main函數。

然後就是在Android裏運行這個main函數需要一些其他的在fftools文件夾下的文件才能編譯成功,這裏大家使用我的項目源碼就可以了

現在需要在java層準備壓縮命令了

                int ret = FFmpegNativeBridge.runCommand(new String[]{"ffmpeg",
                        "-i", et_input.getText().toString(),
                        "-y",
                        "-c:v", "libx264",
                        "-c:a", "aac",
                        "-vf", "scale=-2:640",
                        "-preset", "ultrafast",
                        "-b:v", "450k",
                        "-b:a", "96k",
                        et_output.getText().toString()});

說一下這個命令的含義,不過這個時候我們看看log裏說了啥

開始分割命令行
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Splitting the commandline.

讀取輸入文件url

03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Reading option ‘-i‘ ...
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: matched as input url with argument ‘/storage/emulated/0/pauseRecordDemo/video/video.mp4‘.

當已存在輸出路徑文件,不提示是否覆蓋。

03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Reading option ‘-y‘ ...
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: matched as option ‘y‘ (overwrite output files) with argument ‘1‘.

設置視頻編碼器

03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Reading option ‘-c:v‘ ...
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: matched as option ‘c‘ (codec name) with argument ‘libx264‘.

設置音頻編碼器

03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Reading option ‘-c:a‘ ...
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: matched as option ‘c‘ (codec name) with argument ‘aac‘.

設置輸出視頻尺寸

03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Reading option ‘-vf‘ ...
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: matched as option ‘vf‘ (set video filters) with argument ‘scale=-2:640‘.

配置AVOption轉碼速率為快速

03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Reading option ‘-preset‘ ...
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: matched as AVOption ‘preset‘ with argument ‘ultrafast‘.

配置視頻碼率為450k

03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Reading option ‘-b:v‘ ...
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: matched as option ‘b‘ (video bitrate (please use -b:v)) with argument ‘450k‘.

配置音頻碼率為96k

03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Reading option ‘-b:a‘ ...
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: matched as option ‘b‘ (video bitrate (please use -b:v)) with argument ‘96k‘.

讀取輸出文件路徑

03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Reading option ‘/storage/emulated/0/pauseRecordDemo/video/compress4.mp4‘ ...
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: matched as output url.
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Finished splitting the commandline.

開始解析命令,並打開被壓縮的文件

03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Parsing a group of options: global .
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Applying option y (overwrite output files) with argument 1.
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Successfully parsed a group of options.
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Parsing a group of options: input url /storage/emulated/0/pauseRecordDemo/video/video.mp4.
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Successfully parsed a group of options.
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Opening an input file: /storage/emulated/0/pauseRecordDemo/video/video.mp4.
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Opening ‘/storage/emulated/0/pauseRecordDemo/video/video.mp4‘ for reading
03-10 10:35:29.541 30750-30822/org.voiddog.ffmpeg D/TAG: Setting default whitelist ‘file,crypto‘
03-10 10:35:29.542 30750-30822/org.voiddog.ffmpeg D/TAG: Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
03-10 10:35:29.542 30750-30822/org.voiddog.ffmpeg D/TAG: ISO: File Type Major Brand: mp42
03-10 10:35:29.542 30750-30822/org.voiddog.ffmpeg D/TAG: Unknown dref type 0x206c7275 size 12

stts和ctts是 MOVStreamContext 結構體的成員變量,MOVStreamContext結構用於保存從mov或mp4中進行拆包解復用從頭部得到的信息。我也不太懂

03-10 10:35:29.568 30750-30822/org.voiddog.ffmpeg D/TAG: stts: 2668915 ctts: 18769, ctts_index: 649, ctts_count: 699
03-10 10:35:29.568 30750-30822/org.voiddog.ffmpeg D/TAG: stts: 2672669 ctts: 7508, ctts_index: 650, ctts_count: 699
03-10 10:35:29.568 30750-30822/org.voiddog.ffmpeg D/TAG: stts: 2676423 ctts: 0, ctts_index: 651, ctts_count: 699
03-10 10:35:29.568 30750-30822/org.voiddog.ffmpeg D/TAG: stts: 2680177 ctts: 3753, ctts_index: 652, ctts_count: 699
03-10 10:35:29.568 30750-30822/org.voiddog.ffmpeg D/TAG: stts: 2683930 ctts: 18769, ctts_index: 653, ctts_count: 699

獲得輸入視頻幀率

03-10 10:35:29.570 30750-30822/org.voiddog.ffmpeg D/TAG: rfps: 23.976024 0.000000
03-10 10:35:29.570 30750-30822/org.voiddog.ffmpeg D/TAG: rfps: 23.976024 0.000000
03-10 10:35:29.570 30750-30822/org.voiddog.ffmpeg D/TAG: rfps: 47.952048 0.000000
03-10 10:35:29.570 30750-30822/org.voiddog.ffmpeg D/TAG: rfps: 47.952048 0.000000
03-10 10:35:29.571 30750-30822/org.voiddog.ffmpeg D/TAG: Before avformat_find_stream_info() pos: 7467210 bytes read:60806 seeks:1 nb_streams:2

獲取輸入視頻的信息,比如尺寸、播放位置等。

03-10 10:35:29.678 30750-30822/org.voiddog.ffmpeg D/TAG: Parsing MediaFormat {image-data=java.nio.HeapByteBuffer[pos=0 lim=104 cap=104], mime=video/raw, crop-top=0, crop-right=1279, slice-height=720, color-format=21, height=720, width=1280, crop-bottom=719, crop-left=0, stride=1280}
03-10 10:35:29.678 30750-30822/org.voiddog.ffmpeg I/TAG: Output crop parameters top=0 bottom=719 left=0 right=1279, resulting dimensions width=1280 height=720
03-10 10:35:29.678 30750-30822/org.voiddog.ffmpeg D/TAG: MediaCodec 0xe4732080 started successfully
03-10 10:35:29.678 30750-30822/org.voiddog.ffmpeg I/TAG: MediaCodec started successfully, ret = 0

獲取輸入視頻文件的信息,知道了輸入文件的格式、碼率、時長、比特率等

03-10 10:35:29.706 30750-30822/org.voiddog.ffmpeg D/TAG: After avformat_find_stream_info() pos: 1343 bytes read:93574 seeks:2 frames:4
03-10 10:35:29.706 30750-30822/org.voiddog.ffmpeg I/TAG: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ‘/storage/emulated/0/pauseRecordDemo/video/video.mp4‘:
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: Metadata:
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: major_brand :
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: mp42
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: minor_version :
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: 512
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: compatible_brands:
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: isomiso2avc1mp41
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: encoder :
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: HandBrake 0.10.0 2014112200
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: Duration:
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: 00:00:31.81
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: , start:
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: 0.083000
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: , bitrate:
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: 1878 kb/s
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: Stream #0:0
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: (und)
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg D/TAG: , 3, 1/90000
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: : Video: h264 (avc1 / 0x31637661), nv12, 1280x720, 1728 kb/s
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: ,
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: 23.98 fps,
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: 23.98 tbr,
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: 90k tbn,
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: 90k tbc
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: (default)
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: Metadata:
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: handler_name :
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: VideoHandler
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: Stream #0:1
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: (und)
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg D/TAG: , 1, 1/48000
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: : Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 146 kb/s
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: (default)
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: Metadata:
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: handler_name :
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg I/TAG: Stereo
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg D/TAG: Successfully opened the file.

創建並配置輸出視頻文件

03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg D/TAG: Parsing a group of options: output url /storage/emulated/0/pauseRecordDemo/video/compress4.mp4.
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg D/TAG: Applying option c:v (codec name) with argument libx264.
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg D/TAG: Applying option c:a (codec name) with argument aac.
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg D/TAG: Applying option vf (set video filters) with argument scale=-2:640.
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg D/TAG: Applying option b:v (video bitrate (please use -b:v)) with argument 450k.
03-10 10:35:29.707 30750-30822/org.voiddog.ffmpeg D/TAG: Applying option b:a (video bitrate (please use -b:v)) with argument 96k.
03-10 10:35:29.708 30750-30822/org.voiddog.ffmpeg D/TAG: Successfully parsed a group of options.
03-10 10:35:29.708 30750-30822/org.voiddog.ffmpeg D/TAG: Opening an output file: /storage/emulated/0/pauseRecordDemo/video/compress4.mp4.
03-10 10:35:29.710 30750-30822/org.voiddog.ffmpeg D/TAG: Setting default whitelist ‘file,crypto‘
03-10 10:35:29.711 30750-30822/org.voiddog.ffmpeg D/TAG: Successfully opened the file.
03-10 10:35:29.711 30750-30822/org.voiddog.ffmpeg D/TAG: nal_unit_type: 7, nal_ref_idc: 3

獲取編碼器

03-10 10:35:29.748 30750-30822/org.voiddog.ffmpeg D/TAG: Parsing MediaFormat {image-data=java.nio.HeapByteBuffer[pos=0 lim=104 cap=104], mime=video/raw, crop-top=0, crop-right=1279, slice-height=720, color-format=21, height=720, width=1280, crop-bottom=719, crop-left=0, stride=1280}
03-10 10:35:29.748 30750-30822/org.voiddog.ffmpeg I/TAG: Output crop parameters top=0 bottom=719 left=0 right=1279, resulting dimensions width=1280 height=720
03-10 10:35:29.748 30750-30822/org.voiddog.ffmpeg D/TAG: MediaCodec 0xe4732200 started successfully
03-10 10:35:29.748 30750-30822/org.voiddog.ffmpeg I/TAG: MediaCodec started successfully, ret = 0
03-10 10:35:29.749 30750-30822/org.voiddog.ffmpeg I/TAG: Stream mapping:
03-10 10:35:29.749 30750-30822/org.voiddog.ffmpeg I/TAG: Stream #0:0 -> #0:0
03-10 10:35:29.749 30750-30822/org.voiddog.ffmpeg I/TAG: (h264 (h264_mediacodec) -> h264 (libx264))
03-10 10:35:29.749 30750-30822/org.voiddog.ffmpeg I/TAG: Stream #0:1 -> #0:1
03-10 10:35:29.749 30750-30822/org.voiddog.ffmpeg I/TAG: (aac (native) -> aac (native))

還是配置輸出文件格式信息

03-10 10:35:29.858 30750-30822/org.voiddog.ffmpeg I/TAG: Output MediaFormat changed to {image-data=java.nio.HeapByteBuffer[pos=0 lim=104 cap=104], mime=video/raw, crop-top=0, crop-right=1279, slice-height=720, color-format=21, height=720, width=1280, crop-bottom=719, crop-left=0, stride=1280}
03-10 10:35:29.858 30750-30822/org.voiddog.ffmpeg D/TAG: Parsing MediaFormat {image-data=java.nio.HeapByteBuffer[pos=0 lim=104 cap=104], mime=video/raw, crop-top=0, crop-right=1279, slice-height=720, color-format=21, height=720, width=1280, crop-bottom=719, crop-left=0, stride=1280}
03-10 10:35:29.858 30750-30822/org.voiddog.ffmpeg I/TAG: Output crop parameters top=0 bottom=719 left=0 right=1279, resulting dimensions width=1280 height=720
03-10 10:35:29.859 30750-30822/org.voiddog.ffmpeg D/TAG: cur_dts is invalid (this is harmless if it occurs once at the start per stream)
03-10 10:35:29.860 30750-30822/org.voiddog.ffmpeg D/TAG: cur_dts is invalid (this is harmless if it occurs once at the start per stream)
03-10 10:35:29.862 30750-30822/org.voiddog.ffmpeg D/TAG: cur_dts is invalid (this is harmless if it occurs once at the start per stream)
03-10 10:35:29.863 30750-30822/org.voiddog.ffmpeg D/TAG: Got output buffer 0 offset=0 size=1382400 ts=0 flags=0
03-10 10:35:29.865 30750-30822/org.voiddog.ffmpeg D/TAG: Frame: width=1280 stride=1280 height=720 slice-height=720 crop-top=0 crop-bottom=719 crop-left=0 crop-right=1279 encoder=OMX.IMG.MSVDX.Decoder.AVC
destination linesizes=1280,1280,0
03-10 10:35:29.878 30750-30822/org.voiddog.ffmpeg D/TAG: Setting ‘w‘ to value ‘-2‘
03-10 10:35:29.878 30750-30822/org.voiddog.ffmpeg D/TAG: Setting ‘h‘ to value ‘640‘
03-10 10:35:29.878 30750-30822/org.voiddog.ffmpeg D/TAG: Setting ‘flags‘ to value ‘bicubic‘
03-10 10:35:29.878 30750-30822/org.voiddog.ffmpeg V/TAG: w:-2 h:640 flags:‘bicubic‘ interl:0
03-10 10:35:29.878 30750-30822/org.voiddog.ffmpeg D/TAG: Setting ‘video_size‘ to value ‘1280x720‘
03-10 10:35:29.878 30750-30822/org.voiddog.ffmpeg D/TAG: Setting ‘pix_fmt‘ to value ‘25‘
03-10 10:35:29.879 30750-30822/org.voiddog.ffmpeg D/TAG: Setting ‘time_base‘ to value ‘1/90000‘
03-10 10:35:29.879 30750-30822/org.voiddog.ffmpeg D/TAG: Setting ‘pixel_aspect‘ to value ‘0/1‘
03-10 10:35:29.879 30750-30822/org.voiddog.ffmpeg D/TAG: Setting ‘sws_param‘ to value ‘flags=2‘
03-10 10:35:29.879 30750-30822/org.voiddog.ffmpeg D/TAG: Setting ‘frame_rate‘ to value ‘24000/1001‘
03-10 10:35:29.879 30750-30822/org.voiddog.ffmpeg V/TAG: w:1280 h:720 pixfmt:nv12 tb:1/90000 fr:24000/1001 sar:0/1 sws_param:flags=2
03-10 10:35:29.879 30750-30822/org.voiddog.ffmpeg D/TAG: compat: called with args=[yuv420p|yuvj420p|yuv422p|yuvj422p|yuv444p|yuvj444p|nv12|nv16|nv21]
03-10 10:35:29.879 30750-30822/org.voiddog.ffmpeg D/TAG: Setting ‘pix_fmts‘ to value ‘yuv420p|yuvj420p|yuv422p|yuvj422p|yuv444p|yuvj444p|nv12|nv16|nv21‘
03-10 10:35:29.881 30750-30822/org.voiddog.ffmpeg D/TAG: query_formats: 4 queried, 3 merged, 0 already done, 0 delayed
03-10 10:35:29.898 30750-30822/org.voiddog.ffmpeg V/TAG: w:1280 h:720 fmt:nv12 sar:0/1 -> w:1138 h:640 fmt:nv12 sar:0/1 flags:0x4

然後讀取輸入視頻文件的一幀數據,然後按碼率轉換數據

03-10 10:35:30.514 30750-30822/org.voiddog.ffmpeg D/TAG: Clipping frame in rate conversion by 0.000206
03-10 10:35:30.522 30750-30822/org.voiddog.ffmpeg D/TAG: cur_dts is invalid (this is harmless if it occurs once at the start per stream)
03-10 10:35:30.525 30750-30822/org.voiddog.ffmpeg D/TAG: cur_dts is invalid (this is harmless if it occurs once at the start per stream)
03-10 10:35:30.527 30750-30822/org.voiddog.ffmpeg D/TAG: cur_dts is invalid (this is harmless if it occurs once at the start per stream)

向輸出視頻文件寫入數據,並顯示相關數據,每一次編碼完成都統計一次

03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg I/TAG: video:1674kB audio:315kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead:
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg I/TAG: 0.846781%
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: Input file #0 (/storage/emulated/0/pauseRecordDemo/video/video.mp4):
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: Input stream #0:0 (video):
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: 761 packets read (6857052 bytes);
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: 761 frames decoded
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: ;
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: Input stream #0:1 (audio):
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: 1491 packets read (582072 bytes);
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: 1491 frames decoded
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: (1526784 samples)
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: ;
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: Total: 2252 packets (7439124 bytes) demuxed
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: Output file #0 (/storage/emulated/0/pauseRecordDemo/video/compress4.mp4):
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: Output stream #0:0 (video):
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: 761 frames encoded
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: ;
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: 761 packets muxed (1714451 bytes);
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: Output stream #0:1 (audio):
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: 1491 frames encoded
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: (1526784 samples)
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: ;
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: 1492 packets muxed (322676 bytes);
03-10 10:36:07.483 30750-30822/org.voiddog.ffmpeg V/TAG: Total: 2253 packets (2037127 bytes) muxed

最後輸出視頻編碼完成,得到相關yuv等數據

03-10 10:36:07.514 30750-30822/org.voiddog.ffmpeg D/TAG: 2252 frames successfully decoded, 0 decoding errors
03-10 10:36:07.516 30750-30822/org.voiddog.ffmpeg D/TAG: Statistics: 60 seeks, 2299 writeouts
03-10 10:36:07.516 30750-30822/org.voiddog.ffmpeg I/TAG: frame I:4 Avg QP:29.75 size: 10897
03-10 10:36:07.517 30750-30822/org.voiddog.ffmpeg I/TAG: frame P:757 Avg QP:33.43 size: 2206
03-10 10:36:07.517 30750-30822/org.voiddog.ffmpeg I/TAG: mb I I16..4: 100.0% 0.0% 0.0%
03-10 10:36:07.517 30750-30822/org.voiddog.ffmpeg I/TAG: mb P I16..4: 9.2% 0.0% 0.0% P16..4: 11.0% 0.0% 0.0% 0.0% 0.0% skip:79.8%
03-10 10:36:07.517 30750-30822/org.voiddog.ffmpeg I/TAG: final ratefactor: 36.31
03-10 10:36:07.517 30750-30822/org.voiddog.ffmpeg I/TAG: coded y,uvDC,uvAC intra: 7.9% 10.5% 3.0% inter: 2.6% 2.3% 0.1%
03-10 10:36:07.517 30750-30822/org.voiddog.ffmpeg I/TAG: i16 v,h,dc,p: 59% 22% 12% 8%
03-10 10:36:07.517 30750-30822/org.voiddog.ffmpeg I/TAG: i8c dc,h,v,p: 78% 11% 9% 2%
03-10 10:36:07.517 30750-30822/org.voiddog.ffmpeg I/TAG: kb/s:431.97
03-10 10:36:07.529 30750-30822/org.voiddog.ffmpeg I/TAG: Qavg: 11519.111
03-10 10:36:07.529 30750-30822/org.voiddog.ffmpeg D/TAG: Statistics: 7522283 bytes read, 2 seeks
03-10 10:36:07.531 30750-30821/org.voiddog.ffmpeg I/System.out: ret: 0, time: 37992

效果

參考文章
https://www.cnblogs.com/liusx0303/p/7572050.html
https://www.jianshu.com/p/ceaa286d8aff

Android 音視頻深入 二十 FFmpeg視頻壓縮