Compare commits
38 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 |
@@ -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
|
||||
+3
-7
@@ -25,7 +25,7 @@ Include("cmake/util.cmake")
|
||||
|
||||
# Automatic Versioning
|
||||
set(VERSION_MAJOR 0)
|
||||
set(VERSION_MINOR 1)
|
||||
set(VERSION_MINOR 2)
|
||||
set(VERSION_PATCH 0)
|
||||
set(VERSION_TWEAK 0)
|
||||
set(PROJECT_COMMIT "N/A")
|
||||
@@ -155,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 "23.2.1-ci" 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)
|
||||
@@ -261,8 +261,8 @@ set(PROJECT_GENERATED
|
||||
"${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"
|
||||
@@ -272,10 +272,6 @@ set(PROJECT_PRIVATE
|
||||
"${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/encoders/generic.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/encoders/generic.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/encoders/prores_aw.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/encoders/prores_aw.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ffmpeg/avframe-queue.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ffmpeg/avframe-queue.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/ffmpeg/swscale.hpp"
|
||||
|
||||
+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.
|
||||
|
||||
+7
-1
@@ -7,11 +7,16 @@ matrix:
|
||||
# Build Image & Environment
|
||||
platform: x64
|
||||
|
||||
# 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
|
||||
@@ -29,9 +34,10 @@ install:
|
||||
- cmd: ci/appveyor-install.bat
|
||||
|
||||
build_script:
|
||||
- cmd: node ci/appveyor-build.js
|
||||
- cmd: node ci/builder.js
|
||||
|
||||
after_build:
|
||||
- cmd: node ci/packager.js
|
||||
- cmd: ci/appveyor-package.bat
|
||||
|
||||
# Testing
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
const cp = require('child_process');
|
||||
|
||||
var config32 = cp.spawn(
|
||||
"cmake", [
|
||||
'-H.',
|
||||
'-B"build/32"',
|
||||
'-G"Visual Studio 15 2017"',
|
||||
'-DCMAKE_INSTALL_PREFIX="build/distrib"',
|
||||
'-DCMAKE_PACKAGE_PREFIX="build"',
|
||||
'-DCMAKE_PACKAGE_NAME="xmr-ffmpeg-encoders"'
|
||||
], {
|
||||
windowsVerbatimArguments: true,
|
||||
windowsHide: true
|
||||
}
|
||||
);
|
||||
config32.stdout.on('data', (data) => {
|
||||
process.stdout.write(`[32:Out] ${data}`);
|
||||
});
|
||||
config32.stderr.on('data', (data) => {
|
||||
console.log(`[32:Err] ${data}`);
|
||||
});
|
||||
config32.on('exit', (code, signal) => {
|
||||
if (code != 0) {
|
||||
process.exit(code)
|
||||
}
|
||||
var build32 = cp.spawn(
|
||||
"cmake", [
|
||||
'--build build/32',
|
||||
'--target INSTALL',
|
||||
'--config RelWithDebInfo',
|
||||
'--',
|
||||
'/logger:"C:\\Program Files\\AppVeyor\\BuildAgent\\Appveyor.MSBuildLogger.dll"'
|
||||
], {
|
||||
windowsVerbatimArguments: true,
|
||||
windowsHide: true
|
||||
}
|
||||
);
|
||||
build32.stdout.on('data', (data) => {
|
||||
process.stdout.write(`[32:Out] ${data}`);
|
||||
});
|
||||
build32.stderr.on('data', (data) => {
|
||||
process.stderr.write(`[32:Err] ${data}`);
|
||||
});
|
||||
build32.on('exit', (code, signal) => {
|
||||
if (code != 0) {
|
||||
process.exit(code)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var config64 = cp.spawn(
|
||||
"cmake", [
|
||||
'-H.',
|
||||
'-B"build/64"',
|
||||
'-G"Visual Studio 15 2017 Win64"',
|
||||
'-DCMAKE_INSTALL_PREFIX="build/distrib"',
|
||||
'-DCMAKE_PACKAGE_PREFIX="build"',
|
||||
'-DCMAKE_PACKAGE_NAME="xmr-ffmpeg-encoders"'
|
||||
], {
|
||||
windowsVerbatimArguments: true,
|
||||
windowsHide: true
|
||||
}
|
||||
);
|
||||
config64.stdout.on('data', (data) => {
|
||||
process.stdout.write(`[64:Out] ${data}`);
|
||||
});
|
||||
config64.stderr.on('data', (data) => {
|
||||
console.log(`[64:Err] ${data}`);
|
||||
});
|
||||
config64.on('exit', (code, signal) => {
|
||||
if (code != 0) {
|
||||
process.exit(code)
|
||||
}
|
||||
var build64 = cp.spawn(
|
||||
"cmake", [
|
||||
'--build build/64',
|
||||
'--target INSTALL',
|
||||
'--config RelWithDebInfo',
|
||||
'--',
|
||||
'/logger:"C:\\Program Files\\AppVeyor\\BuildAgent\\Appveyor.MSBuildLogger.dll"'
|
||||
], {
|
||||
windowsVerbatimArguments: true,
|
||||
windowsHide: true
|
||||
}
|
||||
);
|
||||
build64.stdout.on('data', (data) => {
|
||||
process.stdout.write(`[32:Out] ${data}`);
|
||||
});
|
||||
build64.stderr.on('data', (data) => {
|
||||
process.stderr.write(`[32:Err] ${data}`);
|
||||
});
|
||||
build64.on('exit', (code, signal) => {
|
||||
if (code != 0) {
|
||||
process.exit(code)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
@ECHO OFF
|
||||
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 -- 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;
|
||||
@@ -120,6 +120,8 @@ 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."
|
||||
|
||||
+208
-13
@@ -20,22 +20,217 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "hevc.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
using namespace obsffmpeg::codecs::hevc;
|
||||
|
||||
std::map<profile, std::string> obsffmpeg::codecs::hevc::profiles{
|
||||
{profile::MAIN, "main"},
|
||||
{profile::MAIN10, "main10"},
|
||||
{profile::RANGE_EXTENDED, "rext"},
|
||||
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,
|
||||
};
|
||||
|
||||
std::map<tier, std::string> obsffmpeg::codecs::hevc::profile_tiers{
|
||||
{tier::MAIN, "main"},
|
||||
{tier::HIGH, "high"},
|
||||
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;
|
||||
};
|
||||
|
||||
std::map<level, std::string> obsffmpeg::codecs::hevc::levels{
|
||||
{level::L1_0, "1.0"}, {level::L2_0, "2.0"}, {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"},
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
// Codec: HEVC
|
||||
#define P_HEVC "Codec.HEVC"
|
||||
@@ -47,6 +47,7 @@ namespace obsffmpeg {
|
||||
enum class level {
|
||||
L1_0 = 30,
|
||||
L2_0 = 60,
|
||||
L2_1 = 63,
|
||||
L3_0 = 90,
|
||||
L3_1 = 93,
|
||||
L4_0 = 120,
|
||||
@@ -60,11 +61,8 @@ namespace obsffmpeg {
|
||||
UNKNOWN = -1,
|
||||
};
|
||||
|
||||
extern std::map<profile, std::string> profiles;
|
||||
|
||||
extern std::map<tier, std::string> profile_tiers;
|
||||
|
||||
extern std::map<level, std::string> levels;
|
||||
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
|
||||
|
||||
+891
-1
@@ -20,5 +20,895 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "encoder.hpp"
|
||||
#include <iomanip>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#include <util/profiler.hpp>
|
||||
#include "codecs/hevc.hpp"
|
||||
#include "ffmpeg/tools.hpp"
|
||||
#include "plugin.hpp"
|
||||
#include "strings.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
obsffmpeg::encoder::base::~base() {}
|
||||
extern "C" {
|
||||
#include <obs-avc.h>
|
||||
#include <obs-module.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavutil/dict.h>
|
||||
#include <libavutil/frame.h>
|
||||
#include <libavutil/opt.h>
|
||||
#include <libavutil/pixdesc.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
// FFmpeg
|
||||
#define ST_FFMPEG "FFmpeg"
|
||||
#define ST_FFMPEG_CUSTOMSETTINGS "FFmpeg.CustomSettings"
|
||||
#define ST_FFMPEG_THREADS "FFmpeg.Threads"
|
||||
#define ST_FFMPEG_COLORFORMAT "FFmpeg.ColorFormat"
|
||||
#define ST_FFMPEG_STANDARDCOMPLIANCE "FFmpeg.StandardCompliance"
|
||||
|
||||
enum class keyframe_type { SECONDS, FRAMES };
|
||||
|
||||
obsffmpeg::encoder_factory::encoder_factory(const AVCodec* codec) : avcodec_ptr(codec), info()
|
||||
{
|
||||
// Unique Id is FFmpeg name.
|
||||
info.uid = avcodec_ptr->name;
|
||||
|
||||
// Also generate a human readable name while we're at it.
|
||||
{
|
||||
std::stringstream sstr;
|
||||
if (!obsffmpeg::has_codec_handler(avcodec_ptr->name)) {
|
||||
sstr << "[UNSUPPORTED] ";
|
||||
}
|
||||
sstr << (avcodec_ptr->long_name ? avcodec_ptr->long_name : avcodec_ptr->name);
|
||||
if (avcodec_ptr->long_name) {
|
||||
sstr << " (" << avcodec_ptr->name << ")";
|
||||
}
|
||||
info.readable_name = sstr.str();
|
||||
|
||||
// Allow UI Handler to replace visible name.
|
||||
obsffmpeg::find_codec_handler(avcodec_ptr->name)
|
||||
->override_visible_name(avcodec_ptr, info.readable_name);
|
||||
}
|
||||
|
||||
// Assign Ids.
|
||||
{
|
||||
const AVCodecDescriptor* desc = avcodec_descriptor_get(avcodec_ptr->id);
|
||||
if (desc) {
|
||||
info.codec = desc->name;
|
||||
} else {
|
||||
// Fall back to encoder name in the case that FFmpeg itself doesn't know
|
||||
// what codec this actually is.
|
||||
info.codec = avcodec_ptr->name;
|
||||
}
|
||||
}
|
||||
|
||||
info.oei.id = info.uid.c_str();
|
||||
info.oei.codec = info.codec.c_str();
|
||||
|
||||
#ifndef _DEBUG
|
||||
// Is this a deprecated encoder?
|
||||
if (!obsffmpeg::has_codec_handler(avcodec_ptr->name)) {
|
||||
info.oei.caps |= OBS_ENCODER_CAP_DEPRECATED;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
obsffmpeg::encoder_factory::~encoder_factory() {}
|
||||
|
||||
void obsffmpeg::encoder_factory::register_encoder()
|
||||
{
|
||||
// Detect encoder type (only Video and Audio supported)
|
||||
if (avcodec_ptr->type == AVMediaType::AVMEDIA_TYPE_VIDEO) {
|
||||
info.oei.type = obs_encoder_type::OBS_ENCODER_VIDEO;
|
||||
} else if (avcodec_ptr->type == AVMediaType::AVMEDIA_TYPE_AUDIO) {
|
||||
info.oei.type = obs_encoder_type::OBS_ENCODER_AUDIO;
|
||||
} else {
|
||||
throw std::invalid_argument("unsupported codec type");
|
||||
}
|
||||
|
||||
// Register functions.
|
||||
info.oei.create = [](obs_data_t* settings, obs_encoder_t* encoder) {
|
||||
try {
|
||||
return reinterpret_cast<void*>(new obsffmpeg::encoder(settings, encoder));
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
return reinterpret_cast<void*>(0);
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
return reinterpret_cast<void*>(0);
|
||||
}
|
||||
};
|
||||
info.oei.destroy = [](void* ptr) {
|
||||
try {
|
||||
delete reinterpret_cast<encoder*>(ptr);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
info.oei.get_name = [](void* type_data) {
|
||||
try {
|
||||
return reinterpret_cast<encoder_factory*>(type_data)->get_name();
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
info.oei.get_defaults2 = [](obs_data_t* settings, void* type_data) {
|
||||
try {
|
||||
reinterpret_cast<encoder_factory*>(type_data)->get_defaults(settings);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
info.oei.get_properties2 = [](void* ptr, void* type_data) {
|
||||
try {
|
||||
obs_properties_t* props = obs_properties_create();
|
||||
if (type_data != nullptr) {
|
||||
reinterpret_cast<encoder_factory*>(type_data)->get_properties(props);
|
||||
}
|
||||
if (ptr != nullptr) {
|
||||
reinterpret_cast<encoder*>(ptr)->get_properties(props);
|
||||
}
|
||||
return props;
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
info.oei.update = [](void* ptr, obs_data_t* settings) {
|
||||
try {
|
||||
return reinterpret_cast<encoder*>(ptr)->update(settings);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
info.oei.get_sei_data = [](void* ptr, uint8_t** sei_data, size_t* size) {
|
||||
try {
|
||||
return reinterpret_cast<encoder*>(ptr)->get_sei_data(sei_data, size);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
info.oei.get_extra_data = [](void* ptr, uint8_t** extra_data, size_t* size) {
|
||||
try {
|
||||
return reinterpret_cast<encoder*>(ptr)->get_extra_data(extra_data, size);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
|
||||
if (avcodec_ptr->type == AVMediaType::AVMEDIA_TYPE_VIDEO) {
|
||||
info.oei.get_video_info = [](void* ptr, struct video_scale_info* info) {
|
||||
try {
|
||||
reinterpret_cast<encoder*>(ptr)->get_video_info(info);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
info.oei.encode = [](void* ptr, struct encoder_frame* frame, struct encoder_packet* packet,
|
||||
bool* received_packet) {
|
||||
try {
|
||||
return reinterpret_cast<encoder*>(ptr)->video_encode(frame, packet, received_packet);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
info.oei.encode_texture = [](void* ptr, uint32_t handle, int64_t pts, uint64_t lock_key,
|
||||
uint64_t* next_key, struct encoder_packet* packet, bool* received_packet) {
|
||||
try {
|
||||
return reinterpret_cast<encoder*>(ptr)->video_encode_texture(
|
||||
handle, pts, lock_key, next_key, packet, received_packet);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
|
||||
} else if (avcodec_ptr->type == AVMediaType::AVMEDIA_TYPE_AUDIO) {
|
||||
info.oei.get_audio_info = [](void* ptr, struct audio_convert_info* info) {
|
||||
try {
|
||||
reinterpret_cast<encoder*>(ptr)->get_audio_info(info);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
info.oei.get_frame_size = [](void* ptr) {
|
||||
try {
|
||||
return reinterpret_cast<encoder*>(ptr)->get_frame_size();
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
info.oei.encode = [](void* ptr, struct encoder_frame* frame, struct encoder_packet* packet,
|
||||
bool* received_packet) {
|
||||
try {
|
||||
return reinterpret_cast<encoder*>(ptr)->audio_encode(frame, packet, received_packet);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Finally store ourself as type data.
|
||||
info.oei.type_data = this;
|
||||
|
||||
obs_register_encoder(&info.oei);
|
||||
PLOG_DEBUG("Registered encoder #%llX with name '%s' and long name '%s' and caps %llX", avcodec_ptr,
|
||||
avcodec_ptr->name, avcodec_ptr->long_name, avcodec_ptr->capabilities);
|
||||
}
|
||||
|
||||
const char* obsffmpeg::encoder_factory::get_name()
|
||||
{
|
||||
return info.readable_name.c_str();
|
||||
}
|
||||
|
||||
void obsffmpeg::encoder_factory::get_defaults(obs_data_t* settings)
|
||||
{
|
||||
{ // Handler
|
||||
auto ptr = obsffmpeg::find_codec_handler(avcodec_ptr->name);
|
||||
if (ptr) {
|
||||
ptr->get_defaults(settings, avcodec_ptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
if ((avcodec_ptr->capabilities & AV_CODEC_CAP_INTRA_ONLY) == 0) {
|
||||
obs_data_set_default_int(settings, S_KEYFRAMES_INTERVALTYPE, 0);
|
||||
obs_data_set_default_double(settings, S_KEYFRAMES_INTERVAL_SECONDS, 2.0);
|
||||
obs_data_set_default_int(settings, S_KEYFRAMES_INTERVAL_FRAMES, 300);
|
||||
}
|
||||
|
||||
{ // Integrated Options
|
||||
// FFmpeg
|
||||
obs_data_set_default_string(settings, ST_FFMPEG_CUSTOMSETTINGS, "");
|
||||
obs_data_set_default_int(settings, ST_FFMPEG_COLORFORMAT, static_cast<int64_t>(AV_PIX_FMT_NONE));
|
||||
obs_data_set_default_int(settings, ST_FFMPEG_THREADS, 0);
|
||||
obs_data_set_default_int(settings, ST_FFMPEG_STANDARDCOMPLIANCE, FF_COMPLIANCE_STRICT);
|
||||
}
|
||||
}
|
||||
|
||||
static bool modified_keyframes(obs_properties_t* props, obs_property_t*, obs_data_t* settings)
|
||||
{
|
||||
bool is_seconds = obs_data_get_int(settings, S_KEYFRAMES_INTERVALTYPE) == 0;
|
||||
obs_property_set_visible(obs_properties_get(props, S_KEYFRAMES_INTERVAL_FRAMES), !is_seconds);
|
||||
obs_property_set_visible(obs_properties_get(props, S_KEYFRAMES_INTERVAL_SECONDS), is_seconds);
|
||||
return true;
|
||||
}
|
||||
|
||||
void obsffmpeg::encoder_factory::get_properties(obs_properties_t* props)
|
||||
{
|
||||
{ // Handler
|
||||
auto ptr = obsffmpeg::find_codec_handler(avcodec_ptr->name);
|
||||
if (ptr) {
|
||||
ptr->get_properties(props, avcodec_ptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
if ((avcodec_ptr->capabilities & AV_CODEC_CAP_INTRA_ONLY) == 0) {
|
||||
// Key-Frame Options
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, S_KEYFRAMES, TRANSLATE(S_KEYFRAMES), OBS_GROUP_NORMAL, grp);
|
||||
}
|
||||
|
||||
{
|
||||
auto p =
|
||||
obs_properties_add_list(grp, S_KEYFRAMES_INTERVALTYPE, TRANSLATE(S_KEYFRAMES_INTERVALTYPE),
|
||||
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(S_KEYFRAMES_INTERVALTYPE)));
|
||||
obs_property_set_modified_callback(p, modified_keyframes);
|
||||
obs_property_list_add_int(p, TRANSLATE(S_KEYFRAMES_INTERVALTYPE_(Seconds)), 0);
|
||||
obs_property_list_add_int(p, TRANSLATE(S_KEYFRAMES_INTERVALTYPE_(Frames)), 1);
|
||||
}
|
||||
{
|
||||
auto p =
|
||||
obs_properties_add_float(grp, S_KEYFRAMES_INTERVAL_SECONDS, TRANSLATE(S_KEYFRAMES_INTERVAL),
|
||||
0.00, std::numeric_limits<int16_t>::max(), 0.01);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(S_KEYFRAMES_INTERVAL)));
|
||||
obs_property_float_set_suffix(p, " seconds");
|
||||
}
|
||||
{
|
||||
auto p =
|
||||
obs_properties_add_int(grp, S_KEYFRAMES_INTERVAL_FRAMES, TRANSLATE(S_KEYFRAMES_INTERVAL), 0,
|
||||
std::numeric_limits<int32_t>::max(), 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(S_KEYFRAMES_INTERVAL)));
|
||||
obs_property_int_set_suffix(p, " frames");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
auto prs = obs_properties_create();
|
||||
obs_properties_add_group(props, ST_FFMPEG, TRANSLATE(ST_FFMPEG), OBS_GROUP_NORMAL, prs);
|
||||
grp = prs;
|
||||
}
|
||||
|
||||
{
|
||||
auto p =
|
||||
obs_properties_add_text(grp, ST_FFMPEG_CUSTOMSETTINGS, TRANSLATE(ST_FFMPEG_CUSTOMSETTINGS),
|
||||
obs_text_type::OBS_TEXT_DEFAULT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_FFMPEG_CUSTOMSETTINGS)));
|
||||
}
|
||||
if (avcodec_ptr->pix_fmts) {
|
||||
auto p = obs_properties_add_list(grp, ST_FFMPEG_COLORFORMAT, TRANSLATE(ST_FFMPEG_COLORFORMAT),
|
||||
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_FFMPEG_COLORFORMAT)));
|
||||
obs_property_list_add_int(p, TRANSLATE(S_STATE_AUTOMATIC),
|
||||
static_cast<int64_t>(AV_PIX_FMT_NONE));
|
||||
for (auto ptr = avcodec_ptr->pix_fmts; *ptr != AV_PIX_FMT_NONE; ptr++) {
|
||||
obs_property_list_add_int(p, ffmpeg::tools::get_pixel_format_name(*ptr),
|
||||
static_cast<int64_t>(*ptr));
|
||||
}
|
||||
}
|
||||
if (avcodec_ptr->capabilities & (AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS)) {
|
||||
auto p = obs_properties_add_int_slider(grp, ST_FFMPEG_THREADS, TRANSLATE(ST_FFMPEG_THREADS), 0,
|
||||
std::thread::hardware_concurrency() * 2, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_FFMPEG_THREADS)));
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_list(grp, ST_FFMPEG_STANDARDCOMPLIANCE,
|
||||
TRANSLATE(ST_FFMPEG_STANDARDCOMPLIANCE), OBS_COMBO_TYPE_LIST,
|
||||
OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_FFMPEG_STANDARDCOMPLIANCE)));
|
||||
obs_property_list_add_int(p, TRANSLATE(ST_FFMPEG_STANDARDCOMPLIANCE ".VeryStrict"),
|
||||
FF_COMPLIANCE_VERY_STRICT);
|
||||
obs_property_list_add_int(p, TRANSLATE(ST_FFMPEG_STANDARDCOMPLIANCE ".Strict"),
|
||||
FF_COMPLIANCE_STRICT);
|
||||
obs_property_list_add_int(p, TRANSLATE(ST_FFMPEG_STANDARDCOMPLIANCE ".Normal"),
|
||||
FF_COMPLIANCE_NORMAL);
|
||||
obs_property_list_add_int(p, TRANSLATE(ST_FFMPEG_STANDARDCOMPLIANCE ".Unofficial"),
|
||||
FF_COMPLIANCE_UNOFFICIAL);
|
||||
obs_property_list_add_int(p, TRANSLATE(ST_FFMPEG_STANDARDCOMPLIANCE ".Experimental"),
|
||||
FF_COMPLIANCE_EXPERIMENTAL);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const AVCodec* obsffmpeg::encoder_factory::get_avcodec()
|
||||
{
|
||||
return avcodec_ptr;
|
||||
}
|
||||
|
||||
obsffmpeg::encoder::encoder(obs_data_t* settings, obs_encoder_t* encoder)
|
||||
: _self(encoder), _lag_in_frames(0), _count_send_frames(0), _have_first_frame(false), _initialized(false)
|
||||
{
|
||||
_factory = reinterpret_cast<encoder_factory*>(obs_encoder_get_type_data(_self));
|
||||
|
||||
// Verify that the codec actually still exists.
|
||||
_codec = avcodec_find_encoder_by_name(_factory->get_avcodec()->name);
|
||||
if (!_codec) {
|
||||
PLOG_ERROR("Failed to find encoder for codec '%s'.", _factory->get_avcodec()->name);
|
||||
throw std::runtime_error("failed to find codec");
|
||||
}
|
||||
|
||||
// Initialize context.
|
||||
_context = avcodec_alloc_context3(_codec);
|
||||
if (!_context) {
|
||||
PLOG_ERROR("Failed to create context for encoder '%s'.", _codec->name);
|
||||
throw std::runtime_error("failed to create context");
|
||||
}
|
||||
|
||||
// Settings
|
||||
/// Rate Control
|
||||
_context->strict_std_compliance = static_cast<int>(obs_data_get_int(settings, ST_FFMPEG_STANDARDCOMPLIANCE));
|
||||
_context->debug = 0;
|
||||
/// Threading
|
||||
if (_codec->capabilities
|
||||
& (AV_CODEC_CAP_AUTO_THREADS | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS)) {
|
||||
if (_codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) {
|
||||
_context->thread_type |= FF_THREAD_FRAME;
|
||||
}
|
||||
if (_codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) {
|
||||
_context->thread_type |= FF_THREAD_SLICE;
|
||||
}
|
||||
int64_t threads = obs_data_get_int(settings, ST_FFMPEG_THREADS);
|
||||
if (threads > 0) {
|
||||
_context->thread_count = static_cast<int>(threads);
|
||||
_lag_in_frames = _context->thread_count;
|
||||
} else {
|
||||
_context->thread_count = std::thread::hardware_concurrency();
|
||||
_lag_in_frames = _context->thread_count;
|
||||
}
|
||||
}
|
||||
|
||||
// Update settings
|
||||
update(settings);
|
||||
|
||||
av_init_packet(&_current_packet);
|
||||
av_new_packet(&_current_packet, 8 * 1024 * 1024); // 8 MB precached Packet size.
|
||||
}
|
||||
|
||||
obsffmpeg::encoder::~encoder()
|
||||
{
|
||||
if (_context) {
|
||||
// Flush encoders that require it.
|
||||
if ((_codec->capabilities & AV_CODEC_CAP_DELAY) != 0) {
|
||||
avcodec_send_frame(_context, nullptr);
|
||||
while (avcodec_receive_packet(_context, &_current_packet) >= 0) {
|
||||
avcodec_send_frame(_context, nullptr);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
}
|
||||
|
||||
// Close and free context.
|
||||
avcodec_close(_context);
|
||||
avcodec_free_context(&_context);
|
||||
}
|
||||
|
||||
av_packet_unref(&_current_packet);
|
||||
|
||||
_frame_queue.clear();
|
||||
_frame_queue_used.clear();
|
||||
_swscale.finalize();
|
||||
}
|
||||
|
||||
bool obsffmpeg::encoder::initialize()
|
||||
{
|
||||
if (_initialized)
|
||||
return true;
|
||||
|
||||
// Detect supported
|
||||
bool is_format_supported = false;
|
||||
for (auto ptr = _codec->pix_fmts; *ptr != AV_PIX_FMT_NONE; ptr++) {
|
||||
if (*ptr == _format) {
|
||||
is_format_supported = true;
|
||||
}
|
||||
}
|
||||
if (!is_format_supported) {
|
||||
std::stringstream sstr;
|
||||
sstr << "The color format " << ffmpeg::tools::get_pixel_format_name(_format)
|
||||
<< " is not supported by the encoder.";
|
||||
throw std::exception(sstr.str().c_str());
|
||||
}
|
||||
|
||||
if (_codec->type == AVMEDIA_TYPE_VIDEO) {
|
||||
auto encvideo = obs_encoder_video(_self);
|
||||
auto voi = video_output_get_info(encvideo);
|
||||
|
||||
// Set Resolution
|
||||
_context->width = static_cast<int>(_resolution.first);
|
||||
_context->height = static_cast<int>(_resolution.second);
|
||||
|
||||
// Set Color Space, Format and Range
|
||||
_context->colorspace = ffmpeg::tools::obs_videocolorspace_to_avcolorspace(voi->colorspace);
|
||||
_context->color_range = ffmpeg::tools::obs_videorangetype_to_avcolorrange(voi->range);
|
||||
_context->pix_fmt = _format;
|
||||
|
||||
// Set Framerate and Field Order
|
||||
_context->field_order = AV_FIELD_PROGRESSIVE;
|
||||
_context->time_base.num = voi->fps_den;
|
||||
_context->time_base.den = voi->fps_num;
|
||||
_context->ticks_per_frame = 1;
|
||||
}
|
||||
|
||||
// Initialize
|
||||
int res = avcodec_open2(_context, _codec, NULL);
|
||||
if (res < 0) {
|
||||
std::stringstream sstr;
|
||||
sstr << "Failed to initalized encoder '" << _codec->name
|
||||
<< "' due to error: " << ffmpeg::tools::get_error_description(res) << "(" << res
|
||||
<< ")";
|
||||
throw std::runtime_error(sstr.str().c_str());
|
||||
}
|
||||
|
||||
// Initialize Scaler and Frame Queue
|
||||
if (_codec->type == AVMEDIA_TYPE_VIDEO) {
|
||||
_swscale.set_source_format(_format);
|
||||
_swscale.set_target_format(_context->pix_fmt);
|
||||
_swscale.set_target_size(_context->width, _context->height);
|
||||
_swscale.set_source_size(_context->width, _context->height);
|
||||
_swscale.set_target_size(_context->width, _context->height);
|
||||
_swscale.set_source_color(_context->color_range, _context->colorspace);
|
||||
_swscale.set_target_color(_context->color_range, _context->colorspace);
|
||||
|
||||
// Create Scaler
|
||||
if (!_swscale.initialize(SWS_FAST_BILINEAR)) {
|
||||
std::stringstream sstr;
|
||||
sstr << "Failed to initialize frame scaler for pixel format '"
|
||||
<< ffmpeg::tools::get_pixel_format_name(_context->pix_fmt) << "' with color space '"
|
||||
<< ffmpeg::tools::get_color_space_name(_context->colorspace) << "' and "
|
||||
<< (_swscale.is_source_full_range() ? "full" : "partial") << " color range.";
|
||||
throw std::runtime_error(sstr.str().c_str());
|
||||
}
|
||||
|
||||
// Create Frame queue
|
||||
_frame_queue.set_pixel_format(_context->pix_fmt);
|
||||
_frame_queue.set_resolution(_context->width, _context->height);
|
||||
_frame_queue.precache(2);
|
||||
}
|
||||
|
||||
_initialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void obsffmpeg::encoder::get_properties(obs_properties_t* props)
|
||||
{
|
||||
{ // Handler
|
||||
auto ptr = obsffmpeg::find_codec_handler(_codec->name);
|
||||
if (ptr) {
|
||||
ptr->get_properties(props, _codec, _context);
|
||||
}
|
||||
}
|
||||
|
||||
obs_property_set_enabled(obs_properties_get(props, S_KEYFRAMES), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, S_KEYFRAMES_INTERVALTYPE), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, S_KEYFRAMES_INTERVAL_SECONDS), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, S_KEYFRAMES_INTERVAL_FRAMES), false);
|
||||
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_FFMPEG_COLORFORMAT), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_FFMPEG_THREADS), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, ST_FFMPEG_STANDARDCOMPLIANCE), false);
|
||||
}
|
||||
|
||||
bool obsffmpeg::encoder::update(obs_data_t* settings)
|
||||
{
|
||||
{ // Handler
|
||||
auto ptr = obsffmpeg::find_codec_handler(_codec->name);
|
||||
if (ptr) {
|
||||
ptr->update(settings, _codec, _context);
|
||||
}
|
||||
}
|
||||
|
||||
if ((_codec->capabilities & AV_CODEC_CAP_INTRA_ONLY) == 0) {
|
||||
// Key-Frame Options
|
||||
obs_video_info ovi;
|
||||
if (!obs_get_video_info(&ovi)) {
|
||||
throw std::runtime_error("no video info");
|
||||
}
|
||||
|
||||
int64_t kf_type = obs_data_get_int(settings, S_KEYFRAMES_INTERVALTYPE);
|
||||
bool is_seconds = (kf_type == 0);
|
||||
|
||||
if (is_seconds) {
|
||||
_context->gop_size = static_cast<int>(
|
||||
obs_data_get_double(settings, S_KEYFRAMES_INTERVAL_SECONDS) * (ovi.fps_num / ovi.fps_den));
|
||||
} else {
|
||||
_context->gop_size = static_cast<int>(obs_data_get_int(settings, S_KEYFRAMES_INTERVAL_FRAMES));
|
||||
}
|
||||
_context->keyint_min = _context->gop_size;
|
||||
}
|
||||
|
||||
{ // FFmpeg
|
||||
// Apply custom options.
|
||||
av_opt_set_from_string(_context->priv_data, obs_data_get_string(settings, ST_FFMPEG_CUSTOMSETTINGS),
|
||||
nullptr, "=", ";");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void obsffmpeg::encoder::get_audio_info(audio_convert_info*) {}
|
||||
|
||||
size_t obsffmpeg::encoder::get_frame_size()
|
||||
{
|
||||
return size_t();
|
||||
}
|
||||
|
||||
bool obsffmpeg::encoder::audio_encode(encoder_frame*, encoder_packet*, bool*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void obsffmpeg::encoder::get_video_info(video_scale_info* vsi)
|
||||
{
|
||||
obs_data_t* settings = obs_encoder_get_settings(_self);
|
||||
|
||||
AVPixelFormat avformat = static_cast<AVPixelFormat>(obs_data_get_int(settings, ST_FFMPEG_COLORFORMAT));
|
||||
video_format obsformat = ffmpeg::tools::avpixelformat_to_obs_videoformat(avformat);
|
||||
|
||||
if (obsformat != VIDEO_FORMAT_NONE) {
|
||||
vsi->format = obsformat;
|
||||
}
|
||||
|
||||
_resolution.first = vsi->width;
|
||||
_resolution.second = vsi->height;
|
||||
_format = ffmpeg::tools::obs_videoformat_to_avpixelformat(vsi->format);
|
||||
}
|
||||
|
||||
bool obsffmpeg::encoder::get_sei_data(uint8_t** data, size_t* size)
|
||||
{
|
||||
if (_sei_data.size() == 0)
|
||||
return false;
|
||||
|
||||
*data = _sei_data.data();
|
||||
*size = _sei_data.size();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool obsffmpeg::encoder::get_extra_data(uint8_t** data, size_t* size)
|
||||
{
|
||||
if (_extra_data.size() == 0)
|
||||
return false;
|
||||
|
||||
*data = _extra_data.data();
|
||||
*size = _extra_data.size();
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void copy_data(encoder_frame* frame, AVFrame* vframe)
|
||||
{
|
||||
int h_chroma_shift, v_chroma_shift;
|
||||
av_pix_fmt_get_chroma_sub_sample(static_cast<AVPixelFormat>(vframe->format), &h_chroma_shift, &v_chroma_shift);
|
||||
|
||||
for (size_t idx = 0; idx < MAX_AV_PLANES; idx++) {
|
||||
if (!frame->data[idx] || !vframe->data[idx])
|
||||
continue;
|
||||
|
||||
size_t plane_height = vframe->height >> (idx ? v_chroma_shift : 0);
|
||||
|
||||
if (static_cast<uint32_t>(vframe->linesize[idx]) == frame->linesize[idx]) {
|
||||
std::memcpy(vframe->data[idx], frame->data[idx], frame->linesize[idx] * plane_height);
|
||||
} else {
|
||||
size_t ls_in = frame->linesize[idx];
|
||||
size_t ls_out = vframe->linesize[idx];
|
||||
size_t bytes = ls_in < ls_out ? ls_in : ls_out;
|
||||
|
||||
uint8_t* to = vframe->data[idx];
|
||||
uint8_t* from = frame->data[idx];
|
||||
|
||||
for (size_t y = 0; y < plane_height; y++) {
|
||||
std::memcpy(to, from, bytes);
|
||||
to += ls_out;
|
||||
from += ls_in;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool obsffmpeg::encoder::video_encode(encoder_frame* frame, encoder_packet* packet, bool* received_packet)
|
||||
{
|
||||
// Ensure that the encoder was initialized.
|
||||
try {
|
||||
if (!initialize())
|
||||
return false;
|
||||
} catch (std::exception& ex) {
|
||||
PLOG_ERROR("%s", ex.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert frame.
|
||||
std::shared_ptr<AVFrame> vframe = _frame_queue.pop(); // Retrieve an empty frame.
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
ScopeProfiler profile("convert");
|
||||
#endif
|
||||
|
||||
vframe->height = _context->height;
|
||||
vframe->format = _context->pix_fmt;
|
||||
vframe->color_range = _context->color_range;
|
||||
vframe->colorspace = _context->colorspace;
|
||||
vframe->pts = frame->pts;
|
||||
|
||||
if ((_swscale.is_source_full_range() == _swscale.is_target_full_range())
|
||||
&& (_swscale.get_source_colorspace() == _swscale.get_target_colorspace())
|
||||
&& (_swscale.get_source_format() == _swscale.get_target_format())) {
|
||||
copy_data(frame, vframe.get());
|
||||
} else {
|
||||
int res = _swscale.convert(reinterpret_cast<uint8_t**>(frame->data),
|
||||
reinterpret_cast<int*>(frame->linesize), 0, _context->height,
|
||||
vframe->data, vframe->linesize);
|
||||
if (res <= 0) {
|
||||
PLOG_ERROR("Failed to convert frame: %s (%ld).",
|
||||
ffmpeg::tools::get_error_description(res), res);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send and receive frames.
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
ScopeProfiler profile("loop");
|
||||
#endif
|
||||
|
||||
bool sent_frame = false;
|
||||
bool recv_packet = false;
|
||||
bool should_lag = (_lag_in_frames - _count_send_frames) <= 0;
|
||||
|
||||
auto loop_begin = std::chrono::high_resolution_clock::now();
|
||||
auto loop_end = loop_begin + std::chrono::milliseconds(50);
|
||||
|
||||
while ((!sent_frame || (should_lag && !recv_packet))
|
||||
&& !(std::chrono::high_resolution_clock::now() > loop_end)) {
|
||||
bool eagain_is_stupid = false;
|
||||
|
||||
if (!sent_frame) {
|
||||
#ifdef _DEBUG
|
||||
ScopeProfiler profile_inner("send");
|
||||
#endif
|
||||
int res = send_frame(vframe);
|
||||
switch (res) {
|
||||
case 0:
|
||||
sent_frame = true;
|
||||
vframe = nullptr;
|
||||
break;
|
||||
case AVERROR(EAGAIN):
|
||||
// This means we should call receive_packet again, but what do we do with that data?
|
||||
// Why can't we queue on both? Do I really have to implement threading for this stuff?
|
||||
if (*received_packet == true) {
|
||||
PLOG_WARNING(
|
||||
"Skipped frame due to EAGAIN when a packet was already returned.");
|
||||
sent_frame = true;
|
||||
}
|
||||
eagain_is_stupid = true;
|
||||
break;
|
||||
case AVERROR(EOF):
|
||||
PLOG_ERROR("Skipped frame due to end of stream.");
|
||||
sent_frame = true;
|
||||
break;
|
||||
default:
|
||||
PLOG_ERROR("Failed to encode frame: %s (%ld).",
|
||||
ffmpeg::tools::get_error_description(res), res);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!recv_packet) {
|
||||
#ifdef _DEBUG
|
||||
ScopeProfiler profile_inner("recieve");
|
||||
#endif
|
||||
int res = receive_packet(received_packet, packet);
|
||||
switch (res) {
|
||||
case 0:
|
||||
recv_packet = true;
|
||||
break;
|
||||
case AVERROR(EOF):
|
||||
PLOG_ERROR("Received end of file.");
|
||||
recv_packet = true;
|
||||
break;
|
||||
case AVERROR(EAGAIN):
|
||||
if (sent_frame) {
|
||||
recv_packet = true;
|
||||
}
|
||||
if (eagain_is_stupid) {
|
||||
PLOG_ERROR("Both send and recieve returned EAGAIN, encoder is broken.");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
PLOG_ERROR("Failed to receive packet: %s (%ld).",
|
||||
ffmpeg::tools::get_error_description(res), res);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!sent_frame || !recv_packet) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vframe != nullptr) {
|
||||
_frame_queue.push(vframe);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool obsffmpeg::encoder::video_encode_texture(uint32_t, int64_t, uint64_t, uint64_t*, encoder_packet*, bool*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int obsffmpeg::encoder::receive_packet(bool* received_packet, struct encoder_packet* packet)
|
||||
{
|
||||
int res = avcodec_receive_packet(_context, &_current_packet);
|
||||
if (res == 0) {
|
||||
if (!_have_first_frame) {
|
||||
if (_codec->id == AV_CODEC_ID_H264) {
|
||||
uint8_t* tmp_packet;
|
||||
uint8_t* tmp_header;
|
||||
uint8_t* tmp_sei;
|
||||
size_t sz_packet, sz_header, sz_sei;
|
||||
|
||||
obs_extract_avc_headers(_current_packet.data, _current_packet.size, &tmp_packet,
|
||||
&sz_packet, &tmp_header, &sz_header, &tmp_sei, &sz_sei);
|
||||
|
||||
if (sz_header) {
|
||||
_extra_data.resize(sz_header);
|
||||
std::memcpy(_extra_data.data(), tmp_header, sz_header);
|
||||
}
|
||||
|
||||
if (sz_sei) {
|
||||
_sei_data.resize(sz_sei);
|
||||
std::memcpy(_sei_data.data(), tmp_sei, sz_sei);
|
||||
}
|
||||
|
||||
std::memcpy(_current_packet.data, tmp_packet, sz_packet);
|
||||
_current_packet.size = static_cast<int>(sz_packet);
|
||||
|
||||
bfree(tmp_packet);
|
||||
bfree(tmp_header);
|
||||
bfree(tmp_sei);
|
||||
} else if (_codec->id == AV_CODEC_ID_HEVC) {
|
||||
obsffmpeg::codecs::hevc::extract_header_sei(_current_packet.data, _current_packet.size,
|
||||
_extra_data, _sei_data);
|
||||
}
|
||||
_have_first_frame = true;
|
||||
}
|
||||
|
||||
packet->type = OBS_ENCODER_VIDEO;
|
||||
packet->pts = _current_packet.pts;
|
||||
packet->dts = _current_packet.dts;
|
||||
packet->data = _current_packet.data;
|
||||
packet->size = _current_packet.size;
|
||||
packet->keyframe = !!(_current_packet.flags & AV_PKT_FLAG_KEY);
|
||||
packet->drop_priority = packet->keyframe ? 0 : 1;
|
||||
*received_packet = true;
|
||||
|
||||
{
|
||||
std::shared_ptr<AVFrame> uframe = _frame_queue_used.pop_only();
|
||||
_frame_queue.push(uframe);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int obsffmpeg::encoder::send_frame(std::shared_ptr<AVFrame> const frame)
|
||||
{
|
||||
int res = avcodec_send_frame(_context, frame.get());
|
||||
switch (res) {
|
||||
case 0:
|
||||
_frame_queue_used.push(frame);
|
||||
_count_send_frames++;
|
||||
case AVERROR(EAGAIN):
|
||||
case AVERROR(EOF):
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
+78
-103
@@ -19,131 +19,106 @@
|
||||
// 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 <thread>
|
||||
#include "ffmpeg/avframe-queue.hpp"
|
||||
#include "ffmpeg/swscale.hpp"
|
||||
|
||||
#include <obs.h>
|
||||
|
||||
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;
|
||||
class encoder_factory {
|
||||
struct info {
|
||||
std::string uid;
|
||||
std::string codec;
|
||||
std::string readable_name;
|
||||
obs_encoder_info oei;
|
||||
} info;
|
||||
const AVCodec* avcodec_ptr;
|
||||
|
||||
AVCodec* avcodec = nullptr;
|
||||
AVCodecContext* avcontext = nullptr;
|
||||
AVDictionary* avdictionary = nullptr;
|
||||
ffmpeg::swscale swscale;
|
||||
public:
|
||||
encoder_factory(const AVCodec* codec);
|
||||
virtual ~encoder_factory();
|
||||
|
||||
std::pair<uint32_t, uint32_t> resolution;
|
||||
std::pair<uint32_t, uint32_t> framerate;
|
||||
void register_encoder();
|
||||
|
||||
AVPixelFormat source_format;
|
||||
AVColorSpace source_colorspace;
|
||||
AVColorRange source_range;
|
||||
const char* get_name();
|
||||
|
||||
AVPixelFormat target_format;
|
||||
AVColorSpace target_colorspace;
|
||||
AVColorRange target_range;
|
||||
void get_defaults(obs_data_t* settings);
|
||||
|
||||
public:
|
||||
virtual ~base();
|
||||
void get_properties(obs_properties_t* props);
|
||||
|
||||
virtual void get_properties(obs_properties_t* props) = 0;
|
||||
const AVCodec* get_avcodec();
|
||||
};
|
||||
|
||||
virtual bool update(obs_data_t* settings) = 0;
|
||||
class encoder {
|
||||
obs_encoder_t* _self;
|
||||
encoder_factory* _factory;
|
||||
|
||||
virtual bool get_extra_data(uint8_t** extra_data, size_t* size) = 0;
|
||||
const AVCodec* _codec;
|
||||
AVCodecContext* _context;
|
||||
|
||||
virtual bool get_sei_data(uint8_t** sei_data, size_t* size) = 0;
|
||||
bool _initialized;
|
||||
std::pair<size_t, size_t> _resolution;
|
||||
AVPixelFormat _format;
|
||||
|
||||
virtual void get_video_info(struct video_scale_info* info) = 0;
|
||||
ffmpeg::avframe_queue _frame_queue;
|
||||
ffmpeg::avframe_queue _frame_queue_used;
|
||||
ffmpeg::swscale _swscale;
|
||||
AVPacket _current_packet;
|
||||
|
||||
virtual bool encode(struct encoder_frame* frame, struct encoder_packet* packet,
|
||||
bool* received_packet) = 0;
|
||||
};
|
||||
int64_t _lag_in_frames;
|
||||
int64_t _count_send_frames;
|
||||
|
||||
#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 = OBS_ENCODER_CAP_DEPRECATED; \
|
||||
_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)); \
|
||||
}
|
||||
//*/
|
||||
// Extra Data
|
||||
bool _have_first_frame;
|
||||
std::vector<uint8_t> _extra_data;
|
||||
std::vector<uint8_t> _sei_data;
|
||||
|
||||
} // namespace encoder
|
||||
public:
|
||||
encoder(obs_data_t* settings, obs_encoder_t* encoder);
|
||||
virtual ~encoder();
|
||||
|
||||
bool initialize();
|
||||
|
||||
public: // OBS API
|
||||
// Shared
|
||||
void get_properties(obs_properties_t* props);
|
||||
|
||||
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);
|
||||
};
|
||||
} // namespace obsffmpeg
|
||||
|
||||
#endif OBS_FFMPEG_ENCODER_HPP
|
||||
|
||||
@@ -1,818 +0,0 @@
|
||||
// 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 "generic.hpp"
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#include <util/profiler.hpp>
|
||||
#include "ffmpeg/tools.hpp"
|
||||
#include "plugin.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <obs-module.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#include <libavutil/dict.h>
|
||||
#include <libavutil/frame.h>
|
||||
#include <libavutil/opt.h>
|
||||
#include <libavutil/pixdesc.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
// Generic
|
||||
#define P_AUTOMATIC "Automatic"
|
||||
|
||||
// FFmpeg
|
||||
#define P_FFMPEG "FFmpeg"
|
||||
#define P_FFMPEG_CUSTOMSETTINGS "FFmpeg.CustomSettings"
|
||||
#define P_FFMPEG_THREADS "FFmpeg.Threads"
|
||||
#define P_FFMPEG_COLORFORMAT "FFmpeg.ColorFormat"
|
||||
#define P_FFMPEG_STANDARDCOMPLIANCE "FFmpeg.StandardCompliance"
|
||||
|
||||
enum class keyframe_type { Seconds, Frames };
|
||||
|
||||
encoder::generic_factory::generic_factory(AVCodec* codec) : avcodec_ptr(codec), info() {}
|
||||
|
||||
encoder::generic_factory::~generic_factory() {}
|
||||
|
||||
void encoder::generic_factory::register_encoder()
|
||||
{
|
||||
// Generate unique name from given Id
|
||||
{
|
||||
std::stringstream sstr;
|
||||
sstr << "ffmpeg-" << avcodec_ptr->name << "-0x" << std::uppercase << std::setfill('0') << std::setw(8)
|
||||
<< std::hex << avcodec_ptr->capabilities;
|
||||
this->info.uid = sstr.str();
|
||||
}
|
||||
|
||||
// Also generate a human readable name while we're at it.
|
||||
// TODO: Figure out a way to translate from names to other names.
|
||||
{
|
||||
std::stringstream sstr;
|
||||
sstr << (avcodec_ptr->long_name ? avcodec_ptr->long_name : avcodec_ptr->name) << " ("
|
||||
<< avcodec_ptr->name << ")";
|
||||
std::string caps = ffmpeg::tools::translate_encoder_capabilities(avcodec_ptr->capabilities);
|
||||
if (caps.length() != 0) {
|
||||
sstr << " [" << caps << "]";
|
||||
}
|
||||
this->info.readable_name = sstr.str();
|
||||
}
|
||||
|
||||
// Assign Ids.
|
||||
{
|
||||
const AVCodecDescriptor* desc = avcodec_descriptor_get(this->avcodec_ptr->id);
|
||||
if (desc) {
|
||||
this->info.codec = desc->name;
|
||||
} else {
|
||||
this->info.codec = avcodec_ptr->name;
|
||||
}
|
||||
}
|
||||
this->info.oei.id = this->info.uid.c_str();
|
||||
this->info.oei.codec = this->info.codec.c_str();
|
||||
|
||||
// Is this a deprecated encoder?
|
||||
#ifndef _DEBUG
|
||||
if (!obsffmpeg::has_codec_handler(avcodec_ptr->name)) {
|
||||
this->info.oei.caps |= OBS_ENCODER_CAP_DEPRECATED;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Detect encoder type (only Video and Audio supported)
|
||||
if (avcodec_ptr->type == AVMediaType::AVMEDIA_TYPE_VIDEO) {
|
||||
this->info.oei.type = obs_encoder_type::OBS_ENCODER_VIDEO;
|
||||
} else if (avcodec_ptr->type == AVMediaType::AVMEDIA_TYPE_AUDIO) {
|
||||
this->info.oei.type = obs_encoder_type::OBS_ENCODER_AUDIO;
|
||||
} else {
|
||||
throw std::invalid_argument("unsupported codec type");
|
||||
}
|
||||
|
||||
// Register functions.
|
||||
this->info.oei.create = [](obs_data_t* settings, obs_encoder_t* encoder) {
|
||||
try {
|
||||
return reinterpret_cast<void*>(new generic(settings, encoder));
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
return reinterpret_cast<void*>(0);
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
return reinterpret_cast<void*>(0);
|
||||
}
|
||||
};
|
||||
this->info.oei.destroy = [](void* ptr) {
|
||||
try {
|
||||
delete reinterpret_cast<generic*>(ptr);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
this->info.oei.get_name = [](void* type_data) {
|
||||
try {
|
||||
return reinterpret_cast<generic_factory*>(type_data)->get_name();
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
this->info.oei.get_defaults2 = [](obs_data_t* settings, void* type_data) {
|
||||
try {
|
||||
reinterpret_cast<generic_factory*>(type_data)->get_defaults(settings);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
this->info.oei.get_properties2 = [](void* ptr, void* type_data) {
|
||||
try {
|
||||
obs_properties_t* props = obs_properties_create();
|
||||
if (type_data != nullptr) {
|
||||
reinterpret_cast<generic_factory*>(type_data)->get_properties(props);
|
||||
}
|
||||
if (ptr != nullptr) {
|
||||
reinterpret_cast<generic*>(ptr)->get_properties(props);
|
||||
}
|
||||
return props;
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
this->info.oei.update = [](void* ptr, obs_data_t* settings) {
|
||||
try {
|
||||
return reinterpret_cast<generic*>(ptr)->update(settings);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
this->info.oei.get_sei_data = [](void* ptr, uint8_t** sei_data, size_t* size) {
|
||||
try {
|
||||
return reinterpret_cast<generic*>(ptr)->get_sei_data(sei_data, size);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
this->info.oei.get_extra_data = [](void* ptr, uint8_t** extra_data, size_t* size) {
|
||||
try {
|
||||
return reinterpret_cast<generic*>(ptr)->get_extra_data(extra_data, size);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
|
||||
if (this->avcodec_ptr->type == AVMediaType::AVMEDIA_TYPE_VIDEO) {
|
||||
this->info.oei.get_video_info = [](void* ptr, struct video_scale_info* info) {
|
||||
try {
|
||||
reinterpret_cast<generic*>(ptr)->get_video_info(info);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
this->info.oei.encode = [](void* ptr, struct encoder_frame* frame, struct encoder_packet* packet,
|
||||
bool* received_packet) {
|
||||
try {
|
||||
return reinterpret_cast<generic*>(ptr)->video_encode(frame, packet, received_packet);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
this->info.oei.encode_texture = [](void* ptr, uint32_t handle, int64_t pts, uint64_t lock_key,
|
||||
uint64_t* next_key, struct encoder_packet* packet,
|
||||
bool* received_packet) {
|
||||
try {
|
||||
return reinterpret_cast<generic*>(ptr)->video_encode_texture(
|
||||
handle, pts, lock_key, next_key, packet, received_packet);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
|
||||
} else if (this->avcodec_ptr->type == AVMediaType::AVMEDIA_TYPE_AUDIO) {
|
||||
this->info.oei.get_audio_info = [](void* ptr, struct audio_convert_info* info) {
|
||||
try {
|
||||
reinterpret_cast<generic*>(ptr)->get_audio_info(info);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
this->info.oei.get_frame_size = [](void* ptr) {
|
||||
try {
|
||||
return reinterpret_cast<generic*>(ptr)->get_frame_size();
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
this->info.oei.encode = [](void* ptr, struct encoder_frame* frame, struct encoder_packet* packet,
|
||||
bool* received_packet) {
|
||||
try {
|
||||
return reinterpret_cast<generic*>(ptr)->audio_encode(frame, packet, received_packet);
|
||||
} catch (std::exception const& e) {
|
||||
PLOG_ERROR("exception: %s", e.what());
|
||||
throw e;
|
||||
} catch (...) {
|
||||
PLOG_ERROR("unknown exception");
|
||||
throw;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Finally store ourself as type data.
|
||||
this->info.oei.type_data = this;
|
||||
|
||||
obs_register_encoder(&this->info.oei);
|
||||
PLOG_DEBUG("Registered encoder #%llX with name '%s' and long name '%s' and caps %llX", avcodec_ptr,
|
||||
avcodec_ptr->name, avcodec_ptr->long_name, avcodec_ptr->capabilities);
|
||||
}
|
||||
|
||||
const char* encoder::generic_factory::get_name()
|
||||
{
|
||||
return this->info.readable_name.c_str();
|
||||
}
|
||||
|
||||
void encoder::generic_factory::get_defaults(obs_data_t* settings)
|
||||
{
|
||||
{ // Handler
|
||||
auto ptr = obsffmpeg::find_codec_handler(this->avcodec_ptr->name);
|
||||
if (ptr) {
|
||||
ptr->get_defaults(settings, this->avcodec_ptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
{ // Integrated Options
|
||||
// FFmpeg
|
||||
obs_data_set_default_string(settings, P_FFMPEG_CUSTOMSETTINGS, "");
|
||||
obs_data_set_default_int(settings, P_FFMPEG_COLORFORMAT, static_cast<int64_t>(AV_PIX_FMT_NONE));
|
||||
obs_data_set_default_int(settings, P_FFMPEG_THREADS, 0);
|
||||
obs_data_set_default_int(settings, P_FFMPEG_STANDARDCOMPLIANCE, FF_COMPLIANCE_STRICT);
|
||||
}
|
||||
}
|
||||
|
||||
void encoder::generic_factory::get_properties(obs_properties_t* props)
|
||||
{
|
||||
{ // Handler
|
||||
auto ptr = obsffmpeg::find_codec_handler(this->avcodec_ptr->name);
|
||||
if (ptr) {
|
||||
ptr->get_properties(props, this->avcodec_ptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
auto prs = obs_properties_create();
|
||||
obs_properties_add_group(props, P_FFMPEG, TRANSLATE(P_FFMPEG), OBS_GROUP_NORMAL, prs);
|
||||
}
|
||||
|
||||
{
|
||||
auto p =
|
||||
obs_properties_add_text(grp, P_FFMPEG_CUSTOMSETTINGS, TRANSLATE(P_FFMPEG_CUSTOMSETTINGS),
|
||||
obs_text_type::OBS_TEXT_DEFAULT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_FFMPEG_CUSTOMSETTINGS)));
|
||||
}
|
||||
if (this->avcodec_ptr->pix_fmts) {
|
||||
auto p = obs_properties_add_list(grp, P_FFMPEG_COLORFORMAT, TRANSLATE(P_FFMPEG_COLORFORMAT),
|
||||
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_FFMPEG_COLORFORMAT)));
|
||||
obs_property_list_add_int(p, TRANSLATE(P_AUTOMATIC), static_cast<int64_t>(AV_PIX_FMT_NONE));
|
||||
for (auto ptr = this->avcodec_ptr->pix_fmts; *ptr != AV_PIX_FMT_NONE; ptr++) {
|
||||
obs_property_list_add_int(p, ffmpeg::tools::get_pixel_format_name(*ptr),
|
||||
static_cast<int64_t>(*ptr));
|
||||
}
|
||||
}
|
||||
if (this->avcodec_ptr->capabilities & (AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS)) {
|
||||
auto p = obs_properties_add_int_slider(grp, P_FFMPEG_THREADS, TRANSLATE(P_FFMPEG_THREADS), 0,
|
||||
std::thread::hardware_concurrency() * 2, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_FFMPEG_THREADS)));
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_list(grp, P_FFMPEG_STANDARDCOMPLIANCE,
|
||||
TRANSLATE(P_FFMPEG_STANDARDCOMPLIANCE), OBS_COMBO_TYPE_LIST,
|
||||
OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_FFMPEG_STANDARDCOMPLIANCE)));
|
||||
obs_property_list_add_int(p, TRANSLATE(P_FFMPEG_STANDARDCOMPLIANCE ".VeryStrict"),
|
||||
FF_COMPLIANCE_VERY_STRICT);
|
||||
obs_property_list_add_int(p, TRANSLATE(P_FFMPEG_STANDARDCOMPLIANCE ".Strict"),
|
||||
FF_COMPLIANCE_STRICT);
|
||||
obs_property_list_add_int(p, TRANSLATE(P_FFMPEG_STANDARDCOMPLIANCE ".Normal"),
|
||||
FF_COMPLIANCE_NORMAL);
|
||||
obs_property_list_add_int(p, TRANSLATE(P_FFMPEG_STANDARDCOMPLIANCE ".Unofficial"),
|
||||
FF_COMPLIANCE_UNOFFICIAL);
|
||||
obs_property_list_add_int(p, TRANSLATE(P_FFMPEG_STANDARDCOMPLIANCE ".Experimental"),
|
||||
FF_COMPLIANCE_EXPERIMENTAL);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
AVCodec* encoder::generic_factory::get_avcodec()
|
||||
{
|
||||
return this->avcodec_ptr;
|
||||
}
|
||||
|
||||
encoder::generic::generic(obs_data_t* settings, obs_encoder_t* encoder)
|
||||
: self(encoder), lag_in_frames(0), frame_count(0)
|
||||
{
|
||||
this->factory = reinterpret_cast<generic_factory*>(obs_encoder_get_type_data(self));
|
||||
|
||||
// Verify that the codec actually still exists.
|
||||
this->codec = avcodec_find_encoder_by_name(this->factory->get_avcodec()->name);
|
||||
if (!this->codec) {
|
||||
PLOG_ERROR("Failed to find encoder for codec '%s'.", this->factory->get_avcodec()->name);
|
||||
throw std::runtime_error("failed to find codec");
|
||||
}
|
||||
|
||||
// Initialize context.
|
||||
this->context = avcodec_alloc_context3(this->codec);
|
||||
if (!this->context) {
|
||||
PLOG_ERROR("Failed to create context for encoder '%s'.", this->codec->name);
|
||||
throw std::runtime_error("failed to create context");
|
||||
}
|
||||
|
||||
// Settings
|
||||
/// Rate Control
|
||||
this->context->strict_std_compliance =
|
||||
static_cast<int>(obs_data_get_int(settings, P_FFMPEG_STANDARDCOMPLIANCE));
|
||||
this->context->debug = 0;
|
||||
/// Threading
|
||||
if (this->codec->capabilities
|
||||
& (AV_CODEC_CAP_AUTO_THREADS | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS)) {
|
||||
if (this->codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) {
|
||||
this->context->thread_type |= FF_THREAD_FRAME;
|
||||
}
|
||||
if (this->codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) {
|
||||
this->context->thread_type |= FF_THREAD_SLICE;
|
||||
}
|
||||
int64_t threads = obs_data_get_int(settings, P_FFMPEG_THREADS);
|
||||
if (threads > 0) {
|
||||
this->context->thread_count = static_cast<int>(threads);
|
||||
this->lag_in_frames = this->context->thread_count;
|
||||
} else {
|
||||
this->context->thread_count = std::thread::hardware_concurrency();
|
||||
this->lag_in_frames = this->context->thread_count;
|
||||
}
|
||||
}
|
||||
|
||||
// Video and Audio exclusive setup
|
||||
if (this->codec->type == AVMEDIA_TYPE_VIDEO) {
|
||||
// FFmpeg Video Settings
|
||||
auto encvideo = obs_encoder_video(this->self);
|
||||
auto voi = video_output_get_info(encvideo);
|
||||
|
||||
// Resolution
|
||||
this->context->width = voi->width;
|
||||
this->context->height = voi->height;
|
||||
this->swscale.set_source_size(this->context->width, this->context->height);
|
||||
this->swscale.set_target_size(this->context->width, this->context->height);
|
||||
|
||||
// Color
|
||||
this->context->colorspace = ffmpeg::tools::obs_videocolorspace_to_avcolorspace(voi->colorspace);
|
||||
this->context->color_range = ffmpeg::tools::obs_videorangetype_to_avcolorrange(voi->range);
|
||||
this->context->field_order = AV_FIELD_PROGRESSIVE;
|
||||
this->swscale.set_source_color(this->context->color_range, this->context->colorspace);
|
||||
this->swscale.set_target_color(this->context->color_range, this->context->colorspace);
|
||||
|
||||
// Pixel Format
|
||||
{
|
||||
// Due to unsupported color formats and ffmpeg not automatically converting formats from A to B,
|
||||
// we have to detect the closest format that we can still use and initialize our swscale instance
|
||||
// these formats. This has a massive cost attached unfortunately.
|
||||
|
||||
AVPixelFormat source = ffmpeg::tools::obs_videoformat_to_avpixelformat(voi->format);
|
||||
AVPixelFormat target = AV_PIX_FMT_NONE;
|
||||
|
||||
// Prefer lossless or zero-change formats.
|
||||
for (auto ptr = this->codec->pix_fmts; *ptr != AV_PIX_FMT_NONE; ptr++) {
|
||||
switch (source) {
|
||||
case AV_PIX_FMT_RGBA:
|
||||
switch (*ptr) {
|
||||
case AV_PIX_FMT_RGB0:
|
||||
case AV_PIX_FMT_RGBA:
|
||||
target = *ptr;
|
||||
break;
|
||||
case AV_PIX_FMT_BGR0:
|
||||
case AV_PIX_FMT_BGRA:
|
||||
target = *ptr;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case AV_PIX_FMT_BGRA:
|
||||
case AV_PIX_FMT_BGR0:
|
||||
switch (*ptr) {
|
||||
case AV_PIX_FMT_RGB0:
|
||||
case AV_PIX_FMT_RGBA:
|
||||
target = *ptr;
|
||||
break;
|
||||
case AV_PIX_FMT_BGR0:
|
||||
case AV_PIX_FMT_BGRA:
|
||||
target = *ptr;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case AV_PIX_FMT_YUV444P:
|
||||
case AV_PIX_FMT_YUYV422:
|
||||
case AV_PIX_FMT_YVYU422:
|
||||
case AV_PIX_FMT_UYVY422:
|
||||
case AV_PIX_FMT_YUV420P:
|
||||
case AV_PIX_FMT_NV12:
|
||||
if (*ptr == source) {
|
||||
target = *ptr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (target == AV_PIX_FMT_NONE) {
|
||||
int loss = 0;
|
||||
target = avcodec_find_best_pix_fmt_of_list(this->codec->pix_fmts, source, false, &loss);
|
||||
}
|
||||
|
||||
this->context->pix_fmt = target;
|
||||
this->swscale.set_source_format(source);
|
||||
this->swscale.set_target_format(this->context->pix_fmt);
|
||||
|
||||
PLOG_INFO("Automatically detected target format '%s' for source format '%s'.",
|
||||
ffmpeg::tools::get_pixel_format_name(target),
|
||||
ffmpeg::tools::get_pixel_format_name(source));
|
||||
}
|
||||
AVPixelFormat color_format_override =
|
||||
static_cast<AVPixelFormat>(obs_data_get_int(settings, P_FFMPEG_COLORFORMAT));
|
||||
if (color_format_override != AV_PIX_FMT_NONE) {
|
||||
// User specified override for color format.
|
||||
this->context->pix_fmt = color_format_override;
|
||||
this->swscale.set_target_format(this->context->pix_fmt);
|
||||
PLOG_INFO("User specified target format override '%s'.",
|
||||
ffmpeg::tools::get_pixel_format_name(this->context->pix_fmt));
|
||||
}
|
||||
|
||||
// Framerate
|
||||
this->context->time_base.num = voi->fps_den;
|
||||
this->context->time_base.den = voi->fps_num;
|
||||
this->context->ticks_per_frame = 1;
|
||||
} else if (this->codec->type == AVMEDIA_TYPE_AUDIO) {
|
||||
}
|
||||
|
||||
// Update settings
|
||||
this->update(settings);
|
||||
|
||||
// Initialize
|
||||
int res = avcodec_open2(this->context, this->codec, NULL);
|
||||
if (res < 0) {
|
||||
PLOG_ERROR("Failed to initialize encoder '%s' due to error code %lld: %s", this->codec->name, res,
|
||||
ffmpeg::tools::get_error_description(res));
|
||||
throw std::runtime_error(ffmpeg::tools::get_error_description(res));
|
||||
}
|
||||
|
||||
// Video/Audio exclusive setup part 2.
|
||||
if (this->codec->type == AVMEDIA_TYPE_VIDEO) {
|
||||
// Create Scaler
|
||||
if (!swscale.initialize(SWS_FAST_BILINEAR)) {
|
||||
PLOG_ERROR(
|
||||
" Failed to initialize Software Scaler for pixel format '%s' with color space '%s' and "
|
||||
"range '%s'.",
|
||||
ffmpeg::tools::get_pixel_format_name(this->context->pix_fmt),
|
||||
ffmpeg::tools::get_color_space_name(this->context->colorspace),
|
||||
this->swscale.is_source_full_range() ? "Full" : "Partial");
|
||||
throw std::runtime_error("failed to initialize swscaler.");
|
||||
}
|
||||
|
||||
// Create Frame queue
|
||||
this->frame_queue.set_pixel_format(this->context->pix_fmt);
|
||||
this->frame_queue.set_resolution(this->context->width, this->context->height);
|
||||
this->frame_queue.precache(2);
|
||||
} else if (this->codec->type == AVMEDIA_TYPE_AUDIO) {
|
||||
}
|
||||
|
||||
av_init_packet(&this->current_packet);
|
||||
av_new_packet(&this->current_packet, 8 * 1024 * 1024); // 8 MB precached Packet size.
|
||||
}
|
||||
|
||||
encoder::generic::~generic()
|
||||
{
|
||||
av_packet_unref(&this->current_packet);
|
||||
|
||||
this->frame_queue.clear();
|
||||
this->frame_queue_used.clear();
|
||||
this->swscale.finalize();
|
||||
|
||||
if (this->context) {
|
||||
avcodec_close(this->context);
|
||||
avcodec_free_context(&this->context);
|
||||
}
|
||||
}
|
||||
|
||||
void encoder::generic::get_properties(obs_properties_t* props)
|
||||
{
|
||||
{ // Handler
|
||||
auto ptr = obsffmpeg::find_codec_handler(this->codec->name);
|
||||
if (ptr) {
|
||||
ptr->get_properties(props, this->codec, this->context);
|
||||
}
|
||||
}
|
||||
|
||||
obs_property_set_enabled(obs_properties_get(props, P_FFMPEG_COLORFORMAT), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_FFMPEG_THREADS), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_FFMPEG_STANDARDCOMPLIANCE), false);
|
||||
}
|
||||
|
||||
bool encoder::generic::update(obs_data_t* settings)
|
||||
{
|
||||
{ // Handler
|
||||
auto ptr = obsffmpeg::find_codec_handler(this->codec->name);
|
||||
if (ptr) {
|
||||
ptr->update(settings, this->codec, this->context);
|
||||
}
|
||||
}
|
||||
|
||||
{ // FFmpeg
|
||||
// Apply custom options.
|
||||
av_opt_set_from_string(this->context->priv_data, obs_data_get_string(settings, P_FFMPEG_CUSTOMSETTINGS),
|
||||
nullptr, "=", ";");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void encoder::generic::get_audio_info(audio_convert_info*) {}
|
||||
|
||||
size_t encoder::generic::get_frame_size()
|
||||
{
|
||||
return size_t();
|
||||
}
|
||||
|
||||
bool encoder::generic::audio_encode(encoder_frame*, encoder_packet*, bool*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void encoder::generic::get_video_info(video_scale_info*) {}
|
||||
|
||||
bool encoder::generic::get_sei_data(uint8_t**, size_t*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool encoder::generic::get_extra_data(uint8_t** extra_data, size_t* size)
|
||||
{
|
||||
if (!this->context->extradata) {
|
||||
return false;
|
||||
}
|
||||
*extra_data = this->context->extradata;
|
||||
*size = this->context->extradata_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void copy_data(encoder_frame* frame, AVFrame* vframe)
|
||||
{
|
||||
int h_chroma_shift, v_chroma_shift;
|
||||
av_pix_fmt_get_chroma_sub_sample(static_cast<AVPixelFormat>(vframe->format), &h_chroma_shift, &v_chroma_shift);
|
||||
|
||||
for (size_t idx = 0; idx < MAX_AV_PLANES; idx++) {
|
||||
if (!frame->data[idx] || !vframe->data[idx])
|
||||
continue;
|
||||
|
||||
size_t plane_height = vframe->height >> (idx ? v_chroma_shift : 0);
|
||||
|
||||
if (static_cast<uint32_t>(vframe->linesize[idx]) == frame->linesize[idx]) {
|
||||
std::memcpy(vframe->data[idx], frame->data[idx], frame->linesize[idx] * plane_height);
|
||||
} else {
|
||||
size_t ls_in = frame->linesize[idx];
|
||||
size_t ls_out = vframe->linesize[idx];
|
||||
size_t bytes = ls_in < ls_out ? ls_in : ls_out;
|
||||
|
||||
uint8_t* to = vframe->data[idx];
|
||||
uint8_t* from = frame->data[idx];
|
||||
|
||||
for (size_t y = 0; y < plane_height; y++) {
|
||||
std::memcpy(to, from, bytes);
|
||||
to += ls_out;
|
||||
from += ls_in;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool encoder::generic::video_encode(encoder_frame* frame, encoder_packet* packet, bool* received_packet)
|
||||
{
|
||||
// Convert frame.
|
||||
std::shared_ptr<AVFrame> vframe = frame_queue.pop(); // Retrieve an empty frame.
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
ScopeProfiler profile("convert");
|
||||
#endif
|
||||
|
||||
vframe->height = this->context->height;
|
||||
vframe->format = this->context->pix_fmt;
|
||||
vframe->color_range = this->context->color_range;
|
||||
vframe->colorspace = this->context->colorspace;
|
||||
|
||||
if ((swscale.is_source_full_range() == swscale.is_target_full_range())
|
||||
&& (swscale.get_source_colorspace() == swscale.get_target_colorspace())
|
||||
&& (swscale.get_source_format() == swscale.get_target_format())) {
|
||||
copy_data(frame, vframe.get());
|
||||
} else {
|
||||
int res = swscale.convert(reinterpret_cast<uint8_t**>(frame->data),
|
||||
reinterpret_cast<int*>(frame->linesize), 0, this->context->height,
|
||||
vframe->data, vframe->linesize);
|
||||
if (res <= 0) {
|
||||
PLOG_ERROR("Failed to convert frame: %s (%ld).",
|
||||
ffmpeg::tools::get_error_description(res), res);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send and receive frames.
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
ScopeProfiler profile("loop");
|
||||
#endif
|
||||
|
||||
bool sent_frame = false;
|
||||
bool recv_packet = false;
|
||||
bool should_lag = (lag_in_frames - frame_count) <= 0;
|
||||
|
||||
auto loop_begin = std::chrono::high_resolution_clock::now();
|
||||
auto loop_end = loop_begin + std::chrono::milliseconds(50);
|
||||
|
||||
while ((!sent_frame || (should_lag && !recv_packet))
|
||||
&& !(std::chrono::high_resolution_clock::now() > loop_end)) {
|
||||
bool eagain_is_stupid = false;
|
||||
|
||||
if (!sent_frame) {
|
||||
#ifdef _DEBUG
|
||||
ScopeProfiler profile_inner("send");
|
||||
#endif
|
||||
|
||||
vframe->pts = frame->pts;
|
||||
|
||||
int res = send_frame(vframe);
|
||||
switch (res) {
|
||||
case 0:
|
||||
sent_frame = true;
|
||||
vframe = nullptr;
|
||||
break;
|
||||
case AVERROR(EAGAIN):
|
||||
// This means we should call receive_packet again, but what do we do with that data?
|
||||
// Why can't we queue on both? Do I really have to implement threading for this stuff?
|
||||
if (*received_packet == true) {
|
||||
PLOG_WARNING(
|
||||
"Skipped frame due to EAGAIN when a packet was already returned.");
|
||||
sent_frame = true;
|
||||
}
|
||||
eagain_is_stupid = true;
|
||||
break;
|
||||
case AVERROR(EOF):
|
||||
PLOG_ERROR("Skipped frame due to end of stream.");
|
||||
sent_frame = true;
|
||||
break;
|
||||
default:
|
||||
PLOG_ERROR("Failed to encode frame: %s (%ld).",
|
||||
ffmpeg::tools::get_error_description(res), res);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!recv_packet) {
|
||||
#ifdef _DEBUG
|
||||
ScopeProfiler profile_inner("recieve");
|
||||
#endif
|
||||
|
||||
int res = receive_packet(received_packet, packet);
|
||||
switch (res) {
|
||||
case 0:
|
||||
recv_packet = true;
|
||||
break;
|
||||
case AVERROR(EOF):
|
||||
PLOG_ERROR("Received end of file.");
|
||||
recv_packet = true;
|
||||
break;
|
||||
case AVERROR(EAGAIN):
|
||||
if (sent_frame) {
|
||||
recv_packet = true;
|
||||
}
|
||||
if (eagain_is_stupid) {
|
||||
PLOG_ERROR("Both send and recieve returned EAGAIN, encoder is broken.");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
PLOG_ERROR("Failed to receive packet: %s (%ld).",
|
||||
ffmpeg::tools::get_error_description(res), res);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!sent_frame || !recv_packet) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vframe != nullptr) {
|
||||
frame_queue.push(vframe);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool encoder::generic::video_encode_texture(uint32_t, int64_t, uint64_t, uint64_t*, encoder_packet*, bool*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int encoder::generic::receive_packet(bool* received_packet, struct encoder_packet* packet)
|
||||
{
|
||||
int res = avcodec_receive_packet(this->context, &this->current_packet);
|
||||
if (res == 0) {
|
||||
packet->type = OBS_ENCODER_VIDEO;
|
||||
packet->pts = this->current_packet.pts;
|
||||
packet->dts = this->current_packet.dts;
|
||||
packet->data = this->current_packet.data;
|
||||
packet->size = this->current_packet.size;
|
||||
packet->keyframe = !!(this->current_packet.flags & AV_PKT_FLAG_KEY);
|
||||
packet->drop_priority = 0;
|
||||
*received_packet = true;
|
||||
|
||||
{
|
||||
std::shared_ptr<AVFrame> uframe = frame_queue_used.pop_only();
|
||||
frame_queue.push(uframe);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int encoder::generic::send_frame(std::shared_ptr<AVFrame> frame)
|
||||
{
|
||||
int res = avcodec_send_frame(this->context, frame.get());
|
||||
switch (res) {
|
||||
case 0:
|
||||
frame_queue_used.push(frame);
|
||||
frame_count++;
|
||||
case AVERROR(EAGAIN):
|
||||
case AVERROR(EOF):
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
// 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 <condition_variable>
|
||||
#include <encoder.hpp>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include "ffmpeg/avframe-queue.hpp"
|
||||
#include "ffmpeg/swscale.hpp"
|
||||
|
||||
namespace encoder {
|
||||
class generic_factory {
|
||||
struct info {
|
||||
std::string uid;
|
||||
std::string codec;
|
||||
std::string readable_name;
|
||||
obs_encoder_info oei;
|
||||
} info;
|
||||
AVCodec* avcodec_ptr;
|
||||
|
||||
public:
|
||||
generic_factory(AVCodec* codec);
|
||||
virtual ~generic_factory();
|
||||
|
||||
void register_encoder();
|
||||
|
||||
const char* get_name();
|
||||
|
||||
void get_defaults(obs_data_t* settings);
|
||||
|
||||
void get_properties(obs_properties_t* props);
|
||||
|
||||
AVCodec* get_avcodec();
|
||||
|
||||
public:
|
||||
static bool modified_ratecontrol_properties(void* priv, obs_properties_t* props, obs_property_t* prop,
|
||||
obs_data_t* settings);
|
||||
};
|
||||
|
||||
class generic {
|
||||
obs_encoder_t* self;
|
||||
generic_factory* factory;
|
||||
|
||||
AVCodec* codec;
|
||||
AVCodecContext* context;
|
||||
|
||||
ffmpeg::avframe_queue frame_queue;
|
||||
ffmpeg::avframe_queue frame_queue_used;
|
||||
ffmpeg::swscale swscale;
|
||||
AVPacket current_packet;
|
||||
|
||||
int64_t lag_in_frames;
|
||||
int64_t frame_count;
|
||||
|
||||
public:
|
||||
generic(obs_data_t* settings, obs_encoder_t* encoder);
|
||||
virtual ~generic();
|
||||
|
||||
public: // OBS API
|
||||
// Shared
|
||||
void get_properties(obs_properties_t* props);
|
||||
|
||||
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);
|
||||
};
|
||||
} // namespace encoder
|
||||
@@ -1,345 +0,0 @@
|
||||
// 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.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." D_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*) {}
|
||||
|
||||
bool obsffmpeg::encoder::prores_aw::update(obs_data_t*)
|
||||
{
|
||||
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**, size_t*)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void obsffmpeg::encoder::prores_aw::get_video_info(video_scale_info*)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool obsffmpeg::encoder::prores_aw::encode(encoder_frame* frame, encoder_packet* packet, bool* received_packet)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
{
|
||||
ScopeProfiler sp_frame("frame");
|
||||
std::shared_ptr<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.get());
|
||||
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 {
|
||||
std::shared_ptr<AVFrame> uframe = frame_queue_used.pop_only();
|
||||
if (uframe) {
|
||||
if (frame_queue.empty()) {
|
||||
frame_queue.push(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,79 +0,0 @@
|
||||
// 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 <encoder.hpp>
|
||||
#include <vector>
|
||||
#include "ffmpeg/avframe-queue.hpp"
|
||||
|
||||
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
|
||||
@@ -24,11 +24,13 @@
|
||||
|
||||
std::shared_ptr<AVFrame> ffmpeg::avframe_queue::create_frame()
|
||||
{
|
||||
std::shared_ptr<AVFrame> frame =
|
||||
std::shared_ptr<AVFrame>(av_frame_alloc(), [](AVFrame* frame) { av_frame_free(&frame); });
|
||||
frame->width = this->resolution.first;
|
||||
frame->height = this->resolution.second;
|
||||
frame->format = this->format;
|
||||
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.get(), 32);
|
||||
if (res < 0) {
|
||||
@@ -45,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;
|
||||
@@ -67,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;
|
||||
}
|
||||
@@ -90,7 +92,7 @@ void ffmpeg::avframe_queue::clear()
|
||||
frames.clear();
|
||||
}
|
||||
|
||||
void ffmpeg::avframe_queue::push(std::shared_ptr<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);
|
||||
|
||||
@@ -176,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;
|
||||
}
|
||||
|
||||
+29
-11
@@ -40,31 +40,22 @@ std::string ffmpeg::tools::translate_encoder_capabilities(int capabilities)
|
||||
|
||||
// Quality
|
||||
{AV_CODEC_CAP_LOSSLESS, "Lossless"},
|
||||
//{AV_CODEC_CAP_INTRA_ONLY, "I-Frames only"},
|
||||
|
||||
// Threading
|
||||
//{AV_CODEC_CAP_FRAME_THREADS, "Frame-Threading"},
|
||||
//{AV_CODEC_CAP_SLICE_THREADS, "Slice-Threading"},
|
||||
//{AV_CODEC_CAP_AUTO_THREADS, "Automatic-Threading"},
|
||||
|
||||
// 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"},
|
||||
//{AV_CODEC_CAP_DR1, "Uses get_buffer"},
|
||||
//{AV_CODEC_CAP_DELAY, "Requires Flush"},
|
||||
|
||||
// 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_HWACCEL_VDPAU, "AV_CODEC_CAP_HWACCEL_VDPAU"},
|
||||
{AV_CODEC_CAP_AVOID_PROBING, "AV_CODEC_CAP_AVOID_PROBING"},
|
||||
};
|
||||
|
||||
std::stringstream sstr;
|
||||
for (auto kv : caps) {
|
||||
for (auto const kv : caps) {
|
||||
if (capabilities & kv.first) {
|
||||
capabilities &= ~kv.first;
|
||||
sstr << kv.second;
|
||||
@@ -194,6 +185,33 @@ AVPixelFormat ffmpeg::tools::obs_videoformat_to_avpixelformat(video_format v)
|
||||
throw std::invalid_argument("unknown format");
|
||||
}
|
||||
|
||||
video_format ffmpeg::tools::avpixelformat_to_obs_videoformat(AVPixelFormat v)
|
||||
{
|
||||
switch (v) {
|
||||
case AV_PIX_FMT_YUV420P:
|
||||
return VIDEO_FORMAT_I420;
|
||||
case AV_PIX_FMT_NV12:
|
||||
return VIDEO_FORMAT_NV12;
|
||||
case AV_PIX_FMT_YVYU422:
|
||||
return VIDEO_FORMAT_YVYU;
|
||||
case AV_PIX_FMT_YUYV422:
|
||||
return VIDEO_FORMAT_YUY2;
|
||||
case AV_PIX_FMT_UYVY422:
|
||||
return VIDEO_FORMAT_UYVY;
|
||||
case AV_PIX_FMT_RGBA:
|
||||
return VIDEO_FORMAT_RGBA;
|
||||
case AV_PIX_FMT_BGRA:
|
||||
return VIDEO_FORMAT_BGRA;
|
||||
case AV_PIX_FMT_BGR0:
|
||||
return VIDEO_FORMAT_BGRX;
|
||||
case AV_PIX_FMT_GRAY8:
|
||||
return VIDEO_FORMAT_Y800;
|
||||
case AV_PIX_FMT_YUV444P:
|
||||
return VIDEO_FORMAT_I444;
|
||||
}
|
||||
return VIDEO_FORMAT_NONE;
|
||||
}
|
||||
|
||||
AVColorSpace ffmpeg::tools::obs_videocolorspace_to_avcolorspace(video_colorspace v)
|
||||
{
|
||||
switch (v) {
|
||||
@@ -201,7 +219,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");
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ namespace ffmpeg {
|
||||
|
||||
AVPixelFormat obs_videoformat_to_avpixelformat(video_format v);
|
||||
|
||||
video_format avpixelformat_to_obs_videoformat(AVPixelFormat v);
|
||||
|
||||
AVColorSpace obs_videocolorspace_to_avcolorspace(video_colorspace v);
|
||||
|
||||
AVColorRange obs_videorangetype_to_avcolorrange(video_range_type v);
|
||||
|
||||
+51
-24
@@ -20,9 +20,9 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "plugin.hpp"
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include "encoders/generic.hpp"
|
||||
#include "encoders/prores_aw.hpp"
|
||||
#include "encoder.hpp"
|
||||
#include "ui/debug_handler.hpp"
|
||||
#include "ui/handler.hpp"
|
||||
#include "utility.hpp"
|
||||
@@ -45,12 +45,12 @@ std::list<std::function<void()>> obsffmpeg::finalizers;
|
||||
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 codec, std::shared_ptr<obsffmpeg::ui::handler> handler)
|
||||
void obsffmpeg::register_codec_handler(std::string const codec, std::shared_ptr<obsffmpeg::ui::handler> const handler)
|
||||
{
|
||||
codec_to_handler_map.emplace(codec, handler);
|
||||
}
|
||||
|
||||
std::shared_ptr<obsffmpeg::ui::handler> obsffmpeg::find_codec_handler(std::string codec)
|
||||
std::shared_ptr<obsffmpeg::ui::handler> obsffmpeg::find_codec_handler(std::string const codec)
|
||||
{
|
||||
auto found = codec_to_handler_map.find(codec);
|
||||
if (found == codec_to_handler_map.end())
|
||||
@@ -58,56 +58,83 @@ std::shared_ptr<obsffmpeg::ui::handler> obsffmpeg::find_codec_handler(std::strin
|
||||
return found->second;
|
||||
}
|
||||
|
||||
bool obsffmpeg::has_codec_handler(std::string codec)
|
||||
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<AVCodec*, std::shared_ptr<encoder::generic_factory>> generic_factories;
|
||||
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 {
|
||||
// Initialize avcodec.
|
||||
avcodec_register_all();
|
||||
#if FF_API_NEXT
|
||||
if (avcodec_version() < AV_VERSION_INT(58, 0, 0)) {
|
||||
// Initialize avcodec.
|
||||
avcodec_register_all();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Run all initializers.
|
||||
for (auto func : obsffmpeg::initializers) {
|
||||
for (auto const func : obsffmpeg::initializers) {
|
||||
func();
|
||||
}
|
||||
|
||||
// Register all codecs.
|
||||
AVCodec* cdc = nullptr;
|
||||
while ((cdc = av_codec_next(cdc)) != nullptr) {
|
||||
if (!av_codec_is_encoder(cdc))
|
||||
continue;
|
||||
#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<encoder::generic_factory>(cdc);
|
||||
ptr->register_encoder();
|
||||
generic_factories.emplace(cdc, ptr);
|
||||
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
|
||||
|
||||
obsffmpeg::encoder::prores_aw::initialize();
|
||||
return true;
|
||||
} catch (std::exception ex) {
|
||||
} 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 {
|
||||
obsffmpeg::encoder::prores_aw::finalize();
|
||||
|
||||
// Run all finalizers.
|
||||
for (auto func : obsffmpeg::finalizers) {
|
||||
for (auto const func : obsffmpeg::finalizers) {
|
||||
func();
|
||||
}
|
||||
} catch (std::exception ex) {
|
||||
} catch (std::exception& ex) {
|
||||
PLOG_ERROR("Exception during finalizing: %s.", ex.what());
|
||||
} catch (...) {
|
||||
PLOG_ERROR("Unrecognized exception during finalizing.");
|
||||
|
||||
+27
-27
@@ -22,32 +22,32 @@
|
||||
#pragma once
|
||||
#include "utility.hpp"
|
||||
|
||||
#define G_STATE_DEFAULT "State.Default"
|
||||
#define G_STATE_DISABLED "State.Disabled"
|
||||
#define G_STATE_ENABLED "State.Enabled"
|
||||
#define G_STATE_AUTOMATIC "State.Automatic"
|
||||
#define G_STATE_MANUAL "State.Manual"
|
||||
#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 G_RATECONTROL "RateControl"
|
||||
#define G_RATECONTROL_MODE "RateControl.Mode"
|
||||
#define G_RATECONTROL_MODE_(x) "RateControl.Mode." D_VSTR(x)
|
||||
#define G_RATECONTROL_BITRATE_TARGET "RateControl.Bitrate.Target"
|
||||
#define G_RATECONTROL_BITRATE_MINIMUM "RateControl.Bitrate.Minimum"
|
||||
#define G_RATECONTROL_BITRATE_MAXIMUM "RateControl.Bitrate.Maximum"
|
||||
#define G_RATECONTROL_BUFFERSIZE "RateControl.BufferSize"
|
||||
#define G_RATECONTROL_QUALITY_TARGET "RateControl.Quality.Target"
|
||||
#define G_RATECONTROL_QUALITY_MINIMUM "RateControl.Quality.Minimum"
|
||||
#define G_RATECONTROL_QUALITY_MAXIMUM "RateControl.Quality.Maximum"
|
||||
#define G_RATECONTROL_QP_I "RateControl.QP.I"
|
||||
#define G_RATECONTROL_QP_P "RateControl.QP.P"
|
||||
#define G_RATECONTROL_QP_B "RateControl.QP.B"
|
||||
#define G_RATECONTROL_QP_I_INITIAL "RateControl.QP.I.Initial"
|
||||
#define G_RATECONTROL_QP_P_INITIAL "RateControl.QP.P.Initial"
|
||||
#define G_RATECONTROL_QP_B_INITIAL "RateControl.QP.B.Initial"
|
||||
#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 G_KEYFRAMES "KeyFrames"
|
||||
#define G_KEYFRAMES_INTERVALTYPE "KeyFrames.IntervalType"
|
||||
#define G_KEYFRAMES_INTERVALTYPE_(x) "KeyFrames.IntervalType." D_VSTR(x)
|
||||
#define G_KEYFRAMES_INTERVAL "KeyFrames.Interval"
|
||||
#define G_KEYFRAMES_INTERVAL_SECONDS "KeyFrames.Interval.Seconds"
|
||||
#define G_KEYFRAMES_INTERVAL_FRAMES "KeyFrames.Interval.Frames"
|
||||
#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"
|
||||
|
||||
@@ -35,7 +35,7 @@ extern "C" {
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::debug_handler::get_defaults(obs_data_t*, AVCodec*, AVCodecContext*) {}
|
||||
void obsffmpeg::ui::debug_handler::get_defaults(obs_data_t*, const AVCodec*, AVCodecContext*) {}
|
||||
|
||||
template<typename T>
|
||||
std::string to_string(T value){};
|
||||
@@ -64,7 +64,7 @@ std::string to_string(double_t value)
|
||||
return std::string(buf.data(), buf.data() + buf.size());
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::debug_handler::get_properties(obs_properties_t*, AVCodec* codec, AVCodecContext* context)
|
||||
void obsffmpeg::ui::debug_handler::get_properties(obs_properties_t*, const AVCodec* codec, AVCodecContext* context)
|
||||
{
|
||||
if (context)
|
||||
return;
|
||||
@@ -206,4 +206,4 @@ void obsffmpeg::ui::debug_handler::get_properties(obs_properties_t*, AVCodec* co
|
||||
}
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::debug_handler::update(obs_data_t*, AVCodec*, AVCodecContext*) {}
|
||||
void obsffmpeg::ui::debug_handler::update(obs_data_t*, const AVCodec*, AVCodecContext*) {}
|
||||
|
||||
@@ -26,13 +26,14 @@ namespace obsffmpeg {
|
||||
namespace ui {
|
||||
class debug_handler : public handler {
|
||||
public:
|
||||
virtual void get_defaults(obs_data_t* settings, AVCodec* codec,
|
||||
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
|
||||
virtual void get_properties(obs_properties_t* props, AVCodec* codec,
|
||||
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
|
||||
virtual void update(obs_data_t* settings, AVCodec* codec, AVCodecContext* context) override;
|
||||
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
};
|
||||
} // namespace ui
|
||||
} // namespace obsffmpeg
|
||||
|
||||
@@ -20,3 +20,5 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "handler.hpp"
|
||||
|
||||
void obsffmpeg::ui::handler::override_visible_name(const AVCodec*, std::string&) {}
|
||||
|
||||
@@ -21,7 +21,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
extern "C" {
|
||||
#include <obs-data.h>
|
||||
#include <obs-properties.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
@@ -33,12 +36,15 @@ namespace obsffmpeg {
|
||||
namespace ui {
|
||||
class handler {
|
||||
public:
|
||||
virtual void get_defaults(obs_data_t* settings, AVCodec* codec, AVCodecContext* context) = 0;
|
||||
virtual void override_visible_name(const AVCodec* codec, std::string& name);
|
||||
|
||||
virtual void get_properties(obs_properties_t* props, AVCodec* codec,
|
||||
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context) = 0;
|
||||
|
||||
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context) = 0;
|
||||
|
||||
virtual void update(obs_data_t* settings, AVCodec* codec, AVCodecContext* context) = 0;
|
||||
virtual void update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context) = 0;
|
||||
};
|
||||
} // namespace ui
|
||||
} // namespace obsffmpeg
|
||||
|
||||
@@ -79,7 +79,13 @@ INITIALIZER(nvenc_h264_handler_init)
|
||||
});
|
||||
};
|
||||
|
||||
void obsffmpeg::ui::nvenc_h264_handler::get_defaults(obs_data_t* settings, AVCodec* codec, AVCodecContext* context)
|
||||
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::get_defaults(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context)
|
||||
{
|
||||
nvenc::get_defaults(settings, codec, context);
|
||||
|
||||
@@ -87,7 +93,8 @@ void obsffmpeg::ui::nvenc_h264_handler::get_defaults(obs_data_t* settings, AVCod
|
||||
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, AVCodec* codec, AVCodecContext* context)
|
||||
void obsffmpeg::ui::nvenc_h264_handler::get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context)
|
||||
{
|
||||
if (!context) {
|
||||
this->get_encoder_properties(props, codec);
|
||||
@@ -96,7 +103,7 @@ void obsffmpeg::ui::nvenc_h264_handler::get_properties(obs_properties_t* props,
|
||||
}
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::nvenc_h264_handler::update(obs_data_t* settings, AVCodec* codec, AVCodecContext* context)
|
||||
void obsffmpeg::ui::nvenc_h264_handler::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
|
||||
{
|
||||
nvenc::update(settings, codec, context);
|
||||
|
||||
@@ -118,7 +125,7 @@ void obsffmpeg::ui::nvenc_h264_handler::update(obs_data_t* settings, AVCodec* co
|
||||
}
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::nvenc_h264_handler::get_encoder_properties(obs_properties_t* props, AVCodec* codec)
|
||||
void obsffmpeg::ui::nvenc_h264_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec)
|
||||
{
|
||||
nvenc::get_properties_pre(props, codec);
|
||||
|
||||
@@ -133,9 +140,9 @@ void obsffmpeg::ui::nvenc_h264_handler::get_encoder_properties(obs_properties_t*
|
||||
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(G_STATE_DEFAULT),
|
||||
obs_property_list_add_int(p, TRANSLATE(S_STATE_DEFAULT),
|
||||
static_cast<int64_t>(codecs::h264::profile::UNKNOWN));
|
||||
for (auto kv : profiles) {
|
||||
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));
|
||||
}
|
||||
@@ -144,9 +151,9 @@ void obsffmpeg::ui::nvenc_h264_handler::get_encoder_properties(obs_properties_t*
|
||||
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(G_STATE_AUTOMATIC),
|
||||
obs_property_list_add_int(p, TRANSLATE(S_STATE_AUTOMATIC),
|
||||
static_cast<int64_t>(codecs::h264::level::UNKNOWN));
|
||||
for (auto kv : levels) {
|
||||
for (auto const kv : levels) {
|
||||
obs_property_list_add_int(p, kv.second.c_str(), static_cast<int64_t>(kv.first));
|
||||
}
|
||||
}
|
||||
@@ -155,7 +162,7 @@ void obsffmpeg::ui::nvenc_h264_handler::get_encoder_properties(obs_properties_t*
|
||||
nvenc::get_properties_post(props, codec);
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::nvenc_h264_handler::get_runtime_properties(obs_properties_t* props, AVCodec* 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);
|
||||
|
||||
@@ -34,18 +34,22 @@ namespace obsffmpeg {
|
||||
namespace ui {
|
||||
class nvenc_h264_handler : public handler {
|
||||
public:
|
||||
virtual void get_defaults(obs_data_t* settings, AVCodec* codec,
|
||||
virtual void override_visible_name(const AVCodec* codec, std::string& name) override;
|
||||
|
||||
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
|
||||
virtual void get_properties(obs_properties_t* props, AVCodec* codec,
|
||||
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
|
||||
virtual void update(obs_data_t* settings, AVCodec* codec, AVCodecContext* context) override;
|
||||
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
|
||||
private:
|
||||
void get_encoder_properties(obs_properties_t* props, AVCodec* codec);
|
||||
void get_encoder_properties(obs_properties_t* props, const AVCodec* codec);
|
||||
|
||||
void get_runtime_properties(obs_properties_t* props, AVCodec* codec, AVCodecContext* context);
|
||||
void get_runtime_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context);
|
||||
};
|
||||
} // namespace ui
|
||||
} // namespace obsffmpeg
|
||||
|
||||
@@ -56,6 +56,25 @@ Useless except for strict_gop maybe?
|
||||
[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([]() {
|
||||
@@ -63,7 +82,13 @@ INITIALIZER(nvenc_hevc_handler_init)
|
||||
});
|
||||
};
|
||||
|
||||
void obsffmpeg::ui::nvenc_hevc_handler::get_defaults(obs_data_t* settings, AVCodec* codec, AVCodecContext* context)
|
||||
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::get_defaults(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context)
|
||||
{
|
||||
nvenc::get_defaults(settings, codec, context);
|
||||
|
||||
@@ -72,7 +97,8 @@ void obsffmpeg::ui::nvenc_hevc_handler::get_defaults(obs_data_t* settings, AVCod
|
||||
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, AVCodec* codec, AVCodecContext* context)
|
||||
void obsffmpeg::ui::nvenc_hevc_handler::get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context)
|
||||
{
|
||||
if (!context) {
|
||||
this->get_encoder_properties(props, codec);
|
||||
@@ -81,46 +107,33 @@ void obsffmpeg::ui::nvenc_hevc_handler::get_properties(obs_properties_t* props,
|
||||
}
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::nvenc_hevc_handler::update(obs_data_t* settings, AVCodec* codec, AVCodecContext* context)
|
||||
void obsffmpeg::ui::nvenc_hevc_handler::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
|
||||
{
|
||||
nvenc::update(settings, codec, context);
|
||||
|
||||
{ // HEVC Options
|
||||
codecs::hevc::profile profile =
|
||||
static_cast<codecs::hevc::profile>(obs_data_get_int(settings, P_HEVC_PROFILE));
|
||||
switch (profile) {
|
||||
case codecs::hevc::profile::MAIN:
|
||||
case codecs::hevc::profile::MAIN10:
|
||||
case codecs::hevc::profile::RANGE_EXTENDED:
|
||||
av_opt_set_int(context->priv_data, "profile", static_cast<int64_t>(profile), 0);
|
||||
break;
|
||||
default:
|
||||
av_opt_set_int(context->priv_data, "profile", static_cast<int64_t>(codecs::hevc::profile::MAIN),
|
||||
0);
|
||||
break;
|
||||
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);
|
||||
}
|
||||
|
||||
codecs::hevc::tier tier = static_cast<codecs::hevc::tier>(obs_data_get_int(settings, P_HEVC_TIER));
|
||||
switch (tier) {
|
||||
case codecs::hevc::tier::MAIN:
|
||||
case codecs::hevc::tier::HIGH:
|
||||
av_opt_set_int(context->priv_data, "tier", static_cast<int64_t>(tier), 0);
|
||||
break;
|
||||
default:
|
||||
av_opt_set_int(context->priv_data, "tier", static_cast<int64_t>(codecs::hevc::tier::MAIN), 0);
|
||||
break;
|
||||
}
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
codecs::hevc::level level = static_cast<codecs::hevc::level>(obs_data_get_int(settings, P_HEVC_LEVEL));
|
||||
if (level != codecs::hevc::level::UNKNOWN) {
|
||||
av_opt_set_int(context->priv_data, "level", static_cast<int64_t>(level), 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_int(context->priv_data, "level", static_cast<int64_t>(0), 0); // Automatic
|
||||
av_opt_set(context->priv_data, "level", "auto", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::nvenc_hevc_handler::get_encoder_properties(obs_properties_t* props, AVCodec* codec)
|
||||
void obsffmpeg::ui::nvenc_hevc_handler::get_encoder_properties(obs_properties_t* props, const AVCodec* codec)
|
||||
{
|
||||
nvenc::get_properties_pre(props, codec);
|
||||
|
||||
@@ -135,9 +148,9 @@ void obsffmpeg::ui::nvenc_hevc_handler::get_encoder_properties(obs_properties_t*
|
||||
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(G_STATE_DEFAULT),
|
||||
obs_property_list_add_int(p, TRANSLATE(S_STATE_DEFAULT),
|
||||
static_cast<int64_t>(codecs::hevc::profile::UNKNOWN));
|
||||
for (auto kv : codecs::hevc::profiles) {
|
||||
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));
|
||||
}
|
||||
@@ -146,9 +159,9 @@ void obsffmpeg::ui::nvenc_hevc_handler::get_encoder_properties(obs_properties_t*
|
||||
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(G_STATE_DEFAULT),
|
||||
obs_property_list_add_int(p, TRANSLATE(S_STATE_DEFAULT),
|
||||
static_cast<int64_t>(codecs::hevc::tier::UNKNOWN));
|
||||
for (auto kv : codecs::hevc::profile_tiers) {
|
||||
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));
|
||||
}
|
||||
@@ -157,9 +170,9 @@ void obsffmpeg::ui::nvenc_hevc_handler::get_encoder_properties(obs_properties_t*
|
||||
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(G_STATE_AUTOMATIC),
|
||||
obs_property_list_add_int(p, TRANSLATE(S_STATE_AUTOMATIC),
|
||||
static_cast<int64_t>(codecs::hevc::level::UNKNOWN));
|
||||
for (auto kv : codecs::hevc::levels) {
|
||||
for (auto const kv : levels) {
|
||||
obs_property_list_add_int(p, kv.second.c_str(), static_cast<int64_t>(kv.first));
|
||||
}
|
||||
}
|
||||
@@ -168,7 +181,7 @@ void obsffmpeg::ui::nvenc_hevc_handler::get_encoder_properties(obs_properties_t*
|
||||
nvenc::get_properties_post(props, codec);
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::nvenc_hevc_handler::get_runtime_properties(obs_properties_t* props, AVCodec* 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);
|
||||
|
||||
@@ -34,18 +34,22 @@ namespace obsffmpeg {
|
||||
namespace ui {
|
||||
class nvenc_hevc_handler : public handler {
|
||||
public:
|
||||
virtual void get_defaults(obs_data_t* settings, AVCodec* codec,
|
||||
virtual void override_visible_name(const AVCodec* codec, std::string& name) override;
|
||||
|
||||
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
|
||||
virtual void get_properties(obs_properties_t* props, AVCodec* codec,
|
||||
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
|
||||
virtual void update(obs_data_t* settings, AVCodec* codec, AVCodecContext* context) override;
|
||||
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
|
||||
private:
|
||||
void get_encoder_properties(obs_properties_t* props, AVCodec* codec);
|
||||
void get_encoder_properties(obs_properties_t* props, const AVCodec* codec);
|
||||
|
||||
void get_runtime_properties(obs_properties_t* props, AVCodec* codec, AVCodecContext* context);
|
||||
void get_runtime_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context);
|
||||
};
|
||||
} // namespace ui
|
||||
} // namespace obsffmpeg
|
||||
|
||||
+255
-302
@@ -33,60 +33,61 @@ extern "C" {
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
#define P_PRESET "NVENC.Preset"
|
||||
#define P_PRESET_(x) P_PRESET "." D_VSTR(x)
|
||||
#define ST_PRESET "NVENC.Preset"
|
||||
#define ST_PRESET_(x) ST_PRESET "." D_VSTR(x)
|
||||
|
||||
#define P_RATECONTROL "NVENC.RateControl"
|
||||
#define P_RATECONTROL_MODE P_RATECONTROL ".Mode"
|
||||
#define P_RATECONTROL_MODE_(x) P_RATECONTROL_MODE "." D_VSTR(x)
|
||||
#define P_RATECONTROL_TWOPASS P_RATECONTROL ".TwoPass"
|
||||
#define P_RATECONTROL_LOOKAHEAD P_RATECONTROL ".LookAhead"
|
||||
#define P_RATECONTROL_ADAPTIVEI P_RATECONTROL ".AdaptiveI"
|
||||
#define P_RATECONTROL_ADAPTIVEB P_RATECONTROL ".AdaptiveB"
|
||||
#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 P_RATECONTROL_BITRATE P_RATECONTROL ".Bitrate"
|
||||
#define P_RATECONTROL_BITRATE_TARGET P_RATECONTROL_BITRATE ".Target"
|
||||
#define P_RATECONTROL_BITRATE_MAXIMUM P_RATECONTROL_BITRATE ".Maximum"
|
||||
#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 P_RATECONTROL_QUALITY P_RATECONTROL ".Quality"
|
||||
#define P_RATECONTROL_QUALITY_MINIMUM P_RATECONTROL_QUALITY ".Minimum"
|
||||
#define P_RATECONTROL_QUALITY_MAXIMUM P_RATECONTROL_QUALITY ".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 P_RATECONTROL_QP P_RATECONTROL ".QP"
|
||||
#define P_RATECONTROL_QP_I P_RATECONTROL_QP ".I"
|
||||
#define P_RATECONTROL_QP_I_INITIAL P_RATECONTROL_QP_I ".Initial"
|
||||
#define P_RATECONTROL_QP_P P_RATECONTROL_QP ".P"
|
||||
#define P_RATECONTROL_QP_P_INITIAL P_RATECONTROL_QP_P ".Initial"
|
||||
#define P_RATECONTROL_QP_B P_RATECONTROL_QP ".B"
|
||||
#define P_RATECONTROL_QP_B_INITIAL P_RATECONTROL_QP_B ".Initial"
|
||||
#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_ST_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 P_AQ "NVENC.AQ"
|
||||
#define P_AQ_SPATIAL P_AQ ".Spatial"
|
||||
#define P_AQ_TEMPORAL P_AQ ".Temporal"
|
||||
#define P_AQ_STRENGTH P_AQ ".Strength"
|
||||
#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 P_OTHER "NVENC.Other"
|
||||
#define P_OTHER_BFRAMES P_OTHER ".BFrames"
|
||||
#define P_OTHER_BFRAME_REFERENCEMODE P_OTHER ".BFrameReferenceMode"
|
||||
#define P_OTHER_ZEROLATENCY P_OTHER ".ZeroLatency"
|
||||
#define P_OTHER_WEIGHTED_PREDICTION P_OTHER ".WeightedPrediction"
|
||||
#define P_OTHER_NONREFERENCE_PFRAMES P_OTHER ".NonReferencePFrames"
|
||||
#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, P_PRESET_(Default)},
|
||||
{preset::SLOW, P_PRESET_(Slow)},
|
||||
{preset::MEDIUM, P_PRESET_(Medium)},
|
||||
{preset::FAST, P_PRESET_(Fast)},
|
||||
{preset::HIGH_PERFORMANCE, P_PRESET_(HighPerformance)},
|
||||
{preset::HIGH_QUALITY, P_PRESET_(HighQuality)},
|
||||
{preset::BLURAYDISC, P_PRESET_(BluRayDisc)},
|
||||
{preset::LOW_LATENCY, P_PRESET_(LowLatency)},
|
||||
{preset::LOW_LATENCY_HIGH_PERFORMANCE, P_PRESET_(LowLatencyHighPerformance)},
|
||||
{preset::LOW_LATENCY_HIGH_QUALITY, P_PRESET_(LowLatencyHighQuality)},
|
||||
{preset::LOSSLESS, P_PRESET_(Lossless)},
|
||||
{preset::LOSSLESS_HIGH_PERFORMANCE, P_PRESET_(LosslessHighPerformance)},
|
||||
{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{
|
||||
@@ -105,12 +106,12 @@ std::map<preset, std::string> obsffmpeg::nvenc::preset_to_opt{
|
||||
};
|
||||
|
||||
std::map<ratecontrolmode, std::string> obsffmpeg::nvenc::ratecontrolmodes{
|
||||
{ratecontrolmode::CQP, P_RATECONTROL_MODE_(CQP)},
|
||||
{ratecontrolmode::VBR, P_RATECONTROL_MODE_(VBR)},
|
||||
{ratecontrolmode::VBR_HQ, P_RATECONTROL_MODE_(VBR_HQ)},
|
||||
{ratecontrolmode::CBR, P_RATECONTROL_MODE_(CBR)},
|
||||
{ratecontrolmode::CBR_HQ, P_RATECONTROL_MODE_(CBR_HQ)},
|
||||
{ratecontrolmode::CBR_LD_HQ, P_RATECONTROL_MODE_(CBR_LD_HQ)},
|
||||
{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{
|
||||
@@ -119,9 +120,9 @@ std::map<ratecontrolmode, std::string> obsffmpeg::nvenc::ratecontrolmode_to_opt{
|
||||
};
|
||||
|
||||
std::map<b_ref_mode, std::string> obsffmpeg::nvenc::b_ref_modes{
|
||||
{b_ref_mode::DISABLED, G_STATE_DISABLED},
|
||||
{b_ref_mode::EACH, P_OTHER_BFRAME_REFERENCEMODE ".Each"},
|
||||
{b_ref_mode::MIDDLE, P_OTHER_BFRAME_REFERENCEMODE ".Middle"},
|
||||
{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{
|
||||
@@ -130,43 +131,40 @@ std::map<b_ref_mode, std::string> obsffmpeg::nvenc::b_ref_mode_to_opt{
|
||||
{b_ref_mode::MIDDLE, "middle"},
|
||||
};
|
||||
|
||||
void obsffmpeg::nvenc::get_defaults(obs_data_t* settings, AVCodec*, AVCodecContext*)
|
||||
void obsffmpeg::nvenc::get_defaults(obs_data_t* settings, const AVCodec*, AVCodecContext*)
|
||||
{
|
||||
obs_data_set_default_int(settings, P_PRESET, static_cast<int64_t>(preset::DEFAULT));
|
||||
obs_data_set_default_int(settings, ST_PRESET, static_cast<int64_t>(preset::DEFAULT));
|
||||
|
||||
obs_data_set_default_int(settings, P_RATECONTROL_MODE, static_cast<int64_t>(ratecontrolmode::CBR_HQ));
|
||||
obs_data_set_default_int(settings, P_RATECONTROL_TWOPASS, -1);
|
||||
obs_data_set_default_int(settings, P_RATECONTROL_LOOKAHEAD, 0);
|
||||
obs_data_set_default_bool(settings, P_RATECONTROL_ADAPTIVEI, true);
|
||||
obs_data_set_default_bool(settings, P_RATECONTROL_ADAPTIVEB, true);
|
||||
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, P_RATECONTROL_BITRATE_TARGET, 6000);
|
||||
obs_data_set_default_int(settings, P_RATECONTROL_BITRATE_MAXIMUM, 6000);
|
||||
obs_data_set_default_int(settings, G_RATECONTROL_BUFFERSIZE, 12000);
|
||||
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, P_RATECONTROL_QUALITY_MINIMUM, 51);
|
||||
obs_data_set_default_int(settings, P_RATECONTROL_QUALITY_MAXIMUM, -1);
|
||||
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, P_RATECONTROL_QP_I, 21);
|
||||
obs_data_set_default_int(settings, P_RATECONTROL_QP_I_INITIAL, -1);
|
||||
obs_data_set_default_int(settings, P_RATECONTROL_QP_P, 21);
|
||||
obs_data_set_default_int(settings, P_RATECONTROL_QP_P_INITIAL, -1);
|
||||
obs_data_set_default_int(settings, P_RATECONTROL_QP_B, 21);
|
||||
obs_data_set_default_int(settings, P_RATECONTROL_QP_B_INITIAL, -1);
|
||||
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_ST_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_int(settings, G_KEYFRAMES_INTERVALTYPE, 0);
|
||||
obs_data_set_default_double(settings, G_KEYFRAMES_INTERVAL_SECONDS, 2.0);
|
||||
obs_data_set_default_int(settings, G_KEYFRAMES_INTERVAL_FRAMES, 300);
|
||||
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_bool(settings, P_AQ_SPATIAL, true);
|
||||
obs_data_set_default_int(settings, P_AQ_STRENGTH, 8);
|
||||
obs_data_set_default_bool(settings, P_AQ_TEMPORAL, true);
|
||||
|
||||
obs_data_set_default_int(settings, P_OTHER_BFRAMES, 2);
|
||||
obs_data_set_default_int(settings, P_OTHER_BFRAME_REFERENCEMODE, static_cast<int64_t>(b_ref_mode::DISABLED));
|
||||
obs_data_set_default_bool(settings, P_OTHER_ZEROLATENCY, false);
|
||||
obs_data_set_default_bool(settings, P_OTHER_WEIGHTED_PREDICTION, false);
|
||||
obs_data_set_default_bool(settings, P_OTHER_NONREFERENCE_PFRAMES, false);
|
||||
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)
|
||||
@@ -179,7 +177,7 @@ static bool modified_ratecontrol(obs_properties_t* props, obs_property_t*, obs_d
|
||||
bool have_qp = false;
|
||||
bool have_qp_init = false;
|
||||
|
||||
ratecontrolmode rc = static_cast<ratecontrolmode>(obs_data_get_int(settings, P_RATECONTROL_MODE));
|
||||
ratecontrolmode rc = static_cast<ratecontrolmode>(obs_data_get_int(settings, ST_RATECONTROL_MODE));
|
||||
switch (rc) {
|
||||
case ratecontrolmode::CQP:
|
||||
have_qp = true;
|
||||
@@ -198,73 +196,68 @@ static bool modified_ratecontrol(obs_properties_t* props, obs_property_t*, obs_d
|
||||
break;
|
||||
}
|
||||
|
||||
obs_property_set_visible(obs_properties_get(props, P_RATECONTROL_BITRATE), have_bitrate || have_bitrate_max);
|
||||
obs_property_set_visible(obs_properties_get(props, P_RATECONTROL_BITRATE_TARGET), have_bitrate);
|
||||
obs_property_set_visible(obs_properties_get(props, P_RATECONTROL_BITRATE_MAXIMUM), have_bitrate_max);
|
||||
obs_property_set_visible(obs_properties_get(props, G_RATECONTROL_BUFFERSIZE), have_bitrate || have_bitrate_max);
|
||||
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, P_RATECONTROL_QUALITY), have_quality);
|
||||
obs_property_set_visible(obs_properties_get(props, P_RATECONTROL_QUALITY_MINIMUM), have_quality);
|
||||
obs_property_set_visible(obs_properties_get(props, P_RATECONTROL_QUALITY_MAXIMUM), have_quality);
|
||||
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, P_RATECONTROL_QP_I), have_qp);
|
||||
obs_property_set_visible(obs_properties_get(props, P_RATECONTROL_QP_P), have_qp);
|
||||
obs_property_set_visible(obs_properties_get(props, P_RATECONTROL_QP_B), have_qp);
|
||||
obs_property_set_visible(obs_properties_get(props, P_RATECONTROL_QP_I_INITIAL), have_qp_init);
|
||||
obs_property_set_visible(obs_properties_get(props, P_RATECONTROL_QP_P_INITIAL), have_qp_init);
|
||||
obs_property_set_visible(obs_properties_get(props, P_RATECONTROL_QP_B_INITIAL), have_qp_init);
|
||||
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_ST_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, P_RATECONTROL_QUALITY);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_QUALITY_MINIMUM), enabled);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_QUALITY_MAXIMUM), enabled);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool modified_keyframes(obs_properties_t* props, obs_property_t*, obs_data_t* settings)
|
||||
{
|
||||
bool is_seconds = obs_data_get_int(settings, G_KEYFRAMES_INTERVALTYPE) == 0;
|
||||
obs_property_set_visible(obs_properties_get(props, G_KEYFRAMES_INTERVAL_FRAMES), !is_seconds);
|
||||
obs_property_set_visible(obs_properties_get(props, G_KEYFRAMES_INTERVAL_SECONDS), is_seconds);
|
||||
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, P_AQ_SPATIAL);
|
||||
obs_property_set_visible(obs_properties_get(props, P_AQ_STRENGTH), spatial_aq);
|
||||
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, AVCodec*)
|
||||
void obsffmpeg::nvenc::get_properties_pre(obs_properties_t* props, const AVCodec*)
|
||||
{
|
||||
{
|
||||
auto p = obs_properties_add_list(props, P_PRESET, TRANSLATE(P_PRESET), OBS_COMBO_TYPE_LIST,
|
||||
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(P_PRESET)));
|
||||
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, AVCodec* codec)
|
||||
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, P_RATECONTROL, TRANSLATE(P_RATECONTROL), OBS_GROUP_NORMAL, grp);
|
||||
obs_properties_add_group(props, ST_RATECONTROL, TRANSLATE(ST_RATECONTROL), OBS_GROUP_NORMAL,
|
||||
grp);
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_list(grp, P_RATECONTROL_MODE, TRANSLATE(P_RATECONTROL_MODE),
|
||||
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(P_RATECONTROL_MODE)));
|
||||
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()),
|
||||
@@ -273,29 +266,29 @@ void obsffmpeg::nvenc::get_properties_post(obs_properties_t* props, AVCodec* cod
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_list(grp, P_RATECONTROL_TWOPASS, TRANSLATE(P_RATECONTROL_TWOPASS),
|
||||
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(P_RATECONTROL_TWOPASS)));
|
||||
obs_property_list_add_int(p, TRANSLATE(G_STATE_DEFAULT), -1);
|
||||
obs_property_list_add_int(p, TRANSLATE(G_STATE_DISABLED), 0);
|
||||
obs_property_list_add_int(p, TRANSLATE(G_STATE_ENABLED), 1);
|
||||
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, P_RATECONTROL_LOOKAHEAD,
|
||||
TRANSLATE(P_RATECONTROL_LOOKAHEAD), 0, 60, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_RATECONTROL_LOOKAHEAD)));
|
||||
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, P_RATECONTROL_ADAPTIVEI, TRANSLATE(P_RATECONTROL_ADAPTIVEI));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_RATECONTROL_ADAPTIVEI)));
|
||||
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, P_RATECONTROL_ADAPTIVEB, TRANSLATE(P_RATECONTROL_ADAPTIVEB));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_RATECONTROL_ADAPTIVEB)));
|
||||
obs_properties_add_bool(grp, ST_RATECONTROL_ADAPTIVEB, TRANSLATE(ST_RATECONTROL_ADAPTIVEB));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_ADAPTIVEB)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,29 +296,29 @@ void obsffmpeg::nvenc::get_properties_post(obs_properties_t* props, AVCodec* cod
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, P_RATECONTROL_BITRATE, TRANSLATE(P_RATECONTROL_BITRATE),
|
||||
obs_properties_add_group(props, ST_RATECONTROL_BITRATE, TRANSLATE(ST_RATECONTROL_BITRATE),
|
||||
OBS_GROUP_NORMAL, grp);
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_int(grp, P_RATECONTROL_BITRATE_TARGET,
|
||||
TRANSLATE(P_RATECONTROL_BITRATE_TARGET), 1,
|
||||
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(P_RATECONTROL_BITRATE_TARGET)));
|
||||
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, P_RATECONTROL_BITRATE_MAXIMUM,
|
||||
TRANSLATE(P_RATECONTROL_BITRATE_MAXIMUM), 0,
|
||||
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(P_RATECONTROL_BITRATE_MAXIMUM)));
|
||||
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, G_RATECONTROL_BUFFERSIZE, TRANSLATE(G_RATECONTROL_BUFFERSIZE),
|
||||
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(G_RATECONTROL_BUFFERSIZE)));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(S_RATECONTROL_BUFFERSIZE)));
|
||||
obs_property_int_set_suffix(p, " kbit");
|
||||
}
|
||||
}
|
||||
@@ -334,64 +327,71 @@ void obsffmpeg::nvenc::get_properties_post(obs_properties_t* props, AVCodec* cod
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
auto p = obs_properties_add_group(props, P_RATECONTROL_QUALITY,
|
||||
TRANSLATE(P_RATECONTROL_QUALITY), OBS_GROUP_CHECKABLE, grp);
|
||||
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, P_RATECONTROL_QUALITY, TRANSLATE(P_RATECONTROL_QUALITY));
|
||||
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, P_RATECONTROL_QUALITY_MINIMUM,
|
||||
TRANSLATE(P_RATECONTROL_QUALITY_MINIMUM), 0, 51, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_RATECONTROL_QUALITY_MINIMUM)));
|
||||
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, P_RATECONTROL_QUALITY_MAXIMUM,
|
||||
TRANSLATE(P_RATECONTROL_QUALITY_MAXIMUM), -1, 51, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_RATECONTROL_QUALITY_MAXIMUM)));
|
||||
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, P_RATECONTROL_QP, TRANSLATE(P_RATECONTROL_QP),
|
||||
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, P_RATECONTROL_QP_I, TRANSLATE(P_RATECONTROL_QP_I),
|
||||
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(P_RATECONTROL_QP_I)));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QP_I)));
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_int_slider(grp, P_RATECONTROL_QP_I_INITIAL,
|
||||
TRANSLATE(P_RATECONTROL_QP_I_INITIAL), -1, 51, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_RATECONTROL_QP_I_INITIAL)));
|
||||
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, P_RATECONTROL_QP_P, TRANSLATE(P_RATECONTROL_QP_P),
|
||||
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(P_RATECONTROL_QP_P)));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QP_P)));
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_int_slider(grp, P_RATECONTROL_QP_P_INITIAL,
|
||||
TRANSLATE(P_RATECONTROL_QP_P_INITIAL), -1, 51, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_RATECONTROL_QP_P_INITIAL)));
|
||||
auto p = obs_properties_add_int_slider(grp, ST_RATECONTROL_QP_ST_INITIAL,
|
||||
TRANSLATE(ST_RATECONTROL_QP_ST_INITIAL), -1, 51, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QP_ST_INITIAL)));
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_int_slider(grp, P_RATECONTROL_QP_B, TRANSLATE(P_RATECONTROL_QP_B),
|
||||
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(P_RATECONTROL_QP_B)));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(ST_RATECONTROL_QP_B)));
|
||||
}
|
||||
{
|
||||
auto p = obs_properties_add_int_slider(grp, P_RATECONTROL_QP_B_INITIAL,
|
||||
TRANSLATE(P_RATECONTROL_QP_B_INITIAL), -1, 51, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_RATECONTROL_QP_B_INITIAL)));
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,53 +399,22 @@ void obsffmpeg::nvenc::get_properties_post(obs_properties_t* props, AVCodec* cod
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, G_KEYFRAMES, TRANSLATE(G_KEYFRAMES), OBS_GROUP_NORMAL, grp);
|
||||
obs_properties_add_group(props, ST_AQ, TRANSLATE(ST_AQ), OBS_GROUP_NORMAL, grp);
|
||||
}
|
||||
|
||||
{
|
||||
auto p =
|
||||
obs_properties_add_list(grp, G_KEYFRAMES_INTERVALTYPE, TRANSLATE(G_KEYFRAMES_INTERVALTYPE),
|
||||
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(G_KEYFRAMES_INTERVALTYPE)));
|
||||
obs_property_set_modified_callback(p, modified_keyframes);
|
||||
obs_property_list_add_int(p, TRANSLATE(G_KEYFRAMES_INTERVALTYPE_(Seconds)), 0);
|
||||
obs_property_list_add_int(p, TRANSLATE(G_KEYFRAMES_INTERVALTYPE_(Frames)), 1);
|
||||
}
|
||||
{
|
||||
auto p =
|
||||
obs_properties_add_float(grp, G_KEYFRAMES_INTERVAL_SECONDS, TRANSLATE(G_KEYFRAMES_INTERVAL),
|
||||
0.00, std::numeric_limits<int16_t>::max(), 0.01);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(G_KEYFRAMES_INTERVAL)));
|
||||
obs_property_float_set_suffix(p, " seconds");
|
||||
}
|
||||
{
|
||||
auto p =
|
||||
obs_properties_add_int(grp, G_KEYFRAMES_INTERVAL_FRAMES, TRANSLATE(G_KEYFRAMES_INTERVAL), 0,
|
||||
std::numeric_limits<int32_t>::max(), 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(G_KEYFRAMES_INTERVAL)));
|
||||
obs_property_int_set_suffix(p, " frames");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, P_AQ, TRANSLATE(P_AQ), OBS_GROUP_NORMAL, grp);
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_bool(grp, P_AQ_SPATIAL, TRANSLATE(P_AQ_SPATIAL));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_AQ_SPATIAL)));
|
||||
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, P_AQ_STRENGTH, TRANSLATE(P_AQ_STRENGTH), 1, 15, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_AQ_STRENGTH)));
|
||||
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, P_AQ_TEMPORAL, TRANSLATE(P_AQ_TEMPORAL));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_AQ_TEMPORAL)));
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,21 +422,21 @@ void obsffmpeg::nvenc::get_properties_post(obs_properties_t* props, AVCodec* cod
|
||||
obs_properties_t* grp = props;
|
||||
if (!obsffmpeg::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, P_OTHER, TRANSLATE(P_OTHER), OBS_GROUP_NORMAL, grp);
|
||||
obs_properties_add_group(props, ST_OTHER, TRANSLATE(ST_OTHER), OBS_GROUP_NORMAL, grp);
|
||||
}
|
||||
|
||||
{
|
||||
auto p =
|
||||
obs_properties_add_int_slider(grp, P_OTHER_BFRAMES, TRANSLATE(P_OTHER_BFRAMES), 0, 4, 1);
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_OTHER_BFRAMES)));
|
||||
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, P_OTHER_BFRAME_REFERENCEMODE,
|
||||
TRANSLATE(P_OTHER_BFRAME_REFERENCEMODE), OBS_COMBO_TYPE_LIST,
|
||||
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(P_OTHER_BFRAME_REFERENCEMODE)));
|
||||
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));
|
||||
@@ -475,67 +444,64 @@ void obsffmpeg::nvenc::get_properties_post(obs_properties_t* props, AVCodec* cod
|
||||
}
|
||||
|
||||
{
|
||||
auto p = obs_properties_add_bool(grp, P_OTHER_ZEROLATENCY, TRANSLATE(P_OTHER_ZEROLATENCY));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_OTHER_ZEROLATENCY)));
|
||||
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, P_OTHER_WEIGHTED_PREDICTION,
|
||||
TRANSLATE(P_OTHER_WEIGHTED_PREDICTION));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_OTHER_WEIGHTED_PREDICTION)));
|
||||
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, P_OTHER_NONREFERENCE_PFRAMES,
|
||||
TRANSLATE(P_OTHER_NONREFERENCE_PFRAMES));
|
||||
obs_property_set_long_description(p, TRANSLATE(DESC(P_OTHER_NONREFERENCE_PFRAMES)));
|
||||
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, AVCodec*, AVCodecContext*)
|
||||
void obsffmpeg::nvenc::get_runtime_properties(obs_properties_t* props, const AVCodec*, AVCodecContext*)
|
||||
{
|
||||
obs_property_set_enabled(obs_properties_get(props, P_PRESET), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_MODE), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_TWOPASS), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_LOOKAHEAD), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_ADAPTIVEI), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_ADAPTIVEB), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_BITRATE), true);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_BITRATE_TARGET), true);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_BITRATE_MAXIMUM), true);
|
||||
obs_property_set_enabled(obs_properties_get(props, G_RATECONTROL_BUFFERSIZE), true);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_QUALITY), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_QUALITY_MINIMUM), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_QUALITY_MAXIMUM), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_QP), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_QP_I), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_QP_I_INITIAL), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_QP_P), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_QP_P_INITIAL), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_QP_B), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_RATECONTROL_QP_B_INITIAL), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, G_KEYFRAMES), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, G_KEYFRAMES_INTERVALTYPE), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, G_KEYFRAMES_INTERVAL_SECONDS), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, G_KEYFRAMES_INTERVAL_FRAMES), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_AQ), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_AQ_SPATIAL), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_AQ_STRENGTH), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_AQ_TEMPORAL), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_OTHER), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_OTHER_BFRAMES), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_OTHER_BFRAME_REFERENCEMODE), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_OTHER_ZEROLATENCY), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_OTHER_WEIGHTED_PREDICTION), false);
|
||||
obs_property_set_enabled(obs_properties_get(props, P_OTHER_NONREFERENCE_PFRAMES), false);
|
||||
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_ST_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, AVCodec* codec, AVCodecContext* context)
|
||||
void obsffmpeg::nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context)
|
||||
{
|
||||
{
|
||||
preset c_preset = static_cast<preset>(obs_data_get_int(settings, P_PRESET));
|
||||
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);
|
||||
@@ -547,12 +513,11 @@ void obsffmpeg::nvenc::update(obs_data_t* settings, AVCodec* codec, AVCodecConte
|
||||
{ // Rate Control
|
||||
bool have_bitrate = false;
|
||||
bool have_bitrate_max = false;
|
||||
bool have_quality_min = false;
|
||||
bool have_quality_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, P_RATECONTROL_MODE));
|
||||
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);
|
||||
@@ -572,87 +537,75 @@ void obsffmpeg::nvenc::update(obs_data_t* settings, AVCodec* codec, AVCodecConte
|
||||
case ratecontrolmode::VBR_HQ:
|
||||
have_bitrate_max = true;
|
||||
have_bitrate = true;
|
||||
have_quality_min = true;
|
||||
have_quality_max = true;
|
||||
have_quality = true;
|
||||
have_qp_init = true;
|
||||
break;
|
||||
}
|
||||
|
||||
int tp = static_cast<int>(obs_data_get_int(settings, P_RATECONTROL_TWOPASS));
|
||||
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, P_RATECONTROL_LOOKAHEAD));
|
||||
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, P_RATECONTROL_ADAPTIVEI);
|
||||
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, P_RATECONTROL_ADAPTIVEB);
|
||||
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, P_RATECONTROL_BITRATE_TARGET) * 1000);
|
||||
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, P_RATECONTROL_BITRATE_MAXIMUM) * 1000);
|
||||
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, G_RATECONTROL_BUFFERSIZE) * 1000);
|
||||
static_cast<int>(obs_data_get_int(settings, S_RATECONTROL_BUFFERSIZE) * 1000);
|
||||
|
||||
if (have_quality_min && obs_data_get_bool(settings, P_RATECONTROL_QUALITY)) {
|
||||
int qmin = static_cast<int>(obs_data_get_int(settings, P_RATECONTROL_QUALITY_MINIMUM));
|
||||
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) && (have_quality_max)) {
|
||||
if (qmin >= 0) {
|
||||
context->qmax =
|
||||
static_cast<int>(obs_data_get_int(settings, P_RATECONTROL_QUALITY_MAXIMUM));
|
||||
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, P_RATECONTROL_QP_I)), 0);
|
||||
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, P_RATECONTROL_QP_P)), 0);
|
||||
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, P_RATECONTROL_QP_B)), 0);
|
||||
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, P_RATECONTROL_QP_I_INITIAL), 0);
|
||||
obs_data_get_int(settings, ST_RATECONTROL_QP_I_INITIAL), 0);
|
||||
av_opt_set_int(context->priv_data, "init_qpP",
|
||||
obs_data_get_int(settings, P_RATECONTROL_QP_P_INITIAL), 0);
|
||||
obs_data_get_int(settings, ST_RATECONTROL_QP_ST_INITIAL), 0);
|
||||
av_opt_set_int(context->priv_data, "init_qpB",
|
||||
obs_data_get_int(settings, P_RATECONTROL_QP_B_INITIAL), 0);
|
||||
obs_data_get_int(settings, ST_RATECONTROL_QP_B_INITIAL), 0);
|
||||
}
|
||||
}
|
||||
|
||||
{ // Key Frames
|
||||
obs_video_info ovi;
|
||||
if (!obs_get_video_info(&ovi)) {
|
||||
throw std::runtime_error("no video info");
|
||||
}
|
||||
|
||||
int64_t kf_type = obs_data_get_int(settings, G_KEYFRAMES_INTERVALTYPE);
|
||||
bool is_seconds = (kf_type == 0);
|
||||
|
||||
if (is_seconds) {
|
||||
context->gop_size = static_cast<int>(obs_data_get_double(settings, G_KEYFRAMES_INTERVAL_SECONDS)
|
||||
* (ovi.fps_num / ovi.fps_den));
|
||||
} else {
|
||||
context->gop_size = static_cast<int>(obs_data_get_int(settings, G_KEYFRAMES_INTERVAL_FRAMES));
|
||||
}
|
||||
context->keyint_min = context->gop_size;
|
||||
}
|
||||
|
||||
{ // AQ
|
||||
bool saq = obs_data_get_bool(settings, P_AQ_SPATIAL);
|
||||
bool taq = obs_data_get_bool(settings, P_AQ_TEMPORAL);
|
||||
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);
|
||||
@@ -663,16 +616,16 @@ void obsffmpeg::nvenc::update(obs_data_t* settings, AVCodec* codec, AVCodecConte
|
||||
}
|
||||
if (saq) {
|
||||
av_opt_set_int(context->priv_data, "aq-strength",
|
||||
static_cast<int>(obs_data_get_int(settings, P_AQ_STRENGTH)), 0);
|
||||
static_cast<int>(obs_data_get_int(settings, ST_AQ_STRENGTH)), 0);
|
||||
}
|
||||
}
|
||||
|
||||
{ // Other
|
||||
bool zl = obs_data_get_bool(settings, P_OTHER_ZEROLATENCY);
|
||||
bool wp = obs_data_get_bool(settings, P_OTHER_WEIGHTED_PREDICTION);
|
||||
bool nrp = obs_data_get_bool(settings, P_OTHER_NONREFERENCE_PFRAMES);
|
||||
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, P_OTHER_BFRAMES));
|
||||
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);
|
||||
@@ -686,7 +639,7 @@ void obsffmpeg::nvenc::update(obs_data_t* settings, AVCodec* codec, AVCodecConte
|
||||
|
||||
{
|
||||
auto found = b_ref_mode_to_opt.find(
|
||||
static_cast<b_ref_mode>(obs_data_get_int(settings, P_OTHER_BFRAME_REFERENCEMODE)));
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -75,14 +75,14 @@ namespace obsffmpeg {
|
||||
|
||||
extern std::map<b_ref_mode, std::string> b_ref_mode_to_opt;
|
||||
|
||||
void get_defaults(obs_data_t* settings, AVCodec* codec, AVCodecContext* context);
|
||||
void get_defaults(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context);
|
||||
|
||||
void get_properties_pre(obs_properties_t* props, AVCodec* codec);
|
||||
void get_properties_pre(obs_properties_t* props, const AVCodec* codec);
|
||||
|
||||
void get_properties_post(obs_properties_t* props, AVCodec* codec);
|
||||
void get_properties_post(obs_properties_t* props, const AVCodec* codec);
|
||||
|
||||
void get_runtime_properties(obs_properties_t* props, AVCodec* codec, AVCodecContext* context);
|
||||
void get_runtime_properties(obs_properties_t* props, const AVCodec* codec, AVCodecContext* context);
|
||||
|
||||
void update(obs_data_t* settings, AVCodec* codec, AVCodecContext* context);
|
||||
void update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context);
|
||||
} // namespace nvenc
|
||||
} // namespace obsffmpeg
|
||||
|
||||
@@ -41,12 +41,13 @@ INITIALIZER(prores_aw_handler_init)
|
||||
});
|
||||
};
|
||||
|
||||
void obsffmpeg::ui::prores_aw_handler::get_defaults(obs_data_t* settings, AVCodec*, AVCodecContext*)
|
||||
void obsffmpeg::ui::prores_aw_handler::get_defaults(obs_data_t* settings, const AVCodec*, AVCodecContext*)
|
||||
{
|
||||
obs_data_set_default_int(settings, P_PROFILE, 0);
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::prores_aw_handler::get_properties(obs_properties_t* props, AVCodec* codec, AVCodecContext* context)
|
||||
void obsffmpeg::ui::prores_aw_handler::get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context)
|
||||
{
|
||||
if (!context) {
|
||||
auto p = obs_properties_add_list(props, P_PROFILE, TRANSLATE(P_PROFILE), OBS_COMBO_TYPE_LIST,
|
||||
@@ -77,7 +78,7 @@ void obsffmpeg::ui::prores_aw_handler::get_properties(obs_properties_t* props, A
|
||||
}
|
||||
}
|
||||
|
||||
void obsffmpeg::ui::prores_aw_handler::update(obs_data_t* settings, AVCodec*, AVCodecContext* context)
|
||||
void obsffmpeg::ui::prores_aw_handler::update(obs_data_t* settings, const AVCodec*, AVCodecContext* context)
|
||||
{
|
||||
context->profile = static_cast<int>(obs_data_get_int(settings, P_PROFILE));
|
||||
}
|
||||
|
||||
@@ -34,13 +34,14 @@ namespace obsffmpeg {
|
||||
namespace ui {
|
||||
class prores_aw_handler : public handler {
|
||||
public:
|
||||
virtual void get_defaults(obs_data_t* settings, AVCodec* codec,
|
||||
virtual void get_defaults(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
|
||||
virtual void get_properties(obs_properties_t* props, AVCodec* codec,
|
||||
virtual void get_properties(obs_properties_t* props, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
|
||||
virtual void update(obs_data_t* settings, AVCodec* codec, AVCodecContext* context) override;
|
||||
virtual void update(obs_data_t* settings, const AVCodec* codec,
|
||||
AVCodecContext* context) override;
|
||||
};
|
||||
} // namespace ui
|
||||
} // namespace obsffmpeg
|
||||
|
||||
Reference in New Issue
Block a user