Logan R. Kearsley
Logan R. Kearsley

Reputation: 842

Fetch H.264 video dimensions from MPEG-TS stream with corrupted SPS

I am writing an MPEG-TS to MP4 transmuxer, which is mostly working insofar as I get playable MP4 files out of it which have the proper dimensions and playback speed and so forth.

However, I am not sure how VLC (or any other video player I've tested my output on) is figuring out what the proper dimensions for the video are. The width and height values that I calculate from parsing the SPS are total junk; I end up with things like 16x160, or 32x1529.

Now, an avcC box in an MP4 file contains the complete original SPS unit, so I see two possibilities: 1. My SPS parser is actually broken somehow, and MP4 players re-extract width, height, profile, and level info on their own correctly from the complete SPS. In that case, are there test cases I can use for verifying my SPS parser? 2. My SPS parser is fine, and the SPS data really is screwy, and MP4 players are able to retrieve the correct parameters from the video data by some other means. In that case, what is that other means?

EDIT: For reference, here're some of the SPSs I'm trying to parse, and the results I'm getting:

SPS: 0x674d401feca0c8edff807007088003080031e078c18cb0 pic_width_in_mbs_minus1: 0 pic_height_in_map_units_minus1: 0 frame_cropping_flag: 0 frame_mbs_only_flag: 0 width: 16 height: 32

SPS: 0x6742c015d90a07e84003040030f03c58b920 pic_width_in_mbs_minus1: 1 pic_height_in_map_units_minus1: 159 frame_cropping_flag: 1 (bottom offset is 1, the rest are 0) frame_mbs_only_flag: 0 width: 32 height: 5118

SPS: 0x676401eacd940b031a100301003032f162d96

pic_width_in_mbs_minus1: 0 pic_height_in_map_units_minus1: 4 frame_cropping_flag: 0 frame_mbs_only_flag: 0 width: 16 height: 160

My parser code is rather large to include here, but is on GitHub at https://github.com/gliese1337/HLS.js/blob/master/SPSParser.js

Upvotes: 2

Views: 909

Answers (1)

Roman Ryltsov
Roman Ryltsov

Reputation: 69734

This should still be a problem with your SPS parser:

SPS: 0x674d401feca0c8edff807007088003080031e078c18cb0 pic_width_in_mbs_minus1: 0 pic_height_in_map_units_minus1: 0 frame_cropping_flag: 0 frame_mbs_only_flag: 0 width: 16 height: 32

Sequence Parameter Set
profile_idc 77 
constraint_set0_flag 0 
constraint_set1_flag 1 
constraint_set2_flag 0 
constraint_set3_flag 0 
level_idc 31 
seq_parameter_set_id 0 
num_ref_frames 4 
gaps_in_frame_num_value_allowed_flag 0 
pic_width_in_mbs_minus1 24 
pic_height_in_map_units_minus1 13 
frame_mbs_only_flag 1 
direct_8x8_inference_flag 1 
frame_cropping_flag 0 
vui_parameters_present_flag 1 

Resolution: 400x224

Upvotes: 3

Related Questions