void mpeg4_p2_video_packetizer_c::extract_aspect_ratio(const unsigned char *buffer, int size) { if (m_aspect_ratio_extracted) return; if ((0 != m_connected_to) || display_dimensions_or_aspect_ratio_set()) { m_aspect_ratio_extracted = true; return; } uint32_t num, den; if (mpeg4::p2::extract_par(buffer, size, num, den)) { m_aspect_ratio_extracted = true; set_video_aspect_ratio((double)m_hvideo_pixel_width / (double)m_hvideo_pixel_height * (double)num / (double)den, false, OPTION_SOURCE_BITSTREAM); generic_packetizer_c::set_headers(); rerender_track_headers(); mxinfo_tid(m_ti.m_fname, m_ti.m_id, boost::format(Y("Extracted the aspect ratio information from the MPEG4 layer 2 video data and set the display dimensions to %1%/%2%.\n")) % m_hvideo_display_width % m_hvideo_display_height); } else if (50 <= m_frames_output) m_aspect_ratio_extracted = true; }
generic_packetizer_c::generic_packetizer_c(generic_reader_c *reader, track_info_c &ti) : m_num_packets{} , m_next_packet_wo_assigned_timecode{} , m_free_refs{-1} , m_next_free_refs{-1} , m_enqueued_bytes{} , m_safety_last_timecode{} , m_safety_last_duration{} , m_track_entry{} , m_hserialno{-1} , m_htrack_type{-1} , m_htrack_min_cache{} , m_htrack_max_cache{-1} , m_htrack_default_duration{-1} , m_default_duration_forced{true} , m_default_track_warning_printed{} , m_huid{} , m_htrack_max_add_block_ids{-1} , m_haudio_sampling_freq{-1.0} , m_haudio_output_sampling_freq{-1.0} , m_haudio_channels{-1} , m_haudio_bit_depth{-1} , m_hvideo_interlaced_flag{-1} , m_hvideo_pixel_width{-1} , m_hvideo_pixel_height{-1} , m_hvideo_display_width{-1} , m_hvideo_display_height{-1} , m_hcompression{COMPRESSION_UNSPECIFIED} , m_timestamp_factory_application_mode{TFA_AUTOMATIC} , m_last_cue_timecode{-1} , m_has_been_flushed{} , m_prevent_lacing{} , m_connected_successor{} , m_ti{ti} , m_reader{reader} , m_connected_to{} , m_correction_timecode_offset{} , m_append_timecode_offset{} , m_max_timecode_seen{} , m_relaxed_timecode_checking{} { // Let's see if the user specified timecode sync for this track. if (mtx::includes(m_ti.m_timecode_syncs, m_ti.m_id)) m_ti.m_tcsync = m_ti.m_timecode_syncs[m_ti.m_id]; else if (mtx::includes(m_ti.m_timecode_syncs, -1)) m_ti.m_tcsync = m_ti.m_timecode_syncs[-1]; if (0 == m_ti.m_tcsync.numerator) m_ti.m_tcsync.numerator = 1; if (0 == m_ti.m_tcsync.denominator) m_ti.m_tcsync.denominator = 1; // Let's see if the user specified "reset timecodes" for this track. m_ti.m_reset_timecodes = mtx::includes(m_ti.m_reset_timecodes_specs, m_ti.m_id) || mtx::includes(m_ti.m_reset_timecodes_specs, -1); // Let's see if the user has specified which cues he wants for this track. if (mtx::includes(m_ti.m_cue_creations, m_ti.m_id)) m_ti.m_cues = m_ti.m_cue_creations[m_ti.m_id]; else if (mtx::includes(m_ti.m_cue_creations, -1)) m_ti.m_cues = m_ti.m_cue_creations[-1]; // Let's see if the user has given a default track flag for this track. if (mtx::includes(m_ti.m_default_track_flags, m_ti.m_id)) m_ti.m_default_track = m_ti.m_default_track_flags[m_ti.m_id]; else if (mtx::includes(m_ti.m_default_track_flags, -1)) m_ti.m_default_track = m_ti.m_default_track_flags[-1]; // Let's see if the user has given a fix avc fps flag for this track. if (mtx::includes(m_ti.m_fix_bitstream_frame_rate_flags, m_ti.m_id)) m_ti.m_fix_bitstream_frame_rate = m_ti.m_fix_bitstream_frame_rate_flags[m_ti.m_id]; else if (mtx::includes(m_ti.m_fix_bitstream_frame_rate_flags, -1)) m_ti.m_fix_bitstream_frame_rate = m_ti.m_fix_bitstream_frame_rate_flags[-1]; // Let's see if the user has given a forced track flag for this track. if (mtx::includes(m_ti.m_forced_track_flags, m_ti.m_id)) m_ti.m_forced_track = m_ti.m_forced_track_flags[m_ti.m_id]; else if (mtx::includes(m_ti.m_forced_track_flags, -1)) m_ti.m_forced_track = m_ti.m_forced_track_flags[-1]; // Let's see if the user has given a enabled track flag for this track. if (mtx::includes(m_ti.m_enabled_track_flags, m_ti.m_id)) m_ti.m_enabled_track = m_ti.m_enabled_track_flags[m_ti.m_id]; else if (mtx::includes(m_ti.m_enabled_track_flags, -1)) m_ti.m_enabled_track = m_ti.m_enabled_track_flags[-1]; // Let's see if the user has specified a language for this track. if (mtx::includes(m_ti.m_languages, m_ti.m_id)) m_ti.m_language = m_ti.m_languages[m_ti.m_id]; else if (mtx::includes(m_ti.m_languages, -1)) m_ti.m_language = m_ti.m_languages[-1]; // Let's see if the user has specified a sub charset for this track. if (mtx::includes(m_ti.m_sub_charsets, m_ti.m_id)) m_ti.m_sub_charset = m_ti.m_sub_charsets[m_ti.m_id]; else if (mtx::includes(m_ti.m_sub_charsets, -1)) m_ti.m_sub_charset = m_ti.m_sub_charsets[-1]; // Let's see if the user has specified a sub charset for this track. if (mtx::includes(m_ti.m_all_tags, m_ti.m_id)) m_ti.m_tags_file_name = m_ti.m_all_tags[m_ti.m_id]; else if (mtx::includes(m_ti.m_all_tags, -1)) m_ti.m_tags_file_name = m_ti.m_all_tags[-1]; if (!m_ti.m_tags_file_name.empty()) m_ti.m_tags = mtx::xml::ebml_tags_converter_c::parse_file(m_ti.m_tags_file_name, false); // Let's see if the user has specified how this track should be compressed. if (mtx::includes(m_ti.m_compression_list, m_ti.m_id)) m_ti.m_compression = m_ti.m_compression_list[m_ti.m_id]; else if (mtx::includes(m_ti.m_compression_list, -1)) m_ti.m_compression = m_ti.m_compression_list[-1]; // Let's see if the user has specified a name for this track. if (mtx::includes(m_ti.m_track_names, m_ti.m_id)) m_ti.m_track_name = m_ti.m_track_names[m_ti.m_id]; else if (mtx::includes(m_ti.m_track_names, -1)) m_ti.m_track_name = m_ti.m_track_names[-1]; // Let's see if the user has specified external timecodes for this track. if (mtx::includes(m_ti.m_all_ext_timecodes, m_ti.m_id)) m_ti.m_ext_timecodes = m_ti.m_all_ext_timecodes[m_ti.m_id]; else if (mtx::includes(m_ti.m_all_ext_timecodes, -1)) m_ti.m_ext_timecodes = m_ti.m_all_ext_timecodes[-1]; // Let's see if the user has specified an aspect ratio or display dimensions // for this track. int i = LOOKUP_TRACK_ID(m_ti.m_display_properties); if (-2 != i) { display_properties_t &dprop = m_ti.m_display_properties[i]; if (0 > dprop.aspect_ratio) { set_video_display_dimensions(dprop.width, dprop.height, OPTION_SOURCE_COMMAND_LINE); } else { set_video_aspect_ratio(dprop.aspect_ratio, dprop.ar_factor, OPTION_SOURCE_COMMAND_LINE); m_ti.m_aspect_ratio_given = true; } } if (m_ti.m_aspect_ratio_given && m_ti.m_display_dimensions_given) { if (m_ti.m_aspect_ratio_is_factor) mxerror_tid(m_ti.m_fname, m_ti.m_id, boost::format(Y("Both the aspect ratio factor and '--display-dimensions' were given.\n"))); else mxerror_tid(m_ti.m_fname, m_ti.m_id, boost::format(Y("Both the aspect ratio and '--display-dimensions' were given.\n"))); } // Let's see if the user has specified a FourCC for this track. if (mtx::includes(m_ti.m_all_fourccs, m_ti.m_id)) m_ti.m_fourcc = m_ti.m_all_fourccs[m_ti.m_id]; else if (mtx::includes(m_ti.m_all_fourccs, -1)) m_ti.m_fourcc = m_ti.m_all_fourccs[-1]; // Let's see if the user has specified a FourCC for this track. i = LOOKUP_TRACK_ID(m_ti.m_pixel_crop_list); if (-2 != i) set_video_pixel_cropping(m_ti.m_pixel_crop_list[i], OPTION_SOURCE_COMMAND_LINE); // Let's see if the user has specified a stereo mode for this track. i = LOOKUP_TRACK_ID(m_ti.m_stereo_mode_list); if (-2 != i) set_video_stereo_mode(m_ti.m_stereo_mode_list[m_ti.m_id], OPTION_SOURCE_COMMAND_LINE); // Let's see if the user has specified a default duration for this track. if (mtx::includes(m_ti.m_default_durations, m_ti.m_id)) m_htrack_default_duration = m_ti.m_default_durations[m_ti.m_id]; else if (mtx::includes(m_ti.m_default_durations, -1)) m_htrack_default_duration = m_ti.m_default_durations[-1]; else m_default_duration_forced = false; // Let's see if the user has set a max_block_add_id if (mtx::includes(m_ti.m_max_blockadd_ids, m_ti.m_id)) m_htrack_max_add_block_ids = m_ti.m_max_blockadd_ids[m_ti.m_id]; else if (mtx::includes(m_ti.m_max_blockadd_ids, -1)) m_htrack_max_add_block_ids = m_ti.m_max_blockadd_ids[-1]; // Let's see if the user has specified a NALU size length for this track. if (mtx::includes(m_ti.m_nalu_size_lengths, m_ti.m_id)) m_ti.m_nalu_size_length = m_ti.m_nalu_size_lengths[m_ti.m_id]; else if (mtx::includes(m_ti.m_nalu_size_lengths, -1)) m_ti.m_nalu_size_length = m_ti.m_nalu_size_lengths[-1]; // Let's see if the user has specified a compression scheme for this track. if (COMPRESSION_UNSPECIFIED != m_ti.m_compression) m_hcompression = m_ti.m_compression; // Set default header values to 'unset'. if (!m_reader->m_appending) { m_hserialno = create_track_number(); g_packetizers_by_track_num[m_hserialno] = this; } m_timestamp_factory = timestamp_factory_c::create(m_ti.m_ext_timecodes, m_ti.m_fname, m_ti.m_id); // If no external timecode file but a default duration has been // given then create a simple timecode factory that generates the // timecodes for the given FPS. if (!m_timestamp_factory && (-1 != m_htrack_default_duration)) m_timestamp_factory = timestamp_factory_c::create_fps_factory(m_htrack_default_duration, m_ti.m_tcsync); }