一、问题背景
今天上班时,收到华为那边咨询邮件:
分别使用华为新平台手机、老平台手机 各一台,在同一台车机上投屏HICAR ,
同样是H264编码,1920×720的视频数据,
新平台手机编码的视频,在车机上解码的时间在 20ms 以内,
老平台手机编码的视频,在车机上解码的时间有些帧超过100ms。
同步提供了新老平台的 es 流数据。
二、分析
1. 使用 pplay 播放 ES 流数据
命令: ffplay new_platform_fast.es
播放 新平台,解码速度快的 es流数据:
ciellee@sh:~/Desktop/解码速度慢$ ffplay new_platform_fast.es
ffplay version 2.8.6-1ubuntu2 Copyright (c) 2003-2016 the FFmpeg developers
built with gcc 5.3.1 (Ubuntu 5.3.1-11ubuntu1) 20160311
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
Input #0, h264, from 'new_platform_fast.es': 0KB sq= 0B f=0/0
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (Constrained Baseline), yuv420p, 1920x720, 25 fps, 25 tbr, 1200k tbn, 50 tbc
nan M-V: nan fd= 0 aq= 0KB vq= 0KB sq= 0B f=0/0
播放 老平台,解码速度慢的 es流数据:
ciellee@sh:~/Desktop/解码速度慢$ ffplay old_platform_low.es
ffplay version 2.8.6-1ubuntu2 Copyright (c) 2003-2016 the FFmpeg developers
built with gcc 5.3.1 (Ubuntu 5.3.1-11ubuntu1) 20160311
libavutil 54. 31.100 / 54. 31.100
libavcodec 56. 60.100 / 56. 60.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 40.101 / 5. 40.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
libpostproc 53. 3.100 / 53. 3.100
Input #0, h264, from 'old_platform_low.es': 0KB sq= 0B f=0/0
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (Baseline), yuv420p(tv, unknown/bt470bg/unknown), 1920x720, 25 fps, 25 tbr, 1200k tbn, 50 tbc
nan M-V: nan fd= 0 aq= 0KB vq= 119KB sq= 0B f=0/0
分别播放两视频,从视频来看画面都是差不多的。
但从 输出信息,就看到差异了:
播放 新平台,解码速度快的 es流数据:
Stream #0:0: Video: h264 (Constrained Baseline), yuv420p, 1920x720, 25 fps, 25 tbr, 1200k tbn, 50 tbc
播放 老平台,解码速度慢的 es流数据:
Stream #0:0: Video: h264 (Baseline), yuv420p(tv, unknown/bt470bg/unknown), 1920x720, 25 fps, 25 tbr, 1200k tbn, 50
可以看出,视频渲染方式分别是 yuv420p 、yuv420p(tv, unknown/bt470bg/unknown)。
可以看出,老平台中,渲染参数使用了 yuv420p(bt470bg) ,显示的色彩更丰富,解码时间相对长一些是正常的。
而新平台则是渲染数据格式为 yuv420p (undef) 即原色,解码相对快些。
渲染数据格式包括, undef, bt709, bt470m, bt470bg 。
如果一定要两平台效果一样,则修改两华为手机平台渲染参数改为一致即可。
2. 使用 ffprobe -show_format 查看es 流信息
可以看出,信息其实和上面差不多:
新平台,解码速度快的 es流数据:
ciellee@sh:~/Desktop/解码速度慢$ ffprobe -show_format new_platform_fast.es
ffprobe version 2.8.6-1ubuntu2 Copyright (c) 2007-2016 the FFmpeg developers
built with gcc 5.3.1 (Ubuntu 5.3.1-11ubuntu1) 20160311
Input #0, h264, from 'new_platform_fast.es':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (Constrained Baseline), yuv420p, 1920x720, 25 fps, 25 tbr, 1200k tbn, 50 tbc
[FORMAT]
filename=new_platform_fast.es
nb_streams=1
nb_programs=0
format_name=h264
format_long_name=raw H.264 video
start_time=N/A
duration=N/A
size=2853061
bit_rate=N/A
probe_score=51
[/FORMAT]
老平台,解码速度慢的 es流数据:
ciellee@sh:~/Desktop/解码速度慢$ ffprobe -show_format old_platform_low.es
ffprobe version 2.8.6-1ubuntu2 Copyright (c) 2007-2016 the FFmpeg developers
built with gcc 5.3.1 (Ubuntu 5.3.1-11ubuntu1) 20160311
Input #0, h264, from 'old_platform_low.es':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (Baseline), yuv420p(tv, unknown/bt470bg/unknown), 1920x720, 25 fps, 25 tbr, 1200k tbn, 50 tbc
[FORMAT]
filename=old_platform_low.es
nb_streams=1
nb_programs=0
format_name=h264
format_long_name=raw H.264 video
start_time=N/A
duration=N/A
size=13061262
bit_rate=N/A
probe_score=51
[/FORMAT]
关于什么是ES数据流,本文就不赘述了,网上有更详细的文章:
《关于ES、PES、PS以及TS码流》
《H.264代码详解全过程》
《 X264参数设定详细解释》