mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-15 16:25:06 +00:00
5a3954ae0e
Fixes several files incorrectly stated a different license from the actual project, as well as the copyright headers included in all files. This change has no effect on the licensing terms, it should clear up a bit of confusion by contributors. Plus the files get a bit smaller, and we have less duplicated information across the entire project. Overall the project is GPLv2 if not built with Qt, and GPLv3 if it is built with Qt. There are no parts licensed under a different license, all have been adapted from other compatible licenses into GPLv2 or GPLv3.
114 lines
3.9 KiB
C++
114 lines
3.9 KiB
C++
// AUTOGENERATED COPYRIGHT HEADER START
|
|
// Copyright (C) 2022 Carsten Braun <info@braun-cloud.de>
|
|
// Copyright (C) 2022 lainon <GermanAizek@yandex.ru>
|
|
// Copyright (C) 2022-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
|
|
|
#include "dnxhd_handler.hpp"
|
|
#include "common.hpp"
|
|
#include "../codecs/dnxhr.hpp"
|
|
#include "ffmpeg/tools.hpp"
|
|
#include "plugin.hpp"
|
|
|
|
#include "warning-disable.hpp"
|
|
#include <array>
|
|
#include "warning-enable.hpp"
|
|
|
|
using namespace streamfx::encoder::ffmpeg::handler;
|
|
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)
|
|
{
|
|
char buffer[1024];
|
|
snprintf(buffer, sizeof(buffer), "%s.%s", S_CODEC_DNXHR_PROFILE, profile);
|
|
return D_TRANSLATE(buffer);
|
|
}
|
|
|
|
void dnxhd_handler::get_properties(obs_properties_t* props, const AVCodec* codec, AVCodecContext* context, bool)
|
|
{
|
|
AVCodecContext* ctx = context;
|
|
|
|
//Create dummy context if null was passed to the function
|
|
if (!ctx) {
|
|
ctx = avcodec_alloc_context3(codec);
|
|
if (!ctx->priv_data) {
|
|
avcodec_free_context(&ctx);
|
|
return;
|
|
}
|
|
}
|
|
auto p = obs_properties_add_list(props, S_CODEC_DNXHR_PROFILE, D_TRANSLATE(S_CODEC_DNXHR_PROFILE),
|
|
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
|
|
|
|
streamfx::ffmpeg::tools::avoption_list_add_entries(ctx->priv_data, "profile", [&p](const AVOption* opt) {
|
|
if (strcmp(opt->name, "dnxhd") == 0) {
|
|
//Do not show DNxHD profile as it is outdated and should not be used.
|
|
//It's also very picky about framerate and framesize combos, which makes it even less useful
|
|
return;
|
|
}
|
|
|
|
//ffmpeg returns the profiles for DNxHR from highest to lowest.
|
|
//Lowest to highest is what people usually expect.
|
|
//Therefore, new entries will always be inserted at the top, effectively reversing the list
|
|
obs_property_list_insert_string(p, 0, dnx_profile_to_display_name(opt->name), opt->name);
|
|
});
|
|
|
|
//Free context if we created it here
|
|
if (ctx && ctx != context) {
|
|
avcodec_free_context(&ctx);
|
|
}
|
|
}
|
|
|
|
void dnxhd_handler::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
|
|
{
|
|
const char* profile = obs_data_get_string(settings, S_CODEC_DNXHR_PROFILE);
|
|
av_opt_set(context, "profile", profile, AV_OPT_SEARCH_CHILDREN);
|
|
}
|
|
|
|
void dnxhd_handler::log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
|
|
{
|
|
DLOG_INFO("[%s] Avid DNxHR:", codec->name);
|
|
streamfx::ffmpeg::tools::print_av_option_string2(context, "profile", " Profile",
|
|
[](int64_t v, std::string_view o) { return std::string(o); });
|
|
}
|