VideoCommon: Limit maximum denominator for MPEG4

It happened to be under the limit normally, but now that the VBI rate can be changed, that's no longer the case.
This commit is contained in:
Martino Fontana 2025-04-27 13:08:33 +02:00
parent df223a8cd8
commit 86f81872a1
2 changed files with 13 additions and 4 deletions

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "VideoCommon/FrameDumpFFMpeg.h"
#include <cstdint>
#if defined(__FreeBSD__)
#define __STDC_CONSTANT_MACROS 1
@ -62,13 +63,13 @@ struct FrameDumpContext
namespace
{
AVRational GetTimeBaseForCurrentRefreshRate()
AVRational GetTimeBaseForCurrentRefreshRate(int64_t max_denominator)
{
auto& vi = Core::System::GetInstance().GetVideoInterface();
int num;
int den;
av_reduce(&num, &den, int(vi.GetTargetRefreshRateDenominator()),
int(vi.GetTargetRefreshRateNumerator()), std::numeric_limits<int>::max());
int(vi.GetTargetRefreshRateNumerator()), max_denominator);
return AVRational{num, den};
}
@ -248,11 +249,16 @@ bool FFMpegFrameDump::CreateVideoFile()
return false;
}
m_max_denominator = std::numeric_limits<uint64_t>::max();
// Force XVID FourCC for better compatibility when using H.263
if (codec->id == AV_CODEC_ID_MPEG4)
{
m_context->codec->codec_tag = MKTAG('X', 'V', 'I', 'D');
m_max_denominator = std::numeric_limits<unsigned short>::max();
}
const auto time_base = GetTimeBaseForCurrentRefreshRate();
const auto time_base = GetTimeBaseForCurrentRefreshRate(m_max_denominator);
INFO_LOG_FMT(FRAMEDUMP, "Creating video file: {} x {} @ {}/{} fps", m_context->width,
m_context->height, time_base.den, time_base.num);
@ -535,7 +541,7 @@ FrameState FFMpegFrameDump::FetchState(u64 ticks, int frame_number) const
state.frame_number = frame_number;
state.savestate_index = m_savestate_index;
const auto time_base = GetTimeBaseForCurrentRefreshRate();
const auto time_base = GetTimeBaseForCurrentRefreshRate(m_max_denominator);
state.refresh_rate_num = time_base.den;
state.refresh_rate_den = time_base.num;
return state;

View file

@ -62,6 +62,9 @@ private:
// Used for filename generation.
std::time_t m_start_time = {};
u32 m_file_index = 0;
// Some codecs (like MPEG4) have a limit to this
int64_t m_max_denominator = std::numeric_limits<int64_t>::max();
};
#if !defined(HAVE_FFMPEG)