medooze / media-server

WebRTC Media Server
GNU General Public License v2.0
1.36k stars 295 forks source link

h264: full SPS parsing #253

Open mildsunrise opened 9 months ago

mildsunrise commented 9 months ago

Please review #252 first, as it's a dependency for this PR.

Extends H264SeqParameterSet to parse the full descriptor (right now it's not parsing the VUI).

I've basically adapted the code from nal-extractor: https://github.com/medooze/nal-extractor/blob/main/lib/SPS.ts https://github.com/medooze/nal-extractor/blob/main/test/SPS.test.ts

output for:

64001eacb2010020f3cf80b5060606a50000030001000003003c9f162e48

is:

[H264SeqParameterSet
    profile_idc=64
    constraint_set0_flag=0
    constraint_set1_flag=0
    constraint_set2_flag=0
    reserved_zero_5bits=0
    level_idc=1e
    seq_parameter_set_id=0
    log2_max_frame_num_minus4=0
    pic_order_cnt_type=2
    log2_max_pic_order_cnt_lsb_minus4=0
    delta_pic_order_always_zero_flag=0
    offset_for_non_ref_pic=0
    offset_for_top_to_bottom_field=0
    num_ref_frames_in_pic_order_cnt_cycle=0
    num_ref_frames=3
    gaps_in_frame_num_value_allowed_flag=0
    pic_width_in_mbs_minus1=31
    pic_height_in_map_units_minus1=31
    frame_mbs_only_flag=1
    mb_adaptive_frame_field_flag=0
    direct_8x8_inference_flag=1
    frame_crop=[
        left_offset=0
        right_offset=6
        top_offset=0
        bottom_offset=6
    ]
    vui_parameters=[
        aspect_ratio_info=[
            aspect_ratio_idc=1
        ]
        overscan_info=[
            <Not present>
        ]
        video_signal_type=[
            video_format=5
            video_full_range_flag=0
            colour_description=[
                colour_primaries=6
                transfer_characteristics=6
                matrix_coefficients=6
            ]
        ]
        chroma_loc_info=[
            type_top_field=1
            type_bottom_field=1
        ]
        timing_info=[
            num_units_in_tick=1
            time_scale=61
            fixed_frame_rate_flag=1
        ]
        nal_hrd_parameters=[
            <Not present>
        ]
        vcl_hrd_parameters=[
            <Not present>
        ]
        pic_struct_present_flag=1
        bitstream_restriction=[
            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
            max_num_reorder_frames=0
            max_dec_frame_buffering=3
        ]
    ]
    separate_colour_plane_flag=0
[/H264SeqParameterSet]

For some reason time_scale says 61 rather than 60. I'll investigate later.

mildsunrise commented 9 months ago

(rebased)

murillo128 commented 8 months ago

is this ready for review?

mildsunrise commented 8 months ago

it is missing a relatively small change for it to compile without RTTI. sorry, I'll push that change tomorrow. for all other intents and purposes, this can be considered ready to review yes

murillo128 commented 2 months ago

I think we should add exceptions to bitstream readers/writters before merging this PR as I think we can simplify the code a lot once the exceptions are included.