From 3382408b8e2f2b3d9fbd7fd0aad8be0dce3e3af7 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sat, 9 Apr 2022 00:45:49 +0200 Subject: [PATCH] VideoCommon/FrameDump: Allow user to specify a pixel format. --- Source/Core/Core/Config/GraphicsSettings.cpp | 1 + Source/Core/Core/Config/GraphicsSettings.h | 1 + Source/Core/VideoCommon/FrameDump.cpp | 30 ++++++++++++++------ Source/Core/VideoCommon/VideoConfig.cpp | 1 + Source/Core/VideoCommon/VideoConfig.h | 1 + 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/Config/GraphicsSettings.cpp b/Source/Core/Core/Config/GraphicsSettings.cpp index 1015bd47aa..de5003ce9f 100644 --- a/Source/Core/Core/Config/GraphicsSettings.cpp +++ b/Source/Core/Core/Config/GraphicsSettings.cpp @@ -44,6 +44,7 @@ const Info GFX_DUMP_FRAMES_AS_IMAGES{{System::GFX, "Settings", "DumpFrames const Info GFX_USE_FFV1{{System::GFX, "Settings", "UseFFV1"}, false}; const Info GFX_DUMP_FORMAT{{System::GFX, "Settings", "DumpFormat"}, "avi"}; const Info GFX_DUMP_CODEC{{System::GFX, "Settings", "DumpCodec"}, ""}; +const Info GFX_DUMP_PIXEL_FORMAT{{System::GFX, "Settings", "DumpPixelFormat"}, ""}; const Info GFX_DUMP_ENCODER{{System::GFX, "Settings", "DumpEncoder"}, ""}; const Info GFX_DUMP_PATH{{System::GFX, "Settings", "DumpPath"}, ""}; const Info GFX_BITRATE_KBPS{{System::GFX, "Settings", "BitrateKbps"}, 25000}; diff --git a/Source/Core/Core/Config/GraphicsSettings.h b/Source/Core/Core/Config/GraphicsSettings.h index e5289a36de..c97e2338c9 100644 --- a/Source/Core/Core/Config/GraphicsSettings.h +++ b/Source/Core/Core/Config/GraphicsSettings.h @@ -45,6 +45,7 @@ extern const Info GFX_DUMP_FRAMES_AS_IMAGES; extern const Info GFX_USE_FFV1; extern const Info GFX_DUMP_FORMAT; extern const Info GFX_DUMP_CODEC; +extern const Info GFX_DUMP_PIXEL_FORMAT; extern const Info GFX_DUMP_ENCODER; extern const Info GFX_DUMP_PATH; extern const Info GFX_BITRATE_KBPS; diff --git a/Source/Core/VideoCommon/FrameDump.cpp b/Source/Core/VideoCommon/FrameDump.cpp index 7054ba11af..d79eec79f3 100644 --- a/Source/Core/VideoCommon/FrameDump.cpp +++ b/Source/Core/VideoCommon/FrameDump.cpp @@ -21,6 +21,7 @@ extern "C" { #include #include #include +#include #include } @@ -249,19 +250,30 @@ bool FrameDump::CreateVideoFile() m_context->codec->gop_size = 1; m_context->codec->level = 1; - if (m_context->codec->codec_id == AV_CODEC_ID_FFV1) + AVPixelFormat pix_fmt = AV_PIX_FMT_NONE; + + const std::string& pixel_format_string = g_Config.sDumpPixelFormat; + if (!pixel_format_string.empty()) { - m_context->codec->pix_fmt = AV_PIX_FMT_BGR0; + pix_fmt = av_get_pix_fmt(pixel_format_string.c_str()); + if (pix_fmt == AV_PIX_FMT_NONE) + WARN_LOG_FMT(FRAMEDUMP, "Invalid pixel format {}", pixel_format_string); } - else if (m_context->codec->codec_id == AV_CODEC_ID_UTVIDEO) + + if (pix_fmt == AV_PIX_FMT_NONE) { - m_context->codec->pix_fmt = AV_PIX_FMT_GBRP; + if (m_context->codec->codec_id == AV_CODEC_ID_FFV1) + pix_fmt = AV_PIX_FMT_BGR0; + else if (m_context->codec->codec_id == AV_CODEC_ID_UTVIDEO) + pix_fmt = AV_PIX_FMT_GBRP; + else + pix_fmt = AV_PIX_FMT_YUV420P; + } + + m_context->codec->pix_fmt = pix_fmt; + + if (m_context->codec->codec_id == AV_CODEC_ID_UTVIDEO) av_opt_set_int(m_context->codec->priv_data, "pred", 3, 0); // median - } - else - { - m_context->codec->pix_fmt = AV_PIX_FMT_YUV420P; - } if (output_format->flags & AVFMT_GLOBALHEADER) m_context->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index a4aa9bda55..99e174a1d2 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -73,6 +73,7 @@ void VideoConfig::Refresh() bUseFFV1 = Config::Get(Config::GFX_USE_FFV1); sDumpFormat = Config::Get(Config::GFX_DUMP_FORMAT); sDumpCodec = Config::Get(Config::GFX_DUMP_CODEC); + sDumpPixelFormat = Config::Get(Config::GFX_DUMP_PIXEL_FORMAT); sDumpEncoder = Config::Get(Config::GFX_DUMP_ENCODER); sDumpPath = Config::Get(Config::GFX_DUMP_PATH); iBitrateKbps = Config::Get(Config::GFX_BITRATE_KBPS); diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index 659611a170..6cf8122736 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -102,6 +102,7 @@ struct VideoConfig final bool bDumpFramesAsImages = false; bool bUseFFV1 = false; std::string sDumpCodec; + std::string sDumpPixelFormat; std::string sDumpEncoder; std::string sDumpFormat; std::string sDumpPath;