VideoCommon/FrameDump: Allow user to specify a pixel format.

This commit is contained in:
Admiral H. Curtiss 2022-04-09 00:45:49 +02:00
parent 120208ae03
commit 3382408b8e
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
5 changed files with 25 additions and 9 deletions

View File

@ -44,6 +44,7 @@ const Info<bool> GFX_DUMP_FRAMES_AS_IMAGES{{System::GFX, "Settings", "DumpFrames
const Info<bool> GFX_USE_FFV1{{System::GFX, "Settings", "UseFFV1"}, false};
const Info<std::string> GFX_DUMP_FORMAT{{System::GFX, "Settings", "DumpFormat"}, "avi"};
const Info<std::string> GFX_DUMP_CODEC{{System::GFX, "Settings", "DumpCodec"}, ""};
const Info<std::string> GFX_DUMP_PIXEL_FORMAT{{System::GFX, "Settings", "DumpPixelFormat"}, ""};
const Info<std::string> GFX_DUMP_ENCODER{{System::GFX, "Settings", "DumpEncoder"}, ""};
const Info<std::string> GFX_DUMP_PATH{{System::GFX, "Settings", "DumpPath"}, ""};
const Info<int> GFX_BITRATE_KBPS{{System::GFX, "Settings", "BitrateKbps"}, 25000};

View File

@ -45,6 +45,7 @@ extern const Info<bool> GFX_DUMP_FRAMES_AS_IMAGES;
extern const Info<bool> GFX_USE_FFV1;
extern const Info<std::string> GFX_DUMP_FORMAT;
extern const Info<std::string> GFX_DUMP_CODEC;
extern const Info<std::string> GFX_DUMP_PIXEL_FORMAT;
extern const Info<std::string> GFX_DUMP_ENCODER;
extern const Info<std::string> GFX_DUMP_PATH;
extern const Info<int> GFX_BITRATE_KBPS;

View File

@ -21,6 +21,7 @@ extern "C" {
#include <libavutil/log.h>
#include <libavutil/mathematics.h>
#include <libavutil/opt.h>
#include <libavutil/pixdesc.h>
#include <libswscale/swscale.h>
}
@ -249,20 +250,31 @@ bool FrameDump::CreateVideoFile()
m_context->codec->gop_size = 1;
m_context->codec->level = 1;
AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
const std::string& pixel_format_string = g_Config.sDumpPixelFormat;
if (!pixel_format_string.empty())
{
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);
}
if (pix_fmt == AV_PIX_FMT_NONE)
{
if (m_context->codec->codec_id == AV_CODEC_ID_FFV1)
{
m_context->codec->pix_fmt = AV_PIX_FMT_BGR0;
}
pix_fmt = AV_PIX_FMT_BGR0;
else if (m_context->codec->codec_id == AV_CODEC_ID_UTVIDEO)
{
m_context->codec->pix_fmt = AV_PIX_FMT_GBRP;
av_opt_set_int(m_context->codec->priv_data, "pred", 3, 0); // median
}
pix_fmt = AV_PIX_FMT_GBRP;
else
{
m_context->codec->pix_fmt = AV_PIX_FMT_YUV420P;
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
if (output_format->flags & AVFMT_GLOBALHEADER)
m_context->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;

View File

@ -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);

View File

@ -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;