Inspecting H.264 Headers
Introduction
The MPEG4IP project has a nice tool you can use to extract the H264 headers.
Removing file container
If the H.264 video is in a Transport Stream container, you can use GStreamer to remove the TS wrapper:
INPUT_TS_FILE=video.m2t OUTPUT_264_FILE=video.264 gst-launch filesrc location=$INPUT_TS_FILE ! mpegtsdemux ! filesink location=$OUTPUT_264_FILE
If the H.264 video is in an MP4 container, you can use GStreamer to remove the MP4 wrapper:
INPUT_MP4_FILE=vido.mp4 OUTPUT_264_FILE=video.264 gst-launch filesrc location=$INPUT_MP4_FILE ! qtdemux ! h264parse output-format=1 ! filesink location=$OUTPUT_264_FILE
The GStreamer pipeline uses the h264parse element to convert the H264 content from packetized to bytestream in the MP4 file.
Examining H.264 headers
Now you can use the h264_parse tool to extract the H.264 headers. This tool belongs to the MPEG4IP package
h264_parse $OUTPUT_264_FILE
The h264_parse tool expects the H.264 video file to be in bytestream format in order to extract the headers.
Example H.264 header
h264_parse - mpeg4ip version 1.6 Nal length 6 start code 4 bytes ref 0 type 9 Access unit delimeter primary_pic_type: 0 Nal length 47 start code 4 bytes ref 1 type 7 Sequence parameter set profile: 77 constaint_set0_flag: 0 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: 0 pic_order_cnt_type: 0 log2_max_pic_order_cnt_lsb_minus4: 0 num_ref_frames: 2 gaps_in_frame_num_value_allowed_flag: 0 pic_width_in_mbs_minus1: 44 (720) pic_height_in_map_minus1: 14 frame_mbs_only_flag: 0 derived height: 480 mb_adaptive_frame_field_flag: 0 direct_8x8_inference_flag: 1 frame_cropping_flag: 0 vui_parameters_present_flag: 1 aspect_ratio_info_present_flag: 1 aspect_ratio_idc:3 overscan_info_present_flag: 0 video_signal_info_present_flag: 0 chroma_loc_info_present_flag: 0 timing_info_present_flag: 1 num_units_in_tick: 1001 time_scale: 60000 fixed_frame_scale: 1 nal_hrd_parameters_present_flag: 1 cpb_cnt_minus1: 0 bit_rate_scale: 0 cpb_size_scale: 1 bit_rate_value_minus1[0]: 109374 cpb_size_value_minus1[0]: 109374 cbr_flag[0]: 0 initial_cpb_removal_delay_length_minus1: 15 cpb_removal_delay_length_minus1: 23 dpb_output_delay_length_minus1: 23 time_offset_length: 0 vcl_hrd_parameters_present_flag: 1 cpb_cnt_minus1: 0 bit_rate_scale: 0 cpb_size_scale: 1 bit_rate_value_minus1[0]: 109374 cpb_size_value_minus1[0]: 109374 cbr_flag[0]: 0 initial_cpb_removal_delay_length_minus1: 15 cpb_removal_delay_length_minus1: 23 dpb_output_delay_length_minus1: 23 time_offset_length: 0 low_delay_hrd_flag: 0 pic_struct_present_flag: 1 Nal length 9 start code 4 bytes ref 1 type 8 Picture parameter set pic_parameter_set_id: 0 seq_parameter_set_id: 0 entropy_coding_mode_flag: 1 pic_order_present_flag: 0 num_slice_groups_minus1: 0 num_ref_idx_l0_active_minus1: 1 num_ref_idx_l1_active_minus1: 1 weighted_pred_flag: 0 weighted_bipred_idc: 0 pic_init_qp_minus26: 19 pic_init_qs_minus26: 0 chroma_qp_index_offset: 0 deblocking_filter_control_present_flag: 1 constrained_intra_pred_flag: 0 redundant_pic_cnt_present_flag: 0 Nal length 26 start code 4 bytes ref 0 type 6 SEI payload_type: 0 buffering_period payload_size: 9 0xd7 0xe4 0x0 0x0 0x57 0xe4 0x0 0x0 0x40 seq_parameter_set_id: 0 initial_cpb_removal_delay[0]: 45000 initial_cpb_removal_delay_offset[0]: 0 initial_cpb_removal_delay[0]: 45000 initial_cpb_removal_delay_offset[0]: 0 payload_type: 1 pic_timing payload_size: 7 0x0 0x0 0x0 0x0 0x0 0x6 0x14 cpb_removal_delay: 0 dpb_output_delay: 6 pict_struct: 1 clock_timestamp_flag[0]: 0 Nal length 48859 start code 4 bytes ref 1 type 5 Coded slice of an IDR picture first_mb_in_slice: 0 slice_type: 7 (I) pic_parameter_set_id: 0 frame_num: 0 (4 bits) field_pic_flag: 1 bottom_field_flag: 0 idr_pic_id: 0 pic_order_cnt_lsb: 0 Nal length 6 start code 4 bytes ref 0 type 9 Access unit delimeter primary_pic_type: 1 Nal length 15 start code 4 bytes ref 0 type 6 SEI payload_type: 1 pic_timing payload_size: 7 0x0 0x0 0x1 0x0 0x0 0x6 0x24 cpb_removal_delay: 1 dpb_output_delay: 6 pict_struct: 2 clock_timestamp_flag[0]: 0 Nal length 12257 start code 4 bytes ref 1 type 1 Coded slice of non-IDR picture first_mb_in_slice: 0 slice_type: 5 (P) pic_parameter_set_id: 0 frame_num: 0 (4 bits) field_pic_flag: 1 bottom_field_flag: 1 pic_order_cnt_lsb: 1 Nal length 6 start code 4 bytes ref 0 type 9 Access unit delimeter primary_pic_type: 1 Nal length 15 start code 4 bytes ref 0 type 6 SEI payload_type: 1 pic_timing payload_size: 7 0x0 0x0 0x6 0x0 0x0 0x6 0x14 cpb_removal_delay: 6 dpb_output_delay: 6 pict_struct: 1 clock_timestamp_flag[0]: 0 Nal length 8015 start code 4 bytes ref 1 type 1 Coded slice of non-IDR picture first_mb_in_slice: 0 slice_type: 5 (P) pic_parameter_set_id: 0 frame_num: 1 (4 bits) field_pic_flag: 1 bottom_field_flag: 0 pic_order_cnt_lsb: 6 Nal length 6 start code 4 bytes ref 0 type 9 Access unit delimeter primary_pic_type: 1 Nal length 15 start code 4 bytes ref 0 type 6 SEI payload_type: 1 pic_timing payload_size: 7 0x0 0x0 0x7 0x0 0x0 0x6 0x24 cpb_removal_delay: 7 dpb_output_delay: 6 pict_struct: 2 clock_timestamp_flag[0]: 0 ... .. .