mpeg1_2_video_packetizer_c:: mpeg1_2_video_packetizer_c(generic_reader_c *p_reader, track_info_c &p_ti, int version, double fps, int width, int height, int dwidth, int dheight, bool framed) : video_packetizer_c(p_reader, p_ti, "V_MPEG1", fps, width, height) , m_framed(framed) , m_aspect_ratio_extracted(true) { set_codec_id((boost::format("V_MPEG%1%") % version).str()); if (!display_dimensions_or_aspect_ratio_set()) { if ((0 < dwidth) && (0 < dheight)) set_video_display_dimensions(dwidth, dheight, PARAMETER_SOURCE_BITSTREAM); else m_aspect_ratio_extracted = false; } m_timecode_factory_application_mode = TFA_SHORT_QUEUEING; // m_parser.SeparateSequenceHeaders(); }
void theora_video_packetizer_c::extract_aspect_ratio() { if (display_dimensions_or_aspect_ratio_set() || (NULL == m_ti.m_private_data) || (0 == m_ti.m_private_size)) return; memory_cptr private_data = memory_cptr(new memory_c(m_ti.m_private_data, m_ti.m_private_size, false)); std::vector<memory_cptr> packets = unlace_memory_xiph(private_data); for (auto &packet : packets) { if ((0 == packet->get_size()) || (THEORA_HEADERTYPE_IDENTIFICATION != packet->get_buffer()[0])) continue; try { theora_identification_header_t theora; theora_parse_identification_header(packet->get_buffer(), packet->get_size(), theora); if ((0 == theora.display_width) || (0 == theora.display_height)) return; set_video_display_dimensions(theora.display_width, theora.display_height, PARAMETER_SOURCE_BITSTREAM); mxinfo_tid(m_ti.m_fname, m_ti.m_id, boost::format(Y("Extracted the aspect ratio information from the Theora video headers and set the display dimensions to %1%/%2%.\n")) % theora.display_width % theora.display_height); } catch (...) { } return; } }
mpeg1_2_video_packetizer_c:: mpeg1_2_video_packetizer_c(generic_reader_c *p_reader, track_info_c &p_ti, int version, double fps, int width, int height, int dwidth, int dheight, bool framed) : generic_video_packetizer_c{p_reader, p_ti, "V_MPEG1", fps, width, height} , m_framed{framed} , m_aspect_ratio_extracted{true} , m_num_removed_stuffing_bytes{} , m_debug_stuffing_removal{"mpeg1_2|mpeg1_2_stuffing_removal"} { set_codec_id((boost::format("V_MPEG%1%") % version).str()); if (!display_dimensions_or_aspect_ratio_set()) { if ((0 < dwidth) && (0 < dheight)) set_video_display_dimensions(dwidth, dheight, OPTION_SOURCE_BITSTREAM); else m_aspect_ratio_extracted = false; } m_timestamp_factory_application_mode = TFA_SHORT_QUEUEING; // m_parser.SeparateSequenceHeaders(); }
void mpeg1_2_video_packetizer_c::extract_aspect_ratio(const unsigned char *buffer, int size) { float ar; if (display_dimensions_or_aspect_ratio_set()) return; if (!mpeg1_2::extract_ar(buffer, size, ar)) return; set_video_display_dimensions((0 >= ar) || (1 == ar) ? m_width : (int)(m_height * ar), m_height, PARAMETER_SOURCE_BITSTREAM); rerender_track_headers(); m_aspect_ratio_extracted = true; }
void mpeg4_p10_video_packetizer_c::extract_aspect_ratio() { auto result = mpeg4::p10::extract_par(m_ti.m_private_data); set_codec_private(result.new_avcc); if (!result.is_valid() || display_dimensions_or_aspect_ratio_set()) return; auto par = static_cast<double>(result.numerator) / static_cast<double>(result.denominator); set_video_display_dimensions(1 <= par ? std::llround(m_width * par) : m_width, 1 <= par ? m_height : std::llround(m_height / par), OPTION_SOURCE_BITSTREAM); mxinfo_tid(m_ti.m_fname, m_ti.m_id, boost::format(Y("Extracted the aspect ratio information from the MPEG-4 layer 10 (AVC) video data and set the display dimensions to %1%/%2%.\n")) % m_ti.m_display_width % m_ti.m_display_height); }
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); }