Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10571 from AdmiralCurtiss/ffmpeg-custom-pix-fmt
VideoCommon/FrameDump: Allow user to specify a pixel format.
  • Loading branch information
lioncash committed Apr 9, 2022
2 parents d7709d4 + 3382408 commit e932a1b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions Source/Core/Core/Config/GraphicsSettings.cpp
Expand Up @@ -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};
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/Config/GraphicsSettings.h
Expand Up @@ -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;
Expand Down
30 changes: 21 additions & 9 deletions Source/Core/VideoCommon/FrameDump.cpp
Expand Up @@ -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>
}

Expand Down Expand Up @@ -249,20 +250,31 @@ 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)
{
m_context->codec->pix_fmt = AV_PIX_FMT_GBRP;
av_opt_set_int(m_context->codec->priv_data, "pred", 3, 0); // median
}
else

if (pix_fmt == AV_PIX_FMT_NONE)
{
m_context->codec->pix_fmt = AV_PIX_FMT_YUV420P;
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

if (output_format->flags & AVFMT_GLOBALHEADER)
m_context->codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;

Expand Down
1 change: 1 addition & 0 deletions Source/Core/VideoCommon/VideoConfig.cpp
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Source/Core/VideoCommon/VideoConfig.h
Expand Up @@ -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;
Expand Down

0 comments on commit e932a1b

Please sign in to comment.