mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-28 02:21:25 +00:00
code: Migrate encoder::ffmpeg::dnxhd to new loader
This commit is contained in:
parent
0fb670eba4
commit
d8235bf504
4 changed files with 89 additions and 98 deletions
|
@ -1203,8 +1203,8 @@ if(T_CHECK)
|
||||||
is_feature_enabled(ENCODER_FFMPEG_DNXHR T_CHECK)
|
is_feature_enabled(ENCODER_FFMPEG_DNXHR T_CHECK)
|
||||||
if(T_CHECK)
|
if(T_CHECK)
|
||||||
list(APPEND PROJECT_PRIVATE_SOURCE
|
list(APPEND PROJECT_PRIVATE_SOURCE
|
||||||
"source/encoders/ffmpeg/dnxhd_handler.hpp"
|
"source/encoders/ffmpeg/dnxhd.hpp"
|
||||||
"source/encoders/ffmpeg/dnxhd_handler.cpp"
|
"source/encoders/ffmpeg/dnxhd.cpp"
|
||||||
)
|
)
|
||||||
list(APPEND PROJECT_DEFINITIONS
|
list(APPEND PROJECT_DEFINITIONS
|
||||||
ENABLE_ENCODER_FFMPEG_DNXHR
|
ENABLE_ENCODER_FFMPEG_DNXHR
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// Copyright (C) 2022-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
// Copyright (C) 2022-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
||||||
// AUTOGENERATED COPYRIGHT HEADER END
|
// AUTOGENERATED COPYRIGHT HEADER END
|
||||||
|
|
||||||
#include "dnxhd_handler.hpp"
|
#include "dnxhd.hpp"
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
#include "../codecs/dnxhr.hpp"
|
#include "../codecs/dnxhr.hpp"
|
||||||
#include "ffmpeg/tools.hpp"
|
#include "ffmpeg/tools.hpp"
|
||||||
|
@ -14,47 +14,9 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "warning-enable.hpp"
|
#include "warning-enable.hpp"
|
||||||
|
|
||||||
using namespace streamfx::encoder::ffmpeg::handler;
|
using namespace streamfx::encoder::ffmpeg;
|
||||||
using namespace streamfx::encoder::codec::dnxhr;
|
using namespace streamfx::encoder::codec::dnxhr;
|
||||||
|
|
||||||
void dnxhd_handler::adjust_info(ffmpeg_factory* fac, const AVCodec*, std::string&, std::string& name, std::string&)
|
|
||||||
{
|
|
||||||
//Most people don't know what VC3 is and only know it as DNx.
|
|
||||||
//Change name to make it easier to find.
|
|
||||||
name = "Avid DNxHR (via FFmpeg)";
|
|
||||||
}
|
|
||||||
|
|
||||||
void dnxhd_handler::override_colorformat(AVPixelFormat& target_format, obs_data_t* settings, const AVCodec* codec, AVCodecContext*)
|
|
||||||
{
|
|
||||||
static const std::array<std::pair<const char*, AVPixelFormat>, static_cast<size_t>(5)> profile_to_format_map{std::pair{"dnxhr_lb", AV_PIX_FMT_YUV422P}, std::pair{"dnxhr_sq", AV_PIX_FMT_YUV422P}, std::pair{"dnxhr_hq", AV_PIX_FMT_YUV422P}, std::pair{"dnxhr_hqx", AV_PIX_FMT_YUV422P10}, std::pair{"dnxhr_444", AV_PIX_FMT_YUV444P10}};
|
|
||||||
|
|
||||||
const char* selected_profile = obs_data_get_string(settings, S_CODEC_DNXHR_PROFILE);
|
|
||||||
for (const auto& kv : profile_to_format_map) {
|
|
||||||
if (strcmp(kv.first, selected_profile) == 0) {
|
|
||||||
target_format = kv.second;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback for (yet) unknown formats
|
|
||||||
target_format = AV_PIX_FMT_YUV422P;
|
|
||||||
}
|
|
||||||
|
|
||||||
void dnxhd_handler::get_defaults(obs_data_t* settings, const AVCodec*, AVCodecContext*, bool)
|
|
||||||
{
|
|
||||||
obs_data_set_default_string(settings, S_CODEC_DNXHR_PROFILE, "dnxhr_sq");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool dnxhd_handler::has_keyframe_support(ffmpeg_factory* instance)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool dnxhd_handler::has_pixel_format_support(ffmpeg_factory* instance)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const char* dnx_profile_to_display_name(const char* profile)
|
inline const char* dnx_profile_to_display_name(const char* profile)
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
@ -62,13 +24,34 @@ inline const char* dnx_profile_to_display_name(const char* profile)
|
||||||
return D_TRANSLATE(buffer);
|
return D_TRANSLATE(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnxhd_handler::get_properties(obs_properties_t* props, const AVCodec* codec, AVCodecContext* context, bool)
|
dnxhd::dnxhd() : handler("dnxhd") {}
|
||||||
|
|
||||||
|
dnxhd::~dnxhd() {}
|
||||||
|
|
||||||
|
void dnxhd::adjust_info(ffmpeg_factory* factory, std::string& id, std::string& name, std::string& codec)
|
||||||
{
|
{
|
||||||
AVCodecContext* ctx = context;
|
//Most people don't know what VC3 is and only know it as DNx.
|
||||||
|
//Change name to make it easier to find.
|
||||||
|
name = "Avid DNxHR (via FFmpeg)";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dnxhd::has_keyframes(ffmpeg_factory* instance)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnxhd::defaults(ffmpeg_factory* factory, obs_data_t* settings)
|
||||||
|
{
|
||||||
|
obs_data_set_default_string(settings, S_CODEC_DNXHR_PROFILE, "dnxhr_sq");
|
||||||
|
}
|
||||||
|
|
||||||
|
void dnxhd::properties(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_properties_t* props)
|
||||||
|
{
|
||||||
|
AVCodecContext* ctx = instance->get_avcodeccontext();
|
||||||
|
|
||||||
//Create dummy context if null was passed to the function
|
//Create dummy context if null was passed to the function
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
ctx = avcodec_alloc_context3(codec);
|
ctx = avcodec_alloc_context3(factory->get_avcodec());
|
||||||
if (!ctx->priv_data) {
|
if (!ctx->priv_data) {
|
||||||
avcodec_free_context(&ctx);
|
avcodec_free_context(&ctx);
|
||||||
return;
|
return;
|
||||||
|
@ -90,19 +73,37 @@ void dnxhd_handler::get_properties(obs_properties_t* props, const AVCodec* codec
|
||||||
});
|
});
|
||||||
|
|
||||||
//Free context if we created it here
|
//Free context if we created it here
|
||||||
if (ctx && ctx != context) {
|
if (ctx && ctx != instance->get_avcodeccontext()) {
|
||||||
avcodec_free_context(&ctx);
|
avcodec_free_context(&ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnxhd_handler::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
|
void dnxhd::update(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_data_t* settings)
|
||||||
{
|
{
|
||||||
const char* profile = obs_data_get_string(settings, S_CODEC_DNXHR_PROFILE);
|
const char* profile = obs_data_get_string(settings, S_CODEC_DNXHR_PROFILE);
|
||||||
av_opt_set(context, "profile", profile, AV_OPT_SEARCH_CHILDREN);
|
av_opt_set(instance->get_avcodeccontext(), "profile", profile, AV_OPT_SEARCH_CHILDREN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnxhd_handler::log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
|
void dnxhd::log(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_data_t* settings)
|
||||||
{
|
{
|
||||||
DLOG_INFO("[%s] Avid DNxHR:", codec->name);
|
DLOG_INFO("[%s] Avid DNxHR:", factory->get_avcodec()->name);
|
||||||
streamfx::ffmpeg::tools::print_av_option_string2(context, "profile", " Profile", [](int64_t v, std::string_view o) { return std::string(o); });
|
streamfx::ffmpeg::tools::print_av_option_string2(instance->get_avcodeccontext(), "profile", " Profile", [](int64_t v, std::string_view o) { return std::string(o); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dnxhd::override_colorformat(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_data_t* settings, AVPixelFormat& target_format)
|
||||||
|
{
|
||||||
|
static const std::array<std::pair<const char*, AVPixelFormat>, static_cast<size_t>(5)> profile_to_format_map{std::pair{"dnxhr_lb", AV_PIX_FMT_YUV422P}, std::pair{"dnxhr_sq", AV_PIX_FMT_YUV422P}, std::pair{"dnxhr_hq", AV_PIX_FMT_YUV422P}, std::pair{"dnxhr_hqx", AV_PIX_FMT_YUV422P10}, std::pair{"dnxhr_444", AV_PIX_FMT_YUV444P10}};
|
||||||
|
|
||||||
|
const char* selected_profile = obs_data_get_string(settings, S_CODEC_DNXHR_PROFILE);
|
||||||
|
for (const auto& kv : profile_to_format_map) {
|
||||||
|
if (strcmp(kv.first, selected_profile) == 0) {
|
||||||
|
target_format = kv.second;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback for (yet) unknown formats
|
||||||
|
target_format = AV_PIX_FMT_YUV422P;
|
||||||
|
}
|
||||||
|
|
||||||
|
static auto inst = dnxhd();
|
37
source/encoders/ffmpeg/dnxhd.hpp
Normal file
37
source/encoders/ffmpeg/dnxhd.hpp
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
// AUTOGENERATED COPYRIGHT HEADER START
|
||||||
|
// Copyright (C) 2022 Carsten Braun <info@braun-cloud.de>
|
||||||
|
// Copyright (C) 2022-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
||||||
|
// AUTOGENERATED COPYRIGHT HEADER END
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "encoders/encoder-ffmpeg.hpp"
|
||||||
|
#include "encoders/ffmpeg/handler.hpp"
|
||||||
|
|
||||||
|
#include "warning-disable.hpp"
|
||||||
|
extern "C" {
|
||||||
|
#include <libavcodec/avcodec.h>
|
||||||
|
}
|
||||||
|
#include "warning-enable.hpp"
|
||||||
|
|
||||||
|
namespace streamfx::encoder::ffmpeg {
|
||||||
|
class dnxhd : public handler {
|
||||||
|
public:
|
||||||
|
dnxhd();
|
||||||
|
virtual ~dnxhd();
|
||||||
|
|
||||||
|
virtual bool has_keyframes(ffmpeg_factory* factory);
|
||||||
|
|
||||||
|
virtual void adjust_info(ffmpeg_factory* factory, std::string& id, std::string& name, std::string& codec);
|
||||||
|
|
||||||
|
virtual std::string help(ffmpeg_factory* factory) {
|
||||||
|
return "https://github.com/Xaymar/obs-StreamFX/wiki/Encoder-FFmpeg-Avid-DNxHR";
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void defaults(ffmpeg_factory* factory, obs_data_t* settings);
|
||||||
|
virtual void properties(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_properties_t* props);
|
||||||
|
virtual void update(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_data_t* settings);
|
||||||
|
virtual void log(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_data_t* settings);
|
||||||
|
|
||||||
|
virtual void override_colorformat(ffmpeg_factory* factory, ffmpeg_instance* instance, obs_data_t* settings, AVPixelFormat& target_format);
|
||||||
|
};
|
||||||
|
} // namespace streamfx::encoder::ffmpeg
|
|
@ -1,47 +0,0 @@
|
||||||
// AUTOGENERATED COPYRIGHT HEADER START
|
|
||||||
// Copyright (C) 2022 Carsten Braun <info@braun-cloud.de>
|
|
||||||
// Copyright (C) 2022-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
||||||
// AUTOGENERATED COPYRIGHT HEADER END
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "handler.hpp"
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "warning-disable.hpp"
|
|
||||||
#include <libavcodec/avcodec.h>
|
|
||||||
#include "warning-enable.hpp"
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace streamfx::encoder::ffmpeg::handler {
|
|
||||||
class dnxhd_handler : public handler {
|
|
||||||
public:
|
|
||||||
virtual ~dnxhd_handler(){};
|
|
||||||
|
|
||||||
public /*factory*/:
|
|
||||||
virtual void adjust_info(ffmpeg_factory* factory, const AVCodec* codec, std::string& id, std::string& name, std::string& codec_id);
|
|
||||||
|
|
||||||
public /*factory*/:
|
|
||||||
void get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context, bool hw_encode) override;
|
|
||||||
|
|
||||||
virtual std::string_view get_help_url(const AVCodec* codec) override
|
|
||||||
{
|
|
||||||
return "https://github.com/Xaymar/obs-StreamFX/wiki/Encoder-FFmpeg-Avid-DNxHR";
|
|
||||||
};
|
|
||||||
|
|
||||||
public /*support tests*/:
|
|
||||||
virtual bool has_keyframe_support(ffmpeg_factory* instance) override;
|
|
||||||
|
|
||||||
public /*support tests*/:
|
|
||||||
bool has_pixel_format_support(ffmpeg_factory* instance) override;
|
|
||||||
|
|
||||||
public /*settings*/:
|
|
||||||
void get_properties(obs_properties_t* props, const AVCodec* codec, AVCodecContext* context, bool hw_encode) override;
|
|
||||||
|
|
||||||
void update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context) override;
|
|
||||||
|
|
||||||
void log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context) override;
|
|
||||||
|
|
||||||
public /*instance*/:
|
|
||||||
void override_colorformat(AVPixelFormat& target_format, obs_data_t* settings, const AVCodec* codec, AVCodecContext* context) override;
|
|
||||||
};
|
|
||||||
} // namespace streamfx::encoder::ffmpeg::handler
|
|
Loading…
Reference in a new issue