summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/FrameDump.cpp
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2022-03-31 05:24:00 +0200
committerGitHub <noreply@github.com>2022-03-31 05:24:00 +0200
commit4957b2edb99ce04c2b29501aab7aa8682943279e (patch)
treec41b4d925ce55a3eedf4aca41acba2f2c7ce4178 /Source/Core/VideoCommon/FrameDump.cpp
parentcc3f8204dac2c207581cc42f9884d6c907f6d642 (diff)
parent4fad2c26e4f3b94fc12e63a0ec472fec83ceb1fe (diff)
Merge pull request #10530 from shuffle2/win-ffmpeg
windows: move ffmpeg bins to submodule
Diffstat (limited to 'Source/Core/VideoCommon/FrameDump.cpp')
-rw-r--r--Source/Core/VideoCommon/FrameDump.cpp62
1 files changed, 54 insertions, 8 deletions
diff --git a/Source/Core/VideoCommon/FrameDump.cpp b/Source/Core/VideoCommon/FrameDump.cpp
index e137170309..7054ba11af 100644
--- a/Source/Core/VideoCommon/FrameDump.cpp
+++ b/Source/Core/VideoCommon/FrameDump.cpp
@@ -7,6 +7,7 @@
#define __STDC_CONSTANT_MACROS 1
#endif
+#include <array>
#include <sstream>
#include <string>
@@ -16,7 +17,10 @@
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
+#include <libavutil/error.h>
+#include <libavutil/log.h>
#include <libavutil/mathematics.h>
+#include <libavutil/opt.h>
#include <libswscale/swscale.h>
}
@@ -69,11 +73,33 @@ void InitAVCodec()
static bool first_run = true;
if (first_run)
{
-#if LIBAVCODEC_VERSION_MICRO >= 100 && LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
- av_register_all();
-#endif
+ av_log_set_level(AV_LOG_DEBUG);
+ av_log_set_callback([](void* ptr, int level, const char* fmt, va_list vl) {
+ if (level < 0)
+ level = AV_LOG_DEBUG;
+ if (level >= 0)
+ level &= 0xff;
+
+ if (level > av_log_get_level())
+ return;
+
+ auto log_level = Common::Log::LogLevel::LNOTICE;
+ if (level >= AV_LOG_ERROR && level < AV_LOG_WARNING)
+ log_level = Common::Log::LogLevel::LERROR;
+ else if (level >= AV_LOG_WARNING && level < AV_LOG_INFO)
+ log_level = Common::Log::LogLevel::LWARNING;
+ else if (level >= AV_LOG_INFO && level < AV_LOG_DEBUG)
+ log_level = Common::Log::LogLevel::LINFO;
+ else if (level >= AV_LOG_DEBUG)
+ // keep libav debug messages visible in release build of dolphin
+ log_level = Common::Log::LogLevel::LINFO;
+
+ GENERIC_LOG(Common::Log::LogType::FRAMEDUMP, log_level, fmt, vl);
+ });
+
// TODO: We never call avformat_network_deinit.
avformat_network_init();
+
first_run = false;
}
}
@@ -109,6 +135,13 @@ std::string GetDumpPath(const std::string& extension, std::time_t time, u32 inde
return path;
}
+std::string AVErrorString(int error)
+{
+ std::array<char, AV_ERROR_MAX_STRING_SIZE> msg;
+ av_make_error_string(&msg[0], msg.size(), error);
+ return fmt::format("{:8x} {}", (u32)error, &msg[0]);
+}
+
} // namespace
bool FrameDump::Start(int w, int h, u64 start_ticks)
@@ -215,7 +248,20 @@ bool FrameDump::CreateVideoFile()
m_context->codec->time_base = time_base;
m_context->codec->gop_size = 1;
m_context->codec->level = 1;
- m_context->codec->pix_fmt = g_Config.bUseFFV1 ? AV_PIX_FMT_BGR0 : AV_PIX_FMT_YUV420P;
+
+ if (m_context->codec->codec_id == AV_CODEC_ID_FFV1)
+ {
+ m_context->codec->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
+ }
+ 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;
@@ -325,7 +371,7 @@ void FrameDump::AddFrame(const FrameData& frame)
if (const int error = avcodec_send_frame(m_context->codec, m_context->scaled_frame))
{
- ERROR_LOG_FMT(FRAMEDUMP, "Error while encoding video: {}", error);
+ ERROR_LOG_FMT(FRAMEDUMP, "Error while encoding video: {}", AVErrorString(error));
return;
}
@@ -355,7 +401,7 @@ void FrameDump::ProcessPackets()
if (receive_error)
{
- ERROR_LOG_FMT(FRAMEDUMP, "Error receiving packet: {}", receive_error);
+ ERROR_LOG_FMT(FRAMEDUMP, "Error receiving packet: {}", AVErrorString(receive_error));
break;
}
@@ -364,7 +410,7 @@ void FrameDump::ProcessPackets()
if (const int write_error = av_interleaved_write_frame(m_context->format, pkt.get()))
{
- ERROR_LOG_FMT(FRAMEDUMP, "Error writing packet: {}", write_error);
+ ERROR_LOG_FMT(FRAMEDUMP, "Error writing packet: {}", AVErrorString(write_error));
break;
}
}
@@ -377,7 +423,7 @@ void FrameDump::Stop()
// Signal end of stream to encoder.
if (const int flush_error = avcodec_send_frame(m_context->codec, nullptr))
- WARN_LOG_FMT(FRAMEDUMP, "Error sending flush packet: {}", flush_error);
+ WARN_LOG_FMT(FRAMEDUMP, "Error sending flush packet: {}", AVErrorString(flush_error));
ProcessPackets();
av_write_trailer(m_context->format);