Compare commits
149 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 | |||
| 36222cc186 | |||
| 9fcec9b9a9 | |||
| 11f72c9bc7 | |||
| 5c8939b4a8 | |||
| a4b3131c50 | |||
| 617229ce84 | |||
| e3263c2372 | |||
| e84eedb8f9 | |||
| 7faea52d67 | |||
| 6523b82c95 | |||
| 3253e97dec | |||
| 0c9dd4b2f8 | |||
| c6d842d52d | |||
| 61c4c80c8f | |||
| 8af061ea02 | |||
| f5052f45c6 | |||
| f9e56d33f3 | |||
| 6db094d778 | |||
| 8d0b12dfe3 | |||
| fbf5ffb921 | |||
| 8b2fafbbd1 | |||
| 10110cb62e | |||
| e17fa119a1 | |||
| 3e7fd3ea55 | |||
| 97a68404c0 | |||
| 24bc913f53 | |||
| 11cc88deb6 | |||
| 2c2d42ebaf | |||
| c8f3f9201c | |||
| 7c3e313bcd | |||
| adeea2fb43 | |||
| 8c80f6c79e | |||
| ee0c7706a0 | |||
| 8fdc944be8 | |||
| 9dcce1c655 | |||
| 034100e44b | |||
| 0399989238 | |||
| 1a8f4d6a02 | |||
| 60e5499d3d | |||
| d4ffd20085 | |||
| c3d1793f14 | |||
| 57ebb9d866 | |||
| 9f8e4b67c6 | |||
| c61b2aead1 | |||
| f7db2d45af | |||
| 2840a7fbb1 | |||
| 51a5396fb1 | |||
| 9db2219582 | |||
| 68bacc07dc | |||
| fa5c421d34 | |||
| d178200800 | |||
| ac68c2f4c8 | |||
| a5d14c87ff | |||
| de1a687b8d | |||
| 855b3571b1 | |||
| c053933c25 | |||
| e1fbfd707c | |||
| 69f7afef1f | |||
| 5ba4694890 | |||
| e579b10dcd | |||
| f530f9ee9f | |||
| 8b429db62e | |||
| 6851f2321a | |||
| 2472668f1d | |||
| 6eadcfe821 | |||
| 7663a25bb3 | |||
| 38f154531c | |||
| 666fe5fdfb | |||
| f744b1e9cb | |||
| 9552d12ee8 | |||
| f15769ddb7 | |||
| 8b80dc57ad | |||
| 83c9de95f9 | |||
| a298680e07 | |||
| 090dd9dbdc | |||
| d145c672ad | |||
| b7fdd5491a | |||
| cdb03a488e | |||
| bab3bb8853 | |||
| c8470d3b23 | |||
| c7f326d428 | |||
| 0aab0db34a | |||
| 8dbcaf192a | |||
| 830ebf31d9 | |||
| 076df05b37 | |||
| 3bbbea7b42 | |||
| 97a53d261f | |||
| e45a82350e | |||
| b6ad026eb3 | |||
| df63677529 | |||
| d1ff4a7adc | |||
| e5bf18f2a6 | |||
| b442914ebe | |||
| 8fb69d6870 | |||
| dbdf915a07 | |||
| 9ce8f39efc | |||
| 924c64cd37 | |||
| 99003d5193 | |||
| c5d81e41a6 | |||
| 2f0cd790ed | |||
| c5ff5d224d | |||
| 89fd38e604 | |||
| 56807370a9 | |||
| e7c12a52f3 | |||
| 976e5dba4f | |||
| 16015f180b | |||
| 042c934516 | |||
| 53651c29be | |||
| 5b05cc1504 | |||
| 0a20b750b8 | |||
| 9a58a6a5ff | |||
| 143b7f585f | |||
| 93c6f0b35a | |||
| 3154443e18 | |||
| 74fb3a3847 | |||
| 2d131b8566 | |||
| 35db9e714a | |||
| 01e1c70a02 |
+1
-1
@@ -67,7 +67,7 @@ BreakBeforeBraces: Custom
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
#BreakInheritanceList: BeforeColon
|
||||
BreakStringLiterals: true
|
||||
BreakStringLiterals: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
Cpp11BracedListStyle: true
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
issuehunt: xaymar
|
||||
patreon: xaymar
|
||||
custom: https://www.paypal.me/xaymar
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Want a new feature implemented?
|
||||
|
||||
---
|
||||
|
||||
<!--- Please fill out the following template, which will help other contributors review your Issue. -->
|
||||
<!--- Make sure you’ve read the contribution guidelines -->
|
||||
|
||||
### Description
|
||||
<!-- Describe the feature (and behavior) in as much detail as possible (yes, that means write an essay if you have to) -->
|
||||
<!-- Include images of what you expect from the feature -->
|
||||
|
||||
### Checklist:
|
||||
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
||||
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
|
||||
- [ ] I have read the contribution guidelines.
|
||||
- [ ] This feature is necessary and can't be done through other means.
|
||||
- [ ] This feature does not break existing functionality.
|
||||
- [ ] I am willing to hire/pay someone to implement this.
|
||||
@@ -0,0 +1,27 @@
|
||||
---
|
||||
name: Question/Feedback
|
||||
about: Submit a question or some feedback! (Not for bugs, issues or crashes!)
|
||||
|
||||
---
|
||||
|
||||
<!--- Please fill out the following template, which will help other contributors review your Issue. -->
|
||||
<!--- Make sure you’ve read the contribution guidelines -->
|
||||
|
||||
### Description
|
||||
<!-- Describe the feature (and behavior) in as much detail as possible (yes, that means write an essay if you have to) -->
|
||||
<!-- Include images of what you expect from the feature -->
|
||||
|
||||
### System Information
|
||||
<!-- Include as much information about the system you're using as possible. -->
|
||||
- Software Version: [e. g. 1.0.0, 1.2.1, ... - NEVER LATEST]
|
||||
- Operating System: [e. g. Windows, Debian, Ubuntu, RedHat, FreeBSD, ...]
|
||||
- Kernel Version: [e. g. 1903/1809 (Windows), 4.12 (Linux), ...]
|
||||
- CPU: [e. g. Intel i7, AMD Zen2, Qualcomm, ...]
|
||||
- GPU: [e. g. Nvidia RTX 2xxx Series, AMD Radeone 5xxx Series, ...]
|
||||
- RAM: [e. g. 16GB, 32GB, 64GB, ...]
|
||||
|
||||
### Checklist:
|
||||
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
||||
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
|
||||
- [ ] I have read the contribution guidelines.
|
||||
- [ ] This is not a bug, crash or generic issue.
|
||||
@@ -0,0 +1,38 @@
|
||||
---
|
||||
name: Issue/Bug report
|
||||
about: Encountered a problem, a bug or a crash?
|
||||
|
||||
---
|
||||
|
||||
<!--- Please fill out the following template, which will help other contributors review your Issue. -->
|
||||
<!--- Make sure you’ve read the contribution guidelines -->
|
||||
|
||||
### Description
|
||||
<!-- Describe the bug (and behavior) in as much detail as necessary -->
|
||||
<!-- Include screenshots and attach (crash) logs if possible -->
|
||||
|
||||
### Expected Behavior
|
||||
<!-- What is the expected behavior in this case? -->
|
||||
|
||||
### Reproduction Steps
|
||||
<!-- Describe the steps required to get this to happen from a cleanly installed obs-studio -->
|
||||
<!-- Leave out detail that is not relevant to -->
|
||||
1. Open a portal to the Infinite Void
|
||||
2. Summon an ancient God
|
||||
3. Realize your mistake
|
||||
|
||||
### System Information
|
||||
<!-- Include as much information about the system you're using as possible. -->
|
||||
- Software Version: [e. g. 1.0.0, 1.2.1, ... - NEVER LATEST]
|
||||
- Operating System: [e. g. Windows, Debian, Ubuntu, RedHat, FreeBSD, ...]
|
||||
- Kernel Version: [e. g. 1903/1809 (Windows), 4.12 (Linux), ...]
|
||||
- CPU: [e. g. Intel i7, AMD Zen2, Qualcomm, ...]
|
||||
- GPU: [e. g. Nvidia RTX 2xxx Series, AMD Radeone 5xxx Series, ...]
|
||||
- RAM: [e. g. 16GB, 32GB, 64GB, ...]
|
||||
|
||||
### Checklist:
|
||||
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
||||
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
|
||||
- [ ] I have read the contribution guidelines.
|
||||
- [ ] I can reproduce the issue with the exact reproduction steps I have provided.
|
||||
- [ ] The issue appears on all of my systems that can run this software.
|
||||
@@ -0,0 +1,35 @@
|
||||
<!--- Please fill out the following template, which will help other contributors review your Pull Request. -->
|
||||
|
||||
<!--- Make sure you’ve read the contribution guidelines -->
|
||||
|
||||
### Description
|
||||
<!--- Describe your changes in detail. -->
|
||||
<!--- If this change includes UI elements, please include screenshots. -->
|
||||
|
||||
### Motivation and Context
|
||||
<!--- Why is this change required? What problem does it solve? -->
|
||||
<!--- If it fixes an open Mantis issue, or implements feature request -->
|
||||
<!--- from the Ideas page, please link to the issue here. -->
|
||||
|
||||
### How Has This Been Tested?
|
||||
<!--- Please describe in detail how you tested your changes. -->
|
||||
<!--- Include details of your testing environment (hardware, OS version, etc.),-->
|
||||
<!--- and the tests you ran, including how it may affect other areas of code. -->
|
||||
|
||||
### Types of changes
|
||||
<!--- What types of changes does your PR introduce? Uncomment all that apply -->
|
||||
<!--- - Bug fix (non-breaking change which fixes an issue) -->
|
||||
<!--- - New feature (non-breaking change which adds functionality) -->
|
||||
<!--- - Performance enhancement (non-breaking change which improves efficiency) -->
|
||||
<!--- - Code cleanup (non-breaking change which makes code smaller or more readable) -->
|
||||
<!--- - Breaking change (fix or feature that would cause existing functionality to change) -->
|
||||
<!--- - Documentation (a change to documentation pages) -->
|
||||
|
||||
### Checklist:
|
||||
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
||||
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
|
||||
- [ ] My code has been run through [clang-format](https://github.com/obsproject/obs-studio/blob/master/.clang-format).
|
||||
- [ ] I have read the [**contributing** document](https://github.com/obsproject/obs-studio/blob/master/CONTRIBUTING.rst).
|
||||
- [ ] My code is not on the master branch.
|
||||
- [ ] The code has been tested.
|
||||
- [ ] All commit messages are properly formatted and commits squashed where appropriate.
|
||||
@@ -0,0 +1,34 @@
|
||||
name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [windows-2016, windows-2019]
|
||||
include:
|
||||
- os: windows-2016
|
||||
generator_32: "Visual Studio 15 2017"
|
||||
generator_64: "Visual Studio 15 2017 Win64"
|
||||
sysversion: "10.0.17763.0"
|
||||
- os: windows-2019
|
||||
generator_32:
|
||||
generator_64: "Visual Studio 16 2019"
|
||||
sysversion: "10.0.18362.0"
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Clone Repository
|
||||
uses: actions/checkout@v1
|
||||
- name: Update Submodules
|
||||
run: git submodule update --init --force --recursive
|
||||
- name: Install Node.JS 10.x
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 10
|
||||
- name: Build
|
||||
env:
|
||||
CMAKE_GENERATOR_32: ${{ matrix.generator_32 }}
|
||||
CMAKE_GENERATOR_64: ${{ matrix.generator_64 }}
|
||||
CMAKE_SYSTEM_VERSION: ${{ matrix.sysversion }}
|
||||
run: node ./ci/builder.js
|
||||
+125
-81
@@ -1,27 +1,31 @@
|
||||
# A Plugin that integrates the AMD AMF encoder into OBS Studio
|
||||
# Copyright (C) 2016 - 2017 Michael Fabian Dirks
|
||||
# FFMPEG Video Encoder Integration for OBS Studio
|
||||
# Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
# 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:
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
# 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.
|
||||
|
||||
# CMake Setup
|
||||
cmake_minimum_required(VERSION 3.1.0)
|
||||
include("cmake/util.cmake")
|
||||
CMake_Minimum_Required(VERSION 3.8.0)
|
||||
Include("cmake/util.cmake")
|
||||
|
||||
# Automatic Versioning
|
||||
set(VERSION_MAJOR 0)
|
||||
set(VERSION_MINOR 1)
|
||||
set(VERSION_MINOR 3)
|
||||
set(VERSION_PATCH 0)
|
||||
set(VERSION_TWEAK 0)
|
||||
set(PROJECT_COMMIT "N/A")
|
||||
@@ -50,15 +54,37 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# All Warnings, Extra Warnings, Pedantic
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
# using Clang
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-missing-braces -Wmissing-field-initializers -Wno-c++98-compat-pedantic -Wold-style-cast -Wno-documentation -Wno-documentation-unknown-command -Wno-covered-switch-default -Wno-switch-enum")
|
||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
# GCC: -fpermissive is required as GCC does not allow the same template to be in different namespaces.
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -fpermissive -Wno-long-long -Wno-missing-braces -Wmissing-field-initializers")
|
||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
|
||||
# using Intel C++
|
||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
# Force to always compile with W4
|
||||
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
||||
endif()
|
||||
endif()
|
||||
# C++ Standard and Extensions
|
||||
## Use C++17 and no non-standard extensions.
|
||||
set(_CXX_STANDARD 17)
|
||||
set(_CXX_EXTENSIONS OFF)
|
||||
|
||||
# Define Project
|
||||
project(
|
||||
enc-ffmpeg
|
||||
obs-ffmpeg-encoder
|
||||
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_TWEAK}
|
||||
)
|
||||
set(PROJECT_FULL_NAME "FFMPEG Encoder for OBS Studio")
|
||||
set(PROJECT_DESCRIPTION "Plugin for OBS Studio to add FFMPEG options for Recording and Streaming")
|
||||
set(PROJECT_DESCRIPTION "FFmpeg Encoders for OBS Studio")
|
||||
set(PROJECT_AUTHORS "Michael Fabian 'Xaymar' Dirks <info@xaymar.com>")
|
||||
set(PROJECT_COPYRIGHT_YEARS "2018")
|
||||
set(PROJECT_COPYRIGHT_YEARS "2018 - 2019")
|
||||
|
||||
################################################################################
|
||||
# Setup / Bootstrap
|
||||
@@ -97,14 +123,14 @@ configure_file(
|
||||
)
|
||||
|
||||
# Windows
|
||||
## Installer (InnoSetup)
|
||||
Configure_File(
|
||||
if (WIN32)
|
||||
## Installer (InnoSetup)
|
||||
configure_file(
|
||||
"${PROJECT_SOURCE_DIR}/cmake/installer.iss.in"
|
||||
"${PROJECT_BINARY_DIR}/installer.iss"
|
||||
)
|
||||
)
|
||||
|
||||
# Windows Specific Resource Definition
|
||||
if(WIN32)
|
||||
# Windows Specific Resource Definition
|
||||
set(PROJECT_PRODUCT_NAME "${PROJECT_FULL_NAME}")
|
||||
set(PROJECT_COMPANY_NAME "${PROJECT_AUTHORS}")
|
||||
set(PROJECT_COPYRIGHT "${PROJECT_AUTHORS} © ${PROJECT_COPYRIGHT_YEARS}")
|
||||
@@ -118,19 +144,6 @@ if(WIN32)
|
||||
)
|
||||
endif()
|
||||
|
||||
# All Warnings, Extra Warnings, Pedantic
|
||||
if(MSVC)
|
||||
# Force to always compile with W4
|
||||
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
||||
endif()
|
||||
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
||||
# Update if necessary
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# Options
|
||||
################################################################################
|
||||
@@ -142,7 +155,7 @@ mark_as_advanced(FORCE OBS_NATIVE OBS_PACKAGE OBS_REFERENCE OBS_DOWNLOAD)
|
||||
|
||||
if(NOT TARGET libobs)
|
||||
set(${PropertyPrefix}OBS_STUDIO_DIR "" CACHE PATH "OBS Studio Source/Package Directory")
|
||||
set(${PropertyPrefix}OBS_DOWNLOAD_VERSION "22.0.2" CACHE STRING "OBS Studio Version to download")
|
||||
set(${PropertyPrefix}OBS_DOWNLOAD_VERSION "24.0.0-rc2-ci" CACHE STRING "OBS Studio Version to download")
|
||||
endif()
|
||||
|
||||
if(NOT ${PropertyPrefix}OBS_NATIVE)
|
||||
@@ -171,7 +184,7 @@ else()
|
||||
else()
|
||||
message(STATUS "${PROJECT_NAME}: No OBS Studio detected, using downloadable prebuilt binaries.")
|
||||
CacheSet(${PropertyPrefix}OBS_DOWNLOAD TRUE)
|
||||
set(${PropertyPrefix}OBS_DOWNLOAD_URL "https://github.com/Xaymar/obs-studio/releases/download/${OBS_DOWNLOAD_VERSION}/obs-studio-${ARCH}-vs2017.7z")
|
||||
set(${PropertyPrefix}OBS_DOWNLOAD_URL "https://github.com/Xaymar/obs-studio/releases/download/${OBS_DOWNLOAD_VERSION}/obs-studio-${ARCH}-0.0.0.0-vs2017.7z")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -179,17 +192,9 @@ endif()
|
||||
if(${PropertyPrefix}OBS_DOWNLOAD)
|
||||
include("cmake/DownloadProject.cmake")
|
||||
endif()
|
||||
if(NOT ${PropertyPrefix}OBS_NATIVE)
|
||||
include("cmake/cppcheck.cmake")
|
||||
endif()
|
||||
|
||||
# Load OBS Studio
|
||||
if(${PropertyPrefix}OBS_NATIVE)
|
||||
option(BUILD_FFMPEG_ENCODER "Build AMD Encoder module" ON)
|
||||
if (NOT BUILD_FFMPEG_ENCODER)
|
||||
message(STATUS "Not building AMD Encoder")
|
||||
return()
|
||||
endif()
|
||||
elseif(${PropertyPrefix}OBS_PACKAGE)
|
||||
include("${OBS_STUDIO_DIR}/cmake/LibObs/LibObsConfig.cmake")
|
||||
elseif(${PropertyPrefix}OBS_REFERENCE)
|
||||
@@ -203,7 +208,7 @@ elseif(${PropertyPrefix}OBS_DOWNLOAD)
|
||||
)
|
||||
include("${libobs_SOURCE_DIR}/cmake/LibObs/LibObsConfig.cmake")
|
||||
else()
|
||||
message(CRITICAL "Impossible case reached, very system stability.")
|
||||
message(CRITICAL "Impossible case reached, verify system stability.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
@@ -232,37 +237,85 @@ find_package(FFmpeg REQUIRED COMPONENTS avutil avcodec swscale)
|
||||
################################################################################
|
||||
# Code
|
||||
################################################################################
|
||||
set(PROJECT_DATA
|
||||
"${PROJECT_SOURCE_DIR}/data/locale/en-US.ini"
|
||||
"${PROJECT_SOURCE_DIR}/LICENSE"
|
||||
)
|
||||
|
||||
set(PROJECT_LIBRARIES
|
||||
)
|
||||
|
||||
set(PROJECT_TEMPLATES
|
||||
"${PROJECT_SOURCE_DIR}/cmake/version.hpp.in"
|
||||
"${PROJECT_SOURCE_DIR}/cmake/module.cpp.in"
|
||||
)
|
||||
if(WIN32)
|
||||
list(APPEND PROJECT_TEMPLATES
|
||||
"${PROJECT_SOURCE_DIR}/cmake/installer.iss.in"
|
||||
"${PROJECT_SOURCE_DIR}/cmake/version.rc.in"
|
||||
)
|
||||
endif()
|
||||
|
||||
set(PROJECT_GENERATED
|
||||
"${PROJECT_BINARY_DIR}/source/module.cpp"
|
||||
"${PROJECT_BINARY_DIR}/source/version.hpp"
|
||||
)
|
||||
set(PROJECT_PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/source/encoder.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/encoder.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/encoder.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/plugin.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/plugin.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/utility.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/utility.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/encoders/prores_aw.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/encoders/prores_aw.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/strings.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/codecs/hevc.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/codecs/hevc.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/codecs/h264.hpp"
|
||||
"${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.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ffmpeg/swscale.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ffmpeg/swscale.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ffmpeg/tools.hpp"
|
||||
"${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.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ui/debug_handler.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ui/debug_handler.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ui/prores_aw_handler.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ui/prores_aw_handler.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ui/nvenc_shared.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ui/nvenc_shared.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ui/nvenc_h264_handler.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ui/nvenc_h264_handler.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ui/nvenc_hevc_handler.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ui/nvenc_hevc_handler.cpp"
|
||||
)
|
||||
SET(PROJECT_GENERATED
|
||||
"${PROJECT_BINARY_DIR}/source/module.cpp"
|
||||
"${PROJECT_BINARY_DIR}/source/version.hpp"
|
||||
)
|
||||
set(PROJECT_DATA
|
||||
"${PROJECT_SOURCE_DIR}/data/locale/en-US.ini"
|
||||
"${PROJECT_SOURCE_DIR}/LICENSE"
|
||||
)
|
||||
set(PROJECT_LIBRARIES
|
||||
)
|
||||
if(WIN32)
|
||||
list(APPEND PROJECT_PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/source/hwapi/d3d11.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/hwapi/d3d11.cpp"
|
||||
)
|
||||
endif()
|
||||
|
||||
# Source Grouping
|
||||
source_group(TREE "${PROJECT_SOURCE_DIR}" PREFIX "Data Files" FILES ${PROJECT_DATA})
|
||||
source_group(TREE "${PROJECT_SOURCE_DIR}/source" PREFIX "Private Files" FILES ${PROJECT_PRIVATE})
|
||||
source_group(TREE "${PROJECT_BINARY_DIR}/source" PREFIX "Generated Files" FILES ${PROJECT_GENERATED})
|
||||
source_group(TREE "${PROJECT_SOURCE_DIR}/cmake" PREFIX "Template Files" FILES ${PROJECT_TEMPLATES})
|
||||
|
||||
# Filter Sources
|
||||
set(_TMP_SOURCE ${PROJECT_PRIVATE})
|
||||
list(FILTER _TMP_SOURCE INCLUDE REGEX "\.(c|cpp)$")
|
||||
source_group(TREE "${PROJECT_SOURCE_DIR}/source" PREFIX "Source Files" FILES ${_TMP_SOURCE})
|
||||
|
||||
# Filter Headers
|
||||
set(_TMP_HEADER ${PROJECT_PRIVATE})
|
||||
list(FILTER _TMP_HEADER INCLUDE REGEX "\.(h|hpp)$")
|
||||
source_group(TREE "${PROJECT_SOURCE_DIR}/source" PREFIX "Header Files" FILES ${_TMP_HEADER})
|
||||
|
||||
################################################################################
|
||||
# Target
|
||||
@@ -272,6 +325,7 @@ add_library(${PROJECT_NAME} MODULE
|
||||
${PROJECT_GENERATED}
|
||||
${PROJECT_PRIVATE}
|
||||
${PROJECT_DATA}
|
||||
${PROJECT_TEMPLATES}
|
||||
)
|
||||
|
||||
# Include Directories
|
||||
@@ -312,7 +366,7 @@ endif()
|
||||
|
||||
# Link Libraries
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
"${PROJECT_LIBRARIES}"
|
||||
${PROJECT_LIBRARIES}
|
||||
${FFMPEG_LIBRARIES}
|
||||
)
|
||||
|
||||
@@ -367,6 +421,14 @@ if (WIN32)
|
||||
)
|
||||
endif()
|
||||
|
||||
# C++ Standard and Extensions
|
||||
set_target_properties(
|
||||
${PROJECT_NAME}
|
||||
PROPERTIES
|
||||
CXX_STANDARD ${_CXX_STANDARD}
|
||||
CXX_EXTENSIONS ${_CXX_EXTENSIONS}
|
||||
)
|
||||
|
||||
# File Version
|
||||
if(WIN32)
|
||||
set_target_properties(
|
||||
@@ -384,24 +446,6 @@ else()
|
||||
)
|
||||
endif()
|
||||
|
||||
# CPPCheck
|
||||
if(NOT ${PropertyPrefix}OBS_NATIVE)
|
||||
set(excludes )
|
||||
list(APPEND excludes "${OBS_DEPENDENCIES_DIR}")
|
||||
if(${PropertyPrefix}OBS_REFERENCE)
|
||||
list(APPEND excludes "${OBS_STUDIO_DIR}/libobs")
|
||||
elseif(${PropertyPrefix}OBS_PACKAGE)
|
||||
list(APPEND excludes "${OBS_STUDIO_DIR}/libobs")
|
||||
elseif(${PropertyPrefix}OBS_DOWNLOAD)
|
||||
list(APPEND excludes "${libobs_SOURCE_DIR}")
|
||||
endif()
|
||||
|
||||
cppcheck(
|
||||
EXCLUDE ${excludes}
|
||||
)
|
||||
cppcheck_add_project(${PROJECT_NAME})
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# Installation
|
||||
################################################################################
|
||||
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
# Build Instructions
|
||||
The project is compatible with being included directly in an obs-studio build, but can be built standalone. Depending on which you chose, the instructions differ greatly.
|
||||
|
||||
## Building with OBS Studio
|
||||
1. Prepare OBS Studio for building on your platform.
|
||||
2. Navigate to <obs-studio-clone>/plugins in a git-enabled shell.
|
||||
3. Run `git submodule add https://github.com/Xaymar/obs-ffmpeg-encoder.git obs-ffmpeg-encoder` and wait for it to complete.
|
||||
4. Edit the CMakeLists.txt in the same directory and append `add_subdirectory(obs-ffmpeg-encoder)`.
|
||||
5. Use CMake to reconfigure OBS Studio, at which point it should detect the new plugin and allow you to build it.
|
||||
6. Done.
|
||||
|
||||
## Building Standalone
|
||||
This mode of building is used by CI providers and offers the fastest compile time, but does not allow quick testing as it requires a working OBS Studio installation to test.
|
||||
|
||||
1. Install CMake (3.1 or newer) and if you aren't using Windows, build the PACKAGE target in OBS Studio, which will generate a CPack archive in the build folder.
|
||||
2. Clone the obs-ffmpeg-encoder repository using git or a comparable tool.
|
||||
3. Configure obs-ffmpeg-encoder using CMake to build a subdirectory or any other location that is not the same as the source directory, and adjust the following options to suit your needs:
|
||||
- OBS_STUDIO_DIR: Path to a normal or CPack OBS Studio build.
|
||||
- OBS_DOWNLOAD_VERSION: The version to attempt to automatically download and use if no OBS Studio is detected (may not work on all platforms).
|
||||
- CMAKE_INSTALL_PREFIX: Path that the INSTALL target copies files to.
|
||||
- CMAKE_PACKAGE_PREFIX: Path for the archives generated by PACKAGE_ZIP and PACKAGE_7Z.
|
||||
- CMAKE_PACKAGE_NAME: Name for the archives generated by PACKAGE_ZIP and PACKAGE_7Z.
|
||||
- CMAKE_PACKAGE_SUFFIX_OVERRIDE:
|
||||
4. Build obs-ffmpeg-encoder.
|
||||
|
||||
### Installing into a local OBS Studio Installation
|
||||
Modify CMAKE_INSTALL_PREFIX to point at your OBS Studio installation directory (not the data directory) and build the INSTALL target.
|
||||
|
||||
### Packaging Release Archives
|
||||
Generate release archives by building either PACKAGE_ZIP or PACKAGE_7Z. To generate a full release archive, CMAKE_INSTALL_PREFIX has to be set to a directory that only contains release files for this plugin. See the CI scripts for an example on this.
|
||||
|
||||
# Commits
|
||||
Commits should always only focus on a single change that is necessary for that commit to work. For example, a commit that changes how something logs messages should not also include a new blur effect. In those cases, the commit should be split up into two, so that they can be reverted independently from another.
|
||||
|
||||
## Commit Subject
|
||||
The subject line of a commit should begin with the prefix followed by a `: `, and then followed by a summary of what the change does, which should be no longer than 52 alphanumerical characters including whitespace. The prefix is determined by the file being modified, simply remove the extension or find the group that a file belongs to. For example, a modifiation to blur.effect would have the category effects, due to it being re-usable.
|
||||
|
||||
### Prefixes
|
||||
- effects: Anything modifying generic effects like blur.effect, color-conversion.effect, mask.effect, etc.
|
||||
- locale: Changes in `/data/locale`.
|
||||
- shaders: Changes in `/data/shaders` that are not directly influenced by a change to custom shaders.
|
||||
- project: Changes to files like README, CONTRIBUTING, AUTHORS, etc.
|
||||
- cmake: Changes to CMake build scripts.
|
||||
- ci: Changes to Continuous Integration.
|
||||
|
||||
All other files should be prefixed with the main file changed, so a change to the translations for Source Mirror would be `source-mirror: commit`.
|
||||
|
||||
## Commit Messages
|
||||
The commit message should always convey why this change was necessary, what is being changed and how it affects the code when being run. There are rare cases where this can be left out (formatting, refactoring, ...) but it should always be descriptive of what is actually being done.
|
||||
|
||||
# Coding Guidelines
|
||||
|
||||
## Naming
|
||||
The project uses the generally known snake_case for code and the uppercase variant for enumerations and macros:
|
||||
|
||||
### Macros (ELEPHANT_CASE)
|
||||
- Casing: Uppercase
|
||||
- Separator: `_`
|
||||
- Prefixes: `S_` for global values, `ST_` for local (this file) values, `D_` for simple functions, `P_` for complex functions
|
||||
- Suffixes: No
|
||||
|
||||
Example:
|
||||
```
|
||||
#define S_PI 3.14141
|
||||
#define ST_PI2 S_PI / 2.0
|
||||
#define D_(x) S_PI * x
|
||||
#define P_(x, y) double_t x(double_t a, double_t b) { return a * b * y; }
|
||||
```
|
||||
|
||||
### Enumerations (snake_case)
|
||||
- Casing: Lowercase
|
||||
- Separator: `_`
|
||||
|
||||
Example:
|
||||
```
|
||||
enum my_enum {};
|
||||
enum class my_enum_class {};
|
||||
enum class my_enum_class_int : int {};
|
||||
```
|
||||
|
||||
#### Enumeration Entries (ELEPHANT_CASE)
|
||||
- Casing: Uppercase
|
||||
- Separator: `_`
|
||||
|
||||
Example:
|
||||
```
|
||||
enum my_enum {
|
||||
ENTRY_1,
|
||||
ENTRY_2
|
||||
};
|
||||
```
|
||||
|
||||
### Variables (snake_case)
|
||||
- Casing: Lowercase
|
||||
- Separator: `_`
|
||||
- Prefixes: No
|
||||
- Suffixes: No
|
||||
|
||||
Example:
|
||||
```
|
||||
int my_var = 0;
|
||||
```
|
||||
|
||||
### Functions (snake_case)
|
||||
- Casing: Lowercase
|
||||
- Separator: `_`
|
||||
- Prefixes: No
|
||||
- Suffixes: No (differentiate by parameters only)
|
||||
|
||||
Example:
|
||||
```
|
||||
// This is forbidden.
|
||||
void func();
|
||||
int func_int();
|
||||
|
||||
// This is okay.
|
||||
void func();
|
||||
void func(int& result);
|
||||
```
|
||||
|
||||
### Namespaces (snake_case)
|
||||
- Casing: Lowercase
|
||||
- Separator: `_`
|
||||
|
||||
Example:
|
||||
```
|
||||
namespace a_space {};
|
||||
```
|
||||
|
||||
### Classes, Structs, Unions (snake_case)
|
||||
- Casing: Lowercase
|
||||
- Separator: `_`
|
||||
- Prefixes: No
|
||||
- Suffixes: No
|
||||
|
||||
Example:
|
||||
```
|
||||
class a_class {};
|
||||
class interface_class {};
|
||||
```
|
||||
|
||||
#### Interface Classes
|
||||
Interface Classes are handled like normal classes. There are no prefixes or suffixes to attach.
|
||||
|
||||
#### Methods (snake_case)
|
||||
- Casing: Lowercase
|
||||
- Separator: `_`
|
||||
- Prefixes: No
|
||||
- Suffixes: No (differentiate by parameters only)
|
||||
|
||||
Example:
|
||||
```
|
||||
class a_class {
|
||||
// This is forbidden.
|
||||
void func();
|
||||
int func_int();
|
||||
|
||||
// This is okay.
|
||||
void func();
|
||||
void func(int& result);
|
||||
};
|
||||
```
|
||||
|
||||
#### Member Variables (snake_case)
|
||||
- Casing: Lowercase
|
||||
- Separator: `_`
|
||||
- Prefixes: `_` if private, otherwise none
|
||||
- Suffixes: No
|
||||
|
||||
Example:
|
||||
```
|
||||
class a_class {
|
||||
int64_t _local_var;
|
||||
void* _pointer;
|
||||
int32_t _id;
|
||||
};
|
||||
```
|
||||
|
||||
### Type Definitions (snake_case)
|
||||
- Casing: Lowercase
|
||||
- Separator: `_`
|
||||
- Prefixes: No
|
||||
- Suffixes: `_t`
|
||||
|
||||
Example:
|
||||
```
|
||||
typedef int32_t my_type_t;
|
||||
```
|
||||
|
||||
## Preprocessor Macros
|
||||
Preprocessor `#define` Macros should be used sparingly, due to their nature of changing code before the compiler gets a chance to work with it. Unless necessary, they should never be in a header file.
|
||||
|
||||
@@ -1,278 +1,21 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
MIT License
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||
|
||||
Preamble
|
||||
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 licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
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.
|
||||
+43
-20
@@ -1,43 +1,55 @@
|
||||
# Generic Settings
|
||||
version: '{build}-{branch}'
|
||||
pull_requests:
|
||||
do_not_increment_build_number: true
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
# Build Image & Environment
|
||||
platform: x64
|
||||
image: Visual Studio 2017
|
||||
environment:
|
||||
CMAKE_SYSTEM_VERSION: 10.0.16299.91
|
||||
PACKAGE_PREFIX: obs-ffmpeg-encoder
|
||||
INNOSETUP_URL: http://www.jrsoftware.org/download.php/is-unicode.exe
|
||||
|
||||
# Build Tags only
|
||||
skip_non_tags: true
|
||||
|
||||
image:
|
||||
- Visual Studio 2017
|
||||
|
||||
environment:
|
||||
CMAKE_SYSTEM_VERSION: 10.0.17134.0
|
||||
CMAKE_GENERATOR_32: "Visual Studio 15 2017"
|
||||
CMAKE_GENERATOR_64: "Visual Studio 15 2017 Win64"
|
||||
PACKAGE_PREFIX: obs-ffmpeg-encoder
|
||||
INNOSETUP_URL: http://www.jrsoftware.org/download.php/is.exe
|
||||
CURL_VERSION: 7.39.0
|
||||
|
||||
# Resource Cache
|
||||
cache:
|
||||
- inno.exe
|
||||
- build/32/libobs-download
|
||||
- build/32/libobs-src
|
||||
- build/64/libobs-download
|
||||
- build/64/libobs-src
|
||||
|
||||
# Building
|
||||
install:
|
||||
- cmd: ci/appveyor-install.bat
|
||||
|
||||
build_script:
|
||||
- cmd: ci/appveyor-build.bat
|
||||
- cmd: node ci/builder.js
|
||||
|
||||
after_build:
|
||||
- cmd: node ci/packager.js
|
||||
- cmd: ci/appveyor-package.bat
|
||||
|
||||
cache:
|
||||
- inno.exe
|
||||
- build/32/obsdeps-build
|
||||
- build/32/obsdeps-download
|
||||
- build/32/obsdeps-src
|
||||
- build/32/libobs-build
|
||||
- build/32/libobs-download
|
||||
- build/32/libobs-src
|
||||
- build/64/libobs-build
|
||||
- build/64/libobs-download
|
||||
- build/64/libobs-src
|
||||
# Testing
|
||||
test: off
|
||||
|
||||
# Artifacts
|
||||
artifacts:
|
||||
- path: build/obs-ffmpeg-encoder-*.zip
|
||||
- path: build/obs-ffmpeg-encoder-*.7z
|
||||
- path: build/obs-ffmpeg-encoder-*.exe
|
||||
|
||||
# Deploying
|
||||
deploy:
|
||||
- provider: GitHub
|
||||
auth_token:
|
||||
@@ -48,4 +60,15 @@ deploy:
|
||||
on:
|
||||
appveyor_repo_tag: true
|
||||
|
||||
test: off
|
||||
# Notifications
|
||||
notifications:
|
||||
- provider: Webhook
|
||||
url:
|
||||
secure: PTtt5ALhmK0q42jYyx4/Qa1Uf18+gLMXKGdzJjDISJt8IE/K0Zyp58UYmDDbbyLp4pBRf/Ylj8rn/zYL/mqBoDVRIH5zasPqIvBD0ZhtvNjTOxQ3QoRkAmxgpWeMowm3A3I1rLizA2H4EctPpoAJGrvQ1G2HEYn9tVsGYeetFTo=
|
||||
on_build_success: false
|
||||
on_build_failure: false
|
||||
on_build_status_changed: true
|
||||
body: >-
|
||||
{
|
||||
"content": "**Build {{status}}**: [{{commitId}}] {{commitMessage}}\nBy {{commitAuthor}} on {{commitDate}}\n{{buildUrl}}"
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
cmake -H. -B"build/32" -G"Visual Studio 15 2017" -DCMAKE_INSTALL_PREFIX="%CD%/build/distrib" -DCMAKE_PACKAGE_PREFIX="%CD%/build" -DCMAKE_PACKAGE_NAME="obs-ffmpeg-encoder"
|
||||
cmake -H. -B"build/64" -G"Visual Studio 15 2017 Win64" -T"host=x64" -DCMAKE_INSTALL_PREFIX="%CD%/build/distrib" -DCMAKE_PACKAGE_PREFIX="%CD%/build" -DCMAKE_PACKAGE_NAME="obs-ffmpeg-encoder" -DOBS_DEPENDENCIES_DIR="%CD%/build/32/obsdeps-src"
|
||||
cmake --build build/32 --target INSTALL --config RelWithDebInfo -- /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
|
||||
cmake --build build/64 --target INSTALL --config RelWithDebInfo -- /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
|
||||
@@ -1,3 +1,4 @@
|
||||
@ECHO OFF
|
||||
git submodule update --init --force --recursive
|
||||
|
||||
IF EXIST inno.exe (
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
ECHO -- Building 7z Archive --
|
||||
cmake --build build/64 --target PACKAGE_7Z --config RelWithDebInfo
|
||||
ECHO -- Building Zip Archive --
|
||||
cmake --build build/64 --target PACKAGE_ZIP --config RelWithDebInfo
|
||||
@ECHO OFF
|
||||
ECHO -- Building Installer --
|
||||
"C:\Program Files (x86)\Inno Setup 5\ISCC.exe" /Qp ".\build\64\installer.iss" > nul
|
||||
@@ -0,0 +1,95 @@
|
||||
"use strict";
|
||||
|
||||
const process = require('process');
|
||||
const runner = require('./runner.js');
|
||||
let env = process.env;
|
||||
|
||||
let x32_steps = [];
|
||||
let x64_steps = [];
|
||||
|
||||
if ((process.platform == "win32") || (process.platform == "win64")) {
|
||||
// Windows
|
||||
let extra_conf = [
|
||||
`-DCMAKE_SYSTEM_VERSION=${process.env.CMAKE_SYSTEM_VERSION}`,
|
||||
`-DCMAKE_PACKAGE_NAME=obs-ffmpeg-encoder`,
|
||||
'-DCMAKE_INSTALL_PREFIX="build/distrib/"',
|
||||
'-DCMAKE_PACKAGE_PREFIX="build/"',
|
||||
];
|
||||
let extra_build = [
|
||||
|
||||
];
|
||||
|
||||
if(process.env.APPVEYOR) {
|
||||
extra_build.concat(['--', '/logger:"C:\\Program Files\\AppVeyor\\BuildAgent\\Appveyor.MSBuildLogger.dll"']);
|
||||
}
|
||||
|
||||
if ((process.env.CMAKE_GENERATOR_32 !== undefined) && (process.env.CMAKE_GENERATOR_32 !== "")) {
|
||||
x32_steps.push(
|
||||
[ 'cmake', [
|
||||
'-H.',
|
||||
'-Bbuild/32',
|
||||
`-G"${process.env.CMAKE_GENERATOR_32}"`,
|
||||
].concat(extra_conf), env ]
|
||||
);
|
||||
x32_steps.push(
|
||||
[ 'cmake', [
|
||||
'--build', 'build/32',
|
||||
'--config', 'RelWithDebInfo',
|
||||
'--target', 'INSTALL'
|
||||
].concat(extra_build), env ]
|
||||
);
|
||||
}
|
||||
if ((process.env.CMAKE_GENERATOR_64 !== undefined) && (process.env.CMAKE_GENERATOR_64 !== "")) {
|
||||
x64_steps.push(
|
||||
[ 'cmake', [
|
||||
'-H.',
|
||||
'-Bbuild/64',
|
||||
`-G"${process.env.CMAKE_GENERATOR_64}"`,
|
||||
'-T"host=x64"'
|
||||
].concat(extra_conf), env ]
|
||||
);
|
||||
x64_steps.push(
|
||||
[ 'cmake', [
|
||||
'--build', 'build/64',
|
||||
'--config', 'RelWithDebInfo',
|
||||
'--target', 'INSTALL'
|
||||
].concat(extra_build), env ]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Unix
|
||||
|
||||
}
|
||||
|
||||
function runRunners(runnerArray, name) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let local = runnerArray.reverse();
|
||||
while (local.length > 0) {
|
||||
try {
|
||||
let task = local.pop();
|
||||
let work = new runner(name, task[0], task[1], task[2]);
|
||||
await work.run();
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
resolve(0);
|
||||
});
|
||||
}
|
||||
|
||||
let promises = [];
|
||||
promises.push(runRunners(x32_steps, "32-Bit"));
|
||||
promises.push(runRunners(x64_steps, "64-Bit"));
|
||||
Promise.all(promises).then(
|
||||
res => {
|
||||
process.exit(0);
|
||||
},
|
||||
err => {
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
}
|
||||
).catch(err => {
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
})
|
||||
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
|
||||
const process = require('process');
|
||||
const runner = require('./runner.js');
|
||||
|
||||
function runRunners(runnerArray, name) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let local = runnerArray.reverse();
|
||||
while (local.length > 0) {
|
||||
let task = local.pop();
|
||||
let work = new runner(name, task[0], task[1], task[2]);
|
||||
await work.run();
|
||||
}
|
||||
resolve(0);
|
||||
});
|
||||
}
|
||||
|
||||
let env = process.env;
|
||||
let steps = [];
|
||||
|
||||
if ((process.env.CMAKE_GENERATOR_64 !== undefined) && (process.env.CMAKE_GENERATOR_64 !== "")) {
|
||||
steps.push(
|
||||
[ 'cmake', [
|
||||
'--build', 'build/64',
|
||||
'--config', 'RelWithDebInfo',
|
||||
'--target', 'PACKAGE_7Z'
|
||||
], env ]
|
||||
);
|
||||
steps.push(
|
||||
[ 'cmake', [
|
||||
'--build', 'build/64',
|
||||
'--config', 'RelWithDebInfo',
|
||||
'--target', 'PACKAGE_ZIP'
|
||||
], env ]
|
||||
);
|
||||
} else if ((process.env.CMAKE_GENERATOR_32 !== undefined) && (process.env.CMAKE_GENERATOR_32 !== "")) {
|
||||
steps.push(
|
||||
[ 'cmake', [
|
||||
'--build', 'build/32',
|
||||
'--config', 'RelWithDebInfo',
|
||||
'--target', 'PACKAGE_7Z'
|
||||
], env ]
|
||||
);
|
||||
steps.push(
|
||||
[ 'cmake', [
|
||||
'--build', 'build/32',
|
||||
'--config', 'RelWithDebInfo',
|
||||
'--target', 'PACKAGE_ZIP'
|
||||
], env ]
|
||||
);
|
||||
}
|
||||
|
||||
let promises = [];
|
||||
promises.push(runRunners(steps, "32-Bit"));
|
||||
Promise.all(promises).then(
|
||||
res => {
|
||||
process.exit(0);
|
||||
},
|
||||
err => {
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
|
||||
const process = require('process');
|
||||
const cp = require('child_process');
|
||||
|
||||
class Runner {
|
||||
constructor(name, cmd, args, env) {
|
||||
this.name = name;
|
||||
this.cmd = cmd;
|
||||
if (args == undefined)
|
||||
args = [];
|
||||
this.args = args;
|
||||
if (env == undefined)
|
||||
env = process.env;
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
run() {
|
||||
let self = this;
|
||||
return new Promise(function(resolve, reject) {
|
||||
self.proc = cp.spawn(
|
||||
self.cmd, self.args, {
|
||||
windowsVerbatimArguments: true,
|
||||
windowsHide: true,
|
||||
env: self.env,
|
||||
}
|
||||
);
|
||||
self.proc.stdout.on('data', (data) => {
|
||||
process.stdout.write(`[${self.name}:Out] ${data}`);
|
||||
});
|
||||
self.proc.stderr.on('data', (data) => {
|
||||
process.stderr.write(`[${self.name}:Err] ${data}`);
|
||||
});
|
||||
self.proc.on('exit', (code, signal) => {
|
||||
if (code != 0) {
|
||||
reject(code);
|
||||
return;
|
||||
}
|
||||
resolve(code);
|
||||
return;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
execute() {
|
||||
return this.run();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Runner;
|
||||
+150
-14
@@ -1,15 +1,151 @@
|
||||
Bitrate="Bitrate"
|
||||
Bitrate.Description="Bitrate in kbit/s"
|
||||
KeyFrame.Type="Key Frame Type"
|
||||
KeyFrame.Type.Frames="Frames"
|
||||
KeyFrame.Type.Seconds="Seconds"
|
||||
KeyFrame.Interval="Key Frame Interval"
|
||||
KeyFrame.Interval.Description="Interval in which a Key Frame is placed."
|
||||
CustomParameters="Custom Parameters"
|
||||
CustomParameters.Description="Format: key1=val1 key2=val2 key3='val3 val4'"
|
||||
# Generic
|
||||
State.Automatic="Automatic"
|
||||
State.Default="Default"
|
||||
State.Disabled="Disabled"
|
||||
State.Enabled="Enabled"
|
||||
State.Manual="Manual"
|
||||
|
||||
# ProRes
|
||||
ProRes.Profile.Proxy="Proxy (PXY)"
|
||||
ProRes.Profile.Light="Light (LT)"
|
||||
ProRes.Profile.Standard="Standard"
|
||||
ProRes.Profile.HighQuality="High Quality (HQ)"
|
||||
# FFmpeg
|
||||
FFmpeg="FFmpeg Options"
|
||||
FFmpeg.CustomSettings="Custom Settings"
|
||||
FFmpeg.CustomSettings.Description="Custom settings that override any detected options above, use with caution.\nThe input should be in the format 'key=value;key=value;...'."
|
||||
FFmpeg.Threads="Number of Threads"
|
||||
FFmpeg.Threads.Description="The number of threads to use for encoding, if supported by the encoder.\nA value of 0 is equal to 'auto-detect' and may result in excessive CPU usage."
|
||||
FFmpeg.ColorFormat="Override Color Format"
|
||||
FFmpeg.ColorFormat.Description="Overriding the color format can unlock higher quality, but might cause additional stress.\nNot all encoders support all color formats, and you might end up causing errors or corrupted video due to this."
|
||||
FFmpeg.StandardCompliance="Standard Compliance"
|
||||
FFmpeg.StandardCompliance.Description="How strict should the encoder keep to the standard? A strictness below 'Normal' may cause issues with playback."
|
||||
FFmpeg.StandardCompliance.VeryStrict="Very Strict"
|
||||
FFmpeg.StandardCompliance.Strict="Strict"
|
||||
FFmpeg.StandardCompliance.Normal="Normal"
|
||||
FFmpeg.StandardCompliance.Unofficial="Unofficial"
|
||||
FFmpeg.StandardCompliance.Experimental="Experimental"
|
||||
|
||||
# Rate Control
|
||||
RateControl="Rate Control"
|
||||
RateControl.Mode="Method"
|
||||
RateControl.Mode.ConstantBitrate="Constant Bitrate"
|
||||
RateControl.Mode.AverageBitrate="Average Bitrate"
|
||||
RateControl.Mode.VariableBitrate="Variable Bitrate"
|
||||
RateControl.Mode.ConstantQuantizationParameter="Constant Quantization Parameter"
|
||||
RateControl.Mode.ConstantRateFactor="Constant Rate Factor"
|
||||
RateControl.Mode.ConstantQuality="Constant Quality"
|
||||
RateControl.Mode.VariableQuality="Variable Quality"
|
||||
RateControl.Mode.Lossless="Lossless"
|
||||
RateControl.Bitrate.Target="Target Bitrate"
|
||||
RateControl.Bitrate.Minimum="Minimum Bitrate"
|
||||
RateControl.Bitrate.Maximum="Maximum Bitrate"
|
||||
RateControl.Quality.Target="Target Quality"
|
||||
RateControl.Quality.Minimum="Minimum Quality"
|
||||
RateControl.Quality.Maximum="Maximum Quality"
|
||||
RateControl.BufferSize="Buffer Size"
|
||||
RateControl.BufferSize.Description="The size of the buffer to use when determining the remaining available bitrate.\nIdeally should be equal to your bitrate times the key frame interval in seconds."
|
||||
|
||||
# Key Frames
|
||||
KeyFrames="Key Frames"
|
||||
KeyFrames.IntervalType="Interval Type"
|
||||
KeyFrames.IntervalType.Frames="Frames"
|
||||
KeyFrames.IntervalType.Seconds="Seconds"
|
||||
KeyFrames.Interval="Interval"
|
||||
|
||||
# Codec: H264
|
||||
Codec.H264="H264"
|
||||
Codec.H264.Profile="Profile"
|
||||
Codec.H264.Profile.baseline="Baseline"
|
||||
Codec.H264.Profile.main="Main"
|
||||
Codec.H264.Profile.high="High"
|
||||
Codec.H264.Profile.high444p="High 4:4:4 Predictive"
|
||||
Codec.H264.Level="Level"
|
||||
|
||||
# Codec: HEVC
|
||||
Codec.HEVC="HEVC"
|
||||
Codec.HEVC.Profile="Profile"
|
||||
Codec.HEVC.Profile.main="Main"
|
||||
Codec.HEVC.Profile.main10="Main 10-bit"
|
||||
Codec.HEVC.Profile.rext="Range Extended"
|
||||
Codec.HEVC.Tier="Tier"
|
||||
Codec.HEVC.Tier.main="Main"
|
||||
Codec.HEVC.Tier.high="High"
|
||||
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.Preset="Preset"
|
||||
NVENC.Preset.Default="Default"
|
||||
NVENC.Preset.Slow="Slow"
|
||||
NVENC.Preset.Medium="Medium"
|
||||
NVENC.Preset.Fast="Fast"
|
||||
NVENC.Preset.HighPerformance="High Performance"
|
||||
NVENC.Preset.HighQuality="High Quality"
|
||||
NVENC.Preset.BluRayDisc="BluRay Disc"
|
||||
NVENC.Preset.LowLatency="Low Latency"
|
||||
NVENC.Preset.LowLatencyHighPerformance="Low Latency High Performance"
|
||||
NVENC.Preset.LowLatencyHighQuality="Low Latency High Quality"
|
||||
NVENC.Preset.Lossless="Lossless"
|
||||
NVENC.Preset.LosslessHighPerformance="Lossless High Performance"
|
||||
NVENC.RateControl="Rate Control Options"
|
||||
NVENC.RateControl.Mode="Mode"
|
||||
NVENC.RateControl.Mode.CQP="Constant Quantization Parameter"
|
||||
NVENC.RateControl.Mode.VBR="Variable Bitrate"
|
||||
NVENC.RateControl.Mode.VBR_HQ="High Quality Variable Bitrate"
|
||||
NVENC.RateControl.Mode.CBR="Constant Bitrate"
|
||||
NVENC.RateControl.Mode.CBR_HQ="High Quality Constant Bitrate"
|
||||
NVENC.RateControl.Mode.CBR_LD_HQ="Low Delay High Quality Constant Bitrate"
|
||||
NVENC.RateControl.LookAhead="Look Ahead"
|
||||
NVENC.RateControl.LookAhead.Description="Look ahead this many frames while encoding to better distribute bitrate.\nImproves quality slightly at the cost of some GPU time.\nSet to 0 to disable."
|
||||
NVENC.RateControl.AdaptiveI="Enable adaptive I-Frame insertion"
|
||||
NVENC.RateControl.AdaptiveI.Description="Enables adaptive I-Frame insertion.\nOnly has an effect when look ahead is set to a value other than 0."
|
||||
NVENC.RateControl.AdaptiveB="Enable adaptive B-Frame insertion"
|
||||
NVENC.RateControl.AdaptiveB.Description="Enables adaptive B-Frame insertion.\nOnly has an effect when look ahead is set to a value other than 0."
|
||||
NVENC.RateControl.TwoPass="Enable Two Pass"
|
||||
NVENC.RateControl.TwoPass.Description="Enable a secondary pass for encoding, which can help with quality and bitrate stability.\nImproves quality slightly at the cost of some GPU time.\nNvidia Turing hardware might actually see a quality degrade from this."
|
||||
NVENC.RateControl.Bitrate="Bitrate Limits"
|
||||
NVENC.RateControl.Bitrate.Target="Target Bitrate"
|
||||
NVENC.RateControl.Bitrate.Maximum="Maximum Bitrate"
|
||||
NVENC.RateControl.Quality="Enable Quality Limits"
|
||||
NVENC.RateControl.Quality.Minimum="Minimum Quality"
|
||||
NVENC.RateControl.Quality.Minimum.Description="Minimum quality to achieve, with values closer to 0 being better quality."
|
||||
NVENC.RateControl.Quality.Maximum="Maximum Quality"
|
||||
NVENC.RateControl.Quality.Maximum.Description="Maximum quality to achieve, with values closer to 0 being better quality.\nSet to -1 to disable the maximum restriction."
|
||||
NVENC.RateControl.Quality.Target="Target Quality"
|
||||
NVENC.RateControl.Quality.Target.Description="Target quality to achieve, with values closer to 0 being better quality.\nSet to 0 to disable the maximum restriction."
|
||||
NVENC.RateControl.QP="Quantization Parameters"
|
||||
NVENC.RateControl.QP.I="I-Frame QP"
|
||||
NVENC.RateControl.QP.I.Description="Quantization parameter for I-Frames.\nSmaller values mean better quality in exchange for higher bitrate, while higher values mean less bitrate in exchange for less quality."
|
||||
NVENC.RateControl.QP.I.Initial="Initial I-Frame QP"
|
||||
NVENC.RateControl.QP.I.Initial.Description="Initial B-Frame quantization parameter.\nSet to -1 to use the automatically detected value instead."
|
||||
NVENC.RateControl.QP.P="P-Frame QP"
|
||||
NVENC.RateControl.QP.P.Description="Quantization parameter for P-Frames.\nSmaller values mean better quality in exchange for higher bitrate, while higher values mean less bitrate in exchange for less quality."
|
||||
NVENC.RateControl.QP.P.Initial="Initial P-Frame QP"
|
||||
NVENC.RateControl.QP.P.Initial.Description="Initial P-Frame quantization parameter.\nSet to -1 to use the automatically detected value instead."
|
||||
NVENC.RateControl.QP.B="B-Frame QP"
|
||||
NVENC.RateControl.QP.B.Description="Quantization parameter for B-Frames.\nSmaller values mean better quality in exchange for higher bitrate, while higher values mean less bitrate in exchange for less quality."
|
||||
NVENC.RateControl.QP.B.Initial="Initial B-Frame QP"
|
||||
NVENC.RateControl.QP.B.Initial.Description="Initial B-Frame quantization parameter.\nSet to -1 to use the automatically detected value instead."
|
||||
NVENC.AQ="Adaptive Quantization"
|
||||
NVENC.AQ.Spatial="Enable Spatial Adaptive Quantization"
|
||||
NVENC.AQ.Spatial.Description="Enable spatial adaptive quantization, also sometimes referred to as Psychovisual Adaptive Quantization."
|
||||
NVENC.AQ.Strength="Spatial AQ Strength"
|
||||
NVENC.AQ.Strength.Description="Strength of the spatial adaptive quantization.\nValues closer to 15 mean more aggressive, while values closer to 1 mean more relaxed."
|
||||
NVENC.AQ.Temporal="Enable Temporal Adaptive Quantization"
|
||||
NVENC.AQ.Temporal.Description="Enable temporal adaptive quantization."
|
||||
NVENC.Other="Other Options"
|
||||
NVENC.Other.BFrames="Maximum B-Frames"
|
||||
NVENC.Other.BFrames.Description="Maximum number of B-Frames to insert into the encoded bitstream.\nActual number of B-Frames may be lower depending on content and lookahead settings."
|
||||
NVENC.Other.BFrameReferenceMode="B-Frame Reference Mode"
|
||||
NVENC.Other.BFrameReferenceMode.Each="Each B-Frame will be used for references"
|
||||
NVENC.Other.BFrameReferenceMode.Middle="Only (# of B-Frames)/2 will be used for references"
|
||||
NVENC.Other.ZeroLatency="Enable Zero Latency"
|
||||
NVENC.Other.ZeroLatency.Description="Enable zero latency operation, which ensures that there is no reordering delay."
|
||||
NVENC.Other.WeightedPrediction="Enable Weighted Prediction"
|
||||
NVENC.Other.WeightedPrediction.Description="Enable weighted prediction for encoding.\nCan't be used with B-Frames."
|
||||
NVENC.Other.NonReferencePFrames="Enable non-reference P-Frames"
|
||||
NVENC.Other.NonReferencePFrames.Description="Enable the automatic insertion of non-reference P-Frames."
|
||||
|
||||
@@ -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 "h264.hpp"
|
||||
@@ -0,0 +1,67 @@
|
||||
// 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 <map>
|
||||
|
||||
// Codec: H264
|
||||
#define P_H264 "Codec.H264"
|
||||
#define P_H264_PROFILE "Codec.H264.Profile"
|
||||
#define P_H264_LEVEL "Codec.H264.Level"
|
||||
|
||||
namespace obsffmpeg {
|
||||
namespace codecs {
|
||||
namespace h264 {
|
||||
enum class profile {
|
||||
CONSTRAINED_BASELINE,
|
||||
BASELINE,
|
||||
MAIN,
|
||||
HIGH,
|
||||
HIGH444_PREDICTIVE,
|
||||
UNKNOWN = -1,
|
||||
};
|
||||
|
||||
enum class level {
|
||||
L1_0 = 10,
|
||||
L1_0b,
|
||||
L1_1,
|
||||
L1_2,
|
||||
L1_3,
|
||||
L2_0 = 20,
|
||||
L2_1,
|
||||
L2_2,
|
||||
L3_0 = 30,
|
||||
L3_1,
|
||||
L3_2,
|
||||
L4_0 = 40,
|
||||
L4_1,
|
||||
L4_2,
|
||||
L5_0 = 50,
|
||||
L5_1,
|
||||
L5_2,
|
||||
L6_0 = 60,
|
||||
L6_1,
|
||||
L6_2,
|
||||
UNKNOWN = -1,
|
||||
};
|
||||
} // namespace h264
|
||||
} // namespace codecs
|
||||
} // namespace obsffmpeg
|
||||
@@ -0,0 +1,236 @@
|
||||
// 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 "hevc.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
enum class nal_unit_type : uint8_t { // 6 bits
|
||||
TRAIL_N = 0,
|
||||
TRAIL_R = 1,
|
||||
TSA_N = 2,
|
||||
TSA_R = 3,
|
||||
STSA_N = 4,
|
||||
STSA_R = 5,
|
||||
RADL_N = 6,
|
||||
RADL_R = 7,
|
||||
RASL_N = 8,
|
||||
RASL_R = 9,
|
||||
RSV_VCL_N10 = 10,
|
||||
RSV_VCL_R11 = 11,
|
||||
RSV_VCL_N12 = 12,
|
||||
RSV_VCL_R13 = 13,
|
||||
RSV_VCL_N14 = 14,
|
||||
RSV_VCL_R15 = 15,
|
||||
BLA_W_LP = 16,
|
||||
BLA_W_RADL = 17,
|
||||
BLA_N_LP = 18,
|
||||
IDR_W_RADL = 19,
|
||||
IDR_N_LP = 20,
|
||||
CRA = 21,
|
||||
RSV_IRAP_VCL22 = 22,
|
||||
RSV_IRAP_VCL23 = 23,
|
||||
RSV_VCL24 = 24,
|
||||
RSV_VCL25 = 25,
|
||||
RSV_VCL26 = 26,
|
||||
RSV_VCL27 = 27,
|
||||
RSV_VCL28 = 28,
|
||||
RSV_VCL29 = 29,
|
||||
RSV_VCL30 = 30,
|
||||
RSV_VCL31 = 31,
|
||||
VPS = 32,
|
||||
SPS = 33,
|
||||
PPS = 34,
|
||||
AUD = 35,
|
||||
EOS = 36,
|
||||
EOB = 37,
|
||||
FD = 38,
|
||||
PREFIX_SEI = 39,
|
||||
SUFFIX_SEI = 40,
|
||||
RSV_NVCL41 = 41,
|
||||
RSV_NVCL42 = 42,
|
||||
RSV_NVCL43 = 43,
|
||||
RSV_NVCL44 = 44,
|
||||
RSV_NVCL45 = 45,
|
||||
RSV_NVCL46 = 46,
|
||||
RSV_NVCL47 = 47,
|
||||
UNSPEC48 = 48,
|
||||
UNSPEC49 = 49,
|
||||
UNSPEC50 = 50,
|
||||
UNSPEC51 = 51,
|
||||
UNSPEC52 = 52,
|
||||
UNSPEC53 = 53,
|
||||
UNSPEC54 = 54,
|
||||
UNSPEC55 = 55,
|
||||
UNSPEC56 = 56,
|
||||
UNSPEC57 = 57,
|
||||
UNSPEC58 = 58,
|
||||
UNSPEC59 = 59,
|
||||
UNSPEC60 = 60,
|
||||
UNSPEC61 = 61,
|
||||
UNSPEC62 = 62,
|
||||
UNSPEC63 = 63,
|
||||
};
|
||||
|
||||
struct hevc_nal_unit_header {
|
||||
bool zero_bit : 1;
|
||||
nal_unit_type nut : 6;
|
||||
uint8_t layer_id : 6;
|
||||
uint8_t temporal_id_plus1 : 3;
|
||||
};
|
||||
|
||||
struct hevc_nal {
|
||||
hevc_nal_unit_header* header;
|
||||
size_t size = 0;
|
||||
uint8_t* data = nullptr;
|
||||
};
|
||||
|
||||
bool is_nal(uint8_t* data, uint8_t* end)
|
||||
{
|
||||
size_t s = end - data;
|
||||
if (s < 4)
|
||||
return false;
|
||||
|
||||
if (*data != 0x0)
|
||||
return false;
|
||||
if (*(data + 1) != 0x0)
|
||||
return false;
|
||||
if (*(data + 2) != 0x0)
|
||||
return false;
|
||||
if (*(data + 3) != 0x1)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool seek_to_nal(uint8_t*& data, uint8_t* end)
|
||||
{
|
||||
if (data > end)
|
||||
return false;
|
||||
|
||||
for (; data <= end; data++) {
|
||||
if (is_nal(data, end)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t get_nal_size(uint8_t* data, uint8_t* end)
|
||||
{
|
||||
uint8_t* ptr = data + 4;
|
||||
if (!seek_to_nal(ptr, end)) {
|
||||
return end - data;
|
||||
}
|
||||
return ptr - data;
|
||||
}
|
||||
|
||||
bool is_discard_marker(uint8_t* data, uint8_t* end)
|
||||
{
|
||||
size_t s = end - data;
|
||||
if (s < 4)
|
||||
return false;
|
||||
|
||||
if (*data != 0x0)
|
||||
return false;
|
||||
if (*(data + 1) != 0x0)
|
||||
return false;
|
||||
|
||||
if (*(data + 2) == 0x3) {
|
||||
// Discard marker only if the next byte is not 0x0, 0x1, 0x2 or 0x3.
|
||||
if (*(data + 3) != 0x0)
|
||||
return false;
|
||||
if (*(data + 3) != 0x1)
|
||||
return false;
|
||||
if (*(data + 3) != 0x2)
|
||||
return false;
|
||||
if (*(data + 3) != 0x3)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
if (*(data + 2) == 0x0)
|
||||
return true;
|
||||
if (*(data + 2) == 0x1)
|
||||
return true;
|
||||
if (*(data + 2) == 0x2)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool should_discard_nal(uint8_t* data, uint8_t* end)
|
||||
{
|
||||
if (data > end)
|
||||
return true;
|
||||
|
||||
for (; data <= end; data++) {
|
||||
if (is_discard_marker(data, end))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void progress_parse(uint8_t*& ptr, uint8_t* end, size_t& sz)
|
||||
{
|
||||
ptr += sz;
|
||||
sz = get_nal_size(ptr, end);
|
||||
}
|
||||
|
||||
void obsffmpeg::codecs::hevc::extract_header_sei(uint8_t* data, size_t sz_data,
|
||||
std::vector<uint8_t>& header, std::vector<uint8_t>& sei)
|
||||
{
|
||||
uint8_t* ptr = data;
|
||||
uint8_t* end = data + sz_data;
|
||||
|
||||
// Reserve enough memory to store the entire packet data if necessary.
|
||||
header.reserve(sz_data);
|
||||
sei.reserve(sz_data);
|
||||
|
||||
if (!seek_to_nal(ptr, end)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t nal_sz = get_nal_size(ptr, end); nal_sz > 0; progress_parse(ptr, end, nal_sz)) {
|
||||
if (should_discard_nal(ptr + 4, ptr + nal_sz)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
hevc_nal nal;
|
||||
nal.header = reinterpret_cast<hevc_nal_unit_header*>(ptr + 4);
|
||||
nal.size = nal_sz - 4 - 2;
|
||||
nal.data = ptr + 4 + 2;
|
||||
|
||||
switch (nal.header->nut) {
|
||||
case nal_unit_type::VPS:
|
||||
case nal_unit_type::SPS:
|
||||
case nal_unit_type::PPS:
|
||||
header.insert(header.end(), ptr, ptr + nal_sz);
|
||||
break;
|
||||
case nal_unit_type::PREFIX_SEI:
|
||||
case nal_unit_type::SUFFIX_SEI:
|
||||
sei.insert(sei.end(), ptr, ptr + nal_sz);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// 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 <vector>
|
||||
|
||||
// Codec: HEVC
|
||||
#define P_HEVC "Codec.HEVC"
|
||||
#define P_HEVC_PROFILE "Codec.HEVC.Profile"
|
||||
#define P_HEVC_TIER "Codec.HEVC.Tier"
|
||||
#define P_HEVC_LEVEL "Codec.HEVC.Level"
|
||||
|
||||
namespace obsffmpeg {
|
||||
namespace codecs {
|
||||
namespace hevc {
|
||||
enum class profile {
|
||||
MAIN,
|
||||
MAIN10,
|
||||
RANGE_EXTENDED,
|
||||
UNKNOWN = -1,
|
||||
};
|
||||
|
||||
enum class tier {
|
||||
MAIN,
|
||||
HIGH,
|
||||
UNKNOWN = -1,
|
||||
};
|
||||
|
||||
enum class level {
|
||||
L1_0 = 30,
|
||||
L2_0 = 60,
|
||||
L2_1 = 63,
|
||||
L3_0 = 90,
|
||||
L3_1 = 93,
|
||||
L4_0 = 120,
|
||||
L4_1 = 123,
|
||||
L5_0 = 150,
|
||||
L5_1 = 153,
|
||||
L5_2 = 156,
|
||||
L6_0 = 180,
|
||||
L6_1 = 183,
|
||||
L6_2 = 186,
|
||||
UNKNOWN = -1,
|
||||
};
|
||||
|
||||
void extract_header_sei(uint8_t* data, size_t sz_data,
|
||||
std::vector<uint8_t>& header, std::vector<uint8_t>& sei);
|
||||
|
||||
} // namespace hevc
|
||||
} // namespace codecs
|
||||
} // namespace obsffmpeg
|
||||
@@ -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"
|
||||
+1221
-13
File diff suppressed because it is too large
Load Diff
+134
-124
@@ -1,145 +1,155 @@
|
||||
// FFMPEG Video Encoder Integration for OBS Studio
|
||||
// Copyright (C) 2018 - 2018 Michael Fabian Dirks
|
||||
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
// 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:
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
// 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.
|
||||
|
||||
#ifndef OBS_FFMPEG_ENCODER_HPP
|
||||
#define OBS_FFMPEG_ENCODER_HPP
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <stack>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include "ffmpeg/avframe-queue.hpp"
|
||||
#include "ffmpeg/swscale.hpp"
|
||||
|
||||
#include <obs.h>
|
||||
#include "hwapi/base.hpp"
|
||||
#include "ui/handler.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <obs-properties.h>
|
||||
#include <obs.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include "libavcodec/avcodec.h"
|
||||
#include "libswscale/swscale.h"
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavutil/frame.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
namespace obsffmpeg {
|
||||
namespace encoder {
|
||||
class base {
|
||||
protected:
|
||||
obs_encoder_t* self = nullptr;
|
||||
|
||||
AVCodec* avcodec = nullptr;
|
||||
AVCodecContext* avcontext = nullptr;
|
||||
AVDictionary* avdictionary = nullptr;
|
||||
ffmpeg::swscale swscale;
|
||||
|
||||
std::pair<uint32_t, uint32_t> resolution;
|
||||
std::pair<uint32_t, uint32_t> framerate;
|
||||
|
||||
AVPixelFormat source_format;
|
||||
AVColorSpace source_colorspace;
|
||||
AVColorRange source_range;
|
||||
|
||||
AVPixelFormat target_format;
|
||||
AVColorSpace target_colorspace;
|
||||
AVColorRange target_range;
|
||||
|
||||
class unsupported_gpu_exception : public std::runtime_error {
|
||||
public:
|
||||
virtual ~base();
|
||||
|
||||
virtual void get_properties(obs_properties_t* props) = 0;
|
||||
|
||||
virtual bool update(obs_data_t* settings) = 0;
|
||||
|
||||
virtual bool get_extra_data(uint8_t** extra_data, size_t* size) = 0;
|
||||
|
||||
virtual bool get_sei_data(uint8_t** sei_data, size_t* size) = 0;
|
||||
|
||||
virtual void get_video_info(struct video_scale_info* info) = 0;
|
||||
|
||||
virtual bool encode(struct encoder_frame* frame, struct encoder_packet* packet,
|
||||
bool* received_packet) = 0;
|
||||
unsupported_gpu_exception(const std::string& reason) : runtime_error(reason) {}
|
||||
};
|
||||
|
||||
#define make_encoder_base(_source, _target, _name, _codec) \
|
||||
static void* _source##_create(obs_data_t* settings, obs_encoder_t* encoder) \
|
||||
{ \
|
||||
_target* ptr = nullptr; \
|
||||
try { \
|
||||
ptr = new _target(settings, encoder); \
|
||||
} catch (...) { \
|
||||
} \
|
||||
return ptr; \
|
||||
} \
|
||||
static void _source##_destroy(void* ptr) \
|
||||
{ \
|
||||
delete static_cast<_target*>(ptr); \
|
||||
} \
|
||||
static const char* _source##_get_name(void*) \
|
||||
{ \
|
||||
return _name; \
|
||||
} \
|
||||
static obs_properties_t* _source##_get_properties(void* ptr) \
|
||||
{ \
|
||||
obs_properties_t* pr = _target::get_properties(); \
|
||||
if (ptr) { \
|
||||
static_cast<_target*>(ptr)->get_properties(pr); \
|
||||
} \
|
||||
return pr; \
|
||||
} \
|
||||
static void _source##_get_defaults(obs_data_t* settings) \
|
||||
{ \
|
||||
_target::get_defaults(settings); \
|
||||
} \
|
||||
static bool _source##_get_extra_data(void* ptr, uint8_t** extra_data, size_t* size) \
|
||||
{ \
|
||||
return static_cast<_target*>(ptr)->get_extra_data(extra_data, size); \
|
||||
} \
|
||||
static bool _source##_get_sei_data(void* ptr, uint8_t** sei_data, size_t* size) \
|
||||
{ \
|
||||
return static_cast<_target*>(ptr)->get_sei_data(sei_data, size); \
|
||||
} \
|
||||
static void _source##_get_video_info(void* ptr, struct video_scale_info* info) \
|
||||
{ \
|
||||
static_cast<_target*>(ptr)->get_video_info(info); \
|
||||
} \
|
||||
static bool _source##_encode(void* ptr, struct encoder_frame* frame, struct encoder_packet* packet, \
|
||||
bool* received_packet) \
|
||||
{ \
|
||||
return static_cast<_target*>(ptr)->encode(frame, packet, received_packet); \
|
||||
} \
|
||||
static obs_encoder_info _source##_info; \
|
||||
static void _source##_initialize() \
|
||||
{ \
|
||||
_source##_info.id = "obs-ffmpeg-encoder-" #_source; \
|
||||
_source##_info.type = OBS_ENCODER_VIDEO; \
|
||||
_source##_info.caps = 0; \
|
||||
_source##_info.codec = _codec; \
|
||||
_source##_info.create = _source##_create; \
|
||||
_source##_info.destroy = _source##_destroy; \
|
||||
_source##_info.get_name = _source##_get_name; \
|
||||
_source##_info.get_properties = _source##_get_properties; \
|
||||
_source##_info.get_defaults = _source##_get_defaults; \
|
||||
_source##_info.get_extra_data = _source##_get_extra_data; \
|
||||
_source##_info.get_sei_data = _source##_get_sei_data; \
|
||||
_source##_info.get_video_info = _source##_get_video_info; \
|
||||
_source##_info.encode = _source##_encode; \
|
||||
obs_register_encoder(&(_source##_info)); \
|
||||
}
|
||||
//*/
|
||||
struct encoder_info {
|
||||
std::string uid;
|
||||
std::string codec;
|
||||
std::string readable_name;
|
||||
obs_encoder_info oei = {0};
|
||||
};
|
||||
|
||||
} // namespace encoder
|
||||
class encoder_factory {
|
||||
encoder_info info;
|
||||
encoder_info info_fallback;
|
||||
const AVCodec* avcodec_ptr;
|
||||
|
||||
std::shared_ptr<obsffmpeg::ui::handler> _handler;
|
||||
|
||||
public:
|
||||
encoder_factory(const AVCodec* codec);
|
||||
virtual ~encoder_factory();
|
||||
|
||||
void register_encoder();
|
||||
|
||||
void get_defaults(obs_data_t* settings, bool hw_encoder = false);
|
||||
|
||||
void get_properties(obs_properties_t* props, bool hw_encoder = false);
|
||||
|
||||
const AVCodec* get_avcodec();
|
||||
|
||||
const encoder_info& get_info();
|
||||
|
||||
const encoder_info& get_fallback();
|
||||
};
|
||||
|
||||
class encoder {
|
||||
obs_encoder_t* _self;
|
||||
encoder_factory* _factory;
|
||||
|
||||
const AVCodec* _codec;
|
||||
AVCodecContext* _context;
|
||||
|
||||
std::shared_ptr<obsffmpeg::ui::handler> _handler;
|
||||
|
||||
std::shared_ptr<obsffmpeg::hwapi::base> _hwapi;
|
||||
std::shared_ptr<obsffmpeg::hwapi::instance> _hwinst;
|
||||
|
||||
ffmpeg::swscale _swscale;
|
||||
AVPacket _current_packet;
|
||||
|
||||
size_t _lag_in_frames;
|
||||
size_t _count_send_frames;
|
||||
|
||||
// Extra Data
|
||||
bool _have_first_frame;
|
||||
std::vector<uint8_t> _extra_data;
|
||||
std::vector<uint8_t> _sei_data;
|
||||
|
||||
// Frame Stack and Queue
|
||||
std::stack<std::shared_ptr<AVFrame>> _free_frames;
|
||||
std::queue<std::shared_ptr<AVFrame>> _used_frames;
|
||||
std::chrono::high_resolution_clock::time_point _free_frames_last_used;
|
||||
|
||||
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
|
||||
// Shared
|
||||
void get_properties(obs_properties_t* props, bool hw_encode = false);
|
||||
|
||||
bool update(obs_data_t* settings);
|
||||
|
||||
// Audio only
|
||||
void get_audio_info(struct audio_convert_info* info);
|
||||
|
||||
size_t get_frame_size();
|
||||
|
||||
bool audio_encode(struct encoder_frame* frame, struct encoder_packet* packet, bool* received_packet);
|
||||
|
||||
// Video only
|
||||
void get_video_info(struct video_scale_info* info);
|
||||
|
||||
bool get_sei_data(uint8_t** sei_data, size_t* size);
|
||||
|
||||
bool get_extra_data(uint8_t** extra_data, size_t* size);
|
||||
|
||||
bool video_encode(struct encoder_frame* frame, struct encoder_packet* packet, bool* received_packet);
|
||||
|
||||
bool video_encode_texture(uint32_t handle, int64_t pts, uint64_t lock_key, uint64_t* next_key,
|
||||
struct encoder_packet* packet, bool* received_packet);
|
||||
|
||||
int receive_packet(bool* received_packet, struct encoder_packet* packet);
|
||||
|
||||
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
|
||||
|
||||
#endif OBS_FFMPEG_ENCODER_HPP
|
||||
|
||||
@@ -1,343 +0,0 @@
|
||||
// FFMPEG Video Encoder Integration for OBS Studio
|
||||
// Copyright (C) 2018 - 2018 Michael Fabian Dirks
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
|
||||
#include "prores_aw.hpp"
|
||||
#include <obs-module.h>
|
||||
#include <thread>
|
||||
#include "ffmpeg/tools.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
extern "C" {
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include "libavutil/dict.h"
|
||||
#include "libavutil/frame.h"
|
||||
#include "libavutil/opt.h"
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
#include <util/profiler.hpp>
|
||||
|
||||
#define T_PROFILE "ProRes.Profile"
|
||||
#define T_PROFILE_(x) "ProRes.Profile." vstr(x)
|
||||
#define T_CUSTOM "Custom"
|
||||
|
||||
#define LOG_PREFIX "[prores_aw] "
|
||||
|
||||
make_encoder_base(prores_aw, obsffmpeg::encoder::prores_aw, "ProRes (Anatoliy Wasserman) (FFMPEG)", "prores");
|
||||
|
||||
void obsffmpeg::encoder::prores_aw::initialize()
|
||||
{
|
||||
auto avd = avcodec_find_encoder_by_name("prores_aw");
|
||||
if (!avd) {
|
||||
PLOG_INFO("ProRes (Anatoliy Wasserman) not supported.");
|
||||
return;
|
||||
}
|
||||
prores_aw_initialize();
|
||||
PLOG_INFO("ProRes (Anatoliy Wasserman) supported.");
|
||||
}
|
||||
|
||||
void obsffmpeg::encoder::prores_aw::finalize()
|
||||
{
|
||||
//prores_aw_finalize();
|
||||
}
|
||||
|
||||
void obsffmpeg::encoder::prores_aw::get_defaults(obs_data_t* settings)
|
||||
{
|
||||
obs_data_set_default_int(settings, T_PROFILE, static_cast<long long>(profile::HighQuality));
|
||||
}
|
||||
|
||||
obs_properties_t* obsffmpeg::encoder::prores_aw::get_properties()
|
||||
{
|
||||
obs_properties_t* prs = obs_properties_create();
|
||||
obs_property_t* p = nullptr;
|
||||
|
||||
p = obs_properties_add_list(prs, T_PROFILE, TRANSLATE(T_PROFILE), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(T_PROFILE)));
|
||||
obs_property_list_add_int(p, TRANSLATE(T_PROFILE_(Proxy)), static_cast<long long>(profile::Proxy));
|
||||
obs_property_list_add_int(p, TRANSLATE(T_PROFILE_(Light)), static_cast<long long>(profile::Light));
|
||||
obs_property_list_add_int(p, TRANSLATE(T_PROFILE_(Standard)), static_cast<long long>(profile::Standard));
|
||||
obs_property_list_add_int(p, TRANSLATE(T_PROFILE_(HighQuality)), static_cast<long long>(profile::HighQuality));
|
||||
|
||||
p = obs_properties_add_text(prs, T_CUSTOM, TRANSLATE(T_CUSTOM), OBS_TEXT_DEFAULT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(T_CUSTOM)));
|
||||
|
||||
return prs;
|
||||
}
|
||||
|
||||
obsffmpeg::encoder::prores_aw::prores_aw(obs_data_t* settings, obs_encoder_t* encoder)
|
||||
{
|
||||
this->self = encoder;
|
||||
auto encvideo = obs_encoder_video(this->self);
|
||||
auto voi = video_output_get_info(encvideo);
|
||||
|
||||
// Options, Parameters, etc.
|
||||
/// Resolution, Frame Rate
|
||||
this->resolution.first = voi->width;
|
||||
this->resolution.second = voi->height;
|
||||
this->framerate.first = voi->fps_num;
|
||||
this->framerate.second = voi->fps_den;
|
||||
/// Source/Input
|
||||
this->source_colorspace = ffmpeg::tools::obs_videocolorspace_to_avcolorspace(voi->colorspace);
|
||||
this->source_range = ffmpeg::tools::obs_videorangetype_to_avcolorrange(voi->range);
|
||||
this->source_format = ffmpeg::tools::obs_videoformat_to_avpixelformat(voi->format);
|
||||
/// Target/Output
|
||||
this->target_colorspace = this->source_colorspace;
|
||||
this->target_range = this->source_range;
|
||||
switch (voi->format) {
|
||||
case VIDEO_FORMAT_RGBA:
|
||||
case VIDEO_FORMAT_BGRA:
|
||||
case VIDEO_FORMAT_BGRX:
|
||||
this->target_format = AV_PIX_FMT_YUV444P10;
|
||||
this->video_profile = profile::FourFourFourFour;
|
||||
break;
|
||||
case VIDEO_FORMAT_I444:
|
||||
case VIDEO_FORMAT_YVYU:
|
||||
case VIDEO_FORMAT_YUY2:
|
||||
case VIDEO_FORMAT_UYVY:
|
||||
case VIDEO_FORMAT_I420:
|
||||
case VIDEO_FORMAT_NV12:
|
||||
this->video_profile = static_cast<profile>(obs_data_get_int(settings, T_PROFILE));
|
||||
if (this->video_profile == profile::FourFourFourFour) {
|
||||
this->target_format = AV_PIX_FMT_YUV444P10;
|
||||
} else {
|
||||
this->target_format = AV_PIX_FMT_YUV422P10;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Log Settings
|
||||
PLOG_INFO(LOG_PREFIX
|
||||
"Initializing encoder...\n\tResolution: %lux%lu\n\tFramerate: %lu/%lu (%.2lf fps)\n\tInput: %s %s "
|
||||
"%s\n\tOutput: %s %s %s\n\tProfile: %ld",
|
||||
this->resolution.first, this->resolution.second, this->framerate.first, this->framerate.second,
|
||||
(double_t(this->framerate.first) / double_t(this->framerate.second)),
|
||||
ffmpeg::tools::get_pixel_format_name(this->source_format),
|
||||
ffmpeg::tools::get_color_space_name(this->source_colorspace),
|
||||
swscale.is_source_full_range() ? "Full" : "Partial",
|
||||
ffmpeg::tools::get_pixel_format_name(this->target_format),
|
||||
ffmpeg::tools::get_color_space_name(this->target_colorspace),
|
||||
swscale.is_target_full_range() ? "Full" : "Partial", static_cast<int>(this->video_profile));
|
||||
|
||||
// prores_aw restriction
|
||||
if (this->resolution.first % 2 == 1) {
|
||||
PLOG_ERROR(LOG_PREFIX "Width must be a multiple of 2.");
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
// Quit if we for some reason can't find prores_aw anymore.
|
||||
this->avcodec = avcodec_find_encoder_by_name("prores_aw");
|
||||
if (!this->avcodec) {
|
||||
PLOG_ERROR(LOG_PREFIX "Failed to find encoder.");
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
this->avcontext = avcodec_alloc_context3(this->avcodec);
|
||||
if (!this->avcontext) {
|
||||
PLOG_ERROR(LOG_PREFIX "Failed to create context.");
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
// Apply Settings
|
||||
/// Resolution
|
||||
this->avcontext->width = this->resolution.first;
|
||||
this->avcontext->height = this->resolution.second;
|
||||
/// Framerate
|
||||
this->avcontext->time_base.num = this->framerate.first;
|
||||
this->avcontext->time_base.den = this->framerate.second;
|
||||
this->avcontext->ticks_per_frame = 1;
|
||||
/// GOP/Keyframe (ProRes is Intra only)
|
||||
this->avcontext->gop_size = 0;
|
||||
/// Color, Profile
|
||||
this->avcontext->colorspace = this->target_colorspace;
|
||||
this->avcontext->color_range = this->target_range;
|
||||
this->avcontext->pix_fmt = this->target_format;
|
||||
this->avcontext->profile = static_cast<int>(this->video_profile);
|
||||
/// Other
|
||||
this->avcontext->field_order = AV_FIELD_PROGRESSIVE;
|
||||
this->avcontext->strict_std_compliance = FF_COMPLIANCE_NORMAL;
|
||||
this->avcontext->debug = 0;
|
||||
/// Threading
|
||||
this->avcontext->thread_type = FF_THREAD_FRAME;
|
||||
#if defined(__cplusplus)
|
||||
this->avcontext->thread_count = std::thread::hardware_concurrency();
|
||||
#elif defined(_WIN32)
|
||||
{
|
||||
SYSTEM_INFO sysinfo;
|
||||
GetSystemInfo(&sysinfo);
|
||||
this->avcontext->thread_count = sysinfo.dwNumberOfProcessors;
|
||||
}
|
||||
#elif defined(_GNU)
|
||||
this->avcontext->thread_count = 16;
|
||||
#else
|
||||
this->avcontext->thread_count = 16;
|
||||
#endif
|
||||
/// Dynamic Stuff
|
||||
this->update(settings);
|
||||
|
||||
// Open Encoder
|
||||
int res = avcodec_open2(this->avcontext, this->avcodec, NULL);
|
||||
if (res < 0) {
|
||||
avcodec_free_context(&this->avcontext);
|
||||
PLOG_ERROR(LOG_PREFIX "Failed to open codec: %s (%ld).", ffmpeg::tools::get_error_description(res),
|
||||
res);
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
// Configure and initialize SWScale
|
||||
swscale.set_source_size(voi->width, voi->height);
|
||||
swscale.set_source_format(this->source_format);
|
||||
swscale.set_source_color(this->source_range == AVCOL_RANGE_JPEG, this->source_colorspace);
|
||||
swscale.set_target_size(voi->width, voi->height);
|
||||
swscale.set_target_format(this->target_format);
|
||||
swscale.set_target_color(this->target_range == AVCOL_RANGE_JPEG, this->target_colorspace);
|
||||
|
||||
if (!swscale.initialize(SWS_FAST_BILINEAR)) {
|
||||
PLOG_ERROR(LOG_PREFIX "Incompatible conversion parameters:\n\tInput: %s %s %s\n\tOutput: %s %s %s",
|
||||
ffmpeg::tools::get_pixel_format_name(this->source_format),
|
||||
ffmpeg::tools::get_color_space_name(this->source_colorspace),
|
||||
swscale.is_source_full_range() ? "Full" : "Partial",
|
||||
ffmpeg::tools::get_pixel_format_name(this->target_format),
|
||||
ffmpeg::tools::get_color_space_name(this->target_colorspace),
|
||||
swscale.is_target_full_range() ? "Full" : "Partial");
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
frame_queue.set_pixel_format(this->avcontext->pix_fmt);
|
||||
frame_queue.set_resolution(this->resolution.first, this->resolution.second);
|
||||
frame_queue.precache(this->avcontext->thread_count / 2);
|
||||
|
||||
this->current_packet = av_packet_alloc();
|
||||
if (!this->current_packet) {
|
||||
PLOG_ERROR(LOG_PREFIX "Failed to allocated packet.");
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
PLOG_INFO(LOG_PREFIX "Encoder initialized.");
|
||||
}
|
||||
|
||||
obsffmpeg::encoder::prores_aw::~prores_aw()
|
||||
{
|
||||
frame_queue.clear();
|
||||
|
||||
swscale.finalize();
|
||||
if (this->avcontext) {
|
||||
avcodec_close(this->avcontext);
|
||||
avcodec_free_context(&this->avcontext);
|
||||
}
|
||||
}
|
||||
|
||||
void obsffmpeg::encoder::prores_aw::get_properties(obs_properties_t* props) {}
|
||||
|
||||
bool obsffmpeg::encoder::prores_aw::update(obs_data_t* settings)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool obsffmpeg::encoder::prores_aw::get_extra_data(uint8_t** extra_data, size_t* size)
|
||||
{
|
||||
if (!this->avcontext->extradata) {
|
||||
return false;
|
||||
}
|
||||
*extra_data = this->avcontext->extradata;
|
||||
*size = this->avcontext->extradata_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool obsffmpeg::encoder::prores_aw::get_sei_data(uint8_t** sei_data, size_t* size)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void obsffmpeg::encoder::prores_aw::get_video_info(video_scale_info* info)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool obsffmpeg::encoder::prores_aw::encode(encoder_frame* frame, encoder_packet* packet, bool* received_packet)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
{
|
||||
ScopeProfiler sp_frame("frame");
|
||||
AVFrame* vframe = frame_queue.pop();
|
||||
vframe->pts = frame->pts;
|
||||
|
||||
vframe->color_range = this->avcontext->color_range;
|
||||
vframe->colorspace = this->avcontext->colorspace;
|
||||
|
||||
{
|
||||
ScopeProfiler profile("convert");
|
||||
res = swscale.convert(reinterpret_cast<uint8_t**>(frame->data),
|
||||
reinterpret_cast<int*>(frame->linesize), 0, this->resolution.second,
|
||||
vframe->data, vframe->linesize);
|
||||
if (res <= 0) {
|
||||
PLOG_ERROR(LOG_PREFIX "Failed to convert frame: %s (%ld).",
|
||||
ffmpeg::tools::get_error_description(res), res);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ScopeProfiler profile("send");
|
||||
res = avcodec_send_frame(this->avcontext, vframe);
|
||||
if (res < 0) {
|
||||
PLOG_ERROR(LOG_PREFIX "Failed to encode frame: %s (%ld).",
|
||||
ffmpeg::tools::get_error_description(res), res);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
frame_queue_used.push(vframe);
|
||||
}
|
||||
|
||||
{
|
||||
ScopeProfiler profile("receive");
|
||||
res = avcodec_receive_packet(this->avcontext, this->current_packet);
|
||||
if (res < 0) {
|
||||
if (res == AVERROR(EAGAIN)) {
|
||||
*received_packet = false;
|
||||
return true;
|
||||
} else if (res == AVERROR(EOF)) {
|
||||
return true;
|
||||
} else {
|
||||
PLOG_ERROR(LOG_PREFIX "Failed to receive packet: %s (%ld).",
|
||||
ffmpeg::tools::get_error_description(res), res);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
AVFrame* uframe = frame_queue_used.pop_only();
|
||||
if (uframe) {
|
||||
if (frame_queue.empty()) {
|
||||
frame_queue.push(uframe);
|
||||
} else {
|
||||
av_frame_free(&uframe);
|
||||
}
|
||||
}
|
||||
packet->type = OBS_ENCODER_VIDEO;
|
||||
packet->pts = this->current_packet->pts;
|
||||
packet->dts = this->current_packet->pts;
|
||||
packet->data = this->current_packet->data;
|
||||
packet->size = this->current_packet->size;
|
||||
packet->keyframe = true; // There are only keyframes in ProRes (Intra Only)
|
||||
packet->drop_priority = 0;
|
||||
*received_packet = true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
// FFMPEG Video Encoder Integration for OBS Studio
|
||||
// Copyright (C) 2018 - 2018 Michael Fabian Dirks
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
|
||||
#ifndef OBS_FFMPEG_ENCODER_PRORES_AW
|
||||
#define OBS_FFMPEG_ENCODER_PRORES_AW
|
||||
#pragma once
|
||||
|
||||
#include <encoder.hpp>
|
||||
#include "ffmpeg/avframe-queue.hpp"
|
||||
#include <vector>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
}
|
||||
|
||||
namespace obsffmpeg {
|
||||
namespace encoder {
|
||||
class prores_aw : base {
|
||||
enum class profile {
|
||||
Auto = FF_PROFILE_UNKNOWN,
|
||||
Proxy = 0 /*FF_PROFILE_PRORES_PROXY*/,
|
||||
Light = 1 /*FF_PROFILE_PRORES_LT*/,
|
||||
Standard = 2 /*FF_PROFILE_PRORES_STANDARD*/,
|
||||
HighQuality = 3 /*FF_PROFILE_PRORES_HQ*/,
|
||||
FourFourFourFour = 4 /*FF_PROFILE_PRORES_4444*/ // Automatically set if I444 or RGB input.
|
||||
};
|
||||
|
||||
private:
|
||||
profile video_profile = profile::Auto;
|
||||
ffmpeg::avframe_queue frame_queue;
|
||||
ffmpeg::avframe_queue frame_queue_used;
|
||||
AVPacket* current_packet = nullptr;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
prores_aw(obs_data_t* settings, obs_encoder_t* encoder);
|
||||
|
||||
~prores_aw();
|
||||
|
||||
virtual void get_properties(obs_properties_t* props) override;
|
||||
|
||||
virtual bool update(obs_data_t* settings) override;
|
||||
|
||||
virtual bool get_extra_data(uint8_t** extra_data, size_t* size) override;
|
||||
|
||||
virtual bool get_sei_data(uint8_t** sei_data, size_t* size) override;
|
||||
|
||||
virtual void get_video_info(video_scale_info* info) override;
|
||||
|
||||
virtual bool encode(encoder_frame* frame, encoder_packet* packet,
|
||||
bool* received_packet) override;
|
||||
|
||||
public:
|
||||
static void initialize();
|
||||
|
||||
static void finalize();
|
||||
|
||||
static void get_defaults(obs_data_t* settings);
|
||||
|
||||
static obs_properties_t* get_properties();
|
||||
};
|
||||
} // namespace encoder
|
||||
} // namespace obsffmpeg
|
||||
|
||||
#endif OBS_FFMPEG_ENCODER_PRORES_AW
|
||||
@@ -1,30 +1,38 @@
|
||||
// FFMPEG Video Encoder Integration for OBS Studio
|
||||
// Copyright (C) 2018 - 2018 Michael Fabian Dirks
|
||||
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
// 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:
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
// 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 "avframe-queue.hpp"
|
||||
#include "tools.hpp"
|
||||
|
||||
AVFrame* ffmpeg::avframe_queue::create_frame()
|
||||
std::shared_ptr<AVFrame> ffmpeg::avframe_queue::create_frame()
|
||||
{
|
||||
AVFrame* frame = av_frame_alloc();
|
||||
std::shared_ptr<AVFrame> frame = std::shared_ptr<AVFrame>(av_frame_alloc(), [](AVFrame* frame) {
|
||||
av_frame_unref(frame);
|
||||
av_frame_free(&frame);
|
||||
});
|
||||
frame->width = this->resolution.first;
|
||||
frame->height = this->resolution.second;
|
||||
frame->format = this->format;
|
||||
int res = av_frame_get_buffer(frame, 0);
|
||||
|
||||
int res = av_frame_get_buffer(frame.get(), 32);
|
||||
if (res < 0) {
|
||||
throw std::exception(ffmpeg::tools::get_error_description(res));
|
||||
}
|
||||
@@ -32,14 +40,6 @@ AVFrame* ffmpeg::avframe_queue::create_frame()
|
||||
return frame;
|
||||
}
|
||||
|
||||
void ffmpeg::avframe_queue::destroy_frame(AVFrame* frame)
|
||||
{
|
||||
if (frame == nullptr)
|
||||
return;
|
||||
|
||||
av_frame_free(&frame);
|
||||
}
|
||||
|
||||
ffmpeg::avframe_queue::avframe_queue() {}
|
||||
|
||||
ffmpeg::avframe_queue::~avframe_queue()
|
||||
@@ -47,7 +47,7 @@ ffmpeg::avframe_queue::~avframe_queue()
|
||||
clear();
|
||||
}
|
||||
|
||||
void ffmpeg::avframe_queue::set_resolution(uint32_t width, uint32_t height)
|
||||
void ffmpeg::avframe_queue::set_resolution(uint32_t const width, uint32_t const height)
|
||||
{
|
||||
this->resolution.first = width;
|
||||
this->resolution.second = height;
|
||||
@@ -69,7 +69,7 @@ uint32_t ffmpeg::avframe_queue::get_height()
|
||||
return this->resolution.second;
|
||||
}
|
||||
|
||||
void ffmpeg::avframe_queue::set_pixel_format(AVPixelFormat format)
|
||||
void ffmpeg::avframe_queue::set_pixel_format(AVPixelFormat const format)
|
||||
{
|
||||
this->format = format;
|
||||
}
|
||||
@@ -89,23 +89,19 @@ void ffmpeg::avframe_queue::precache(size_t count)
|
||||
void ffmpeg::avframe_queue::clear()
|
||||
{
|
||||
std::unique_lock<std::mutex> ulock(this->lock);
|
||||
for (AVFrame* frame : frames) {
|
||||
destroy_frame(frame);
|
||||
}
|
||||
frames.clear();
|
||||
}
|
||||
|
||||
void ffmpeg::avframe_queue::push(AVFrame* frame)
|
||||
void ffmpeg::avframe_queue::push(std::shared_ptr<AVFrame> const frame)
|
||||
{
|
||||
std::unique_lock<std::mutex> ulock(this->lock);
|
||||
frames.push_back(frame);
|
||||
}
|
||||
|
||||
AVFrame* ffmpeg::avframe_queue::pop()
|
||||
std::shared_ptr<AVFrame> ffmpeg::avframe_queue::pop()
|
||||
{
|
||||
std::unique_lock<std::mutex> ulock(this->lock);
|
||||
|
||||
AVFrame* ret = nullptr;
|
||||
std::shared_ptr<AVFrame> ret;
|
||||
while (ret == nullptr) {
|
||||
if (frames.size() == 0) {
|
||||
ret = create_frame();
|
||||
@@ -115,9 +111,9 @@ AVFrame* ffmpeg::avframe_queue::pop()
|
||||
ret = create_frame();
|
||||
} else {
|
||||
frames.pop_front();
|
||||
if ((ret->width != this->resolution.first) || (ret->height != this->resolution.second)
|
||||
if ((static_cast<uint32_t>(ret->width) != this->resolution.first)
|
||||
|| (static_cast<uint32_t>(ret->height) != this->resolution.second)
|
||||
|| (ret->format != this->format)) {
|
||||
destroy_frame(ret);
|
||||
ret = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -126,13 +122,13 @@ AVFrame* ffmpeg::avframe_queue::pop()
|
||||
return ret;
|
||||
}
|
||||
|
||||
AVFrame* ffmpeg::avframe_queue::pop_only()
|
||||
std::shared_ptr<AVFrame> ffmpeg::avframe_queue::pop_only()
|
||||
{
|
||||
std::unique_lock<std::mutex> ulock(this->lock);
|
||||
if (frames.size() == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
AVFrame* ret = frames.front();
|
||||
std::shared_ptr<AVFrame> ret = frames.front();
|
||||
if (ret == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -1,41 +1,44 @@
|
||||
// FFMPEG Video Encoder Integration for OBS Studio
|
||||
// Copyright (C) 2018 - 2018 Michael Fabian Dirks
|
||||
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
// 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:
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
// 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.
|
||||
|
||||
#ifndef OBS_FFMPEG_FFMPEG_AVFRAME_QUEUE
|
||||
#define OBS_FFMPEG_FFMPEG_AVFRAME_QUEUE
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
|
||||
extern "C" {
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavutil/frame.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
namespace ffmpeg {
|
||||
class avframe_queue {
|
||||
std::deque<AVFrame*> frames;
|
||||
std::deque<std::shared_ptr<AVFrame>> frames;
|
||||
std::mutex lock;
|
||||
|
||||
std::pair<uint32_t, uint32_t> resolution;
|
||||
AVPixelFormat format = AV_PIX_FMT_NONE;
|
||||
|
||||
AVFrame* create_frame();
|
||||
void destroy_frame(AVFrame* frame);
|
||||
std::shared_ptr<AVFrame> create_frame();
|
||||
|
||||
public:
|
||||
avframe_queue();
|
||||
@@ -53,18 +56,14 @@ namespace ffmpeg {
|
||||
|
||||
void clear();
|
||||
|
||||
void push(AVFrame* frame);
|
||||
void push(std::shared_ptr<AVFrame> frame);
|
||||
|
||||
AVFrame* pop();
|
||||
std::shared_ptr<AVFrame> pop();
|
||||
|
||||
AVFrame* pop_only();
|
||||
std::shared_ptr<AVFrame> pop_only();
|
||||
|
||||
bool empty();
|
||||
|
||||
size_t size();
|
||||
|
||||
|
||||
};
|
||||
} // namespace ffmpeg
|
||||
|
||||
#endif OBS_FFMPEG_FFMPEG_AVFRAME_QUEUE
|
||||
|
||||
+23
-15
@@ -1,19 +1,23 @@
|
||||
// FFMPEG Video Encoder Integration for OBS Studio
|
||||
// Copyright (C) 2018 - 2018 Michael Fabian Dirks
|
||||
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
// 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:
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
// 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 "swscale.hpp"
|
||||
#include <stdexcept>
|
||||
@@ -94,7 +98,11 @@ void ffmpeg::swscale::set_target_size(uint32_t width, uint32_t height)
|
||||
target_size.second = height;
|
||||
}
|
||||
|
||||
void ffmpeg::swscale::get_target_size(uint32_t& width, uint32_t& height) {}
|
||||
void ffmpeg::swscale::get_target_size(uint32_t& width, uint32_t& height)
|
||||
{
|
||||
width = target_size.first;
|
||||
height = target_size.second;
|
||||
}
|
||||
|
||||
std::pair<uint32_t, uint32_t> ffmpeg::swscale::get_target_size()
|
||||
{
|
||||
@@ -168,8 +176,8 @@ bool ffmpeg::swscale::initialize(int flags)
|
||||
}
|
||||
|
||||
sws_setColorspaceDetails(this->context, sws_getCoefficients(source_colorspace), source_full_range ? 1 : 0,
|
||||
sws_getCoefficients(target_colorspace), target_full_range ? 1 : 0, 1l << 16 | 0l,
|
||||
1l << 16 | 0l, 1l << 16 | 0l);
|
||||
sws_getCoefficients(target_colorspace), target_full_range ? 1 : 0, 1L << 16 | 0L,
|
||||
1L << 16 | 0L, 1L << 16 | 0L);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+19
-12
@@ -1,19 +1,23 @@
|
||||
// FFMPEG Video Encoder Integration for OBS Studio
|
||||
// Copyright (C) 2018 - 2018 Michael Fabian Dirks
|
||||
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
// 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:
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
// 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.
|
||||
|
||||
#ifndef OBS_FFMPEG_FFMPEG_SWSCALE
|
||||
#define OBS_FFMPEG_FFMPEG_SWSCALE
|
||||
@@ -23,8 +27,11 @@
|
||||
#include <utility>
|
||||
|
||||
extern "C" {
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavutil/pixfmt.h>
|
||||
#include <libswscale/swscale.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
namespace ffmpeg {
|
||||
|
||||
+224
-37
@@ -1,26 +1,75 @@
|
||||
// FFMPEG Video Encoder Integration for OBS Studio
|
||||
// Copyright (C) 2018 - 2018 Michael Fabian Dirks
|
||||
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
// 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:
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
// 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 "tools.hpp"
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
extern "C" {
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavutil/error.h>
|
||||
#include <libavutil/pixdesc.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
std::string ffmpeg::tools::translate_encoder_capabilities(int capabilities)
|
||||
{
|
||||
// Sorted by relative importance.
|
||||
std::pair<int, std::string> caps[] = {
|
||||
{AV_CODEC_CAP_EXPERIMENTAL, "Experimental"},
|
||||
|
||||
// Quality
|
||||
{AV_CODEC_CAP_LOSSLESS, "Lossless"},
|
||||
|
||||
// Features
|
||||
{AV_CODEC_CAP_PARAM_CHANGE, "Dynamic Parameter Change"},
|
||||
{AV_CODEC_CAP_SUBFRAMES, "Sub-Frames"},
|
||||
{AV_CODEC_CAP_VARIABLE_FRAME_SIZE, "Variable Frame Size"},
|
||||
{AV_CODEC_CAP_SMALL_LAST_FRAME, "Small Final Frame"},
|
||||
|
||||
// Other
|
||||
{AV_CODEC_CAP_TRUNCATED, "Truncated"},
|
||||
{AV_CODEC_CAP_CHANNEL_CONF, "AV_CODEC_CAP_CHANNEL_CONF"},
|
||||
{AV_CODEC_CAP_DRAW_HORIZ_BAND, "AV_CODEC_CAP_DRAW_HORIZ_BAND"},
|
||||
{AV_CODEC_CAP_AVOID_PROBING, "AV_CODEC_CAP_AVOID_PROBING"},
|
||||
};
|
||||
|
||||
std::stringstream sstr;
|
||||
for (auto const kv : caps) {
|
||||
if (capabilities & kv.first) {
|
||||
capabilities &= ~kv.first;
|
||||
sstr << kv.second;
|
||||
if (capabilities != 0) {
|
||||
sstr << ", ";
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sstr.str();
|
||||
}
|
||||
|
||||
const char* ffmpeg::tools::get_pixel_format_name(AVPixelFormat v)
|
||||
@@ -67,38 +116,92 @@ const char* ffmpeg::tools::get_error_description(int error)
|
||||
switch (error) {
|
||||
case AVERROR(EPERM):
|
||||
return "Permission Denied";
|
||||
// case AVERROR(ENOENT):
|
||||
// case AVERROR(ESRCH):
|
||||
// case AVERROR(EINTR):
|
||||
// case AVERROR(EIO):
|
||||
// case AVERROR(ENXIO):
|
||||
// case AVERROR(E2BIG):
|
||||
// case AVERROR(ENOEXEC):
|
||||
// case AVERROR(EBADF):
|
||||
// case AVERROR(ECHILD):
|
||||
// case AVERROR(EAGAIN):
|
||||
case AVERROR(ENOMEM):
|
||||
return "Out Of Memory";
|
||||
// case AVERROR(EACCES):
|
||||
// case AVERROR(EFAULT):
|
||||
// case AVERROR(EBUSY):
|
||||
// case AVERROR(EEXIST):
|
||||
// case AVERROR(EXDEV):
|
||||
// case AVERROR(ENODEV):
|
||||
// case AVERROR(ENOTDIR):
|
||||
// case AVERROR(EISDIR):
|
||||
// case AVERROR(ENFILE):
|
||||
// case AVERROR(EMFILE):
|
||||
// case AVERROR(ENOTTY):
|
||||
// case AVERROR(EFBIG):
|
||||
// case AVERROR(ENOSPC):
|
||||
// case AVERROR(ESPIPE):
|
||||
// case AVERROR(EROFS):
|
||||
// case AVERROR(EMLINK):
|
||||
// case AVERROR(EPIPE):
|
||||
// case AVERROR(EDOM):
|
||||
// case AVERROR(EDEADLK):
|
||||
// case AVERROR(ENAMETOOLONG):
|
||||
// case AVERROR(ENOLCK):
|
||||
// case AVERROR(ENOSYS):
|
||||
// case AVERROR(ENOTEMPTY):
|
||||
case AVERROR(EINVAL):
|
||||
return "Invalid Value for Parameter";
|
||||
return "Invalid Value(s)";
|
||||
case AVERROR(ERANGE):
|
||||
return "Out of Range";
|
||||
// case AVERROR(EILSEQ):
|
||||
// case AVERROR(STRUNCATE):
|
||||
}
|
||||
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)
|
||||
{
|
||||
switch (v) {
|
||||
// 32-Bits
|
||||
case VIDEO_FORMAT_BGRX:
|
||||
return AV_PIX_FMT_BGRA;
|
||||
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;
|
||||
auto found = obs_to_av_format_map.find(v);
|
||||
if (found != obs_to_av_format_map.end()) {
|
||||
return found->second;
|
||||
}
|
||||
throw std::invalid_argument("unknown format");
|
||||
return AV_PIX_FMT_NONE;
|
||||
}
|
||||
|
||||
video_format ffmpeg::tools::avpixelformat_to_obs_videoformat(AVPixelFormat v)
|
||||
{
|
||||
for (const auto& kv : obs_to_av_format_map) {
|
||||
if (kv.second == v)
|
||||
return kv.first;
|
||||
}
|
||||
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)
|
||||
@@ -108,7 +211,7 @@ AVColorSpace ffmpeg::tools::obs_videocolorspace_to_avcolorspace(video_colorspace
|
||||
case VIDEO_CS_709:
|
||||
return AVCOL_SPC_BT709;
|
||||
case VIDEO_CS_601:
|
||||
return AVCOL_SPC_SMPTE170M;
|
||||
return AVCOL_SPC_BT470BG;
|
||||
}
|
||||
throw std::invalid_argument("unknown color space");
|
||||
}
|
||||
@@ -117,10 +220,94 @@ AVColorRange ffmpeg::tools::obs_videorangetype_to_avcolorrange(video_range_type
|
||||
{
|
||||
switch (v) {
|
||||
case VIDEO_RANGE_DEFAULT:
|
||||
case VIDEO_RANGE_FULL:
|
||||
return AVCOL_RANGE_JPEG;
|
||||
case VIDEO_RANGE_PARTIAL:
|
||||
return AVCOL_RANGE_MPEG;
|
||||
case VIDEO_RANGE_FULL:
|
||||
return AVCOL_RANGE_JPEG;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
+32
-13
@@ -1,32 +1,41 @@
|
||||
// FFMPEG Video Encoder Integration for OBS Studio
|
||||
// Copyright (C) 2018 - 2018 Michael Fabian Dirks
|
||||
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
// 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:
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
// 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.
|
||||
|
||||
#ifndef OBS_FFMPEG_FFMPEG_UTILITY
|
||||
#define OBS_FFMPEG_FFMPEG_UTILITY
|
||||
#pragma once
|
||||
|
||||
#include <obs.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavutil/pixfmt.h>
|
||||
}
|
||||
|
||||
namespace ffmpeg {
|
||||
namespace tools {
|
||||
std::string translate_encoder_capabilities(int capabilities);
|
||||
|
||||
const char* get_pixel_format_name(AVPixelFormat v);
|
||||
|
||||
const char* get_color_space_name(AVColorSpace v);
|
||||
@@ -35,10 +44,20 @@ namespace ffmpeg {
|
||||
|
||||
AVPixelFormat obs_videoformat_to_avpixelformat(video_format 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);
|
||||
|
||||
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 ffmpeg
|
||||
|
||||
#endif OBS_FFMPEG_FFMPEG_UTILITY
|
||||
|
||||
@@ -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
|
||||
+121
-35
@@ -1,55 +1,141 @@
|
||||
// FFMPEG Video Encoder Integration for OBS Studio
|
||||
// Copyright (C) 2018 - 2018 Michael Fabian Dirks
|
||||
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
// 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:
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
// 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 "plugin.hpp"
|
||||
#include <obs-module.h>
|
||||
#include <obs.h>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include "encoder.hpp"
|
||||
#include "ui/debug_handler.hpp"
|
||||
#include "ui/handler.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include "encoders/prores_aw.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <obs-module.h>
|
||||
#include <obs.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavcodec/avcodec.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
MODULE_EXPORT bool obs_module_load(void)
|
||||
// Initializers and finalizers.
|
||||
std::list<std::function<void()>> obsffmpeg::initializers;
|
||||
|
||||
std::list<std::function<void()>> obsffmpeg::finalizers;
|
||||
|
||||
// Codec to Handler mapping.
|
||||
static std::map<std::string, std::shared_ptr<obsffmpeg::ui::handler>> codec_to_handler_map;
|
||||
static std::shared_ptr<obsffmpeg::ui::handler> debug_handler = std::make_shared<obsffmpeg::ui::debug_handler>();
|
||||
|
||||
void obsffmpeg::register_codec_handler(std::string const codec, std::shared_ptr<obsffmpeg::ui::handler> const handler)
|
||||
{
|
||||
try {
|
||||
avcodec_register_all();
|
||||
obsffmpeg::encoder::prores_aw::initialize();
|
||||
return true;
|
||||
} catch (std::exception ex) {
|
||||
PLOG_ERROR("Exception during initalization: %s.", ex.what());
|
||||
} catch (...) {
|
||||
PLOG_ERROR("Unrecognized exception during initalization.");
|
||||
}
|
||||
return false;
|
||||
codec_to_handler_map.emplace(codec, handler);
|
||||
}
|
||||
|
||||
MODULE_EXPORT void obs_module_unload(void)
|
||||
std::shared_ptr<obsffmpeg::ui::handler> obsffmpeg::find_codec_handler(std::string const codec)
|
||||
{
|
||||
try {
|
||||
obsffmpeg::encoder::prores_aw::finalize();
|
||||
} catch (std::exception ex) {
|
||||
PLOG_ERROR("Exception during finalizing: %s.", ex.what());
|
||||
} catch (...) {
|
||||
PLOG_ERROR("Unrecognized exception during finalizing.");
|
||||
}
|
||||
auto found = codec_to_handler_map.find(codec);
|
||||
if (found == codec_to_handler_map.end())
|
||||
return debug_handler;
|
||||
return found->second;
|
||||
}
|
||||
|
||||
bool obsffmpeg::has_codec_handler(std::string const codec)
|
||||
{
|
||||
auto found = codec_to_handler_map.find(codec);
|
||||
return (found != codec_to_handler_map.end());
|
||||
}
|
||||
|
||||
static std::map<const AVCodec*, std::shared_ptr<obsffmpeg::encoder_factory>> generic_factories;
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4996) // Handled by software and precompiler branch
|
||||
MODULE_EXPORT bool obs_module_load(void)
|
||||
try {
|
||||
#if FF_API_NEXT
|
||||
if (avcodec_version() < AV_VERSION_INT(58, 0, 0)) {
|
||||
// Initialize avcodec.
|
||||
avcodec_register_all();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Run all initializers.
|
||||
for (auto const func : obsffmpeg::initializers) {
|
||||
func();
|
||||
}
|
||||
|
||||
// Register all codecs.
|
||||
#if FF_API_NEXT
|
||||
if (avcodec_version() < AV_VERSION_INT(58, 0, 0)) {
|
||||
AVCodec* cdc = nullptr;
|
||||
while ((cdc = av_codec_next(cdc)) != nullptr) {
|
||||
if (!av_codec_is_encoder(cdc))
|
||||
continue;
|
||||
|
||||
if ((cdc->type == AVMediaType::AVMEDIA_TYPE_AUDIO)
|
||||
|| (cdc->type == AVMediaType::AVMEDIA_TYPE_VIDEO)) {
|
||||
auto ptr = std::make_shared<obsffmpeg::encoder_factory>(cdc);
|
||||
ptr->register_encoder();
|
||||
generic_factories.emplace(cdc, ptr);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 58
|
||||
void* storage = nullptr;
|
||||
const AVCodec* cdc = nullptr;
|
||||
for (cdc = av_codec_iterate(&storage); cdc != nullptr; cdc = av_codec_iterate(&storage)) {
|
||||
if (!av_codec_is_encoder(cdc))
|
||||
continue;
|
||||
|
||||
if ((cdc->type == AVMediaType::AVMEDIA_TYPE_AUDIO)
|
||||
|| (cdc->type == AVMediaType::AVMEDIA_TYPE_VIDEO)) {
|
||||
auto ptr = std::make_shared<obsffmpeg::encoder_factory>(cdc);
|
||||
ptr->register_encoder();
|
||||
generic_factories.emplace(cdc, ptr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if FF_API_NEXT
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
} catch (std::exception& ex) {
|
||||
PLOG_ERROR("Exception during initalization: %s.", ex.what());
|
||||
return false;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("Unrecognized exception during initalization.");
|
||||
return false;
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
MODULE_EXPORT void obs_module_unload(void)
|
||||
try {
|
||||
// Run all finalizers.
|
||||
for (auto const func : obsffmpeg::finalizers) {
|
||||
func();
|
||||
}
|
||||
} catch (std::exception& ex) {
|
||||
PLOG_ERROR("Exception during finalizing: %s.", ex.what());
|
||||
} catch (...) {
|
||||
PLOG_ERROR("Unrecognized exception during finalizing.");
|
||||
}
|
||||
|
||||
+29
-16
@@ -1,30 +1,43 @@
|
||||
// FFMPEG Video Encoder Integration for OBS Studio
|
||||
// Copyright (C) 2018 - 2018 Michael Fabian Dirks
|
||||
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
// 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:
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
// 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.
|
||||
|
||||
#ifndef OBS_FFMPEG_PLUGIN_HPP
|
||||
#define OBS_FFMPEG_PLUGIN_HPP
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <obs-module.h>
|
||||
#include "ui/handler.hpp"
|
||||
|
||||
namespace obsffmpeg {
|
||||
extern std::list<std::function<void()>> initializers;
|
||||
|
||||
extern std::list<std::function<void()>> finalizers;
|
||||
|
||||
void register_codec_handler(std::string codec, std::shared_ptr<obsffmpeg::ui::handler> handler);
|
||||
|
||||
std::shared_ptr<obsffmpeg::ui::handler> find_codec_handler(std::string codec);
|
||||
|
||||
bool has_codec_handler(std::string codec);
|
||||
|
||||
} // namespace obsffmpeg
|
||||
|
||||
#endif OBS_FFMPEG_PLUGIN_HPP
|
||||
MODULE_EXPORT bool obs_module_load(void);
|
||||
MODULE_EXPORT void obs_module_unload(void);
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
// 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 "utility.hpp"
|
||||
|
||||
#define S_STATE_DEFAULT "State.Default"
|
||||
#define S_STATE_DISABLED "State.Disabled"
|
||||
#define S_STATE_ENABLED "State.Enabled"
|
||||
#define S_STATE_AUTOMATIC "State.Automatic"
|
||||
#define S_STATE_MANUAL "State.Manual"
|
||||
|
||||
#define S_RATECONTROL "RateControl"
|
||||
#define S_RATECONTROL_MODE "RateControl.Mode"
|
||||
#define S_RATECONTROL_MODE_(x) "RateControl.Mode." D_VSTR(x)
|
||||
#define S_RATECONTROL_BITRATE_TARGET "RateControl.Bitrate.Target"
|
||||
#define S_RATECONTROL_BITRATE_MINIMUM "RateControl.Bitrate.Minimum"
|
||||
#define S_RATECONTROL_BITRATE_MAXIMUM "RateControl.Bitrate.Maximum"
|
||||
#define S_RATECONTROL_BUFFERSIZE "RateControl.BufferSize"
|
||||
#define S_RATECONTROL_QUALITY_TARGET "RateControl.Quality.Target"
|
||||
#define S_RATECONTROL_QUALITY_MINIMUM "RateControl.Quality.Minimum"
|
||||
#define S_RATECONTROL_QUALITY_MAXIMUM "RateControl.Quality.Maximum"
|
||||
#define S_RATECONTROL_QP_I "RateControl.QP.I"
|
||||
#define S_RATECONTROL_QP_P "RateControl.QP.P"
|
||||
#define S_RATECONTROL_QP_B "RateControl.QP.B"
|
||||
#define S_RATECONTROL_QP_I_INITIAL "RateControl.QP.I.Initial"
|
||||
#define S_RATECONTROL_QP_P_INITIAL "RateControl.QP.P.Initial"
|
||||
#define S_RATECONTROL_QP_B_INITIAL "RateControl.QP.B.Initial"
|
||||
|
||||
#define S_KEYFRAMES "KeyFrames"
|
||||
#define S_KEYFRAMES_INTERVALTYPE "KeyFrames.IntervalType"
|
||||
#define S_KEYFRAMES_INTERVALTYPE_(x) "KeyFrames.IntervalType." D_VSTR(x)
|
||||
#define S_KEYFRAMES_INTERVAL "KeyFrames.Interval"
|
||||
#define S_KEYFRAMES_INTERVAL_SECONDS "KeyFrames.Interval.Seconds"
|
||||
#define S_KEYFRAMES_INTERVAL_FRAMES "KeyFrames.Interval.Frames"
|
||||
@@ -0,0 +1,210 @@
|
||||
// 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 "debug_handler.hpp"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "handler.hpp"
|
||||
#include "plugin.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <obs-properties.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavutil/opt.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::debug_handler::get_defaults(obs_data_t*, const AVCodec*, AVCodecContext*, bool) {}
|
||||
|
||||
template<typename T>
|
||||
std::string to_string(T value){};
|
||||
|
||||
template<>
|
||||
std::string to_string(int64_t value)
|
||||
{
|
||||
std::vector<char> buf(32);
|
||||
snprintf(buf.data(), buf.size(), "%lld", value);
|
||||
return std::string(buf.data(), buf.data() + buf.size());
|
||||
}
|
||||
|
||||
template<>
|
||||
std::string to_string(uint64_t value)
|
||||
{
|
||||
std::vector<char> buf(32);
|
||||
snprintf(buf.data(), buf.size(), "%llu", value);
|
||||
return std::string(buf.data(), buf.data() + buf.size());
|
||||
}
|
||||
|
||||
template<>
|
||||
std::string to_string(double_t value)
|
||||
{
|
||||
std::vector<char> buf(32);
|
||||
snprintf(buf.data(), buf.size(), "%f", value);
|
||||
return std::string(buf.data(), buf.data() + buf.size());
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::debug_handler::get_properties(obs_properties_t*, const AVCodec* codec, AVCodecContext* context,
|
||||
bool)
|
||||
{
|
||||
if (context)
|
||||
return;
|
||||
|
||||
AVCodecContext* ctx = avcodec_alloc_context3(codec);
|
||||
if (!ctx->priv_data) {
|
||||
avcodec_free_context(&ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
PLOG_INFO("Options for '%s':", codec->name);
|
||||
|
||||
std::pair<AVOptionType, std::string> opt_type_name[] = {
|
||||
{AV_OPT_TYPE_FLAGS, "Flags"},
|
||||
{AV_OPT_TYPE_INT, "Int"},
|
||||
{AV_OPT_TYPE_INT64, "Int64"},
|
||||
{AV_OPT_TYPE_DOUBLE, "Double"},
|
||||
{AV_OPT_TYPE_FLOAT, "Float"},
|
||||
{AV_OPT_TYPE_STRING, "String"},
|
||||
{AV_OPT_TYPE_RATIONAL, "Rational"},
|
||||
{AV_OPT_TYPE_BINARY, "Binary"},
|
||||
{AV_OPT_TYPE_DICT, "Dictionary"},
|
||||
{AV_OPT_TYPE_UINT64, "Unsigned Int64"},
|
||||
{AV_OPT_TYPE_CONST, "Constant"},
|
||||
{AV_OPT_TYPE_IMAGE_SIZE, "Image Size"},
|
||||
{AV_OPT_TYPE_PIXEL_FMT, "Pixel Format"},
|
||||
{AV_OPT_TYPE_SAMPLE_FMT, "Sample Format"},
|
||||
{AV_OPT_TYPE_VIDEO_RATE, "Video Rate"},
|
||||
{AV_OPT_TYPE_DURATION, "Duration"},
|
||||
{AV_OPT_TYPE_COLOR, "Color"},
|
||||
{AV_OPT_TYPE_CHANNEL_LAYOUT, "Layout"},
|
||||
{AV_OPT_TYPE_BOOL, "Bool"},
|
||||
};
|
||||
std::map<std::string, AVOptionType> unit_types;
|
||||
|
||||
const AVOption* opt = nullptr;
|
||||
while ((opt = av_opt_next(ctx->priv_data, opt)) != nullptr) {
|
||||
std::string type_name = "";
|
||||
for (auto kv : opt_type_name) {
|
||||
if (opt->type == kv.first) {
|
||||
type_name = kv.second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (opt->type == AV_OPT_TYPE_CONST) {
|
||||
if (opt->unit == nullptr) {
|
||||
PLOG_INFO(" Constant '%s' and help text '%s' with unknown settings.", opt->name,
|
||||
opt->help);
|
||||
} else {
|
||||
auto unit_type = unit_types.find(opt->unit);
|
||||
if (unit_type == unit_types.end()) {
|
||||
PLOG_INFO(" [%s] Flag '%s' and help text '%s' with value '%lld'.", opt->unit,
|
||||
opt->name, opt->help, opt->default_val.i64);
|
||||
} else {
|
||||
std::string out;
|
||||
switch (unit_type->second) {
|
||||
case AV_OPT_TYPE_BOOL:
|
||||
out = opt->default_val.i64 ? "true" : "false";
|
||||
break;
|
||||
case AV_OPT_TYPE_INT:
|
||||
out = to_string(opt->default_val.i64);
|
||||
break;
|
||||
case AV_OPT_TYPE_UINT64:
|
||||
out = to_string(static_cast<uint64_t>(opt->default_val.i64));
|
||||
break;
|
||||
case AV_OPT_TYPE_FLAGS:
|
||||
out = to_string(static_cast<uint64_t>(opt->default_val.i64));
|
||||
break;
|
||||
case AV_OPT_TYPE_FLOAT:
|
||||
case AV_OPT_TYPE_DOUBLE:
|
||||
out = to_string(opt->default_val.dbl);
|
||||
break;
|
||||
case AV_OPT_TYPE_STRING:
|
||||
out = opt->default_val.str;
|
||||
break;
|
||||
case AV_OPT_TYPE_BINARY:
|
||||
case AV_OPT_TYPE_IMAGE_SIZE:
|
||||
case AV_OPT_TYPE_PIXEL_FMT:
|
||||
case AV_OPT_TYPE_SAMPLE_FMT:
|
||||
case AV_OPT_TYPE_VIDEO_RATE:
|
||||
case AV_OPT_TYPE_DURATION:
|
||||
case AV_OPT_TYPE_COLOR:
|
||||
case AV_OPT_TYPE_CHANNEL_LAYOUT:
|
||||
break;
|
||||
}
|
||||
|
||||
PLOG_INFO(" [%s] Constant '%s' and help text '%s' with value '%s'.", opt->unit,
|
||||
opt->name, opt->help, out.c_str());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (opt->unit != nullptr) {
|
||||
unit_types.emplace(opt->name, opt->type);
|
||||
}
|
||||
|
||||
std::string minimum = "", maximum = "", out;
|
||||
minimum = to_string(opt->min);
|
||||
maximum = to_string(opt->max);
|
||||
{
|
||||
switch (opt->type) {
|
||||
case AV_OPT_TYPE_BOOL:
|
||||
out = opt->default_val.i64 ? "true" : "false";
|
||||
break;
|
||||
case AV_OPT_TYPE_INT:
|
||||
out = to_string(opt->default_val.i64);
|
||||
break;
|
||||
case AV_OPT_TYPE_UINT64:
|
||||
out = to_string(static_cast<uint64_t>(opt->default_val.i64));
|
||||
break;
|
||||
case AV_OPT_TYPE_FLAGS:
|
||||
out = to_string(static_cast<uint64_t>(opt->default_val.i64));
|
||||
break;
|
||||
case AV_OPT_TYPE_FLOAT:
|
||||
case AV_OPT_TYPE_DOUBLE:
|
||||
out = to_string(opt->default_val.dbl);
|
||||
break;
|
||||
case AV_OPT_TYPE_STRING:
|
||||
out = opt->default_val.str ? opt->default_val.str : "<invalid>";
|
||||
break;
|
||||
case AV_OPT_TYPE_BINARY:
|
||||
case AV_OPT_TYPE_IMAGE_SIZE:
|
||||
case AV_OPT_TYPE_PIXEL_FMT:
|
||||
case AV_OPT_TYPE_SAMPLE_FMT:
|
||||
case AV_OPT_TYPE_VIDEO_RATE:
|
||||
case AV_OPT_TYPE_DURATION:
|
||||
case AV_OPT_TYPE_COLOR:
|
||||
case AV_OPT_TYPE_CHANNEL_LAYOUT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PLOG_INFO(
|
||||
" Option '%s'%s%s%s with help '%s' of type '%s' with default value '%s', minimum '%s' and maximum '%s'.",
|
||||
opt->name, opt->unit ? " with unit (" : "", opt->unit ? opt->unit : "",
|
||||
opt->unit ? ")" : "", opt->help, type_name.c_str(), out.c_str(), minimum.c_str(),
|
||||
maximum.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::debug_handler::update(obs_data_t*, const AVCodec*, AVCodecContext*) {}
|
||||
@@ -0,0 +1,39 @@
|
||||
// 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 "handler.hpp"
|
||||
|
||||
namespace obsffmpeg {
|
||||
namespace ui {
|
||||
class debug_handler : public handler {
|
||||
public:
|
||||
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,
|
||||
AVCodecContext* context, bool hw_encode) override;
|
||||
|
||||
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
};
|
||||
} // namespace ui
|
||||
} // namespace obsffmpeg
|
||||
@@ -0,0 +1,53 @@
|
||||
// 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 "handler.hpp"
|
||||
|
||||
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*) {}
|
||||
@@ -0,0 +1,74 @@
|
||||
// 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 <string>
|
||||
#include "hwapi/base.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <obs.h>
|
||||
|
||||
#include <obs-data.h>
|
||||
#include <obs-encoder.h>
|
||||
#include <obs-properties.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavcodec/avcodec.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
namespace obsffmpeg {
|
||||
namespace ui {
|
||||
class handler {
|
||||
public:
|
||||
virtual void override_visible_name(const AVCodec* codec, std::string& name);
|
||||
|
||||
virtual void override_info(obs_encoder_info* main, obs_encoder_info* fallback);
|
||||
|
||||
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,
|
||||
AVCodecContext* context, bool hw_encode);
|
||||
|
||||
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 obsffmpeg
|
||||
@@ -0,0 +1,192 @@
|
||||
// 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 "nvenc_h264_handler.hpp"
|
||||
#include "codecs/h264.hpp"
|
||||
#include "nvenc_shared.hpp"
|
||||
#include "plugin.hpp"
|
||||
#include "strings.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <obs-module.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavutil/opt.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
/* Missing Options:
|
||||
|
||||
Seem to be covered by initQP_* instead.
|
||||
- [obs-ffmpeg-encoder] Option 'cq' with help 'Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control' of type 'Float' with default value '0.000000', minimum '0.000000' and maximum '51.000000'.
|
||||
- [obs-ffmpeg-encoder] Option 'qp' with help 'Constant quantization parameter rate control method' of type 'Int' with default value '-1', minimum '-1.000000' and maximum '51.000000'.
|
||||
|
||||
Not sure what there are useful for.
|
||||
[obs-ffmpeg-encoder] Option 'aud' with help 'Use access unit delimiters' of type 'Bool' with default value 'false', minimum '0.000000' and maximum '1.000000'.
|
||||
[obs-ffmpeg-encoder] Option 'surfaces' with help 'Number of concurrent surfaces' of type 'Int' with default value '0', minimum '0.000000' and maximum '64.000000'.
|
||||
[obs-ffmpeg-encoder] Option 'delay' with help 'Delay frame output by the given amount of frames' of type 'Int' with default value '2147483647', minimum '0.000000' and maximum '2147483647.000000'.
|
||||
|
||||
Should probably add this.
|
||||
[obs-ffmpeg-encoder] Option 'gpu' with unit (gpu) with help 'Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on.' of type 'Int' with default value '-1', minimum '-2.000000' and maximum '2147483647.000000'.
|
||||
[obs-ffmpeg-encoder] [gpu] Constant 'any' and help text 'Pick the first device available' with value '-1'.
|
||||
[obs-ffmpeg-encoder] [gpu] Constant 'list' and help text 'List the available devices' with value '-2'.
|
||||
|
||||
Useless except for strict_gop maybe?
|
||||
[obs-ffmpeg-encoder] Option 'forced-idr' with help 'If forcing keyframes, force them as IDR frames.' of type 'Bool' with default value 'false', minimum '-1.000000' and maximum '1.000000'.
|
||||
[obs-ffmpeg-encoder] Option 'strict_gop' with help 'Set 1 to minimize GOP-to-GOP rate fluctuations' of type 'Bool' with default value 'false', minimum '0.000000' and maximum '1.000000'.
|
||||
[obs-ffmpeg-encoder] Option 'bluray-compat' with help 'Bluray compatibility workarounds' of type 'Bool' with default value 'false', minimum '0.000000' and maximum '1.000000'.
|
||||
*/
|
||||
|
||||
using namespace obsffmpeg::codecs::h264;
|
||||
using namespace obsffmpeg::nvenc;
|
||||
|
||||
std::map<profile, std::string> profiles{
|
||||
{profile::BASELINE, "baseline"},
|
||||
{profile::MAIN, "main"},
|
||||
{profile::HIGH, "high"},
|
||||
{profile::HIGH444_PREDICTIVE, "high444p"},
|
||||
};
|
||||
|
||||
std::map<level, std::string> levels{
|
||||
{level::L1_0, "1.0"}, {level::L1_0b, "1.0b"}, {level::L1_1, "1.1"}, {level::L1_2, "1.2"}, {level::L1_3, "1.3"},
|
||||
{level::L2_0, "2.0"}, {level::L2_1, "2.1"}, {level::L2_2, "2.2"}, {level::L3_0, "3.0"}, {level::L3_1, "3.1"},
|
||||
{level::L3_2, "3.2"}, {level::L4_0, "4.0"}, {level::L4_1, "4.1"}, {level::L4_2, "4.2"}, {level::L5_0, "5.0"},
|
||||
{level::L5_1, "5.1"}, {level::L5_2, "5.2"},
|
||||
};
|
||||
|
||||
INITIALIZER(nvenc_h264_handler_init)
|
||||
{
|
||||
obsffmpeg::initializers.push_back([]() {
|
||||
obsffmpeg::register_codec_handler("h264_nvenc", std::make_shared<obsffmpeg::ui::nvenc_h264_handler>());
|
||||
});
|
||||
};
|
||||
|
||||
void obsffmpeg::ui::nvenc_h264_handler::override_visible_name(const AVCodec*, std::string& name)
|
||||
{
|
||||
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,
|
||||
AVCodecContext* context, bool)
|
||||
{
|
||||
nvenc::get_defaults(settings, codec, context);
|
||||
|
||||
obs_data_set_default_int(settings, P_H264_PROFILE, static_cast<int64_t>(codecs::h264::profile::HIGH));
|
||||
obs_data_set_default_int(settings, P_H264_LEVEL, static_cast<int64_t>(codecs::h264::level::UNKNOWN));
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::nvenc_h264_handler::get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context, bool)
|
||||
{
|
||||
if (!context) {
|
||||
this->get_encoder_properties(props, codec);
|
||||
} else {
|
||||
this->get_runtime_properties(props, codec, context);
|
||||
}
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::nvenc_h264_handler::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
|
||||
{
|
||||
nvenc::update(settings, codec, context);
|
||||
|
||||
{
|
||||
auto found =
|
||||
profiles.find(static_cast<codecs::h264::profile>(obs_data_get_int(settings, P_H264_PROFILE)));
|
||||
if (found != profiles.end()) {
|
||||
av_opt_set(context->priv_data, "profile", found->second.c_str(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto found = levels.find(static_cast<codecs::h264::level>(obs_data_get_int(settings, P_H264_LEVEL)));
|
||||
if (found != levels.end()) {
|
||||
av_opt_set(context->priv_data, "level", found->second.c_str(), 0);
|
||||
} else {
|
||||
av_opt_set(context->priv_data, "level", "auto", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
nvenc::get_properties_pre(props, codec);
|
||||
|
||||
{
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, P_H264, TRANSLATE(P_H264), OBS_GROUP_NORMAL, grp);
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_list(grp, P_H264_PROFILE, TRANSLATE(P_H264_PROFILE),
|
||||
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_H264_PROFILE)));
|
||||
obs_property_list_add_int(p, TRANSLATE(S_STATE_DEFAULT),
|
||||
static_cast<int64_t>(codecs::h264::profile::UNKNOWN));
|
||||
for (auto const kv : profiles) {
|
||||
std::string trans = std::string(P_H264_PROFILE) + "." + kv.second;
|
||||
obs_property_list_add_int(p, TRANSLATE(trans.c_str()), static_cast<int64_t>(kv.first));
|
||||
}
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_list(grp, P_H264_LEVEL, TRANSLATE(P_H264_LEVEL),
|
||||
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_H264_LEVEL)));
|
||||
obs_property_list_add_int(p, TRANSLATE(S_STATE_AUTOMATIC),
|
||||
static_cast<int64_t>(codecs::h264::level::UNKNOWN));
|
||||
for (auto const kv : levels) {
|
||||
obs_property_list_add_int(p, kv.second.c_str(), static_cast<int64_t>(kv.first));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nvenc::get_properties_post(props, codec);
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::nvenc_h264_handler::get_runtime_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context)
|
||||
{
|
||||
nvenc::get_runtime_properties(props, codec, context);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// 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 "handler.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <obs-properties.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavcodec/avcodec.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
namespace obsffmpeg {
|
||||
namespace ui {
|
||||
class nvenc_h264_handler : public handler {
|
||||
public:
|
||||
virtual void override_visible_name(const AVCodec* codec, std::string& name) override;
|
||||
|
||||
virtual void override_lag_in_frames(size_t& lag, obs_data_t* settings, const AVCodec* codec,
|
||||
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,
|
||||
AVCodecContext* context, bool hw_encode) override;
|
||||
|
||||
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
|
||||
virtual void log_options(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
|
||||
private:
|
||||
void get_encoder_properties(obs_properties_t* props, const AVCodec* codec);
|
||||
|
||||
void get_runtime_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context);
|
||||
};
|
||||
} // namespace ui
|
||||
} // namespace obsffmpeg
|
||||
@@ -0,0 +1,215 @@
|
||||
// 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 "nvenc_hevc_handler.hpp"
|
||||
#include "codecs/hevc.hpp"
|
||||
#include "nvenc_shared.hpp"
|
||||
#include "plugin.hpp"
|
||||
#include "strings.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <obs-module.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavutil/opt.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
/* Missing Options:
|
||||
|
||||
Seem to be covered by initQP_* instead.
|
||||
- [obs-ffmpeg-encoder] Option 'cq' with help 'Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control' of type 'Float' with default value '0.000000', minimum '0.000000' and maximum '51.000000'.
|
||||
- [obs-ffmpeg-encoder] Option 'qp' with help 'Constant quantization parameter rate control method' of type 'Int' with default value '-1', minimum '-1.000000' and maximum '51.000000'.
|
||||
|
||||
Not sure what there are useful for.
|
||||
[obs-ffmpeg-encoder] Option 'aud' with help 'Use access unit delimiters' of type 'Bool' with default value 'false', minimum '0.000000' and maximum '1.000000'.
|
||||
[obs-ffmpeg-encoder] Option 'surfaces' with help 'Number of concurrent surfaces' of type 'Int' with default value '0', minimum '0.000000' and maximum '64.000000'.
|
||||
[obs-ffmpeg-encoder] Option 'delay' with help 'Delay frame output by the given amount of frames' of type 'Int' with default value '2147483647', minimum '0.000000' and maximum '2147483647.000000'.
|
||||
|
||||
Should probably add this.
|
||||
[obs-ffmpeg-encoder] Option 'gpu' with unit (gpu) with help 'Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on.' of type 'Int' with default value '-1', minimum '-2.000000' and maximum '2147483647.000000'.
|
||||
[obs-ffmpeg-encoder] [gpu] Constant 'any' and help text 'Pick the first device available' with value '-1'.
|
||||
[obs-ffmpeg-encoder] [gpu] Constant 'list' and help text 'List the available devices' with value '-2'.
|
||||
|
||||
Useless except for strict_gop maybe?
|
||||
[obs-ffmpeg-encoder] Option 'forced-idr' with help 'If forcing keyframes, force them as IDR frames.' of type 'Bool' with default value 'false', minimum '-1.000000' and maximum '1.000000'.
|
||||
[obs-ffmpeg-encoder] Option 'strict_gop' with help 'Set 1 to minimize GOP-to-GOP rate fluctuations' of type 'Bool' with default value 'false', minimum '0.000000' and maximum '1.000000'.
|
||||
[obs-ffmpeg-encoder] Option 'bluray-compat' with help 'Bluray compatibility workarounds' of type 'Bool' with default value 'false', minimum '0.000000' and maximum '1.000000'.
|
||||
*/
|
||||
|
||||
using namespace obsffmpeg::codecs::hevc;
|
||||
|
||||
std::map<profile, std::string> profiles{
|
||||
{profile::MAIN, "main"},
|
||||
{profile::MAIN10, "main10"},
|
||||
{profile::RANGE_EXTENDED, "rext"},
|
||||
};
|
||||
|
||||
std::map<tier, std::string> tiers{
|
||||
{tier::MAIN, "main"},
|
||||
{tier::HIGH, "high"},
|
||||
};
|
||||
|
||||
std::map<level, std::string> levels{
|
||||
{level::L1_0, "1.0"}, {level::L2_0, "2.0"}, {level::L2_1, "2.1"}, {level::L3_0, "3.0"}, {level::L3_1, "3.1"},
|
||||
{level::L4_0, "4.0"}, {level::L4_1, "4.1"}, {level::L5_0, "5.0"}, {level::L5_1, "5.1"}, {level::L5_2, "5.2"},
|
||||
{level::L6_0, "6.0"}, {level::L6_1, "6.1"}, {level::L6_2, "6.2"},
|
||||
};
|
||||
|
||||
INITIALIZER(nvenc_hevc_handler_init)
|
||||
{
|
||||
obsffmpeg::initializers.push_back([]() {
|
||||
obsffmpeg::register_codec_handler("hevc_nvenc", std::make_shared<obsffmpeg::ui::nvenc_hevc_handler>());
|
||||
});
|
||||
};
|
||||
|
||||
void obsffmpeg::ui::nvenc_hevc_handler::override_visible_name(const AVCodec*, std::string& name)
|
||||
{
|
||||
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,
|
||||
AVCodecContext* context, bool)
|
||||
{
|
||||
nvenc::get_defaults(settings, codec, context);
|
||||
|
||||
obs_data_set_default_int(settings, P_HEVC_PROFILE, static_cast<int64_t>(codecs::hevc::profile::MAIN));
|
||||
obs_data_set_default_int(settings, P_HEVC_TIER, static_cast<int64_t>(codecs::hevc::profile::MAIN));
|
||||
obs_data_set_default_int(settings, P_HEVC_LEVEL, static_cast<int64_t>(codecs::hevc::level::UNKNOWN));
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::nvenc_hevc_handler::get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context, bool)
|
||||
{
|
||||
if (!context) {
|
||||
this->get_encoder_properties(props, codec);
|
||||
} else {
|
||||
this->get_runtime_properties(props, codec, context);
|
||||
}
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::nvenc_hevc_handler::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
|
||||
{
|
||||
nvenc::update(settings, codec, context);
|
||||
|
||||
{ // HEVC Options
|
||||
auto found = profiles.find(static_cast<profile>(obs_data_get_int(settings, P_HEVC_PROFILE)));
|
||||
if (found != profiles.end()) {
|
||||
av_opt_set(context->priv_data, "profile", found->second.c_str(), 0);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto found = tiers.find(static_cast<tier>(obs_data_get_int(settings, P_HEVC_TIER)));
|
||||
if (found != tiers.end()) {
|
||||
av_opt_set(context->priv_data, "tier", found->second.c_str(), 0);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto found = levels.find(static_cast<level>(obs_data_get_int(settings, P_HEVC_LEVEL)));
|
||||
if (found != levels.end()) {
|
||||
av_opt_set(context->priv_data, "level", found->second.c_str(), 0);
|
||||
} else {
|
||||
av_opt_set(context->priv_data, "level", "auto", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
nvenc::get_properties_pre(props, codec);
|
||||
|
||||
{
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, P_HEVC, TRANSLATE(P_HEVC), OBS_GROUP_NORMAL, grp);
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_list(grp, P_HEVC_PROFILE, TRANSLATE(P_HEVC_PROFILE),
|
||||
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_HEVC_PROFILE)));
|
||||
obs_property_list_add_int(p, TRANSLATE(S_STATE_DEFAULT),
|
||||
static_cast<int64_t>(codecs::hevc::profile::UNKNOWN));
|
||||
for (auto const kv : profiles) {
|
||||
std::string trans = std::string(P_HEVC_PROFILE) + "." + kv.second;
|
||||
obs_property_list_add_int(p, TRANSLATE(trans.c_str()), static_cast<int64_t>(kv.first));
|
||||
}
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_list(grp, P_HEVC_TIER, TRANSLATE(P_HEVC_TIER), OBS_COMBO_TYPE_LIST,
|
||||
OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_HEVC_TIER)));
|
||||
obs_property_list_add_int(p, TRANSLATE(S_STATE_DEFAULT),
|
||||
static_cast<int64_t>(codecs::hevc::tier::UNKNOWN));
|
||||
for (auto const kv : tiers) {
|
||||
std::string trans = std::string(P_HEVC_TIER) + "." + kv.second;
|
||||
obs_property_list_add_int(p, TRANSLATE(trans.c_str()), static_cast<int64_t>(kv.first));
|
||||
}
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_list(grp, P_HEVC_LEVEL, TRANSLATE(P_HEVC_LEVEL),
|
||||
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_HEVC_LEVEL)));
|
||||
obs_property_list_add_int(p, TRANSLATE(S_STATE_AUTOMATIC),
|
||||
static_cast<int64_t>(codecs::hevc::level::UNKNOWN));
|
||||
for (auto const kv : levels) {
|
||||
obs_property_list_add_int(p, kv.second.c_str(), static_cast<int64_t>(kv.first));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nvenc::get_properties_post(props, codec);
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::nvenc_hevc_handler::get_runtime_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context)
|
||||
{
|
||||
nvenc::get_runtime_properties(props, codec, context);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// 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 "handler.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <obs-properties.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavcodec/avcodec.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
namespace obsffmpeg {
|
||||
namespace ui {
|
||||
class nvenc_hevc_handler : public handler {
|
||||
public:
|
||||
virtual void override_visible_name(const AVCodec* codec, std::string& name) override;
|
||||
|
||||
virtual void override_lag_in_frames(size_t& lag, obs_data_t* settings, const AVCodec* codec,
|
||||
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,
|
||||
AVCodecContext* context, bool hw_encode) override;
|
||||
|
||||
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
|
||||
virtual void log_options(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
|
||||
private:
|
||||
void get_encoder_properties(obs_properties_t* props, const AVCodec* codec);
|
||||
|
||||
void get_runtime_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context);
|
||||
};
|
||||
} // namespace ui
|
||||
} // namespace obsffmpeg
|
||||
@@ -0,0 +1,772 @@
|
||||
// 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 "nvenc_shared.hpp"
|
||||
#include <algorithm>
|
||||
#include "codecs/hevc.hpp"
|
||||
#include "plugin.hpp"
|
||||
#include "strings.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <obs-module.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavutil/opt.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
#define ST_PRESET "NVENC.Preset"
|
||||
#define ST_PRESET_(x) ST_PRESET "." D_VSTR(x)
|
||||
|
||||
#define ST_RATECONTROL "NVENC.RateControl"
|
||||
#define ST_RATECONTROL_MODE ST_RATECONTROL ".Mode"
|
||||
#define ST_RATECONTROL_MODE_(x) ST_RATECONTROL_MODE "." D_VSTR(x)
|
||||
#define ST_RATECONTROL_TWOPASS ST_RATECONTROL ".TwoPass"
|
||||
#define ST_RATECONTROL_LOOKAHEAD ST_RATECONTROL ".LookAhead"
|
||||
#define ST_RATECONTROL_ADAPTIVEI ST_RATECONTROL ".AdaptiveI"
|
||||
#define ST_RATECONTROL_ADAPTIVEB ST_RATECONTROL ".AdaptiveB"
|
||||
|
||||
#define ST_RATECONTROL_BITRATE ST_RATECONTROL ".Bitrate"
|
||||
#define ST_RATECONTROL_BITRATE_TARGET ST_RATECONTROL_BITRATE ".Target"
|
||||
#define ST_RATECONTROL_BITRATE_MAXIMUM ST_RATECONTROL_BITRATE ".Maximum"
|
||||
|
||||
#define ST_RATECONTROL_QUALITY ST_RATECONTROL ".Quality"
|
||||
#define ST_RATECONTROL_QUALITY_MINIMUM ST_RATECONTROL_QUALITY ".Minimum"
|
||||
#define ST_RATECONTROL_QUALITY_MAXIMUM ST_RATECONTROL_QUALITY ".Maximum"
|
||||
#define ST_RATECONTROL_QUALITY_TARGET ST_RATECONTROL_QUALITY ".Target"
|
||||
|
||||
#define ST_RATECONTROL_QP ST_RATECONTROL ".QP"
|
||||
#define ST_RATECONTROL_QP_I ST_RATECONTROL_QP ".I"
|
||||
#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_INITIAL ST_RATECONTROL_QP_P ".Initial"
|
||||
#define ST_RATECONTROL_QP_B ST_RATECONTROL_QP ".B"
|
||||
#define ST_RATECONTROL_QP_B_INITIAL ST_RATECONTROL_QP_B ".Initial"
|
||||
|
||||
#define ST_AQ "NVENC.AQ"
|
||||
#define ST_AQ_SPATIAL ST_AQ ".Spatial"
|
||||
#define ST_AQ_TEMPORAL ST_AQ ".Temporal"
|
||||
#define ST_AQ_STRENGTH ST_AQ ".Strength"
|
||||
|
||||
#define ST_OTHER "NVENC.Other"
|
||||
#define ST_OTHER_BFRAMES ST_OTHER ".BFrames"
|
||||
#define ST_OTHER_BFRAME_REFERENCEMODE ST_OTHER ".BFrameReferenceMode"
|
||||
#define ST_OTHER_ZEROLATENCY ST_OTHER ".ZeroLatency"
|
||||
#define ST_OTHER_WEIGHTED_PREDICTION ST_OTHER ".WeightedPrediction"
|
||||
#define ST_OTHER_NONREFERENCE_PFRAMES ST_OTHER ".NonReferencePFrames"
|
||||
|
||||
using namespace obsffmpeg::nvenc;
|
||||
|
||||
std::map<preset, std::string> obsffmpeg::nvenc::presets{
|
||||
{preset::DEFAULT, ST_PRESET_(Default)},
|
||||
{preset::SLOW, ST_PRESET_(Slow)},
|
||||
{preset::MEDIUM, ST_PRESET_(Medium)},
|
||||
{preset::FAST, ST_PRESET_(Fast)},
|
||||
{preset::HIGH_PERFORMANCE, ST_PRESET_(HighPerformance)},
|
||||
{preset::HIGH_QUALITY, ST_PRESET_(HighQuality)},
|
||||
{preset::BLURAYDISC, ST_PRESET_(BluRayDisc)},
|
||||
{preset::LOW_LATENCY, ST_PRESET_(LowLatency)},
|
||||
{preset::LOW_LATENCY_HIGH_PERFORMANCE, ST_PRESET_(LowLatencyHighPerformance)},
|
||||
{preset::LOW_LATENCY_HIGH_QUALITY, ST_PRESET_(LowLatencyHighQuality)},
|
||||
{preset::LOSSLESS, ST_PRESET_(Lossless)},
|
||||
{preset::LOSSLESS_HIGH_PERFORMANCE, ST_PRESET_(LosslessHighPerformance)},
|
||||
};
|
||||
|
||||
std::map<preset, std::string> obsffmpeg::nvenc::preset_to_opt{
|
||||
{preset::DEFAULT, "default"},
|
||||
{preset::SLOW, "slow"},
|
||||
{preset::MEDIUM, "medium"},
|
||||
{preset::FAST, "fast"},
|
||||
{preset::HIGH_PERFORMANCE, "hp"},
|
||||
{preset::HIGH_QUALITY, "hq"},
|
||||
{preset::BLURAYDISC, "bd"},
|
||||
{preset::LOW_LATENCY, "ll"},
|
||||
{preset::LOW_LATENCY_HIGH_PERFORMANCE, "llhp"},
|
||||
{preset::LOW_LATENCY_HIGH_QUALITY, "llhq"},
|
||||
{preset::LOSSLESS, "lossless"},
|
||||
{preset::LOSSLESS_HIGH_PERFORMANCE, "losslesshp"},
|
||||
};
|
||||
|
||||
std::map<ratecontrolmode, std::string> obsffmpeg::nvenc::ratecontrolmodes{
|
||||
{ratecontrolmode::CQP, ST_RATECONTROL_MODE_(CQP)},
|
||||
{ratecontrolmode::VBR, ST_RATECONTROL_MODE_(VBR)},
|
||||
{ratecontrolmode::VBR_HQ, ST_RATECONTROL_MODE_(VBR_HQ)},
|
||||
{ratecontrolmode::CBR, ST_RATECONTROL_MODE_(CBR)},
|
||||
{ratecontrolmode::CBR_HQ, ST_RATECONTROL_MODE_(CBR_HQ)},
|
||||
{ratecontrolmode::CBR_LD_HQ, ST_RATECONTROL_MODE_(CBR_LD_HQ)},
|
||||
};
|
||||
|
||||
std::map<ratecontrolmode, std::string> obsffmpeg::nvenc::ratecontrolmode_to_opt{
|
||||
{ratecontrolmode::CQP, "constqp"}, {ratecontrolmode::VBR, "vbr"}, {ratecontrolmode::VBR_HQ, "vbr_hq"},
|
||||
{ratecontrolmode::CBR, "cbr"}, {ratecontrolmode::CBR_HQ, "cbr_hq"}, {ratecontrolmode::CBR_LD_HQ, "cbr_ld_hq"},
|
||||
};
|
||||
|
||||
std::map<b_ref_mode, std::string> obsffmpeg::nvenc::b_ref_modes{
|
||||
{b_ref_mode::DISABLED, S_STATE_DISABLED},
|
||||
{b_ref_mode::EACH, ST_OTHER_BFRAME_REFERENCEMODE ".Each"},
|
||||
{b_ref_mode::MIDDLE, ST_OTHER_BFRAME_REFERENCEMODE ".Middle"},
|
||||
};
|
||||
|
||||
std::map<b_ref_mode, std::string> obsffmpeg::nvenc::b_ref_mode_to_opt{
|
||||
{b_ref_mode::DISABLED, "disabled"},
|
||||
{b_ref_mode::EACH, "each"},
|
||||
{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*)
|
||||
{
|
||||
obs_data_set_default_int(settings, ST_PRESET, static_cast<int64_t>(preset::DEFAULT));
|
||||
|
||||
obs_data_set_default_int(settings, ST_RATECONTROL_MODE, static_cast<int64_t>(ratecontrolmode::CBR_HQ));
|
||||
obs_data_set_default_int(settings, ST_RATECONTROL_TWOPASS, -1);
|
||||
obs_data_set_default_int(settings, ST_RATECONTROL_LOOKAHEAD, 0);
|
||||
obs_data_set_default_bool(settings, ST_RATECONTROL_ADAPTIVEI, true);
|
||||
obs_data_set_default_bool(settings, ST_RATECONTROL_ADAPTIVEB, true);
|
||||
|
||||
obs_data_set_default_int(settings, ST_RATECONTROL_BITRATE_TARGET, 6000);
|
||||
obs_data_set_default_int(settings, ST_RATECONTROL_BITRATE_MAXIMUM, 6000);
|
||||
obs_data_set_default_int(settings, S_RATECONTROL_BUFFERSIZE, 12000);
|
||||
|
||||
obs_data_set_default_int(settings, ST_RATECONTROL_QUALITY_MINIMUM, 51);
|
||||
obs_data_set_default_int(settings, ST_RATECONTROL_QUALITY_MAXIMUM, -1);
|
||||
obs_data_set_default_int(settings, ST_RATECONTROL_QUALITY_TARGET, 0);
|
||||
|
||||
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_P, 21);
|
||||
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_INITIAL, -1);
|
||||
|
||||
obs_data_set_default_bool(settings, ST_AQ_SPATIAL, true);
|
||||
obs_data_set_default_int(settings, ST_AQ_STRENGTH, 8);
|
||||
obs_data_set_default_bool(settings, ST_AQ_TEMPORAL, true);
|
||||
|
||||
obs_data_set_default_int(settings, ST_OTHER_BFRAMES, 2);
|
||||
obs_data_set_default_int(settings, ST_OTHER_BFRAME_REFERENCEMODE, static_cast<int64_t>(b_ref_mode::DISABLED));
|
||||
obs_data_set_default_bool(settings, ST_OTHER_ZEROLATENCY, false);
|
||||
obs_data_set_default_bool(settings, ST_OTHER_WEIGHTED_PREDICTION, false);
|
||||
obs_data_set_default_bool(settings, ST_OTHER_NONREFERENCE_PFRAMES, false);
|
||||
}
|
||||
|
||||
static bool modified_ratecontrol(obs_properties_t* props, obs_property_t*, obs_data_t* settings)
|
||||
{
|
||||
using namespace obsffmpeg::nvenc;
|
||||
|
||||
bool have_bitrate = false;
|
||||
bool have_bitrate_max = false;
|
||||
bool have_quality = false;
|
||||
bool have_qp = false;
|
||||
bool have_qp_init = false;
|
||||
|
||||
ratecontrolmode rc = static_cast<ratecontrolmode>(obs_data_get_int(settings, ST_RATECONTROL_MODE));
|
||||
switch (rc) {
|
||||
case ratecontrolmode::CQP:
|
||||
have_qp = true;
|
||||
break;
|
||||
case ratecontrolmode::CBR:
|
||||
case ratecontrolmode::CBR_HQ:
|
||||
case ratecontrolmode::CBR_LD_HQ:
|
||||
have_bitrate = true;
|
||||
break;
|
||||
case ratecontrolmode::VBR:
|
||||
case ratecontrolmode::VBR_HQ:
|
||||
have_bitrate = true;
|
||||
have_bitrate_max = true;
|
||||
have_quality = true;
|
||||
have_qp_init = true;
|
||||
break;
|
||||
}
|
||||
|
||||
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_BITRATE), have_bitrate || have_bitrate_max);
|
||||
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_BITRATE_TARGET), have_bitrate);
|
||||
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_BITRATE_MAXIMUM), have_bitrate_max);
|
||||
obs_property_set_visible(obs_properties_get(props, S_RATECONTROL_BUFFERSIZE), have_bitrate || have_bitrate_max);
|
||||
|
||||
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QUALITY), have_quality);
|
||||
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QUALITY_MINIMUM), have_quality);
|
||||
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QUALITY_MAXIMUM), have_quality);
|
||||
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QUALITY_TARGET), have_quality);
|
||||
|
||||
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QP), have_qp || have_qp_init);
|
||||
obs_property_set_visible(obs_properties_get(props, ST_RATECONTROL_QP_I), 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_I_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);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool modified_quality(obs_properties_t* props, obs_property_t*, obs_data_t* settings)
|
||||
{
|
||||
bool enabled = obs_data_get_bool(settings, ST_RATECONTROL_QUALITY);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QUALITY_MINIMUM), enabled);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QUALITY_MAXIMUM), enabled);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool modified_aq(obs_properties_t* props, obs_property_t*, obs_data_t* settings)
|
||||
{
|
||||
bool spatial_aq = obs_data_get_bool(settings, ST_AQ_SPATIAL);
|
||||
obs_property_set_visible(obs_properties_get(props, ST_AQ_STRENGTH), spatial_aq);
|
||||
return true;
|
||||
}
|
||||
|
||||
void obsffmpeg::nvenc::get_properties_pre(obs_properties_t* props, const AVCodec*)
|
||||
{
|
||||
{
|
||||
auto p = obs_properties_add_list(props, ST_PRESET, TRANSLATE(ST_PRESET), OBS_COMBO_TYPE_LIST,
|
||||
OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_PRESET)));
|
||||
for (auto kv : presets) {
|
||||
obs_property_list_add_int(p, TRANSLATE(kv.second.c_str()), static_cast<int64_t>(kv.first));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void obsffmpeg::nvenc::get_properties_post(obs_properties_t* props, const AVCodec* codec)
|
||||
{
|
||||
{ // Rate Control
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, ST_RATECONTROL, TRANSLATE(ST_RATECONTROL), OBS_GROUP_NORMAL,
|
||||
grp);
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_list(grp, ST_RATECONTROL_MODE, TRANSLATE(ST_RATECONTROL_MODE),
|
||||
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_MODE)));
|
||||
obs_property_set_modified_callback(p, modified_ratecontrol);
|
||||
for (auto kv : ratecontrolmodes) {
|
||||
obs_property_list_add_int(p, TRANSLATE(kv.second.c_str()),
|
||||
static_cast<int64_t>(kv.first));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_list(grp, ST_RATECONTROL_TWOPASS, TRANSLATE(ST_RATECONTROL_TWOPASS),
|
||||
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_TWOPASS)));
|
||||
obs_property_list_add_int(p, TRANSLATE(S_STATE_DEFAULT), -1);
|
||||
obs_property_list_add_int(p, TRANSLATE(S_STATE_DISABLED), 0);
|
||||
obs_property_list_add_int(p, TRANSLATE(S_STATE_ENABLED), 1);
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_int_slider(grp, ST_RATECONTROL_LOOKAHEAD,
|
||||
TRANSLATE(ST_RATECONTROL_LOOKAHEAD), 0, 32, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_LOOKAHEAD)));
|
||||
obs_property_int_set_suffix(p, " frames");
|
||||
}
|
||||
{
|
||||
auto p =
|
||||
obs_properties_add_bool(grp, ST_RATECONTROL_ADAPTIVEI, TRANSLATE(ST_RATECONTROL_ADAPTIVEI));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_ADAPTIVEI)));
|
||||
}
|
||||
if (strcmp(codec->name, "h264_nvenc") == 0) {
|
||||
auto p =
|
||||
obs_properties_add_bool(grp, ST_RATECONTROL_ADAPTIVEB, TRANSLATE(ST_RATECONTROL_ADAPTIVEB));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_ADAPTIVEB)));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, ST_RATECONTROL_BITRATE, TRANSLATE(ST_RATECONTROL_BITRATE),
|
||||
OBS_GROUP_NORMAL, grp);
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_int(grp, ST_RATECONTROL_BITRATE_TARGET,
|
||||
TRANSLATE(ST_RATECONTROL_BITRATE_TARGET), 1,
|
||||
std::numeric_limits<int32_t>::max(), 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_BITRATE_TARGET)));
|
||||
obs_property_int_set_suffix(p, " kbit/s");
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_int(grp, ST_RATECONTROL_BITRATE_MAXIMUM,
|
||||
TRANSLATE(ST_RATECONTROL_BITRATE_MAXIMUM), 0,
|
||||
std::numeric_limits<int32_t>::max(), 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_BITRATE_MAXIMUM)));
|
||||
obs_property_int_set_suffix(p, " kbit/s");
|
||||
}
|
||||
{
|
||||
auto p =
|
||||
obs_properties_add_int(grp, S_RATECONTROL_BUFFERSIZE, TRANSLATE(S_RATECONTROL_BUFFERSIZE),
|
||||
0, std::numeric_limits<int32_t>::max(), 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(S_RATECONTROL_BUFFERSIZE)));
|
||||
obs_property_int_set_suffix(p, " kbit");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
auto p = obs_properties_add_group(props, ST_RATECONTROL_QUALITY,
|
||||
TRANSLATE(ST_RATECONTROL_QUALITY), OBS_GROUP_CHECKABLE, grp);
|
||||
obs_property_set_modified_callback(p, modified_quality);
|
||||
} else {
|
||||
auto p =
|
||||
obs_properties_add_bool(props, ST_RATECONTROL_QUALITY, TRANSLATE(ST_RATECONTROL_QUALITY));
|
||||
obs_property_set_modified_callback(p, modified_quality);
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_int_slider(grp, ST_RATECONTROL_QUALITY_MINIMUM,
|
||||
TRANSLATE(ST_RATECONTROL_QUALITY_MINIMUM), 0, 51, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QUALITY_MINIMUM)));
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_int_slider(grp, ST_RATECONTROL_QUALITY_MAXIMUM,
|
||||
TRANSLATE(ST_RATECONTROL_QUALITY_MAXIMUM), -1, 51, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QUALITY_MAXIMUM)));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_float_slider(props, ST_RATECONTROL_QUALITY_TARGET,
|
||||
TRANSLATE(ST_RATECONTROL_QUALITY_TARGET), 0, 100, 0.01);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QUALITY_TARGET)));
|
||||
}
|
||||
|
||||
{
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
auto p = obs_properties_add_group(props, ST_RATECONTROL_QP, TRANSLATE(ST_RATECONTROL_QP),
|
||||
OBS_GROUP_CHECKABLE, grp);
|
||||
obs_property_set_modified_callback(p, modified_quality);
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_int_slider(grp, ST_RATECONTROL_QP_I, TRANSLATE(ST_RATECONTROL_QP_I),
|
||||
0, 51, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QP_I)));
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_int_slider(grp, ST_RATECONTROL_QP_I_INITIAL,
|
||||
TRANSLATE(ST_RATECONTROL_QP_I_INITIAL), -1, 51, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QP_I_INITIAL)));
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_int_slider(grp, ST_RATECONTROL_QP_P, TRANSLATE(ST_RATECONTROL_QP_P),
|
||||
0, 51, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QP_P)));
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_int_slider(grp, ST_RATECONTROL_QP_P_INITIAL,
|
||||
TRANSLATE(ST_RATECONTROL_QP_P_INITIAL), -1, 51, 1);
|
||||
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),
|
||||
0, 51, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QP_B)));
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_int_slider(grp, ST_RATECONTROL_QP_B_INITIAL,
|
||||
TRANSLATE(ST_RATECONTROL_QP_B_INITIAL), -1, 51, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QP_B_INITIAL)));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, ST_AQ, TRANSLATE(ST_AQ), OBS_GROUP_NORMAL, grp);
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_bool(grp, ST_AQ_SPATIAL, TRANSLATE(ST_AQ_SPATIAL));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_AQ_SPATIAL)));
|
||||
obs_property_set_modified_callback(p, modified_aq);
|
||||
}
|
||||
{
|
||||
auto p =
|
||||
obs_properties_add_int_slider(grp, ST_AQ_STRENGTH, TRANSLATE(ST_AQ_STRENGTH), 1, 15, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_AQ_STRENGTH)));
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_bool(grp, ST_AQ_TEMPORAL, TRANSLATE(ST_AQ_TEMPORAL));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_AQ_TEMPORAL)));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, ST_OTHER, TRANSLATE(ST_OTHER), OBS_GROUP_NORMAL, grp);
|
||||
}
|
||||
|
||||
{
|
||||
auto p =
|
||||
obs_properties_add_int_slider(grp, ST_OTHER_BFRAMES, TRANSLATE(ST_OTHER_BFRAMES), 0, 4, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_OTHER_BFRAMES)));
|
||||
obs_property_int_set_suffix(p, " frames");
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_list(grp, ST_OTHER_BFRAME_REFERENCEMODE,
|
||||
TRANSLATE(ST_OTHER_BFRAME_REFERENCEMODE), OBS_COMBO_TYPE_LIST,
|
||||
OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_OTHER_BFRAME_REFERENCEMODE)));
|
||||
for (auto kv : b_ref_modes) {
|
||||
obs_property_list_add_int(p, TRANSLATE(kv.second.c_str()),
|
||||
static_cast<int64_t>(kv.first));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_bool(grp, ST_OTHER_ZEROLATENCY, TRANSLATE(ST_OTHER_ZEROLATENCY));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_OTHER_ZEROLATENCY)));
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_bool(grp, ST_OTHER_WEIGHTED_PREDICTION,
|
||||
TRANSLATE(ST_OTHER_WEIGHTED_PREDICTION));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_OTHER_WEIGHTED_PREDICTION)));
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_bool(grp, ST_OTHER_NONREFERENCE_PFRAMES,
|
||||
TRANSLATE(ST_OTHER_NONREFERENCE_PFRAMES));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_OTHER_NONREFERENCE_PFRAMES)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void obsffmpeg::nvenc::get_runtime_properties(obs_properties_t* props, const AVCodec*, AVCodecContext*)
|
||||
{
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_PRESET), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_MODE), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_TWOPASS), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_LOOKAHEAD), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_ADAPTIVEI), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_ADAPTIVEB), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_BITRATE), true);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_BITRATE_TARGET), true);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_BITRATE_MAXIMUM), true);
|
||||
obs_property_set_enabled(obs_properties_get(props, S_RATECONTROL_BUFFERSIZE), true);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QUALITY), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QUALITY_MINIMUM), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QUALITY_MAXIMUM), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QUALITY_TARGET), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_RATECONTROL_QP), 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_P), 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_INITIAL), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_AQ), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_AQ_SPATIAL), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_AQ_STRENGTH), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_AQ_TEMPORAL), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_OTHER), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_OTHER_BFRAMES), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_OTHER_BFRAME_REFERENCEMODE), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_OTHER_ZEROLATENCY), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_OTHER_WEIGHTED_PREDICTION), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_OTHER_NONREFERENCE_PFRAMES), false);
|
||||
}
|
||||
|
||||
void obsffmpeg::nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
|
||||
{
|
||||
{
|
||||
preset c_preset = static_cast<preset>(obs_data_get_int(settings, ST_PRESET));
|
||||
auto found = preset_to_opt.find(c_preset);
|
||||
if (found != preset_to_opt.end()) {
|
||||
av_opt_set(context->priv_data, "preset", found->second.c_str(), 0);
|
||||
} else {
|
||||
av_opt_set(context->priv_data, "preset", nullptr, 0);
|
||||
}
|
||||
}
|
||||
|
||||
{ // Rate Control
|
||||
bool have_bitrate = false;
|
||||
bool have_bitrate_max = false;
|
||||
bool have_quality = false;
|
||||
bool have_qp = false;
|
||||
bool have_qp_init = false;
|
||||
|
||||
ratecontrolmode rc = static_cast<ratecontrolmode>(obs_data_get_int(settings, ST_RATECONTROL_MODE));
|
||||
auto rcopt = nvenc::ratecontrolmode_to_opt.find(rc);
|
||||
if (rcopt != nvenc::ratecontrolmode_to_opt.end()) {
|
||||
av_opt_set(context->priv_data, "rc", rcopt->second.c_str(), 0);
|
||||
}
|
||||
|
||||
switch (rc) {
|
||||
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;
|
||||
}
|
||||
|
||||
int tp = static_cast<int>(obs_data_get_int(settings, ST_RATECONTROL_TWOPASS));
|
||||
if (tp >= 0) {
|
||||
av_opt_set_int(context->priv_data, "2pass", tp ? 1 : 0, 0);
|
||||
}
|
||||
|
||||
int la = static_cast<int>(obs_data_get_int(settings, ST_RATECONTROL_LOOKAHEAD));
|
||||
av_opt_set_int(context->priv_data, "lookahead", la, 0);
|
||||
if (la > 0) {
|
||||
bool adapt_i = obs_data_get_bool(settings, ST_RATECONTROL_ADAPTIVEI);
|
||||
av_opt_set_int(context->priv_data, "no-scenecut", !adapt_i ? 1 : 0, 0);
|
||||
|
||||
if (strcmp(codec->name, "h264_nvenc")) {
|
||||
bool adapt_b = obs_data_get_bool(settings, ST_RATECONTROL_ADAPTIVEB);
|
||||
av_opt_set_int(context->priv_data, "b_adapt", adapt_b ? 1 : 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (have_bitrate)
|
||||
context->bit_rate =
|
||||
static_cast<int>(obs_data_get_int(settings, ST_RATECONTROL_BITRATE_TARGET) * 1000);
|
||||
if (have_bitrate_max)
|
||||
context->rc_max_rate =
|
||||
static_cast<int>(obs_data_get_int(settings, ST_RATECONTROL_BITRATE_MAXIMUM) * 1000);
|
||||
if (have_bitrate || have_bitrate_max)
|
||||
context->rc_buffer_size =
|
||||
static_cast<int>(obs_data_get_int(settings, S_RATECONTROL_BUFFERSIZE) * 1000);
|
||||
|
||||
if (have_quality && obs_data_get_bool(settings, ST_RATECONTROL_QUALITY)) {
|
||||
int qmin = static_cast<int>(obs_data_get_int(settings, ST_RATECONTROL_QUALITY_MINIMUM));
|
||||
context->qmin = qmin;
|
||||
if (qmin >= 0) {
|
||||
context->qmax =
|
||||
static_cast<int>(obs_data_get_int(settings, ST_RATECONTROL_QUALITY_MAXIMUM));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
double_t v = obs_data_get_double(settings, ST_RATECONTROL_QUALITY_TARGET) / 100.0 * 51.0;
|
||||
if (v > 0) {
|
||||
av_opt_set_double(context->priv_data, "cq", v, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (have_qp) {
|
||||
av_opt_set_int(context->priv_data, "init_qpI",
|
||||
static_cast<int>(obs_data_get_int(settings, ST_RATECONTROL_QP_I)), 0);
|
||||
av_opt_set_int(context->priv_data, "init_qpP",
|
||||
static_cast<int>(obs_data_get_int(settings, ST_RATECONTROL_QP_P)), 0);
|
||||
av_opt_set_int(context->priv_data, "init_qpB",
|
||||
static_cast<int>(obs_data_get_int(settings, ST_RATECONTROL_QP_B)), 0);
|
||||
}
|
||||
if (have_qp_init) {
|
||||
av_opt_set_int(context->priv_data, "init_qpI",
|
||||
obs_data_get_int(settings, ST_RATECONTROL_QP_I_INITIAL), 0);
|
||||
av_opt_set_int(context->priv_data, "init_qpP",
|
||||
obs_data_get_int(settings, ST_RATECONTROL_QP_P_INITIAL), 0);
|
||||
av_opt_set_int(context->priv_data, "init_qpB",
|
||||
obs_data_get_int(settings, ST_RATECONTROL_QP_B_INITIAL), 0);
|
||||
}
|
||||
}
|
||||
|
||||
{ // AQ
|
||||
bool saq = obs_data_get_bool(settings, ST_AQ_SPATIAL);
|
||||
bool taq = obs_data_get_bool(settings, ST_AQ_TEMPORAL);
|
||||
|
||||
if (strcmp(codec->name, "h264_nvenc")) {
|
||||
av_opt_set_int(context->priv_data, "spatial-aq", saq ? 1 : 0, 0);
|
||||
av_opt_set_int(context->priv_data, "temporal-aq", taq ? 1 : 0, 0);
|
||||
} else {
|
||||
av_opt_set_int(context->priv_data, "spatial_aq", saq ? 1 : 0, 0);
|
||||
av_opt_set_int(context->priv_data, "temporal_aq", taq ? 1 : 0, 0);
|
||||
}
|
||||
if (saq) {
|
||||
av_opt_set_int(context->priv_data, "aq-strength",
|
||||
static_cast<int>(obs_data_get_int(settings, ST_AQ_STRENGTH)), 0);
|
||||
}
|
||||
}
|
||||
|
||||
{ // Other
|
||||
bool zl = obs_data_get_bool(settings, ST_OTHER_ZEROLATENCY);
|
||||
bool wp = obs_data_get_bool(settings, ST_OTHER_WEIGHTED_PREDICTION);
|
||||
bool nrp = obs_data_get_bool(settings, ST_OTHER_NONREFERENCE_PFRAMES);
|
||||
|
||||
context->max_b_frames = static_cast<int>(obs_data_get_int(settings, ST_OTHER_BFRAMES));
|
||||
|
||||
av_opt_set_int(context->priv_data, "zerolatency", zl ? 1 : 0, 0);
|
||||
av_opt_set_int(context->priv_data, "nonref_p", nrp ? 1 : 0, 0);
|
||||
|
||||
if ((context->max_b_frames != 0) && wp) {
|
||||
PLOG_WARNING(
|
||||
"Automatically disabled weighted prediction due to being incompatible with B-Frames.");
|
||||
} else {
|
||||
av_opt_set_int(context->priv_data, "weighted_pred", wp ? 1 : 0, 0);
|
||||
}
|
||||
|
||||
{
|
||||
auto found = b_ref_mode_to_opt.find(
|
||||
static_cast<b_ref_mode>(obs_data_get_int(settings, ST_OTHER_BFRAME_REFERENCEMODE)));
|
||||
if (found != b_ref_mode_to_opt.end()) {
|
||||
av_opt_set(context->priv_data, "b_ref_mode", found->second.c_str(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
// 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 <map>
|
||||
#include "utility.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <obs-properties.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavcodec/avcodec.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
namespace obsffmpeg {
|
||||
namespace nvenc {
|
||||
enum class preset : int64_t {
|
||||
DEFAULT,
|
||||
SLOW,
|
||||
MEDIUM,
|
||||
FAST,
|
||||
HIGH_PERFORMANCE,
|
||||
HIGH_QUALITY,
|
||||
BLURAYDISC,
|
||||
LOW_LATENCY,
|
||||
LOW_LATENCY_HIGH_PERFORMANCE,
|
||||
LOW_LATENCY_HIGH_QUALITY,
|
||||
LOSSLESS,
|
||||
LOSSLESS_HIGH_PERFORMANCE,
|
||||
};
|
||||
|
||||
enum class ratecontrolmode : int64_t {
|
||||
CQP,
|
||||
VBR,
|
||||
VBR_HQ,
|
||||
CBR,
|
||||
CBR_HQ,
|
||||
CBR_LD_HQ,
|
||||
};
|
||||
|
||||
enum class b_ref_mode : int64_t {
|
||||
DISABLED,
|
||||
EACH,
|
||||
MIDDLE,
|
||||
};
|
||||
|
||||
extern std::map<preset, std::string> presets;
|
||||
|
||||
extern std::map<preset, std::string> preset_to_opt;
|
||||
|
||||
extern std::map<ratecontrolmode, std::string> ratecontrolmodes;
|
||||
|
||||
extern std::map<ratecontrolmode, std::string> ratecontrolmode_to_opt;
|
||||
|
||||
extern std::map<b_ref_mode, std::string> b_ref_modes;
|
||||
|
||||
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_properties_pre(obs_properties_t* props, const AVCodec* codec);
|
||||
|
||||
void get_properties_post(obs_properties_t* props, const AVCodec* codec);
|
||||
|
||||
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 log_options(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context);
|
||||
} // namespace nvenc
|
||||
} // namespace obsffmpeg
|
||||
@@ -0,0 +1,128 @@
|
||||
// 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_aw_handler.hpp"
|
||||
#include "codecs/prores.hpp"
|
||||
#include "plugin.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <obs-module.h>
|
||||
}
|
||||
|
||||
INITIALIZER(prores_aw_handler_init)
|
||||
{
|
||||
obsffmpeg::initializers.push_back([]() {
|
||||
obsffmpeg::register_codec_handler("prores_aw", std::make_shared<obsffmpeg::ui::prores_aw_handler>());
|
||||
});
|
||||
};
|
||||
|
||||
void obsffmpeg::ui::prores_aw_handler::override_colorformat(AVPixelFormat& target_format, obs_data_t* settings,
|
||||
const AVCodec* codec, AVCodecContext*)
|
||||
{
|
||||
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,
|
||||
AVCodecContext* context, bool)
|
||||
{
|
||||
if (!context) {
|
||||
auto p = obs_properties_add_list(props, P_PRORES_PROFILE, TRANSLATE(P_PRORES_PROFILE),
|
||||
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_PRORES_PROFILE)));
|
||||
for (auto ptr = codec->profiles; ptr->profile != FF_PROFILE_UNKNOWN; ptr++) {
|
||||
if (strcmp("apco", ptr->name) == 0) {
|
||||
obs_property_list_add_int(p, TRANSLATE(P_PRORES_PROFILE_APCO),
|
||||
static_cast<int64_t>(ptr->profile));
|
||||
} else if (strcmp("apcs", ptr->name) == 0) {
|
||||
obs_property_list_add_int(p, TRANSLATE(P_PRORES_PROFILE_APCS),
|
||||
static_cast<int64_t>(ptr->profile));
|
||||
} else if (strcmp("apcn", ptr->name) == 0) {
|
||||
obs_property_list_add_int(p, TRANSLATE(P_PRORES_PROFILE_APCN),
|
||||
static_cast<int64_t>(ptr->profile));
|
||||
} else if (strcmp("apch", ptr->name) == 0) {
|
||||
obs_property_list_add_int(p, TRANSLATE(P_PRORES_PROFILE_APCH),
|
||||
static_cast<int64_t>(ptr->profile));
|
||||
} else if (strcmp("ap4h", ptr->name) == 0) {
|
||||
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));
|
||||
} else {
|
||||
obs_property_list_add_int(p, ptr->name, ptr->profile);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// 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 "handler.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <obs-properties.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavcodec/avcodec.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
namespace obsffmpeg {
|
||||
namespace ui {
|
||||
class prores_aw_handler : public handler {
|
||||
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,
|
||||
AVCodecContext* context, bool hw_encode) override;
|
||||
|
||||
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context, bool hw_encode) override;
|
||||
|
||||
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
||||
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 obsffmpeg
|
||||
@@ -0,0 +1,20 @@
|
||||
// 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.
|
||||
|
||||
+60
-18
@@ -1,28 +1,35 @@
|
||||
// FFMPEG Video Encoder Integration for OBS Studio
|
||||
// Copyright (C) 2018 - 2018 Michael Fabian Dirks
|
||||
// Copyright (c) 2019 Michael Fabian Dirks <info@xaymar.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
// 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:
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
// 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.
|
||||
|
||||
#ifndef OBS_FFMPEG_UTILITY_HPP
|
||||
#define OBS_FFMPEG_UTILITY_HPP
|
||||
#pragma once
|
||||
|
||||
#include "version.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <obs-config.h>
|
||||
#include <obs.h>
|
||||
}
|
||||
|
||||
// Logging
|
||||
#define PLOG(level, ...) blog(level, "["##PROJECT_NAME##"] " __VA_ARGS__);
|
||||
#define PLOG(level, ...) blog(level, "[obs-ffmpeg-encoder] " __VA_ARGS__);
|
||||
#define PLOG_ERROR(...) PLOG(LOG_ERROR, __VA_ARGS__)
|
||||
#define PLOG_WARNING(...) PLOG(LOG_WARNING, __VA_ARGS__)
|
||||
#define PLOG_INFO(...) PLOG(LOG_INFO, __VA_ARGS__)
|
||||
@@ -42,7 +49,42 @@
|
||||
#define DESC(x) x ".Description"
|
||||
|
||||
// Other
|
||||
#define vstr(s) dstr(s)
|
||||
#define dstr(s) #s
|
||||
#define D_STR(s) #s
|
||||
#define D_VSTR(s) D_STR(s)
|
||||
|
||||
#endif OBS_FFMPEG_UTILITY_HPP
|
||||
// Initializer
|
||||
#ifdef __cplusplus
|
||||
#define INITIALIZER(f) \
|
||||
static void f(void); \
|
||||
struct f##_t_ { \
|
||||
f##_t_(void) \
|
||||
{ \
|
||||
f(); \
|
||||
} \
|
||||
}; \
|
||||
static f##_t_ f##_; \
|
||||
static void f(void)
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma section(".CRT$XCU", read)
|
||||
#define INITIALIZER2_(f, p) \
|
||||
static void f(void); \
|
||||
__declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \
|
||||
__pragma(comment(linker, "/include:" p #f "_")) static void f(void)
|
||||
#ifdef _WIN64
|
||||
#define INITIALIZER(f) INITIALIZER2_(f, "")
|
||||
#else
|
||||
#define INITIALIZER(f) INITIALIZER2_(f, "_")
|
||||
#endif
|
||||
#else
|
||||
#define INITIALIZER(f) \
|
||||
static void f(void) __attribute__((constructor)); \
|
||||
static void f(void)
|
||||
#endif
|
||||
|
||||
// Helpers
|
||||
namespace obsffmpeg {
|
||||
bool inline are_property_groups_broken()
|
||||
{
|
||||
return obs_get_version() < MAKE_SEMANTIC_VERSION(24, 0, 0);
|
||||
}
|
||||
} // namespace obsffmpeg
|
||||
|
||||
Reference in New Issue
Block a user