项目源码
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视频压缩(附源码下载)的更多相关文章

  1. Android中Canvas绘图基础详解(附源码下载) (转)

    Android中Canvas绘图基础详解(附源码下载) 原文链接  http://blog.csdn.net/iispring/article/details/49770651   AndroidCa ...

  2. arcgis api 4.x for js 自定义 Draw 绘制手绘面以及手绘线,只针对二维视图(附源码下载)

    前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 4.x for js:esri 官网 api,里面详细的介绍 arcgis api 4.x 各个类 ...

  3. Android 音视频深入 二十一 FFmpeg视频剪切

    视频剪切我意外的发现上一次的视频压缩的代码能够运行FFmpeg视频剪切的命令,但是不能做视频合并的命令,因为不能读取记录了几个视频的路径的txt文件. 这里我就说直说视频剪切的过程,不说代码,只说lo ...

  4. Android Paint的使用以及方法介绍(附源码下载)

    要绘图,首先得调整画笔,待画笔调整好之后,再将图像绘制到画布上,这样才可以显示在手机屏幕上.Android 中的画笔是 Paint类,Paint 中包含了很多方法对其属性进行设置,主要方法如下: se ...

  5. wpf 模拟抖音很火的罗盘时钟,附源码,下载就能跑

    wpf 模拟抖音很火的罗盘时钟,附源码 前端时间突然发现,抖音火了个壁纸,就是黑底蕾丝~~~  错错错,黑底白字的罗盘时钟! 作为程序员的我,也觉得很新颖,所以想空了研究下,这不,空下来了就用wpf, ...

  6. android Activity实现底部滑动弹出窗口及源码下载地址

    在做微信.微博.qq等分享时,一般是点击分享按钮后会从底部弹出滑动窗口,然后选择要分享的社交平台进行分享.今日头条.腾讯新闻等内容App的评论也是从底部滑动弹出输入窗口,进行评论输入的.本篇文章就讲讲 ...

  7. 照片管家iOS-实现本地相册、视频、安全保护、社交分享源码下载Demo

    <照片管家> APP功能: 1.本地照片批量导入与编辑 2.本地视频存储与播放 3.手势密码.数字密码.TouchID安全保护 4.QQ.微信.微博.空间社交分享 5.其他细节功能. 运用 ...

  8. Android 音视频深入 十六 FFmpeg 推流手机摄像头,实现直播 (附源码下载)

    源码地址https://github.com/979451341/RtmpCamera/tree/master 配置RMTP服务器,虽然之前说了,这里就直接粘贴过来吧 1.配置RTMP服务器 这个我不 ...

  9. Android 音视频深入 十五 FFmpeg 推流mp4文件(附源码下载)

    源码地址https://github.com/979451341/Rtmp 1.配置RTMP服务器 这个我不多说贴两个博客分别是在mac和windows环境上的,大家跟着弄 MAC搭建RTMP服务器h ...

随机推荐

  1. 登录获取session

  2. line-height应用实例

    实例1:图片水平垂直居中 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  3. ASP.NET - Validators

    ASP.NET validation controls validate the user input data to ensure that useless, unauthenticated, or ...

  4. docker入门实例

    Docker 是什么? 我们在理解 Docker 之前,首先得先区分清楚两个概念,容器和虚拟机. 每台虚拟机都需要有自己的操作系统,虚拟机一旦被开启,预分配给它的资源将全部被占用. 每一台虚拟机包括应 ...

  5. Groovy 语法学习

    一.配置 Groovy 环境: 下载 Groovy(Groovy 依赖 Java,所以需要 JDK 环境):http://www.groovy-lang.org/download.html 配置环境变 ...

  6. 常量(constant)

    在java语言中,主要用final来定义一个常量.常量一旦被初始化不能更改其值. 常量:大写字母和下划线:MAX_VALUE final double PI = 3.14; PI = 3.15;//编 ...

  7. javascript 删除 url 中指定参数,并返回 url

    // 删除url中某个参数,并跳转function funcUrlDel(name){ var loca = window.location; var baseUrl = loca.origin + ...

  8. GIT导出差异版本更新的文件列表

    之前写了一篇SVN导出差异版本更新的文件列表 这次写git如何导出差异化版本文件列表 查找了一番,发现git diff这个命令 $ git diff 2da595c daea1d6 --name-on ...

  9. 第 9 章 数据管理 - 075 - 配置 VirtualBox backend

    配置 VirtualBox backend 在 VirtualBox 宿主机上启动 vboxwebsrv 服务: C:\Program Files\Oracle\VirtualBox > VBo ...

  10. IDEA永久激活方法

    Idea版本:2018.1.5 准备工作: 1.安装,从官网下载安装,点击进去之后,进行选择需要的版本 2.下载破解包: 链接:https://pan.baidu.com/s/1lCb0MGetP1_ ...