Ogg/OGM reader: use rationals for calculation of display dimensions & frame rate

This commit is contained in:
Moritz Bunkus 2021-07-06 09:23:04 +02:00
parent 9e1c043a31
commit 4b74b43fdb
No known key found for this signature in database
GPG Key ID: 74AF00ADF2E32C85

View File

@ -1487,8 +1487,8 @@ generic_packetizer_c *
ogm_v_theora_demuxer_c::create_packetizer() { ogm_v_theora_demuxer_c::create_packetizer() {
m_ti.m_private_data = lace_memory_xiph(packet_data); m_ti.m_private_data = lace_memory_xiph(packet_data);
double fps = (double)theora.frn / (double)theora.frd; auto frame_rate = mtx::rational(theora.frn, theora.frd);
generic_packetizer_c *ptzr_obj = new theora_video_packetizer_c(reader, m_ti, static_cast<int64_t>(1'000'000'000.0 / fps), theora.fmbw, theora.fmbh); auto ptzr_obj = new theora_video_packetizer_c(reader, m_ti, mtx::to_int(1'000'000'000 / frame_rate), theora.fmbw, theora.fmbh);
reader->show_packetizer_info(m_ti.m_id, *ptzr_obj); reader->show_packetizer_info(m_ti.m_id, *ptzr_obj);
@ -1555,12 +1555,12 @@ ogm_v_vp8_demuxer_c::initialize() {
unsigned int par_den = get_uint16_be(&vp8_header.par_den); unsigned int par_den = get_uint16_be(&vp8_header.par_den);
if ((0 != par_num) && (0 != par_den)) { if ((0 != par_num) && (0 != par_den)) {
if ((static_cast<double>(pixel_width) / static_cast<double>(pixel_height)) < (static_cast<double>(par_num) / static_cast<double>(par_den))) { if (mtx::rational(pixel_width, pixel_height) < mtx::rational(par_num, par_den)) {
display_width = std::llround(static_cast<double>(pixel_width) * par_num / par_den); display_width = mtx::to_int_rounded(mtx::rational(pixel_width * par_num, par_den));
display_height = pixel_height; display_height = pixel_height;
} else { } else {
display_width = pixel_width; display_width = pixel_width;
display_height = std::llround(static_cast<double>(pixel_height) * par_den / par_num); display_height = mtx::to_int_rounded(mtx::rational(pixel_height * par_den, par_num));
} }
} else { } else {
@ -1570,7 +1570,7 @@ ogm_v_vp8_demuxer_c::initialize() {
frame_rate_num = static_cast<uint64_t>(get_uint32_be(&vp8_header.frame_rate_num)); frame_rate_num = static_cast<uint64_t>(get_uint32_be(&vp8_header.frame_rate_num));
frame_rate_den = static_cast<uint64_t>(get_uint32_be(&vp8_header.frame_rate_den)); frame_rate_den = static_cast<uint64_t>(get_uint32_be(&vp8_header.frame_rate_den));
default_duration = frame_rate_den * 1000000000ull / frame_rate_num; default_duration = mtx::to_int(mtx::rational(frame_rate_den, frame_rate_num) * 1'000'000'000);
} }
generic_packetizer_c * generic_packetizer_c *