{"id":2005,"date":"2020-01-20T18:18:00","date_gmt":"2020-01-20T16:18:00","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=2005"},"modified":"2020-01-20T18:41:07","modified_gmt":"2020-01-20T16:41:07","slug":"telegram-bot-to-extract-contents-of-h-264-parameter-set-nal-units","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/2005","title":{"rendered":"Telegram bot to extract  contents of H.264 parameter set NAL units"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In continuation of <a href=\"https:\/\/alax.info\/blog\/2004\">previous post about C++\/WinRT and Telegram<\/a>, here we with <a href=\"https:\/\/t.me\/ParameterSetAnalyzeBot\">@ParameterSetAnalyzeBot<\/a>: &#8220;Your buddy to extract H.264 parameter set NAL data&#8221;. In a chat, it expects an MP4 file with an H.264 video track sent him (her?). Then it extracts data from sample description box and deciphers into readable form:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"338\" height=\"600\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2020\/01\/image-1-338x600.png\" alt=\"\" class=\"wp-image-2006\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2020\/01\/image-1-338x600.png 338w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2020\/01\/image-1-180x320.png 180w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2020\/01\/image-1-600x1067.png 600w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2020\/01\/image-1.png 720w\" sizes=\"auto, (max-width: 338px) 100vw, 338px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">It&#8217;s literally taking the MP4 file to the Media Foundation <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/medfound\/source-reader\">Source Reader API<\/a>, pulls <code><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/medfound\/mf-mt-mpeg-sequence-header-attribute\">MF_MT_MPEG_SEQUENCE_HEADER<\/a><\/code> and pipe the data to <code><a href=\"https:\/\/github.com\/roman380\/h264bitstream\">h264_analyze<\/a><\/code> tool (my fork of it has Visual Studio 2019 project, and is added ability to take input from <code>stdin<\/code> for piping needs).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It will probably not be online forever, but it&#8217;s live. Be aware that <a href=\"https:\/\/core.telegram.org\/bots\/api#file\">Telegram limits file transmissions to 20 MB per file<\/a> at the moment.<\/p>\n\n\n\n<!--more-->\n\n\n\n<pre class=\"wp-block-preformatted\">!! Found NAL at offset 3 (0x0003), size 31 (0x001F) \n 0.8: forbidden_zero_bit: 0 \n 0.7: nal-&gt;nal_ref_idc: 3 \n 0.5: nal-&gt;nal_unit_type: 7 \n 1.8: sps-&gt;profile_idc: 77 \n 2.8: sps-&gt;constraint_set0_flag: 0 \n 2.7: sps-&gt;constraint_set1_flag: 0 \n 2.6: sps-&gt;constraint_set2_flag: 0 \n 2.5: sps-&gt;constraint_set3_flag: 0 \n 2.4: sps-&gt;constraint_set4_flag: 0 \n 2.3: sps-&gt;constraint_set5_flag: 0 \n 2.2: reserved_zero_2bits: 0 \n 3.8: sps-&gt;level_idc: 31 \n 4.8: sps-&gt;seq_parameter_set_id: 0 \n 4.7: sps-&gt;log2_max_frame_num_minus4: 3 \n 4.2: sps-&gt;pic_order_cnt_type: 0 \n 4.1: sps-&gt;log2_max_pic_order_cnt_lsb_minus4: 0 \n 5.8: sps-&gt;num_ref_frames: 4 \n 5.3: sps-&gt;gaps_in_frame_num_value_allowed_flag: 0 \n 5.2: sps-&gt;pic_width_in_mbs_minus1: 79 \n 7.5: sps-&gt;pic_height_in_map_units_minus1: 44 \n 8.2: sps-&gt;frame_mbs_only_flag: 1 \n 8.1: sps-&gt;direct_8x8_inference_flag: 1 \n 9.8: sps-&gt;frame_cropping_flag: 0 \n 9.7: sps-&gt;vui_parameters_present_flag: 1 \n 9.6: sps-&gt;vui.aspect_ratio_info_present_flag: 1 \n 9.5: sps-&gt;vui.aspect_ratio_idc: 255 \n 10.5: sps-&gt;vui.sar_width: 1 \n 12.5: sps-&gt;vui.sar_height: 1 \n 14.5: sps-&gt;vui.overscan_info_present_flag: 0 \n 14.4: sps-&gt;vui.video_signal_type_present_flag: 1 \n 14.3: sps-&gt;vui.video_format: 0 \n 15.8: sps-&gt;vui.video_full_range_flag: 0 \n 15.7: sps-&gt;vui.colour_description_present_flag: 0 \n 15.6: sps-&gt;vui.chroma_loc_info_present_flag: 0 \n 15.5: sps-&gt;vui.timing_info_present_flag: 1 \n 15.4: sps-&gt;vui.num_units_in_tick: 1 \n 19.4: sps-&gt;vui.time_scale: 50 \n 23.4: sps-&gt;vui.fixed_frame_rate_flag: 1 \n 23.3: sps-&gt;vui.nal_hrd_parameters_present_flag: 0 \n 23.2: sps-&gt;vui.vcl_hrd_parameters_present_flag: 0 \n 23.1: sps-&gt;vui.pic_struct_present_flag: 0 \n 24.8: sps-&gt;vui.bitstream_restriction_flag: 1 \n 24.7: sps-&gt;vui.motion_vectors_over_pic_boundaries_flag: 1 \n 24.6: sps-&gt;vui.max_bytes_per_pic_denom: 2 \n 24.3: sps-&gt;vui.max_bits_per_mb_denom: 1 \n 25.8: sps-&gt;vui.log2_max_mv_length_horizontal: 16 \n 26.7: sps-&gt;vui.log2_max_mv_length_vertical: 16 \n 27.6: sps-&gt;vui.num_reorder_frames: 0 \n 27.5: sps-&gt;vui.max_dec_frame_buffering: 4 \n 28.8: rbsp_stop_one_bit: 1 \n 28.7: rbsp_alignment_zero_bit: 0 \n 28.6: rbsp_alignment_zero_bit: 0 \n 28.5: rbsp_alignment_zero_bit: 0 \n 28.4: rbsp_alignment_zero_bit: 0 \n 28.3: rbsp_alignment_zero_bit: 0 \n 28.2: rbsp_alignment_zero_bit: 0 \n 28.1: rbsp_alignment_zero_bit: 0 \n!! Found NAL at offset 37 (0x0025), size 4 (0x0004) \n 0.8: forbidden_zero_bit: 0 \n 0.7: nal-&gt;nal_ref_idc: 3 \n 0.5: nal-&gt;nal_unit_type: 8 \n 1.8: pps-&gt;pic_parameter_set_id: 0 \n 1.7: pps-&gt;seq_parameter_set_id: 0 \n 1.6: pps-&gt;entropy_coding_mode_flag: 1 \n 1.5: pps-&gt;pic_order_present_flag: 0 \n 1.4: pps-&gt;num_slice_groups_minus1: 0 \n 1.3: pps-&gt;num_ref_idx_l0_active_minus1: 0 \n 1.2: pps-&gt;num_ref_idx_l1_active_minus1: 0 \n 1.1: pps-&gt;weighted_pred_flag: 0 \n 2.8: pps-&gt;weighted_bipred_idc: 0 \n 2.6: pps-&gt;pic_init_qp_minus26: 0 \n 2.5: pps-&gt;pic_init_qs_minus26: 0 \n 2.4: pps-&gt;chroma_qp_index_offset: 0 \n 2.3: pps-&gt;deblocking_filter_control_present_flag: 0 \n 2.2: pps-&gt;constrained_intra_pred_flag: 0 \n 2.1: pps-&gt;redundant_pic_cnt_present_flag: 0 \n 3.8: rbsp_stop_one_bit: 1 \n 3.7: rbsp_alignment_zero_bit: 0 \n 3.6: rbsp_alignment_zero_bit: 0 \n 3.5: rbsp_alignment_zero_bit: 0 \n 3.4: rbsp_alignment_zero_bit: 0 \n 3.3: rbsp_alignment_zero_bit: 0 \n 3.2: rbsp_alignment_zero_bit: 0 \n 3.1: rbsp_alignment_zero_bit: 0<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Maybe it is worth adding full Media Foundation attribute printout as well, and similar H.265\/HEVC data. This will have to wait for next occasion though.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And &#8211; yeah &#8211; it does have support for fragmented MP4 too:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2020\/01\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"398\" height=\"600\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2020\/01\/image-2-398x600.png\" alt=\"\" class=\"wp-image-2007\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2020\/01\/image-2-398x600.png 398w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2020\/01\/image-2-212x320.png 212w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2020\/01\/image-2-768x1158.png 768w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2020\/01\/image-2-600x904.png 600w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2020\/01\/image-2.png 944w\" sizes=\"auto, (max-width: 398px) 100vw, 398px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>In continuation of previous post about C++\/WinRT and Telegram, here we with @ParameterSetAnalyzeBot: &#8220;Your buddy to extract H.264 parameter set NAL data&#8221;. In a chat, it expects an MP4 file with an H.264 video track sent him (her?). Then it extracts data from sample description box and deciphers into readable form: It&#8217;s literally taking the&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/2005\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[105,379,592,486],"class_list":["post-2005","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-bot","tag-h-264","tag-telegram","tag-video"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/2005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=2005"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/2005\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=2005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=2005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=2005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}