IOS播放器对播放文件要求比较严格,对于一些异常文件兼容性不是特别好,而且IOS播放器相对封闭,无法查看源代码或者看相关日志跟踪问题,所以定位IOS播放问题可谓是费时费力。本文就两个比较常见的案例进行分析,希望对大家分析IOS播放异常问题有所帮助。
现象:播放画面无卡顿,音频听起来有噪音,音频有卡顿感。
原因:音频时间戳混乱,存在误差,不严格对齐。可以使用如下代码进行分析
pktDuaraion = pkt.pts - last_pts; printf("**********************************************\n" "pts duration: %d, tb: 1/%d, msDuration: %f\n" "pkt duration: %d, tb: 1/%d, msDuration: %f\n" "cal duration: %d, tb: 1/%d, msDuration: %f\n", pktDuaraion, timeBase->den, float(pktDuaraion) / timeBase->den, pkt.duration, timeBase->den, float(pkt.duration) / timeBase->den, av_get_audio_frame_duration(rtmpReader.GetRtmpAudioContext(), pkt.size), rtmpReader.GetRtmpAudioContext()->sample_rate, av_get_audio_frame_duration(rtmpReader.GetRtmpAudioContext(), pkt.size) / float(rtmpReader.GetRtmpAudioContext()->sample_rate));
由此可知,cal duration是准确值,是数据实际能播放的时长,而前两个duration是记录或者计算出来的,不一定是准确。当其他两个值和cal duration差距过大时,即文件记录的时间戳出现异常,那么就可能会导致IOS播放异常。
异常举例:
正常举例:
解决方案:生成录制文件时,边录制边利用cal duration重新生成音频时间戳,不过该方案涉及到修改文件的时间戳,存在错改时间戳的风险,需业务评估后再使用。
现象:播放不流畅或者播放加速,音频闪现一些杂音,无法听清。播放过程中可能会导致IOS播放器闪退。
原因:音频声道数异常,例如文件数据本是单声道,文件却记录为双声道,反之亦然。
简单分析如下:
1.使用MP4 Reader查看问题文件的音频元数据信息
可以看到文件的Audio Decoder Specific Info为 11 88,这两个字节的解读可以使用如下代码
5 bits: object type if (object type == 31) 6 bits + 32: object type 4 bits: frequency index if (frequency index == 15) 24 bits: frequency 4 bits: channel configuration var bits: AOT Specific Config
11 88 = 00010 0011 0001 000 即
object type = 00010 = 2
frequency index = 0011 = 3
channel configuration = 0001 = 1
使用以上数据进行查如下三表
Audio Object Types MPEG-4 Audio Object Types: · 0: Null · 1: AAC Main · 2: AAC LC (Low Complexity) · 3: AAC SSR (Scalable Sample Rate) · 4: AAC LTP (Long Term Prediction) · 5: SBR (Spectral Band Replication) · 6: AAC Scalable · 7: TwinVQ · 8: CELP (Code Excited Linear Prediction) · 9: HXVC (Harmonic Vector eXcitation Coding) · 10: Reserved · 11: Reserved · 12: TTSI (Text-To-Speech Interface) · 13: Main Synthesis · 14: Wavetable Synthesis · 15: General MIDI · 16: Algorithmic Synthesis and Audio Effects · 17: ER (Error Resilient) AAC LC · 18: Reserved · 19: ER AAC LTP · 20: ER AAC Scalable · 21: ER TwinVQ · 22: ER BSAC (Bit-Sliced Arithmetic Coding) · 23: ER AAC LD (Low Delay) · 24: ER CELP · 25: ER HVXC · 26: ER HILN (Harmonic and Individual Lines plus Noise) · 27: ER Parametric · 28: SSC (SinuSoidal Coding) · 29: PS (Parametric Stereo) · 30: MPEG Surround · 31: (Escape value) · 32: Layer-1 · 33: Layer-2 · 34: Layer-3 · 35: DST (Direct Stream Transfer) · 36: ALS (Audio Lossless) · 37: SLS (Scalable LosslesS) · 38: SLS non-core · 39: ER AAC ELD (Enhanced Low Delay) · 40: SMR (Symbolic Music Representation) Simple · 41: SMR Main · 42: USAC (Unified Speech and Audio Coding) (no SBR) · 43: SAOC (Spatial Audio Object Coding) · 44: LD MPEG Surround · 45: USAC
Sampling Frequencies There are 13 supported frequencies: · 0: 96000 Hz · 1: 88200 Hz · 2: 64000 Hz · 3: 48000 Hz · 4: 44100 Hz · 5: 32000 Hz · 6: 24000 Hz · 7: 22050 Hz · 8: 16000 Hz · 9: 12000 Hz · 10: 11025 Hz · 11: 8000 Hz · 12: 7350 Hz · 13: Reserved · 14: Reserved · 15: frequency is written explictly
Channel Configurations These are the channel configurations: · 0: Defined in AOT Specifc Config · 1: 1 channel: front-center · 2: 2 channels: front-left, front-right · 3: 3 channels: front-center, front-left, front-right · 4: 4 channels: front-center, front-left, front-right, back-center · 5: 5 channels: front-center, front-left, front-right, back-left, back-right · 6: 6 channels: front-center, front-left, front-right, back-left, back-right, LFE-channel · 7: 8 channels: front-center, front-left, front-right, side-left, side-right, back-left, back-right, LFE-channel · 8-15: Reserved
可知该文件标记为单声道,使用二进制编辑软件把文件强制修改为双声道文件,即11 88改成11 90
修改后文件可以播放。
原创声明,本文系作者授权云+社区发表,未经许可,不得转载。
如有侵权,请联系 yunjia_community@tencent.com 删除。
我来说两句