Android 音视频深入 二十 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

效果

Android 音视频深入 二十  FFmpeg视频压缩(附源码下载)

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

上一篇:关于sql server远程访问Oracle数据库 OpenQuery查询返回多条数据的问题


下一篇:Python函数的作用域规则和闭包