Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b07365cdc4 | |||
| f21cbe9aba | |||
| 403b43e77b | |||
| 58d8713369 | |||
| 2f8acc58cf | |||
| e4e76dae8f | |||
| 4cac28a8a3 | |||
| d0dc4be985 | |||
| 4836f9dda6 | |||
| 650b397ced | |||
| d3f7b15633 | |||
| 545dcd6d50 | |||
| 0461b20e1b | |||
| b3a6dbb1b4 | |||
| fe71944199 | |||
| cbd39a8c2a | |||
| 62eae3827b | |||
| 38e7639862 | |||
| 6bc1cb9c88 | |||
| c63900d575 | |||
| 9efda8af8d | |||
| 0c9764a15c | |||
| 5c5a235502 | |||
| 2ebf90ffd7 | |||
| a32f8dd28b | |||
| d8a692de93 | |||
| a9f39527f6 | |||
| 71440ed3c5 | |||
| 3bd147e6e7 | |||
| 8b6af720bf | |||
| 993a4f8110 |
+13
-2
@@ -25,7 +25,7 @@ Include("cmake/util.cmake")
|
|||||||
|
|
||||||
# Automatic Versioning
|
# Automatic Versioning
|
||||||
set(VERSION_MAJOR 0)
|
set(VERSION_MAJOR 0)
|
||||||
set(VERSION_MINOR 2)
|
set(VERSION_MINOR 3)
|
||||||
set(VERSION_PATCH 0)
|
set(VERSION_PATCH 0)
|
||||||
set(VERSION_TWEAK 0)
|
set(VERSION_TWEAK 0)
|
||||||
set(PROJECT_COMMIT "N/A")
|
set(PROJECT_COMMIT "N/A")
|
||||||
@@ -272,12 +272,16 @@ set(PROJECT_PRIVATE
|
|||||||
"${PROJECT_SOURCE_DIR}/source/codecs/hevc.cpp"
|
"${PROJECT_SOURCE_DIR}/source/codecs/hevc.cpp"
|
||||||
"${PROJECT_SOURCE_DIR}/source/codecs/h264.hpp"
|
"${PROJECT_SOURCE_DIR}/source/codecs/h264.hpp"
|
||||||
"${PROJECT_SOURCE_DIR}/source/codecs/h264.cpp"
|
"${PROJECT_SOURCE_DIR}/source/codecs/h264.cpp"
|
||||||
|
"${PROJECT_SOURCE_DIR}/source/codecs/prores.hpp"
|
||||||
|
"${PROJECT_SOURCE_DIR}/source/codecs/prores.cpp"
|
||||||
"${PROJECT_SOURCE_DIR}/source/ffmpeg/avframe-queue.cpp"
|
"${PROJECT_SOURCE_DIR}/source/ffmpeg/avframe-queue.cpp"
|
||||||
"${PROJECT_SOURCE_DIR}/source/ffmpeg/avframe-queue.hpp"
|
"${PROJECT_SOURCE_DIR}/source/ffmpeg/avframe-queue.hpp"
|
||||||
"${PROJECT_SOURCE_DIR}/source/ffmpeg/swscale.hpp"
|
"${PROJECT_SOURCE_DIR}/source/ffmpeg/swscale.hpp"
|
||||||
"${PROJECT_SOURCE_DIR}/source/ffmpeg/swscale.cpp"
|
"${PROJECT_SOURCE_DIR}/source/ffmpeg/swscale.cpp"
|
||||||
"${PROJECT_SOURCE_DIR}/source/ffmpeg/tools.hpp"
|
"${PROJECT_SOURCE_DIR}/source/ffmpeg/tools.hpp"
|
||||||
"${PROJECT_SOURCE_DIR}/source/ffmpeg/tools.cpp"
|
"${PROJECT_SOURCE_DIR}/source/ffmpeg/tools.cpp"
|
||||||
|
"${PROJECT_SOURCE_DIR}/source/hwapi/base.hpp"
|
||||||
|
"${PROJECT_SOURCE_DIR}/source/hwapi/base.cpp"
|
||||||
"${PROJECT_SOURCE_DIR}/source/ui/handler.hpp"
|
"${PROJECT_SOURCE_DIR}/source/ui/handler.hpp"
|
||||||
"${PROJECT_SOURCE_DIR}/source/ui/handler.cpp"
|
"${PROJECT_SOURCE_DIR}/source/ui/handler.cpp"
|
||||||
"${PROJECT_SOURCE_DIR}/source/ui/debug_handler.hpp"
|
"${PROJECT_SOURCE_DIR}/source/ui/debug_handler.hpp"
|
||||||
@@ -291,6 +295,12 @@ set(PROJECT_PRIVATE
|
|||||||
"${PROJECT_SOURCE_DIR}/source/ui/nvenc_hevc_handler.hpp"
|
"${PROJECT_SOURCE_DIR}/source/ui/nvenc_hevc_handler.hpp"
|
||||||
"${PROJECT_SOURCE_DIR}/source/ui/nvenc_hevc_handler.cpp"
|
"${PROJECT_SOURCE_DIR}/source/ui/nvenc_hevc_handler.cpp"
|
||||||
)
|
)
|
||||||
|
if(WIN32)
|
||||||
|
list(APPEND PROJECT_PRIVATE
|
||||||
|
"${PROJECT_SOURCE_DIR}/source/hwapi/d3d11.hpp"
|
||||||
|
"${PROJECT_SOURCE_DIR}/source/hwapi/d3d11.cpp"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Source Grouping
|
# Source Grouping
|
||||||
source_group(TREE "${PROJECT_SOURCE_DIR}" PREFIX "Data Files" FILES ${PROJECT_DATA})
|
source_group(TREE "${PROJECT_SOURCE_DIR}" PREFIX "Data Files" FILES ${PROJECT_DATA})
|
||||||
@@ -315,6 +325,7 @@ add_library(${PROJECT_NAME} MODULE
|
|||||||
${PROJECT_GENERATED}
|
${PROJECT_GENERATED}
|
||||||
${PROJECT_PRIVATE}
|
${PROJECT_PRIVATE}
|
||||||
${PROJECT_DATA}
|
${PROJECT_DATA}
|
||||||
|
${PROJECT_TEMPLATES}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Include Directories
|
# Include Directories
|
||||||
@@ -355,7 +366,7 @@ endif()
|
|||||||
|
|
||||||
# Link Libraries
|
# Link Libraries
|
||||||
target_link_libraries(${PROJECT_NAME}
|
target_link_libraries(${PROJECT_NAME}
|
||||||
"${PROJECT_LIBRARIES}"
|
${PROJECT_LIBRARIES}
|
||||||
${FFMPEG_LIBRARIES}
|
${FFMPEG_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+9
-14
@@ -48,20 +48,6 @@ KeyFrames.IntervalType.Frames="Frames"
|
|||||||
KeyFrames.IntervalType.Seconds="Seconds"
|
KeyFrames.IntervalType.Seconds="Seconds"
|
||||||
KeyFrames.Interval="Interval"
|
KeyFrames.Interval="Interval"
|
||||||
|
|
||||||
# Apple ProRes
|
|
||||||
AppleProRes.Profile="Profile"
|
|
||||||
AppleProRes.Profile.APCO="Proxy"
|
|
||||||
AppleProRes.Profile.APCS="LT"
|
|
||||||
AppleProRes.Profile.APCN="Standard Definition"
|
|
||||||
AppleProRes.Profile.APCH="High Quality"
|
|
||||||
AppleProRes.Profile.AP4H="4444"
|
|
||||||
|
|
||||||
# ProRes
|
|
||||||
ProRes.Profile.Proxy="Proxy (PXY)"
|
|
||||||
ProRes.Profile.Light="Light (LT)"
|
|
||||||
ProRes.Profile.Standard="Standard"
|
|
||||||
ProRes.Profile.HighQuality="High Quality (HQ)"
|
|
||||||
|
|
||||||
# Codec: H264
|
# Codec: H264
|
||||||
Codec.H264="H264"
|
Codec.H264="H264"
|
||||||
Codec.H264.Profile="Profile"
|
Codec.H264.Profile="Profile"
|
||||||
@@ -82,6 +68,15 @@ Codec.HEVC.Tier.main="Main"
|
|||||||
Codec.HEVC.Tier.high="High"
|
Codec.HEVC.Tier.high="High"
|
||||||
Codec.HEVC.Level="Level"
|
Codec.HEVC.Level="Level"
|
||||||
|
|
||||||
|
# Codec: Apple ProRes
|
||||||
|
Codec.ProRes.Profile="Profile"
|
||||||
|
Codec.ProRes.Profile.APCO="422 Proxy/PXY (APCO)"
|
||||||
|
Codec.ProRes.Profile.APCS="422 Light/LT (APCS)"
|
||||||
|
Codec.ProRes.Profile.APCN="422 Standard (APCN)"
|
||||||
|
Codec.ProRes.Profile.APCH="422 High Quality/HQ (APCH)"
|
||||||
|
Codec.ProRes.Profile.AP4H="4444 Standard (AP4H)"
|
||||||
|
Codec.ProRes.Profile.AP4X="4444 Extra Quality/XQ (AP4X)"
|
||||||
|
|
||||||
# NVENC
|
# NVENC
|
||||||
NVENC.Preset="Preset"
|
NVENC.Preset="Preset"
|
||||||
NVENC.Preset.Default="Default"
|
NVENC.Preset.Default="Default"
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// FFMPEG Video Encoder Integration for OBS Studio
|
||||||
|
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
#include "prores.hpp"
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
// FFMPEG Video Encoder Integration for OBS Studio
|
||||||
|
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Codec: ProRes
|
||||||
|
#define P_PRORES "Codec.ProRes"
|
||||||
|
#define P_PRORES_PROFILE "Codec.ProRes.Profile"
|
||||||
|
#define P_PRORES_PROFILE_APCS "Codec.ProRes.Profile.APCS"
|
||||||
|
#define P_PRORES_PROFILE_APCO "Codec.ProRes.Profile.APCO"
|
||||||
|
#define P_PRORES_PROFILE_APCN "Codec.ProRes.Profile.APCN"
|
||||||
|
#define P_PRORES_PROFILE_APCH "Codec.ProRes.Profile.APCH"
|
||||||
|
#define P_PRORES_PROFILE_AP4H "Codec.ProRes.Profile.AP4H"
|
||||||
|
#define P_PRORES_PROFILE_AP4X "Codec.ProRes.Profile.AP4X"
|
||||||
+811
-497
File diff suppressed because it is too large
Load Diff
+55
-24
@@ -23,9 +23,14 @@
|
|||||||
|
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <queue>
|
||||||
|
#include <stack>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
#include "ffmpeg/avframe-queue.hpp"
|
#include "ffmpeg/avframe-queue.hpp"
|
||||||
#include "ffmpeg/swscale.hpp"
|
#include "ffmpeg/swscale.hpp"
|
||||||
|
#include "hwapi/base.hpp"
|
||||||
|
#include "ui/handler.hpp"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <obs-properties.h>
|
#include <obs-properties.h>
|
||||||
@@ -38,28 +43,40 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace obsffmpeg {
|
namespace obsffmpeg {
|
||||||
|
class unsupported_gpu_exception : public std::runtime_error {
|
||||||
|
public:
|
||||||
|
unsupported_gpu_exception(const std::string& reason) : runtime_error(reason) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct encoder_info {
|
||||||
|
std::string uid;
|
||||||
|
std::string codec;
|
||||||
|
std::string readable_name;
|
||||||
|
obs_encoder_info oei = {0};
|
||||||
|
};
|
||||||
|
|
||||||
class encoder_factory {
|
class encoder_factory {
|
||||||
struct info {
|
encoder_info info;
|
||||||
std::string uid;
|
encoder_info info_fallback;
|
||||||
std::string codec;
|
|
||||||
std::string readable_name;
|
|
||||||
obs_encoder_info oei;
|
|
||||||
} info;
|
|
||||||
const AVCodec* avcodec_ptr;
|
const AVCodec* avcodec_ptr;
|
||||||
|
|
||||||
|
std::shared_ptr<obsffmpeg::ui::handler> _handler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
encoder_factory(const AVCodec* codec);
|
encoder_factory(const AVCodec* codec);
|
||||||
virtual ~encoder_factory();
|
virtual ~encoder_factory();
|
||||||
|
|
||||||
void register_encoder();
|
void register_encoder();
|
||||||
|
|
||||||
const char* get_name();
|
void get_defaults(obs_data_t* settings, bool hw_encoder = false);
|
||||||
|
|
||||||
void get_defaults(obs_data_t* settings);
|
void get_properties(obs_properties_t* props, bool hw_encoder = false);
|
||||||
|
|
||||||
void get_properties(obs_properties_t* props);
|
|
||||||
|
|
||||||
const AVCodec* get_avcodec();
|
const AVCodec* get_avcodec();
|
||||||
|
|
||||||
|
const encoder_info& get_info();
|
||||||
|
|
||||||
|
const encoder_info& get_fallback();
|
||||||
};
|
};
|
||||||
|
|
||||||
class encoder {
|
class encoder {
|
||||||
@@ -69,32 +86,43 @@ namespace obsffmpeg {
|
|||||||
const AVCodec* _codec;
|
const AVCodec* _codec;
|
||||||
AVCodecContext* _context;
|
AVCodecContext* _context;
|
||||||
|
|
||||||
bool _initialized;
|
std::shared_ptr<obsffmpeg::ui::handler> _handler;
|
||||||
std::pair<size_t, size_t> _resolution;
|
|
||||||
AVPixelFormat _format;
|
|
||||||
|
|
||||||
ffmpeg::avframe_queue _frame_queue;
|
std::shared_ptr<obsffmpeg::hwapi::base> _hwapi;
|
||||||
ffmpeg::avframe_queue _frame_queue_used;
|
std::shared_ptr<obsffmpeg::hwapi::instance> _hwinst;
|
||||||
ffmpeg::swscale _swscale;
|
|
||||||
AVPacket _current_packet;
|
|
||||||
|
|
||||||
int64_t _lag_in_frames;
|
ffmpeg::swscale _swscale;
|
||||||
int64_t _count_send_frames;
|
AVPacket _current_packet;
|
||||||
|
|
||||||
|
size_t _lag_in_frames;
|
||||||
|
size_t _count_send_frames;
|
||||||
|
|
||||||
// Extra Data
|
// Extra Data
|
||||||
bool _have_first_frame;
|
bool _have_first_frame;
|
||||||
std::vector<uint8_t> _extra_data;
|
std::vector<uint8_t> _extra_data;
|
||||||
std::vector<uint8_t> _sei_data;
|
std::vector<uint8_t> _sei_data;
|
||||||
|
|
||||||
public:
|
// Frame Stack and Queue
|
||||||
encoder(obs_data_t* settings, obs_encoder_t* encoder);
|
std::stack<std::shared_ptr<AVFrame>> _free_frames;
|
||||||
virtual ~encoder();
|
std::queue<std::shared_ptr<AVFrame>> _used_frames;
|
||||||
|
std::chrono::high_resolution_clock::time_point _free_frames_last_used;
|
||||||
|
|
||||||
bool initialize();
|
void initialize_sw(obs_data_t* settings);
|
||||||
|
void initialize_hw(obs_data_t* settings);
|
||||||
|
|
||||||
|
void push_free_frame(std::shared_ptr<AVFrame> frame);
|
||||||
|
std::shared_ptr<AVFrame> pop_free_frame();
|
||||||
|
|
||||||
|
void push_used_frame(std::shared_ptr<AVFrame> frame);
|
||||||
|
std::shared_ptr<AVFrame> pop_used_frame();
|
||||||
|
|
||||||
|
public:
|
||||||
|
encoder(obs_data_t* settings, obs_encoder_t* encoder, bool is_texture_encode = false);
|
||||||
|
virtual ~encoder();
|
||||||
|
|
||||||
public: // OBS API
|
public: // OBS API
|
||||||
// Shared
|
// Shared
|
||||||
void get_properties(obs_properties_t* props);
|
void get_properties(obs_properties_t* props, bool hw_encode = false);
|
||||||
|
|
||||||
bool update(obs_data_t* settings);
|
bool update(obs_data_t* settings);
|
||||||
|
|
||||||
@@ -120,5 +148,8 @@ namespace obsffmpeg {
|
|||||||
int receive_packet(bool* received_packet, struct encoder_packet* packet);
|
int receive_packet(bool* received_packet, struct encoder_packet* packet);
|
||||||
|
|
||||||
int send_frame(std::shared_ptr<AVFrame> frame);
|
int send_frame(std::shared_ptr<AVFrame> frame);
|
||||||
|
|
||||||
|
bool encode_avframe(std::shared_ptr<AVFrame> frame, struct encoder_packet* packet,
|
||||||
|
bool* received_packet);
|
||||||
};
|
};
|
||||||
} // namespace obsffmpeg
|
} // namespace obsffmpeg
|
||||||
|
|||||||
+120
-44
@@ -20,6 +20,8 @@
|
|||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
#include "tools.hpp"
|
#include "tools.hpp"
|
||||||
|
#include <list>
|
||||||
|
#include <map>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
@@ -159,59 +161,49 @@ const char* ffmpeg::tools::get_error_description(int error)
|
|||||||
return "Not Translated Yet";
|
return "Not Translated Yet";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::map<video_format, AVPixelFormat> obs_to_av_format_map = {
|
||||||
|
{VIDEO_FORMAT_I420, AV_PIX_FMT_YUV420P}, // YUV 4:2:0
|
||||||
|
{VIDEO_FORMAT_NV12, AV_PIX_FMT_NV12}, // NV12 Packed YUV
|
||||||
|
{VIDEO_FORMAT_YVYU, AV_PIX_FMT_YVYU422}, // YVYU Packed YUV
|
||||||
|
{VIDEO_FORMAT_YUY2, AV_PIX_FMT_YUYV422}, // YUYV Packed YUV
|
||||||
|
{VIDEO_FORMAT_UYVY, AV_PIX_FMT_UYVY422}, // UYVY Packed YUV
|
||||||
|
{VIDEO_FORMAT_RGBA, AV_PIX_FMT_RGBA}, //
|
||||||
|
{VIDEO_FORMAT_BGRA, AV_PIX_FMT_BGRA}, //
|
||||||
|
{VIDEO_FORMAT_BGRX, AV_PIX_FMT_BGR0}, //
|
||||||
|
{VIDEO_FORMAT_Y800, AV_PIX_FMT_GRAY8}, //
|
||||||
|
{VIDEO_FORMAT_I444, AV_PIX_FMT_YUV444P}, //
|
||||||
|
{VIDEO_FORMAT_BGR3, AV_PIX_FMT_BGR24}, //
|
||||||
|
{VIDEO_FORMAT_I422, AV_PIX_FMT_YUV422P}, //
|
||||||
|
{VIDEO_FORMAT_I40A, AV_PIX_FMT_YUVA420P}, //
|
||||||
|
{VIDEO_FORMAT_I42A, AV_PIX_FMT_YUVA422P}, //
|
||||||
|
{VIDEO_FORMAT_YUVA, AV_PIX_FMT_YUVA444P}, //
|
||||||
|
//{VIDEO_FORMAT_AYUV, AV_PIX_FMT_AYUV444P}, //
|
||||||
|
};
|
||||||
|
|
||||||
AVPixelFormat ffmpeg::tools::obs_videoformat_to_avpixelformat(video_format v)
|
AVPixelFormat ffmpeg::tools::obs_videoformat_to_avpixelformat(video_format v)
|
||||||
{
|
{
|
||||||
switch (v) {
|
auto found = obs_to_av_format_map.find(v);
|
||||||
// 32-Bits
|
if (found != obs_to_av_format_map.end()) {
|
||||||
case VIDEO_FORMAT_BGRX:
|
return found->second;
|
||||||
return AV_PIX_FMT_BGR0;
|
|
||||||
case VIDEO_FORMAT_BGRA:
|
|
||||||
return AV_PIX_FMT_BGRA;
|
|
||||||
case VIDEO_FORMAT_RGBA:
|
|
||||||
return AV_PIX_FMT_RGBA;
|
|
||||||
case VIDEO_FORMAT_I444:
|
|
||||||
return AV_PIX_FMT_YUV444P;
|
|
||||||
case VIDEO_FORMAT_YUY2:
|
|
||||||
return AV_PIX_FMT_YUYV422;
|
|
||||||
case VIDEO_FORMAT_YVYU:
|
|
||||||
return AV_PIX_FMT_YVYU422;
|
|
||||||
case VIDEO_FORMAT_UYVY:
|
|
||||||
return AV_PIX_FMT_UYVY422;
|
|
||||||
case VIDEO_FORMAT_I420:
|
|
||||||
return AV_PIX_FMT_YUV420P;
|
|
||||||
case VIDEO_FORMAT_NV12:
|
|
||||||
return AV_PIX_FMT_NV12;
|
|
||||||
}
|
}
|
||||||
throw std::invalid_argument("unknown format");
|
return AV_PIX_FMT_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
video_format ffmpeg::tools::avpixelformat_to_obs_videoformat(AVPixelFormat v)
|
video_format ffmpeg::tools::avpixelformat_to_obs_videoformat(AVPixelFormat v)
|
||||||
{
|
{
|
||||||
switch (v) {
|
for (const auto& kv : obs_to_av_format_map) {
|
||||||
case AV_PIX_FMT_YUV420P:
|
if (kv.second == v)
|
||||||
return VIDEO_FORMAT_I420;
|
return kv.first;
|
||||||
case AV_PIX_FMT_NV12:
|
|
||||||
return VIDEO_FORMAT_NV12;
|
|
||||||
case AV_PIX_FMT_YVYU422:
|
|
||||||
return VIDEO_FORMAT_YVYU;
|
|
||||||
case AV_PIX_FMT_YUYV422:
|
|
||||||
return VIDEO_FORMAT_YUY2;
|
|
||||||
case AV_PIX_FMT_UYVY422:
|
|
||||||
return VIDEO_FORMAT_UYVY;
|
|
||||||
case AV_PIX_FMT_RGBA:
|
|
||||||
return VIDEO_FORMAT_RGBA;
|
|
||||||
case AV_PIX_FMT_BGRA:
|
|
||||||
return VIDEO_FORMAT_BGRA;
|
|
||||||
case AV_PIX_FMT_BGR0:
|
|
||||||
return VIDEO_FORMAT_BGRX;
|
|
||||||
case AV_PIX_FMT_GRAY8:
|
|
||||||
return VIDEO_FORMAT_Y800;
|
|
||||||
case AV_PIX_FMT_YUV444P:
|
|
||||||
return VIDEO_FORMAT_I444;
|
|
||||||
}
|
}
|
||||||
return VIDEO_FORMAT_NONE;
|
return VIDEO_FORMAT_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AVPixelFormat ffmpeg::tools::get_least_lossy_format(const AVPixelFormat* haystack, AVPixelFormat needle)
|
||||||
|
{
|
||||||
|
int data_loss = 0;
|
||||||
|
return avcodec_find_best_pix_fmt_of_list(haystack, needle, 0, &data_loss);
|
||||||
|
}
|
||||||
|
|
||||||
AVColorSpace ffmpeg::tools::obs_videocolorspace_to_avcolorspace(video_colorspace v)
|
AVColorSpace ffmpeg::tools::obs_videocolorspace_to_avcolorspace(video_colorspace v)
|
||||||
{
|
{
|
||||||
switch (v) {
|
switch (v) {
|
||||||
@@ -228,10 +220,94 @@ AVColorRange ffmpeg::tools::obs_videorangetype_to_avcolorrange(video_range_type
|
|||||||
{
|
{
|
||||||
switch (v) {
|
switch (v) {
|
||||||
case VIDEO_RANGE_DEFAULT:
|
case VIDEO_RANGE_DEFAULT:
|
||||||
case VIDEO_RANGE_FULL:
|
|
||||||
return AVCOL_RANGE_JPEG;
|
|
||||||
case VIDEO_RANGE_PARTIAL:
|
case VIDEO_RANGE_PARTIAL:
|
||||||
return AVCOL_RANGE_MPEG;
|
return AVCOL_RANGE_MPEG;
|
||||||
|
case VIDEO_RANGE_FULL:
|
||||||
|
return AVCOL_RANGE_JPEG;
|
||||||
}
|
}
|
||||||
throw std::invalid_argument("unknown range");
|
throw std::invalid_argument("unknown range");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ffmpeg::tools::can_hardware_encode(const AVCodec* codec)
|
||||||
|
{
|
||||||
|
AVPixelFormat hardware_formats[] = {AV_PIX_FMT_D3D11};
|
||||||
|
|
||||||
|
for (const AVPixelFormat* fmt = codec->pix_fmts; (fmt != nullptr) && (*fmt != AV_PIX_FMT_NONE); fmt++) {
|
||||||
|
for (auto cmp : hardware_formats) {
|
||||||
|
if (*fmt == cmp) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<AVPixelFormat> ffmpeg::tools::get_software_formats(const AVPixelFormat* list)
|
||||||
|
{
|
||||||
|
AVPixelFormat hardware_formats[] = {
|
||||||
|
#if FF_API_VAAPI
|
||||||
|
AV_PIX_FMT_VAAPI_MOCO,
|
||||||
|
AV_PIX_FMT_VAAPI_IDCT,
|
||||||
|
#endif
|
||||||
|
AV_PIX_FMT_VAAPI,
|
||||||
|
AV_PIX_FMT_DXVA2_VLD,
|
||||||
|
AV_PIX_FMT_VDPAU,
|
||||||
|
AV_PIX_FMT_QSV,
|
||||||
|
AV_PIX_FMT_MMAL,
|
||||||
|
AV_PIX_FMT_D3D11VA_VLD,
|
||||||
|
AV_PIX_FMT_CUDA,
|
||||||
|
AV_PIX_FMT_XVMC,
|
||||||
|
AV_PIX_FMT_VIDEOTOOLBOX,
|
||||||
|
AV_PIX_FMT_MEDIACODEC,
|
||||||
|
AV_PIX_FMT_D3D11,
|
||||||
|
AV_PIX_FMT_OPENCL,
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<AVPixelFormat> fmts;
|
||||||
|
for (auto fmt = list; fmt && (*fmt != AV_PIX_FMT_NONE); fmt++) {
|
||||||
|
bool is_blacklisted = false;
|
||||||
|
for (auto blacklisted : hardware_formats) {
|
||||||
|
if (*fmt == blacklisted)
|
||||||
|
is_blacklisted = true;
|
||||||
|
}
|
||||||
|
if (!is_blacklisted)
|
||||||
|
fmts.push_back(*fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
fmts.push_back(AV_PIX_FMT_NONE);
|
||||||
|
|
||||||
|
return std::move(fmts);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ffmpeg::tools::setup_obs_color(video_colorspace colorspace, video_range_type range, AVCodecContext* context)
|
||||||
|
{
|
||||||
|
std::map<video_colorspace, std::tuple<AVColorSpace, AVColorPrimaries, AVColorTransferCharacteristic>>
|
||||||
|
colorspaces = {
|
||||||
|
{VIDEO_CS_DEFAULT, {AVCOL_SPC_BT470BG, AVCOL_PRI_BT470BG, AVCOL_TRC_SMPTE170M}},
|
||||||
|
{VIDEO_CS_601, {AVCOL_SPC_BT470BG, AVCOL_PRI_BT470BG, AVCOL_TRC_SMPTE170M}},
|
||||||
|
{VIDEO_CS_709, {AVCOL_SPC_BT709, AVCOL_PRI_BT709, AVCOL_TRC_BT709}},
|
||||||
|
};
|
||||||
|
std::map<video_range_type, AVColorRange> colorranges = {
|
||||||
|
{VIDEO_RANGE_DEFAULT, AVCOL_RANGE_MPEG},
|
||||||
|
{VIDEO_RANGE_PARTIAL, AVCOL_RANGE_MPEG},
|
||||||
|
{VIDEO_RANGE_FULL, AVCOL_RANGE_JPEG},
|
||||||
|
};
|
||||||
|
|
||||||
|
{
|
||||||
|
auto found = colorspaces.find(colorspace);
|
||||||
|
if (found != colorspaces.end()) {
|
||||||
|
context->colorspace = std::get<AVColorSpace>(found->second);
|
||||||
|
context->color_primaries = std::get<AVColorPrimaries>(found->second);
|
||||||
|
context->color_trc = std::get<AVColorTransferCharacteristic>(found->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto found = colorranges.find(range);
|
||||||
|
if (found != colorranges.end()) {
|
||||||
|
context->color_range = found->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Downscaling should result in downscaling, not pixelation
|
||||||
|
context->chroma_sample_location = AVCHROMA_LOC_CENTER;
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,8 +25,10 @@
|
|||||||
|
|
||||||
#include <obs.h>
|
#include <obs.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
#include <libavcodec/avcodec.h>
|
||||||
#include <libavutil/pixfmt.h>
|
#include <libavutil/pixfmt.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,9 +46,17 @@ namespace ffmpeg {
|
|||||||
|
|
||||||
video_format avpixelformat_to_obs_videoformat(AVPixelFormat v);
|
video_format avpixelformat_to_obs_videoformat(AVPixelFormat v);
|
||||||
|
|
||||||
|
AVPixelFormat get_least_lossy_format(const AVPixelFormat* haystack, AVPixelFormat needle);
|
||||||
|
|
||||||
AVColorSpace obs_videocolorspace_to_avcolorspace(video_colorspace v);
|
AVColorSpace obs_videocolorspace_to_avcolorspace(video_colorspace v);
|
||||||
|
|
||||||
AVColorRange obs_videorangetype_to_avcolorrange(video_range_type v);
|
AVColorRange obs_videorangetype_to_avcolorrange(video_range_type v);
|
||||||
|
|
||||||
|
bool can_hardware_encode(const AVCodec* codec);
|
||||||
|
|
||||||
|
std::vector<AVPixelFormat> get_software_formats(const AVPixelFormat* list);
|
||||||
|
|
||||||
|
void setup_obs_color(video_colorspace colorspace, video_range_type range, AVCodecContext* context);
|
||||||
} // namespace tools
|
} // namespace tools
|
||||||
} // namespace ffmpeg
|
} // namespace ffmpeg
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// FFMPEG Video Encoder Integration for OBS Studio
|
||||||
|
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
#include "base.hpp"
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
// FFMPEG Video Encoder Integration for OBS Studio
|
||||||
|
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cinttypes>
|
||||||
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4244)
|
||||||
|
#include <libavutil/frame.h>
|
||||||
|
#include <libavutil/hwcontext.h>
|
||||||
|
#pragma warning(pop)
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace obsffmpeg {
|
||||||
|
namespace hwapi {
|
||||||
|
struct device {
|
||||||
|
std::pair<int64_t, int64_t> id;
|
||||||
|
std::string name;
|
||||||
|
};
|
||||||
|
|
||||||
|
class instance;
|
||||||
|
|
||||||
|
class base {
|
||||||
|
public:
|
||||||
|
virtual std::list<obsffmpeg::hwapi::device> enumerate_adapters() = 0;
|
||||||
|
|
||||||
|
virtual std::shared_ptr<obsffmpeg::hwapi::instance> create(obsffmpeg::hwapi::device target) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class instance {
|
||||||
|
public:
|
||||||
|
virtual AVBufferRef* create_device_context() = 0;
|
||||||
|
|
||||||
|
virtual std::shared_ptr<AVFrame> allocate_frame(AVBufferRef* frames) = 0;
|
||||||
|
|
||||||
|
virtual void copy_from_obs(AVBufferRef* frames, uint32_t handle, uint64_t lock_key,
|
||||||
|
uint64_t* next_lock_key, std::shared_ptr<AVFrame> frame) = 0;
|
||||||
|
|
||||||
|
virtual std::shared_ptr<AVFrame> avframe_from_obs(AVBufferRef* frames, uint32_t handle,
|
||||||
|
uint64_t lock_key,
|
||||||
|
uint64_t* next_lock_key) = 0;
|
||||||
|
};
|
||||||
|
} // namespace hwapi
|
||||||
|
} // namespace obsffmpeg
|
||||||
@@ -0,0 +1,217 @@
|
|||||||
|
// FFMPEG Video Encoder Integration for OBS Studio
|
||||||
|
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
#include "d3d11.hpp"
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable : 4244)
|
||||||
|
#include <libavutil/hwcontext_d3d11va.h>
|
||||||
|
#pragma warning(pop)
|
||||||
|
}
|
||||||
|
|
||||||
|
obsffmpeg::hwapi::d3d11::d3d11() : _dxgi_module(0), _d3d11_module(0)
|
||||||
|
{
|
||||||
|
_dxgi_module = LoadLibraryW(L"dxgi.dll");
|
||||||
|
if (!_dxgi_module)
|
||||||
|
throw std::runtime_error("Unable to load DXGI");
|
||||||
|
|
||||||
|
_d3d11_module = LoadLibraryW(L"d3d11.dll");
|
||||||
|
if (!_d3d11_module)
|
||||||
|
throw std::runtime_error("Unable to load D3D11");
|
||||||
|
|
||||||
|
_CreateDXGIFactory = reinterpret_cast<CreateDXGIFactory_t>(GetProcAddress(_dxgi_module, "CreateDXGIFactory"));
|
||||||
|
_CreateDXGIFactory1 =
|
||||||
|
reinterpret_cast<CreateDXGIFactory1_t>(GetProcAddress(_dxgi_module, "CreateDXGIFactory1"));
|
||||||
|
_D3D11CreateDevice = reinterpret_cast<D3D11CreateDevice_t>(GetProcAddress(_d3d11_module, "D3D11CreateDevice"));
|
||||||
|
|
||||||
|
if (!_CreateDXGIFactory && !_CreateDXGIFactory1)
|
||||||
|
throw std::runtime_error("DXGI not supported");
|
||||||
|
|
||||||
|
if (!_D3D11CreateDevice)
|
||||||
|
throw std::runtime_error("D3D11 not supported");
|
||||||
|
|
||||||
|
HRESULT hr = _CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&_dxgifactory);
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
std::stringstream sstr;
|
||||||
|
sstr << "Failed to create DXGI Factory (" << hr << ")";
|
||||||
|
throw std::runtime_error(sstr.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
obsffmpeg::hwapi::d3d11::~d3d11()
|
||||||
|
{
|
||||||
|
FreeLibrary(_dxgi_module);
|
||||||
|
FreeLibrary(_d3d11_module);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<obsffmpeg::hwapi::device> obsffmpeg::hwapi::d3d11::enumerate_adapters()
|
||||||
|
{
|
||||||
|
std::list<device> adapters;
|
||||||
|
|
||||||
|
// Enumerate Adapters
|
||||||
|
IDXGIAdapter1* dxgi_adapter = nullptr;
|
||||||
|
for (UINT idx = 0; !FAILED(_dxgifactory->EnumAdapters1(idx, &dxgi_adapter)); idx++) {
|
||||||
|
DXGI_ADAPTER_DESC1 desc = DXGI_ADAPTER_DESC1();
|
||||||
|
dxgi_adapter->GetDesc1(&desc);
|
||||||
|
|
||||||
|
std::vector<char> buf(1024);
|
||||||
|
size_t len = snprintf(buf.data(), buf.size(), "%ls (VEN_%04x/DEV_%04x/SUB_%04x/REV_%04x)",
|
||||||
|
desc.Description, desc.VendorId, desc.DeviceId, desc.SubSysId, desc.Revision);
|
||||||
|
|
||||||
|
device dev;
|
||||||
|
dev.name = std::string(buf.data(), buf.data() + len);
|
||||||
|
dev.id.first = desc.AdapterLuid.HighPart;
|
||||||
|
dev.id.second = desc.AdapterLuid.LowPart;
|
||||||
|
|
||||||
|
adapters.push_back(dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::move(adapters);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<obsffmpeg::hwapi::instance> obsffmpeg::hwapi::d3d11::create(obsffmpeg::hwapi::device target)
|
||||||
|
{
|
||||||
|
std::shared_ptr<d3d11_instance> inst;
|
||||||
|
ATL::CComPtr<ID3D11Device> device;
|
||||||
|
ATL::CComPtr<ID3D11DeviceContext> context;
|
||||||
|
IDXGIAdapter1* adapter = nullptr;
|
||||||
|
|
||||||
|
// Find the correct "Adapter" (device).
|
||||||
|
IDXGIAdapter1* dxgi_adapter = nullptr;
|
||||||
|
for (UINT idx = 0; !FAILED(_dxgifactory->EnumAdapters1(idx, &dxgi_adapter)); idx++) {
|
||||||
|
DXGI_ADAPTER_DESC1 desc = DXGI_ADAPTER_DESC1();
|
||||||
|
dxgi_adapter->GetDesc1(&desc);
|
||||||
|
|
||||||
|
if ((desc.AdapterLuid.LowPart == target.id.second) && (desc.AdapterLuid.HighPart == target.id.first)) {
|
||||||
|
adapter = dxgi_adapter;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a D3D11 Device
|
||||||
|
UINT device_flags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
|
||||||
|
std::vector<D3D_FEATURE_LEVEL> feature_levels = {D3D_FEATURE_LEVEL_12_1, D3D_FEATURE_LEVEL_12_0,
|
||||||
|
D3D_FEATURE_LEVEL_11_1};
|
||||||
|
|
||||||
|
if (FAILED(_D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_HARDWARE, NULL, device_flags, feature_levels.data(),
|
||||||
|
static_cast<UINT>(feature_levels.size()), D3D11_SDK_VERSION, &device, NULL,
|
||||||
|
&context))) {
|
||||||
|
throw std::runtime_error("Failed to create D3D11 device for target.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::make_shared<d3d11_instance>(device, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct D3D11AVFrame {
|
||||||
|
ATL::CComPtr<ID3D11Texture2D> handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
obsffmpeg::hwapi::d3d11_instance::d3d11_instance(ATL::CComPtr<ID3D11Device> device,
|
||||||
|
ATL::CComPtr<ID3D11DeviceContext> context)
|
||||||
|
{
|
||||||
|
_device = device;
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
obsffmpeg::hwapi::d3d11_instance::~d3d11_instance() {}
|
||||||
|
|
||||||
|
AVBufferRef* obsffmpeg::hwapi::d3d11_instance::create_device_context()
|
||||||
|
{
|
||||||
|
AVBufferRef* dctx_ref = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_D3D11VA);
|
||||||
|
if (!dctx_ref)
|
||||||
|
throw std::runtime_error("Failed to allocate AVHWDeviceContext.");
|
||||||
|
|
||||||
|
AVHWDeviceContext* dctx = reinterpret_cast<AVHWDeviceContext*>(dctx_ref->data);
|
||||||
|
AVD3D11VADeviceContext* d3d11va = reinterpret_cast<AVD3D11VADeviceContext*>(dctx->hwctx);
|
||||||
|
|
||||||
|
// TODO: Determine if these need an additional reference.
|
||||||
|
d3d11va->device = _device;
|
||||||
|
d3d11va->device->AddRef();
|
||||||
|
d3d11va->device_context = _context;
|
||||||
|
d3d11va->device_context->AddRef();
|
||||||
|
|
||||||
|
if (av_hwdevice_ctx_init(dctx_ref) < 0)
|
||||||
|
throw std::runtime_error("Failed to initialize AVHWDeviceContext.");
|
||||||
|
|
||||||
|
return dctx_ref;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<AVFrame> obsffmpeg::hwapi::d3d11_instance::allocate_frame(AVBufferRef* frames)
|
||||||
|
{
|
||||||
|
auto frame = std::shared_ptr<AVFrame>(av_frame_alloc(), [](AVFrame* frame) {
|
||||||
|
av_frame_unref(frame);
|
||||||
|
av_frame_free(&frame);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (av_hwframe_get_buffer(frames, frame.get(), 0) < 0) {
|
||||||
|
throw std::runtime_error("Failed to create AVFrame.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
void obsffmpeg::hwapi::d3d11_instance::copy_from_obs(AVBufferRef*, uint32_t handle, uint64_t lock_key,
|
||||||
|
uint64_t* next_lock_key, std::shared_ptr<AVFrame> frame)
|
||||||
|
{
|
||||||
|
ATL::CComPtr<IDXGIKeyedMutex> mutex;
|
||||||
|
ATL::CComPtr<ID3D11Texture2D> input;
|
||||||
|
|
||||||
|
if (FAILED(_device->OpenSharedResource(reinterpret_cast<HANDLE>(static_cast<uintptr_t>(handle)),
|
||||||
|
__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&input)))) {
|
||||||
|
throw std::runtime_error("Failed to open shared texture resource.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FAILED(input->QueryInterface(__uuidof(IDXGIKeyedMutex), reinterpret_cast<void**>(&mutex)))) {
|
||||||
|
throw std::runtime_error("Failed to retrieve mutex for texture resource.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FAILED(mutex->AcquireSync(lock_key, 1000))) {
|
||||||
|
throw std::runtime_error("Failed to acquire lock on input texture.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set some parameters on the input texture, and get its description.
|
||||||
|
UINT evict = input->GetEvictionPriority();
|
||||||
|
input->SetEvictionPriority(DXGI_RESOURCE_PRIORITY_MAXIMUM);
|
||||||
|
|
||||||
|
// Clone the content of the input texture.
|
||||||
|
_context->CopyResource(reinterpret_cast<ID3D11Texture2D*>(frame->data[0]), input);
|
||||||
|
|
||||||
|
// Restore original parameters on input.
|
||||||
|
input->SetEvictionPriority(evict);
|
||||||
|
|
||||||
|
if (FAILED(mutex->ReleaseSync(lock_key))) {
|
||||||
|
throw std::runtime_error("Failed to release lock on input texture.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Determine if this is necessary.
|
||||||
|
mutex->ReleaseSync(*next_lock_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<AVFrame> obsffmpeg::hwapi::d3d11_instance::avframe_from_obs(AVBufferRef* frames, uint32_t handle,
|
||||||
|
uint64_t lock_key, uint64_t* next_lock_key)
|
||||||
|
{
|
||||||
|
auto frame = this->allocate_frame(frames);
|
||||||
|
this->copy_from_obs(frames, handle, lock_key, next_lock_key, frame);
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
// FFMPEG Video Encoder Integration for OBS Studio
|
||||||
|
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
|
#include <atlutil.h>
|
||||||
|
#include <d3d11.h>
|
||||||
|
#include <d3d11_1.h>
|
||||||
|
#include <dxgi.h>
|
||||||
|
#include "base.hpp"
|
||||||
|
|
||||||
|
namespace obsffmpeg {
|
||||||
|
namespace hwapi {
|
||||||
|
class d3d11 : public ::obsffmpeg::hwapi::base {
|
||||||
|
typedef HRESULT(__stdcall* CreateDXGIFactory_t)(REFIID, void**);
|
||||||
|
typedef HRESULT(__stdcall* CreateDXGIFactory1_t)(REFIID, void**);
|
||||||
|
typedef HRESULT(__stdcall* D3D11CreateDevice_t)(_In_opt_ IDXGIAdapter*, D3D_DRIVER_TYPE,
|
||||||
|
HMODULE, UINT, CONST D3D_FEATURE_LEVEL*, UINT,
|
||||||
|
UINT, _Out_opt_ ID3D11Device**,
|
||||||
|
_Out_opt_ D3D_FEATURE_LEVEL*,
|
||||||
|
_Out_opt_ ID3D11DeviceContext**);
|
||||||
|
|
||||||
|
HMODULE _dxgi_module;
|
||||||
|
CreateDXGIFactory_t _CreateDXGIFactory;
|
||||||
|
CreateDXGIFactory1_t _CreateDXGIFactory1;
|
||||||
|
|
||||||
|
HMODULE _d3d11_module;
|
||||||
|
D3D11CreateDevice_t _D3D11CreateDevice;
|
||||||
|
|
||||||
|
ATL::CComPtr<IDXGIFactory1> _dxgifactory;
|
||||||
|
|
||||||
|
public:
|
||||||
|
d3d11();
|
||||||
|
virtual ~d3d11();
|
||||||
|
|
||||||
|
virtual std::list<obsffmpeg::hwapi::device> enumerate_adapters() override;
|
||||||
|
|
||||||
|
virtual std::shared_ptr<obsffmpeg::hwapi::instance>
|
||||||
|
create(obsffmpeg::hwapi::device target) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class d3d11_instance : public ::obsffmpeg::hwapi::instance {
|
||||||
|
ATL::CComPtr<ID3D11Device> _device;
|
||||||
|
ATL::CComPtr<ID3D11DeviceContext> _context;
|
||||||
|
|
||||||
|
public:
|
||||||
|
d3d11_instance(ATL::CComPtr<ID3D11Device> device, ATL::CComPtr<ID3D11DeviceContext> context);
|
||||||
|
virtual ~d3d11_instance();
|
||||||
|
|
||||||
|
virtual AVBufferRef* create_device_context() override;
|
||||||
|
|
||||||
|
virtual std::shared_ptr<AVFrame> allocate_frame(AVBufferRef* frames) override;
|
||||||
|
|
||||||
|
virtual void copy_from_obs(AVBufferRef* frames, uint32_t handle, uint64_t lock_key,
|
||||||
|
uint64_t* next_lock_key, std::shared_ptr<AVFrame> frame) override;
|
||||||
|
|
||||||
|
virtual std::shared_ptr<AVFrame> avframe_from_obs(AVBufferRef* frames, uint32_t handle,
|
||||||
|
uint64_t lock_key,
|
||||||
|
uint64_t* next_lock_key) override;
|
||||||
|
};
|
||||||
|
} // namespace hwapi
|
||||||
|
} // namespace obsffmpeg
|
||||||
@@ -35,7 +35,7 @@ extern "C" {
|
|||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
}
|
}
|
||||||
|
|
||||||
void obsffmpeg::ui::debug_handler::get_defaults(obs_data_t*, const AVCodec*, AVCodecContext*) {}
|
void obsffmpeg::ui::debug_handler::get_defaults(obs_data_t*, const AVCodec*, AVCodecContext*, bool) {}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string to_string(T value){};
|
std::string to_string(T value){};
|
||||||
@@ -64,7 +64,8 @@ std::string to_string(double_t value)
|
|||||||
return std::string(buf.data(), buf.data() + buf.size());
|
return std::string(buf.data(), buf.data() + buf.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void obsffmpeg::ui::debug_handler::get_properties(obs_properties_t*, const AVCodec* codec, AVCodecContext* context)
|
void obsffmpeg::ui::debug_handler::get_properties(obs_properties_t*, const AVCodec* codec, AVCodecContext* context,
|
||||||
|
bool)
|
||||||
{
|
{
|
||||||
if (context)
|
if (context)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ namespace obsffmpeg {
|
|||||||
namespace ui {
|
namespace ui {
|
||||||
class debug_handler : public handler {
|
class debug_handler : public handler {
|
||||||
public:
|
public:
|
||||||
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec,
|
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context,
|
||||||
AVCodecContext* context) override;
|
bool hw_encode) override;
|
||||||
|
|
||||||
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||||
AVCodecContext* context) override;
|
AVCodecContext* context, bool hw_encode) override;
|
||||||
|
|
||||||
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
||||||
AVCodecContext* context) override;
|
AVCodecContext* context) override;
|
||||||
|
|||||||
@@ -22,3 +22,32 @@
|
|||||||
#include "handler.hpp"
|
#include "handler.hpp"
|
||||||
|
|
||||||
void obsffmpeg::ui::handler::override_visible_name(const AVCodec*, std::string&) {}
|
void obsffmpeg::ui::handler::override_visible_name(const AVCodec*, std::string&) {}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::handler::override_info(obs_encoder_info*, obs_encoder_info*) {}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::handler::override_colorformat(AVPixelFormat&, obs_data_t*, const AVCodec*, AVCodecContext*) {}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::handler::override_lag_in_frames(size_t&, obs_data_t*, const AVCodec*, AVCodecContext*) {}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::handler::get_defaults(obs_data_t*, const AVCodec*, AVCodecContext*, bool) {}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::handler::get_properties(obs_properties_t*, const AVCodec*, AVCodecContext*, bool) {}
|
||||||
|
|
||||||
|
obsffmpeg::hwapi::device obsffmpeg::ui::handler::find_hw_device(std::shared_ptr<obsffmpeg::hwapi::base>, const AVCodec*,
|
||||||
|
AVCodecContext*)
|
||||||
|
{
|
||||||
|
return obsffmpeg::hwapi::device();
|
||||||
|
}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::handler::update(obs_data_t*, const AVCodec*, AVCodecContext*) {}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::handler::log_options(obs_data_t*, const AVCodec*, AVCodecContext*) {}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::handler::import_from_ffmpeg(const std::string, obs_data_t*, const AVCodec*, AVCodecContext*) {}
|
||||||
|
|
||||||
|
std::string obsffmpeg::ui::handler::export_for_ffmpeg(obs_data_t*, const AVCodec*, AVCodecContext*)
|
||||||
|
{
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::handler::process_avpacket(AVPacket&, const AVCodec*, AVCodecContext*) {}
|
||||||
|
|||||||
+28
-4
@@ -22,9 +22,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "hwapi/base.hpp"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
#include <obs.h>
|
||||||
|
|
||||||
#include <obs-data.h>
|
#include <obs-data.h>
|
||||||
|
#include <obs-encoder.h>
|
||||||
#include <obs-properties.h>
|
#include <obs-properties.h>
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 4244)
|
#pragma warning(disable : 4244)
|
||||||
@@ -38,13 +42,33 @@ namespace obsffmpeg {
|
|||||||
public:
|
public:
|
||||||
virtual void override_visible_name(const AVCodec* codec, std::string& name);
|
virtual void override_visible_name(const AVCodec* codec, std::string& name);
|
||||||
|
|
||||||
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec,
|
virtual void override_info(obs_encoder_info* main, obs_encoder_info* fallback);
|
||||||
AVCodecContext* context) = 0;
|
|
||||||
|
virtual void override_colorformat(AVPixelFormat& target_format, obs_data_t* settings,
|
||||||
|
const AVCodec* codec, AVCodecContext* context);
|
||||||
|
|
||||||
|
virtual void override_lag_in_frames(size_t& lag, obs_data_t* settings, const AVCodec* codec,
|
||||||
|
AVCodecContext* context);
|
||||||
|
|
||||||
|
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context, bool hw_encode);
|
||||||
|
|
||||||
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||||
AVCodecContext* context) = 0;
|
AVCodecContext* context, bool hw_encode);
|
||||||
|
|
||||||
virtual void update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context) = 0;
|
virtual obsffmpeg::hwapi::device find_hw_device(std::shared_ptr<obsffmpeg::hwapi::base> api,
|
||||||
|
const AVCodec* codec, AVCodecContext* context);
|
||||||
|
|
||||||
|
virtual void update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context);
|
||||||
|
|
||||||
|
virtual void log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context);
|
||||||
|
|
||||||
|
virtual void import_from_ffmpeg(const std::string ffmpeg, obs_data_t* settings,
|
||||||
|
const AVCodec* codec, AVCodecContext* context);
|
||||||
|
|
||||||
|
virtual std::string export_for_ffmpeg(obs_data_t* settings, const AVCodec* codec,
|
||||||
|
AVCodecContext* context);
|
||||||
|
|
||||||
|
virtual void process_avpacket(AVPacket& packet, const AVCodec* codec, AVCodecContext* context);
|
||||||
};
|
};
|
||||||
} // namespace ui
|
} // namespace ui
|
||||||
} // namespace obsffmpeg
|
} // namespace obsffmpeg
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ Useless except for strict_gop maybe?
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using namespace obsffmpeg::codecs::h264;
|
using namespace obsffmpeg::codecs::h264;
|
||||||
|
using namespace obsffmpeg::nvenc;
|
||||||
|
|
||||||
std::map<profile, std::string> profiles{
|
std::map<profile, std::string> profiles{
|
||||||
{profile::BASELINE, "baseline"},
|
{profile::BASELINE, "baseline"},
|
||||||
@@ -84,8 +85,14 @@ void obsffmpeg::ui::nvenc_h264_handler::override_visible_name(const AVCodec*, st
|
|||||||
name = "H.264/AVC Encoder (NVidia NVENC)";
|
name = "H.264/AVC Encoder (NVidia NVENC)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::nvenc_h264_handler::override_lag_in_frames(size_t& lag, obs_data_t* settings, const AVCodec* codec,
|
||||||
|
AVCodecContext* context)
|
||||||
|
{
|
||||||
|
nvenc::override_lag_in_frames(lag, settings, codec, context);
|
||||||
|
}
|
||||||
|
|
||||||
void obsffmpeg::ui::nvenc_h264_handler::get_defaults(obs_data_t* settings, const AVCodec* codec,
|
void obsffmpeg::ui::nvenc_h264_handler::get_defaults(obs_data_t* settings, const AVCodec* codec,
|
||||||
AVCodecContext* context)
|
AVCodecContext* context, bool)
|
||||||
{
|
{
|
||||||
nvenc::get_defaults(settings, codec, context);
|
nvenc::get_defaults(settings, codec, context);
|
||||||
|
|
||||||
@@ -94,7 +101,7 @@ void obsffmpeg::ui::nvenc_h264_handler::get_defaults(obs_data_t* settings, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void obsffmpeg::ui::nvenc_h264_handler::get_properties(obs_properties_t* props, const AVCodec* codec,
|
void obsffmpeg::ui::nvenc_h264_handler::get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||||
AVCodecContext* context)
|
AVCodecContext* context, bool)
|
||||||
{
|
{
|
||||||
if (!context) {
|
if (!context) {
|
||||||
this->get_encoder_properties(props, codec);
|
this->get_encoder_properties(props, codec);
|
||||||
@@ -125,6 +132,22 @@ void obsffmpeg::ui::nvenc_h264_handler::update(obs_data_t* settings, const AVCod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::nvenc_h264_handler::log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
|
||||||
|
{
|
||||||
|
nvenc::log_options(settings, codec, context);
|
||||||
|
|
||||||
|
profile cfg_profile = static_cast<profile>(obs_data_get_int(settings, P_H264_PROFILE));
|
||||||
|
level cfg_level = static_cast<level>(obs_data_get_int(settings, P_H264_LEVEL));
|
||||||
|
|
||||||
|
auto found1 = profiles.find(cfg_profile);
|
||||||
|
if (found1 != profiles.end())
|
||||||
|
PLOG_INFO("[%s] H.264 Profile: %s", codec->name, found1->second.c_str());
|
||||||
|
|
||||||
|
auto found2 = levels.find(cfg_level);
|
||||||
|
if (found2 != levels.end())
|
||||||
|
PLOG_INFO("[%s] H.264 Level: %s", codec->name, found2->second.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
void obsffmpeg::ui::nvenc_h264_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec)
|
void obsffmpeg::ui::nvenc_h264_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec)
|
||||||
{
|
{
|
||||||
nvenc::get_properties_pre(props, codec);
|
nvenc::get_properties_pre(props, codec);
|
||||||
|
|||||||
@@ -36,15 +36,21 @@ namespace obsffmpeg {
|
|||||||
public:
|
public:
|
||||||
virtual void override_visible_name(const AVCodec* codec, std::string& name) override;
|
virtual void override_visible_name(const AVCodec* codec, std::string& name) override;
|
||||||
|
|
||||||
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec,
|
virtual void override_lag_in_frames(size_t& lag, obs_data_t* settings, const AVCodec* codec,
|
||||||
AVCodecContext* context) override;
|
AVCodecContext* context) override;
|
||||||
|
|
||||||
|
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context,
|
||||||
|
bool hw_encode) override;
|
||||||
|
|
||||||
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||||
AVCodecContext* context) override;
|
AVCodecContext* context, bool hw_encode) override;
|
||||||
|
|
||||||
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
||||||
AVCodecContext* context) override;
|
AVCodecContext* context) override;
|
||||||
|
|
||||||
|
virtual void log_options(obs_data_t* settings, const AVCodec* codec,
|
||||||
|
AVCodecContext* context) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void get_encoder_properties(obs_properties_t* props, const AVCodec* codec);
|
void get_encoder_properties(obs_properties_t* props, const AVCodec* codec);
|
||||||
|
|
||||||
|
|||||||
@@ -87,8 +87,14 @@ void obsffmpeg::ui::nvenc_hevc_handler::override_visible_name(const AVCodec*, st
|
|||||||
name = "H.265/HEVC Encoder (NVidia NVENC)";
|
name = "H.265/HEVC Encoder (NVidia NVENC)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::nvenc_hevc_handler::override_lag_in_frames(size_t& lag, obs_data_t* settings, const AVCodec* codec,
|
||||||
|
AVCodecContext* context)
|
||||||
|
{
|
||||||
|
nvenc::override_lag_in_frames(lag, settings, codec, context);
|
||||||
|
}
|
||||||
|
|
||||||
void obsffmpeg::ui::nvenc_hevc_handler::get_defaults(obs_data_t* settings, const AVCodec* codec,
|
void obsffmpeg::ui::nvenc_hevc_handler::get_defaults(obs_data_t* settings, const AVCodec* codec,
|
||||||
AVCodecContext* context)
|
AVCodecContext* context, bool)
|
||||||
{
|
{
|
||||||
nvenc::get_defaults(settings, codec, context);
|
nvenc::get_defaults(settings, codec, context);
|
||||||
|
|
||||||
@@ -98,7 +104,7 @@ void obsffmpeg::ui::nvenc_hevc_handler::get_defaults(obs_data_t* settings, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void obsffmpeg::ui::nvenc_hevc_handler::get_properties(obs_properties_t* props, const AVCodec* codec,
|
void obsffmpeg::ui::nvenc_hevc_handler::get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||||
AVCodecContext* context)
|
AVCodecContext* context, bool)
|
||||||
{
|
{
|
||||||
if (!context) {
|
if (!context) {
|
||||||
this->get_encoder_properties(props, codec);
|
this->get_encoder_properties(props, codec);
|
||||||
@@ -133,6 +139,27 @@ void obsffmpeg::ui::nvenc_hevc_handler::update(obs_data_t* settings, const AVCod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::nvenc_hevc_handler::log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
|
||||||
|
{
|
||||||
|
nvenc::log_options(settings, codec, context);
|
||||||
|
|
||||||
|
profile cfg_profile = static_cast<profile>(obs_data_get_int(settings, P_HEVC_PROFILE));
|
||||||
|
tier cfg_tier = static_cast<tier>(obs_data_get_int(settings, P_HEVC_TIER));
|
||||||
|
level cfg_level = static_cast<level>(obs_data_get_int(settings, P_HEVC_LEVEL));
|
||||||
|
|
||||||
|
auto found1 = profiles.find(cfg_profile);
|
||||||
|
if (found1 != profiles.end())
|
||||||
|
PLOG_INFO("[%s] H.265 Profile: %s", codec->name, found1->second.c_str());
|
||||||
|
|
||||||
|
auto found2 = levels.find(cfg_level);
|
||||||
|
if (found2 != levels.end())
|
||||||
|
PLOG_INFO("[%s] H.265 Level: %s", codec->name, found2->second.c_str());
|
||||||
|
|
||||||
|
auto found3 = tiers.find(cfg_tier);
|
||||||
|
if (found3 != tiers.end())
|
||||||
|
PLOG_INFO("[%s] H.265 Tier: %s", codec->name, found3->second.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
void obsffmpeg::ui::nvenc_hevc_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec)
|
void obsffmpeg::ui::nvenc_hevc_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec)
|
||||||
{
|
{
|
||||||
nvenc::get_properties_pre(props, codec);
|
nvenc::get_properties_pre(props, codec);
|
||||||
|
|||||||
@@ -36,15 +36,21 @@ namespace obsffmpeg {
|
|||||||
public:
|
public:
|
||||||
virtual void override_visible_name(const AVCodec* codec, std::string& name) override;
|
virtual void override_visible_name(const AVCodec* codec, std::string& name) override;
|
||||||
|
|
||||||
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec,
|
virtual void override_lag_in_frames(size_t& lag, obs_data_t* settings, const AVCodec* codec,
|
||||||
AVCodecContext* context) override;
|
AVCodecContext* context) override;
|
||||||
|
|
||||||
|
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context,
|
||||||
|
bool hw_encode) override;
|
||||||
|
|
||||||
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||||
AVCodecContext* context) override;
|
AVCodecContext* context, bool hw_encode) override;
|
||||||
|
|
||||||
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
||||||
AVCodecContext* context) override;
|
AVCodecContext* context) override;
|
||||||
|
|
||||||
|
virtual void log_options(obs_data_t* settings, const AVCodec* codec,
|
||||||
|
AVCodecContext* context) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void get_encoder_properties(obs_properties_t* props, const AVCodec* codec);
|
void get_encoder_properties(obs_properties_t* props, const AVCodec* codec);
|
||||||
|
|
||||||
|
|||||||
+132
-8
@@ -20,6 +20,7 @@
|
|||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
#include "nvenc_shared.hpp"
|
#include "nvenc_shared.hpp"
|
||||||
|
#include <algorithm>
|
||||||
#include "codecs/hevc.hpp"
|
#include "codecs/hevc.hpp"
|
||||||
#include "plugin.hpp"
|
#include "plugin.hpp"
|
||||||
#include "strings.hpp"
|
#include "strings.hpp"
|
||||||
@@ -57,7 +58,7 @@ extern "C" {
|
|||||||
#define ST_RATECONTROL_QP_I ST_RATECONTROL_QP ".I"
|
#define ST_RATECONTROL_QP_I ST_RATECONTROL_QP ".I"
|
||||||
#define ST_RATECONTROL_QP_I_INITIAL ST_RATECONTROL_QP_I ".Initial"
|
#define ST_RATECONTROL_QP_I_INITIAL ST_RATECONTROL_QP_I ".Initial"
|
||||||
#define ST_RATECONTROL_QP_P ST_RATECONTROL_QP ".P"
|
#define ST_RATECONTROL_QP_P ST_RATECONTROL_QP ".P"
|
||||||
#define ST_RATECONTROL_QP_ST_INITIAL ST_RATECONTROL_QP_P ".Initial"
|
#define ST_RATECONTROL_QP_P_INITIAL ST_RATECONTROL_QP_P ".Initial"
|
||||||
#define ST_RATECONTROL_QP_B ST_RATECONTROL_QP ".B"
|
#define ST_RATECONTROL_QP_B ST_RATECONTROL_QP ".B"
|
||||||
#define ST_RATECONTROL_QP_B_INITIAL ST_RATECONTROL_QP_B ".Initial"
|
#define ST_RATECONTROL_QP_B_INITIAL ST_RATECONTROL_QP_B ".Initial"
|
||||||
|
|
||||||
@@ -131,6 +132,19 @@ std::map<b_ref_mode, std::string> obsffmpeg::nvenc::b_ref_mode_to_opt{
|
|||||||
{b_ref_mode::MIDDLE, "middle"},
|
{b_ref_mode::MIDDLE, "middle"},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void obsffmpeg::nvenc::override_lag_in_frames(size_t& lag, obs_data_t*, const AVCodec*, AVCodecContext* context)
|
||||||
|
{
|
||||||
|
// With NVENC, the number of frames lagged before we get our first
|
||||||
|
// packet is determined by the number of b-frames. Threads, lookahead
|
||||||
|
// frames and various other settings are ignored.
|
||||||
|
// The minimum number of lagged frames is 1.
|
||||||
|
|
||||||
|
int64_t rcla = 0;
|
||||||
|
av_opt_get_int(context, "rc-lookahead", AV_OPT_SEARCH_CHILDREN, &rcla);
|
||||||
|
|
||||||
|
lag = static_cast<size_t>(std::max(1ll + static_cast<int64_t>(context->max_b_frames), rcla));
|
||||||
|
}
|
||||||
|
|
||||||
void obsffmpeg::nvenc::get_defaults(obs_data_t* settings, const AVCodec*, AVCodecContext*)
|
void obsffmpeg::nvenc::get_defaults(obs_data_t* settings, const AVCodec*, AVCodecContext*)
|
||||||
{
|
{
|
||||||
obs_data_set_default_int(settings, ST_PRESET, static_cast<int64_t>(preset::DEFAULT));
|
obs_data_set_default_int(settings, ST_PRESET, static_cast<int64_t>(preset::DEFAULT));
|
||||||
@@ -152,7 +166,7 @@ void obsffmpeg::nvenc::get_defaults(obs_data_t* settings, const AVCodec*, AVCode
|
|||||||
obs_data_set_default_int(settings, ST_RATECONTROL_QP_I, 21);
|
obs_data_set_default_int(settings, ST_RATECONTROL_QP_I, 21);
|
||||||
obs_data_set_default_int(settings, ST_RATECONTROL_QP_I_INITIAL, -1);
|
obs_data_set_default_int(settings, ST_RATECONTROL_QP_I_INITIAL, -1);
|
||||||
obs_data_set_default_int(settings, ST_RATECONTROL_QP_P, 21);
|
obs_data_set_default_int(settings, ST_RATECONTROL_QP_P, 21);
|
||||||
obs_data_set_default_int(settings, ST_RATECONTROL_QP_ST_INITIAL, -1);
|
obs_data_set_default_int(settings, ST_RATECONTROL_QP_P_INITIAL, -1);
|
||||||
obs_data_set_default_int(settings, ST_RATECONTROL_QP_B, 21);
|
obs_data_set_default_int(settings, ST_RATECONTROL_QP_B, 21);
|
||||||
obs_data_set_default_int(settings, ST_RATECONTROL_QP_B_INITIAL, -1);
|
obs_data_set_default_int(settings, ST_RATECONTROL_QP_B_INITIAL, -1);
|
||||||
|
|
||||||
@@ -211,7 +225,7 @@ static bool modified_ratecontrol(obs_properties_t* props, obs_property_t*, obs_d
|
|||||||
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QP_P), have_qp);
|
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QP_P), have_qp);
|
||||||
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QP_B), have_qp);
|
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QP_B), have_qp);
|
||||||
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QP_I_INITIAL), have_qp_init);
|
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QP_I_INITIAL), have_qp_init);
|
||||||
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QP_ST_INITIAL), have_qp_init);
|
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QP_P_INITIAL), have_qp_init);
|
||||||
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QP_B_INITIAL), have_qp_init);
|
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QP_B_INITIAL), have_qp_init);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -379,9 +393,9 @@ void obsffmpeg::nvenc::get_properties_post(obs_properties_t* props, const AVCode
|
|||||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QP_P)));
|
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QP_P)));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto p = obs_properties_add_int_slider(grp, ST_RATECONTROL_QP_ST_INITIAL,
|
auto p = obs_properties_add_int_slider(grp, ST_RATECONTROL_QP_P_INITIAL,
|
||||||
TRANSLATE(ST_RATECONTROL_QP_ST_INITIAL), -1, 51, 1);
|
TRANSLATE(ST_RATECONTROL_QP_P_INITIAL), -1, 51, 1);
|
||||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QP_ST_INITIAL)));
|
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QP_P_INITIAL)));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto p = obs_properties_add_int_slider(grp, ST_RATECONTROL_QP_B, TRANSLATE(ST_RATECONTROL_QP_B),
|
auto p = obs_properties_add_int_slider(grp, ST_RATECONTROL_QP_B, TRANSLATE(ST_RATECONTROL_QP_B),
|
||||||
@@ -483,7 +497,7 @@ void obsffmpeg::nvenc::get_runtime_properties(obs_properties_t* props, const AVC
|
|||||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QP_I), false);
|
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QP_I), false);
|
||||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QP_I_INITIAL), false);
|
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QP_I_INITIAL), false);
|
||||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QP_P), false);
|
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QP_P), false);
|
||||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QP_ST_INITIAL), false);
|
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QP_P_INITIAL), false);
|
||||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QP_B), false);
|
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QP_B), false);
|
||||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QP_B_INITIAL), false);
|
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QP_B_INITIAL), false);
|
||||||
obs_property_set_enabled(obs_properties_get(props, ST_AQ), false);
|
obs_property_set_enabled(obs_properties_get(props, ST_AQ), false);
|
||||||
@@ -597,7 +611,7 @@ void obsffmpeg::nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCode
|
|||||||
av_opt_set_int(context->priv_data, "init_qpI",
|
av_opt_set_int(context->priv_data, "init_qpI",
|
||||||
obs_data_get_int(settings, ST_RATECONTROL_QP_I_INITIAL), 0);
|
obs_data_get_int(settings, ST_RATECONTROL_QP_I_INITIAL), 0);
|
||||||
av_opt_set_int(context->priv_data, "init_qpP",
|
av_opt_set_int(context->priv_data, "init_qpP",
|
||||||
obs_data_get_int(settings, ST_RATECONTROL_QP_ST_INITIAL), 0);
|
obs_data_get_int(settings, ST_RATECONTROL_QP_P_INITIAL), 0);
|
||||||
av_opt_set_int(context->priv_data, "init_qpB",
|
av_opt_set_int(context->priv_data, "init_qpB",
|
||||||
obs_data_get_int(settings, ST_RATECONTROL_QP_B_INITIAL), 0);
|
obs_data_get_int(settings, ST_RATECONTROL_QP_B_INITIAL), 0);
|
||||||
}
|
}
|
||||||
@@ -646,3 +660,113 @@ void obsffmpeg::nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void obsffmpeg::nvenc::log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
|
||||||
|
{
|
||||||
|
preset cfg_preset = static_cast<preset>(obs_data_get_int(settings, ST_PRESET));
|
||||||
|
|
||||||
|
auto found1 = preset_to_opt.find(cfg_preset);
|
||||||
|
if (found1 != preset_to_opt.end())
|
||||||
|
PLOG_INFO("[%s] Preset: %s", codec->name, found1->second.c_str());
|
||||||
|
|
||||||
|
ratecontrolmode cfg_rc_mode = static_cast<ratecontrolmode>(obs_data_get_int(settings, ST_RATECONTROL_MODE));
|
||||||
|
int64_t cfg_rc_2pass = obs_data_get_int(settings, ST_RATECONTROL_TWOPASS);
|
||||||
|
int64_t cfg_rc_lahead = obs_data_get_int(settings, ST_RATECONTROL_LOOKAHEAD);
|
||||||
|
bool cfg_rc_adapti = obs_data_get_bool(settings, ST_RATECONTROL_ADAPTIVEI);
|
||||||
|
bool cfg_rc_adaptb = obs_data_get_bool(settings, ST_RATECONTROL_ADAPTIVEB);
|
||||||
|
|
||||||
|
auto found2 = ratecontrolmode_to_opt.find(cfg_rc_mode);
|
||||||
|
if (found2 != ratecontrolmode_to_opt.end())
|
||||||
|
PLOG_INFO("[%s] Rate Control: %s", codec->name, found2->second.c_str());
|
||||||
|
PLOG_INFO("[%s] Two Pass: %s", codec->name,
|
||||||
|
cfg_rc_2pass == 1 ? "Enabled" : (cfg_rc_2pass == 0 ? "Disabled" : "Default"));
|
||||||
|
PLOG_INFO("[%s] Lookahead: %" PRId64 " Frames", codec->name, cfg_rc_lahead);
|
||||||
|
if (cfg_rc_adapti && cfg_rc_lahead > 0)
|
||||||
|
PLOG_INFO("[%s] Adaptive I-Frames Enabled", codec->name);
|
||||||
|
if (cfg_rc_adaptb && cfg_rc_lahead > 0)
|
||||||
|
PLOG_INFO("[%s] Adaptive B-Frames Enabled", codec->name);
|
||||||
|
|
||||||
|
int64_t cfg_rc_bitrate = obs_data_get_int(settings, ST_RATECONTROL_BITRATE_TARGET);
|
||||||
|
int64_t cfg_rc_max_bitrate = obs_data_get_int(settings, ST_RATECONTROL_BITRATE_MAXIMUM);
|
||||||
|
int64_t cfg_rc_bufsize = obs_data_get_int(settings, S_RATECONTROL_BUFFERSIZE);
|
||||||
|
bool cfg_rc_quality = obs_data_get_bool(settings, ST_RATECONTROL_QUALITY);
|
||||||
|
int64_t cfg_rc_quality_min = obs_data_get_int(settings, ST_RATECONTROL_QUALITY_MINIMUM);
|
||||||
|
int64_t cfg_rc_quality_max = obs_data_get_int(settings, ST_RATECONTROL_QUALITY_MAXIMUM);
|
||||||
|
double_t cfg_rc_quality_tgt = obs_data_get_double(settings, ST_RATECONTROL_QUALITY_TARGET) / 100.0 * 51.0;
|
||||||
|
int64_t cfg_rc_qp_i = obs_data_get_int(settings, ST_RATECONTROL_QP_I);
|
||||||
|
int64_t cfg_rc_qp_p = obs_data_get_int(settings, ST_RATECONTROL_QP_P);
|
||||||
|
int64_t cfg_rc_qp_b = obs_data_get_int(settings, ST_RATECONTROL_QP_B);
|
||||||
|
int64_t cfg_rc_qp_i_init = obs_data_get_int(settings, ST_RATECONTROL_QP_I_INITIAL);
|
||||||
|
int64_t cfg_rc_qp_p_init = obs_data_get_int(settings, ST_RATECONTROL_QP_P_INITIAL);
|
||||||
|
int64_t cfg_rc_qp_b_init = obs_data_get_int(settings, ST_RATECONTROL_QP_B_INITIAL);
|
||||||
|
|
||||||
|
{
|
||||||
|
bool have_bitrate = false;
|
||||||
|
bool have_bitrate_max = false;
|
||||||
|
bool have_quality = false;
|
||||||
|
bool have_qp = false;
|
||||||
|
bool have_qp_init = false;
|
||||||
|
|
||||||
|
switch (cfg_rc_mode) {
|
||||||
|
case ratecontrolmode::CQP:
|
||||||
|
have_qp = true;
|
||||||
|
break;
|
||||||
|
case ratecontrolmode::CBR:
|
||||||
|
case ratecontrolmode::CBR_HQ:
|
||||||
|
case ratecontrolmode::CBR_LD_HQ:
|
||||||
|
have_bitrate = true;
|
||||||
|
av_opt_set_int(context->priv_data, "cbr", 1, 0);
|
||||||
|
break;
|
||||||
|
case ratecontrolmode::VBR:
|
||||||
|
case ratecontrolmode::VBR_HQ:
|
||||||
|
have_bitrate_max = true;
|
||||||
|
have_bitrate = true;
|
||||||
|
have_quality = true;
|
||||||
|
have_qp_init = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
PLOG_INFO("[%s] Buffer Size: %" PRId64, codec->name, cfg_rc_bufsize);
|
||||||
|
if (have_bitrate)
|
||||||
|
PLOG_INFO("[%s] Bitrate Target: %" PRId64, codec->name, cfg_rc_bitrate);
|
||||||
|
if (have_bitrate_max)
|
||||||
|
PLOG_INFO("[%s] Bitrate Maximum: %" PRId64, codec->name, cfg_rc_max_bitrate);
|
||||||
|
if (have_quality && cfg_rc_quality) {
|
||||||
|
PLOG_INFO("[%s] Quality Limits:", codec->name);
|
||||||
|
PLOG_INFO("[%s] Minimum: %" PRId64, codec->name, cfg_rc_quality_min);
|
||||||
|
PLOG_INFO("[%s] Maximum: %" PRId64, codec->name, cfg_rc_quality_max);
|
||||||
|
PLOG_INFO("[%s] Target: %f", codec->name, cfg_rc_quality_tgt);
|
||||||
|
}
|
||||||
|
if (have_qp)
|
||||||
|
PLOG_INFO("[%s] QP Values: %" PRId64 "/%" PRId64 "/%" PRId64, codec->name, cfg_rc_qp_i,
|
||||||
|
cfg_rc_qp_p, cfg_rc_qp_b);
|
||||||
|
if (have_qp_init)
|
||||||
|
PLOG_INFO("[%s] Initial QP Values: %" PRId64 "/%" PRId64 "/%" PRId64, codec->name,
|
||||||
|
cfg_rc_qp_i_init, cfg_rc_qp_p_init, cfg_rc_qp_b_init);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cfg_aq_spatial = obs_data_get_bool(settings, ST_AQ_SPATIAL);
|
||||||
|
int64_t cfg_aq_strength = obs_data_get_int(settings, ST_AQ_STRENGTH);
|
||||||
|
bool cfg_aq_temporal = obs_data_get_bool(settings, ST_AQ_TEMPORAL);
|
||||||
|
if (cfg_aq_spatial)
|
||||||
|
PLOG_INFO("[%s] Spatial AQ Enabled: Strength %" PRId64, codec->name, cfg_aq_strength);
|
||||||
|
if (cfg_aq_temporal)
|
||||||
|
PLOG_INFO("[%s] Temporal AQ Enabled", codec->name);
|
||||||
|
|
||||||
|
int64_t cfg_bf = obs_data_get_int(settings, ST_OTHER_BFRAMES);
|
||||||
|
b_ref_mode cfg_bf_mode = static_cast<b_ref_mode>(obs_data_get_int(settings, ST_OTHER_BFRAME_REFERENCEMODE));
|
||||||
|
bool cfg_zerolatency = obs_data_get_bool(settings, ST_OTHER_ZEROLATENCY);
|
||||||
|
bool cfg_weightp = obs_data_get_bool(settings, ST_OTHER_WEIGHTED_PREDICTION);
|
||||||
|
bool cfg_nonrefp = obs_data_get_bool(settings, ST_OTHER_NONREFERENCE_PFRAMES);
|
||||||
|
|
||||||
|
PLOG_INFO("[%s] B-Frames: %" PRId64, codec->name, cfg_bf);
|
||||||
|
auto found3 = b_ref_mode_to_opt.find(cfg_bf_mode);
|
||||||
|
if (found3 != b_ref_mode_to_opt.end())
|
||||||
|
PLOG_INFO("[%s] Reference Mode: %s", codec->name, found3->second.c_str());
|
||||||
|
if (cfg_zerolatency)
|
||||||
|
PLOG_INFO("[%s] Zero Latency Enabled", codec->name);
|
||||||
|
if (cfg_weightp)
|
||||||
|
PLOG_INFO("[%s] Weighted Prediction Enabled", codec->name);
|
||||||
|
if (cfg_nonrefp)
|
||||||
|
PLOG_INFO("[%s] Non-Ref P-Frames Enabled", codec->name);
|
||||||
|
}
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ namespace obsffmpeg {
|
|||||||
|
|
||||||
extern std::map<b_ref_mode, std::string> b_ref_mode_to_opt;
|
extern std::map<b_ref_mode, std::string> b_ref_mode_to_opt;
|
||||||
|
|
||||||
|
void override_lag_in_frames(size_t& lag, obs_data_t* settings, const AVCodec* codec,
|
||||||
|
AVCodecContext* context);
|
||||||
|
|
||||||
void get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context);
|
void get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context);
|
||||||
|
|
||||||
void get_properties_pre(obs_properties_t* props, const AVCodec* codec);
|
void get_properties_pre(obs_properties_t* props, const AVCodec* codec);
|
||||||
@@ -84,5 +87,7 @@ namespace obsffmpeg {
|
|||||||
void get_runtime_properties(obs_properties_t* props, const AVCodec* codec, AVCodecContext* context);
|
void get_runtime_properties(obs_properties_t* props, const AVCodec* codec, AVCodecContext* context);
|
||||||
|
|
||||||
void update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context);
|
void update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context);
|
||||||
|
|
||||||
|
void log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context);
|
||||||
} // namespace nvenc
|
} // namespace nvenc
|
||||||
} // namespace obsffmpeg
|
} // namespace obsffmpeg
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
#include "prores_aw_handler.hpp"
|
#include "prores_aw_handler.hpp"
|
||||||
|
#include "codecs/prores.hpp"
|
||||||
#include "plugin.hpp"
|
#include "plugin.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
@@ -27,13 +28,6 @@ extern "C" {
|
|||||||
#include <obs-module.h>
|
#include <obs-module.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
#define P_PROFILE "AppleProRes.Profile"
|
|
||||||
#define P_PROFILE_APCO "AppleProRes.Profile.APCO"
|
|
||||||
#define P_PROFILE_APCS "AppleProRes.Profile.APCS"
|
|
||||||
#define P_PROFILE_APCN "AppleProRes.Profile.APCN"
|
|
||||||
#define P_PROFILE_APCH "AppleProRes.Profile.APCH"
|
|
||||||
#define P_PROFILE_AP4H "AppleProRes.Profile.AP4H"
|
|
||||||
|
|
||||||
INITIALIZER(prores_aw_handler_init)
|
INITIALIZER(prores_aw_handler_init)
|
||||||
{
|
{
|
||||||
obsffmpeg::initializers.push_back([]() {
|
obsffmpeg::initializers.push_back([]() {
|
||||||
@@ -41,44 +35,94 @@ INITIALIZER(prores_aw_handler_init)
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
void obsffmpeg::ui::prores_aw_handler::get_defaults(obs_data_t* settings, const AVCodec*, AVCodecContext*)
|
void obsffmpeg::ui::prores_aw_handler::override_colorformat(AVPixelFormat& target_format, obs_data_t* settings,
|
||||||
|
const AVCodec* codec, AVCodecContext*)
|
||||||
{
|
{
|
||||||
obs_data_set_default_int(settings, P_PROFILE, 0);
|
std::string profile = "";
|
||||||
|
|
||||||
|
int profile_id = static_cast<int>(obs_data_get_int(settings, P_PRORES_PROFILE));
|
||||||
|
for (auto ptr = codec->profiles; ptr->profile != FF_PROFILE_UNKNOWN; ptr++) {
|
||||||
|
if (ptr->profile == profile_id) {
|
||||||
|
profile = ptr->name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unordered_map<AVPixelFormat, std::list<std::string>> valid_formats = {
|
||||||
|
{AV_PIX_FMT_YUV422P10, {"apco", "apcs", "apcn", "apch"}}, {AV_PIX_FMT_YUV444P10, {"ap4h", "ap4x"}}};
|
||||||
|
|
||||||
|
for (auto kv : valid_formats) {
|
||||||
|
for (auto name : kv.second) {
|
||||||
|
if (profile == name) {
|
||||||
|
target_format = kv.first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::prores_aw_handler::get_defaults(obs_data_t* settings, const AVCodec*, AVCodecContext*, bool)
|
||||||
|
{
|
||||||
|
obs_data_set_default_int(settings, P_PRORES_PROFILE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void obsffmpeg::ui::prores_aw_handler::get_properties(obs_properties_t* props, const AVCodec* codec,
|
void obsffmpeg::ui::prores_aw_handler::get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||||
AVCodecContext* context)
|
AVCodecContext* context, bool)
|
||||||
{
|
{
|
||||||
if (!context) {
|
if (!context) {
|
||||||
auto p = obs_properties_add_list(props, P_PROFILE, TRANSLATE(P_PROFILE), OBS_COMBO_TYPE_LIST,
|
auto p = obs_properties_add_list(props, P_PRORES_PROFILE, TRANSLATE(P_PRORES_PROFILE),
|
||||||
OBS_COMBO_FORMAT_INT);
|
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
||||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_PROFILE)));
|
obs_property_set_long_description(p, TRANSLATE(DESC(P_PRORES_PROFILE)));
|
||||||
for (auto ptr = codec->profiles; ptr->profile != FF_PROFILE_UNKNOWN; ptr++) {
|
for (auto ptr = codec->profiles; ptr->profile != FF_PROFILE_UNKNOWN; ptr++) {
|
||||||
if (strcmp("apco", ptr->name) == 0) {
|
if (strcmp("apco", ptr->name) == 0) {
|
||||||
obs_property_list_add_int(p, TRANSLATE(P_PROFILE_APCO),
|
obs_property_list_add_int(p, TRANSLATE(P_PRORES_PROFILE_APCO),
|
||||||
static_cast<int64_t>(ptr->profile));
|
static_cast<int64_t>(ptr->profile));
|
||||||
} else if (strcmp("apcs", ptr->name) == 0) {
|
} else if (strcmp("apcs", ptr->name) == 0) {
|
||||||
obs_property_list_add_int(p, TRANSLATE(P_PROFILE_APCS),
|
obs_property_list_add_int(p, TRANSLATE(P_PRORES_PROFILE_APCS),
|
||||||
static_cast<int64_t>(ptr->profile));
|
static_cast<int64_t>(ptr->profile));
|
||||||
} else if (strcmp("apcn", ptr->name) == 0) {
|
} else if (strcmp("apcn", ptr->name) == 0) {
|
||||||
obs_property_list_add_int(p, TRANSLATE(P_PROFILE_APCN),
|
obs_property_list_add_int(p, TRANSLATE(P_PRORES_PROFILE_APCN),
|
||||||
static_cast<int64_t>(ptr->profile));
|
static_cast<int64_t>(ptr->profile));
|
||||||
} else if (strcmp("apch", ptr->name) == 0) {
|
} else if (strcmp("apch", ptr->name) == 0) {
|
||||||
obs_property_list_add_int(p, TRANSLATE(P_PROFILE_APCH),
|
obs_property_list_add_int(p, TRANSLATE(P_PRORES_PROFILE_APCH),
|
||||||
static_cast<int64_t>(ptr->profile));
|
static_cast<int64_t>(ptr->profile));
|
||||||
} else if (strcmp("ap4h", ptr->name) == 0) {
|
} else if (strcmp("ap4h", ptr->name) == 0) {
|
||||||
obs_property_list_add_int(p, TRANSLATE(P_PROFILE_AP4H),
|
obs_property_list_add_int(p, TRANSLATE(P_PRORES_PROFILE_AP4H),
|
||||||
|
static_cast<int64_t>(ptr->profile));
|
||||||
|
} else if (strcmp("ap4x", ptr->name) == 0) {
|
||||||
|
obs_property_list_add_int(p, TRANSLATE(P_PRORES_PROFILE_AP4X),
|
||||||
static_cast<int64_t>(ptr->profile));
|
static_cast<int64_t>(ptr->profile));
|
||||||
} else {
|
} else {
|
||||||
obs_property_list_add_int(p, ptr->name, ptr->profile);
|
obs_property_list_add_int(p, ptr->name, ptr->profile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
obs_property_set_enabled(obs_properties_get(props, P_PROFILE), false);
|
obs_property_set_enabled(obs_properties_get(props, P_PRORES_PROFILE), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void obsffmpeg::ui::prores_aw_handler::update(obs_data_t* settings, const AVCodec*, AVCodecContext* context)
|
void obsffmpeg::ui::prores_aw_handler::update(obs_data_t* settings, const AVCodec*, AVCodecContext* context)
|
||||||
{
|
{
|
||||||
context->profile = static_cast<int>(obs_data_get_int(settings, P_PROFILE));
|
context->profile = static_cast<int>(obs_data_get_int(settings, P_PRORES_PROFILE));
|
||||||
|
}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::prores_aw_handler::log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext*)
|
||||||
|
{
|
||||||
|
for (auto ptr = codec->profiles; ptr->profile != FF_PROFILE_UNKNOWN; ptr++) {
|
||||||
|
if (ptr->profile == static_cast<int>(obs_data_get_int(settings, P_PRORES_PROFILE)))
|
||||||
|
PLOG_INFO("[%s] Profile: %s", codec->name, ptr->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void obsffmpeg::ui::prores_aw_handler::process_avpacket(AVPacket& packet, const AVCodec*, AVCodecContext*)
|
||||||
|
{
|
||||||
|
//FFmpeg Bug:
|
||||||
|
// When ProRes content is stored in Matroska, FFmpeg strips the size
|
||||||
|
// from the atom. Later when the ProRes content is demuxed from Matroska,
|
||||||
|
// FFmpeg creates an atom with the incorrect size, as the ATOM size
|
||||||
|
// should be content + atom, but FFmpeg set it to only be content. This
|
||||||
|
// difference leads to decoders to be off by 8 bytes.
|
||||||
|
//Fix (until FFmpeg stops being broken):
|
||||||
|
// Pad the packet with 8 bytes of 0x00.
|
||||||
|
|
||||||
|
av_grow_packet(&packet, 8);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,14 +34,22 @@ namespace obsffmpeg {
|
|||||||
namespace ui {
|
namespace ui {
|
||||||
class prores_aw_handler : public handler {
|
class prores_aw_handler : public handler {
|
||||||
public:
|
public:
|
||||||
|
virtual void override_colorformat(AVPixelFormat& target_format, obs_data_t* settings,
|
||||||
|
const AVCodec* codec, AVCodecContext* context) override;
|
||||||
|
|
||||||
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec,
|
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec,
|
||||||
AVCodecContext* context) override;
|
AVCodecContext* context, bool hw_encode) override;
|
||||||
|
|
||||||
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||||
AVCodecContext* context) override;
|
AVCodecContext* context, bool hw_encode) override;
|
||||||
|
|
||||||
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
||||||
AVCodecContext* context) override;
|
AVCodecContext* context) override;
|
||||||
|
|
||||||
|
virtual void log_options(obs_data_t* settings, const AVCodec* codec,
|
||||||
|
AVCodecContext* context) override;
|
||||||
|
|
||||||
|
virtual void process_avpacket(AVPacket& packet, const AVCodec* codec, AVCodecContext* context) override;
|
||||||
};
|
};
|
||||||
} // namespace ui
|
} // namespace ui
|
||||||
} // namespace obsffmpeg
|
} // namespace obsffmpeg
|
||||||
|
|||||||
Reference in New Issue
Block a user