Merge pull request #10571 from AdmiralCurtiss/ffmpeg-custom-pix-fmt

VideoCommon/FrameDump: Allow user to specify a pixel format.
This commit is contained in:
Mai M 2022-04-09 14:19:39 -04:00 committed by GitHub
commit e932a1bfb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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,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;

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;