You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

解析MP4 avcC盒内H264 SPS时序信息取值异常排查

H264 SPS时序信息解析异常问题

问题描述

解析MP4文件avcC盒内的H264 SPS(序列参数集)时,其余字段解析结果均符合预期,仅时序信息取值解析错误。
通过十六进制编辑器提取的待解析SPS字节数据如下:

byte[] spsSmall =
{
    0x67, 0x42, 0xC0, 0x1E, 0x9E, 0x21, 0x81, 0x18, 0x53, 0x4D, 0x40, 0x40,
    0x40, 0x50, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00, 0x00, 0x03, 0x03, 0xC8,
    0xF1, 0x62, 0xEE
};

将对应MP4片段转换为.h264格式后,H264 Analyzer输出的解析报告如下:

Nal length 29 start code 4 bytes 
 ref 3 type 7 Sequence parameter set
   profile: 66
   constaint_set0_flag: 1
   constaint_set1_flag: 1
   constaint_set2_flag: 0
   constaint_set3_flag: 0
   level_idc: 30
   seq parameter set id: 0
   log2_max_frame_num_minus4: 6
   pic_order_cnt_type: 0
    log2_max_pic_order_cnt_lsb_minus4: 7
   num_ref_frames: 2
   gaps_in_frame_num_value_allowed_flag: 0
   pic_width_in_mbs_minus1: 34 (560)
   pic_height_in_map_minus1: 19
   frame_mbs_only_flag: 1
     derived height: 320
   direct_8x8_inference_flag: 1
   frame_cropping_flag: 0
   vui_parameters_present_flag: 1
    aspect_ratio_info_present_flag: 0
    overscan_info_present_flag: 0
    video_signal_info_present_flag: 1
     video_format: 5
     video_full_range_flag: 0
     colour_description_present_flag: 1
      colour_primaries: 1
      transfer_characteristics: 1
      matrix_coefficients: 1
    chroma_loc_info_present_flag: 0
    timing_info_present_flag: 1
     num_units_in_tick: 1
     time_scale: 60
     fixed_frame_scale: 1
    nal_hrd_parameters_present_flag: 0
    vcl_hrd_parameters_present_flag: 0
    pic_struct_present_flag: 0
    motion_vectors_over_pic_boundaries_flag: 1
    max_bytes_per_pic_denom: 0
    max_bits_per_mb_denom: 0
    log2_max_mv_length_horizontal: 10
    log2_max_mv_length_vertical: 10
    num_reorder_frames: 0
     max_dec_frame_buffering: 2

根据解析报告,预期得到的num_units_in_tick值为1、time_scale值为60,但实际解析结果为num_units_in_tick=48、time_scale=16777216,解析逻辑可参考对应项目源码中SequenceParameterSet.cs文件第259行的实现。

已完成排查

  • 对照FFmpeg等主流开源实现核对解析流程,未发现逻辑差异
  • 测试其他视频片段时,均仅出现时序信息解析错误,其余字段解析正常
  • 查阅现有H264规范文档,未找到遗漏的解析规则
  • 时序信息字段前的colour_primaries、transfer_characteristics、matrix_coefficients三个字段均能正确解析出值1,若存在比特流读取偏移,三个连续字段全部解析正确的概率极低,暂未定位到偏移问题
  • 查阅相关技术资料看到如下表述:

If you are using field-based video then this will be a field rate, so you'll have to halve it to get a frame rate.

  • 已尝试将时序字段的读取位宽从32位调整为16位,也尝试过对读取结果做折半处理,均无法得到接近预期的数值,暂不理解上述场编码相关表述的具体适配场景

诉求

寻求该问题的具体排查方向。


内容的提问来源于stack exchange,提问作者Island

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.28 12:09:21