2015-02-06 03:17:33 -08:00
|
|
|
#include <string>
|
2016-07-04 23:11:24 -07:00
|
|
|
#include <algorithm>
|
2015-02-06 03:17:33 -08:00
|
|
|
#include <QMessageBox>
|
2017-05-13 14:06:32 -07:00
|
|
|
#include "qt-wrappers.hpp"
|
2015-07-02 01:00:22 -07:00
|
|
|
#include "audio-encoders.hpp"
|
2015-02-06 03:17:33 -08:00
|
|
|
#include "window-basic-main.hpp"
|
|
|
|
#include "window-basic-main-outputs.hpp"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2015-09-06 16:19:53 -07:00
|
|
|
static void OBSStreamStarting(void *data, calldata_t *params)
|
|
|
|
{
|
|
|
|
BasicOutputHandler *output = static_cast<BasicOutputHandler*>(data);
|
|
|
|
obs_output_t *obj = (obs_output_t*)calldata_ptr(params, "output");
|
|
|
|
|
|
|
|
int sec = (int)obs_output_get_active_delay(obj);
|
|
|
|
if (sec == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
output->delayActive = true;
|
|
|
|
QMetaObject::invokeMethod(output->main,
|
|
|
|
"StreamDelayStarting", Q_ARG(int, sec));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void OBSStreamStopping(void *data, calldata_t *params)
|
|
|
|
{
|
|
|
|
BasicOutputHandler *output = static_cast<BasicOutputHandler*>(data);
|
|
|
|
obs_output_t *obj = (obs_output_t*)calldata_ptr(params, "output");
|
|
|
|
|
|
|
|
int sec = (int)obs_output_get_active_delay(obj);
|
|
|
|
if (sec == 0)
|
2016-06-22 01:47:08 -07:00
|
|
|
QMetaObject::invokeMethod(output->main, "StreamStopping");
|
|
|
|
else
|
|
|
|
QMetaObject::invokeMethod(output->main,
|
|
|
|
"StreamDelayStopping", Q_ARG(int, sec));
|
2015-09-06 16:19:53 -07:00
|
|
|
}
|
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
static void OBSStartStreaming(void *data, calldata_t *params)
|
|
|
|
{
|
|
|
|
BasicOutputHandler *output = static_cast<BasicOutputHandler*>(data);
|
2015-09-06 16:07:45 -07:00
|
|
|
output->streamingActive = true;
|
2015-02-06 03:17:33 -08:00
|
|
|
QMetaObject::invokeMethod(output->main, "StreamingStart");
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void OBSStopStreaming(void *data, calldata_t *params)
|
|
|
|
{
|
|
|
|
BasicOutputHandler *output = static_cast<BasicOutputHandler*>(data);
|
|
|
|
int code = (int)calldata_int(params, "code");
|
2017-05-15 03:03:00 -07:00
|
|
|
const char *last_error = calldata_string(params, "last_error");
|
|
|
|
|
|
|
|
QString arg_last_error = QString::fromUtf8(last_error);
|
2015-02-06 03:17:33 -08:00
|
|
|
|
2015-09-06 16:07:45 -07:00
|
|
|
output->streamingActive = false;
|
2015-09-06 16:19:53 -07:00
|
|
|
output->delayActive = false;
|
2015-02-06 03:17:33 -08:00
|
|
|
QMetaObject::invokeMethod(output->main,
|
2017-05-15 03:03:00 -07:00
|
|
|
"StreamingStop", Q_ARG(int, code), Q_ARG(QString, arg_last_error));
|
2015-02-06 03:17:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void OBSStartRecording(void *data, calldata_t *params)
|
|
|
|
{
|
|
|
|
BasicOutputHandler *output = static_cast<BasicOutputHandler*>(data);
|
|
|
|
|
2015-09-06 16:07:45 -07:00
|
|
|
output->recordingActive = true;
|
2015-02-06 03:17:33 -08:00
|
|
|
QMetaObject::invokeMethod(output->main, "RecordingStart");
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void OBSStopRecording(void *data, calldata_t *params)
|
|
|
|
{
|
|
|
|
BasicOutputHandler *output = static_cast<BasicOutputHandler*>(data);
|
2015-06-09 21:00:22 -07:00
|
|
|
int code = (int)calldata_int(params, "code");
|
2015-02-06 03:17:33 -08:00
|
|
|
|
2015-09-06 16:07:45 -07:00
|
|
|
output->recordingActive = false;
|
2015-06-09 21:00:22 -07:00
|
|
|
QMetaObject::invokeMethod(output->main,
|
|
|
|
"RecordingStop", Q_ARG(int, code));
|
2015-02-06 03:17:33 -08:00
|
|
|
|
|
|
|
UNUSED_PARAMETER(params);
|
|
|
|
}
|
|
|
|
|
2016-06-22 01:47:08 -07:00
|
|
|
static void OBSRecordStopping(void *data, calldata_t *params)
|
|
|
|
{
|
|
|
|
BasicOutputHandler *output = static_cast<BasicOutputHandler*>(data);
|
|
|
|
QMetaObject::invokeMethod(output->main, "RecordStopping");
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(params);
|
|
|
|
}
|
|
|
|
|
2016-12-09 14:40:04 -08:00
|
|
|
static void OBSStartReplayBuffer(void *data, calldata_t *params)
|
|
|
|
{
|
|
|
|
BasicOutputHandler *output = static_cast<BasicOutputHandler*>(data);
|
|
|
|
|
|
|
|
output->replayBufferActive = true;
|
|
|
|
QMetaObject::invokeMethod(output->main, "ReplayBufferStart");
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void OBSStopReplayBuffer(void *data, calldata_t *params)
|
|
|
|
{
|
|
|
|
BasicOutputHandler *output = static_cast<BasicOutputHandler*>(data);
|
|
|
|
int code = (int)calldata_int(params, "code");
|
|
|
|
|
|
|
|
output->replayBufferActive = false;
|
|
|
|
QMetaObject::invokeMethod(output->main,
|
|
|
|
"ReplayBufferStop", Q_ARG(int, code));
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void OBSReplayBufferStopping(void *data, calldata_t *params)
|
|
|
|
{
|
|
|
|
BasicOutputHandler *output = static_cast<BasicOutputHandler*>(data);
|
|
|
|
QMetaObject::invokeMethod(output->main, "ReplayBufferStopping");
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(params);
|
|
|
|
}
|
|
|
|
|
2016-03-25 02:43:38 -07:00
|
|
|
static void FindBestFilename(string &strPath, bool noSpace)
|
|
|
|
{
|
|
|
|
int num = 2;
|
|
|
|
|
|
|
|
if (!os_file_exists(strPath.c_str()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const char *ext = strrchr(strPath.c_str(), '.');
|
|
|
|
if (!ext)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int extStart = int(ext - strPath.c_str());
|
|
|
|
for (;;) {
|
|
|
|
string testPath = strPath;
|
|
|
|
string numStr;
|
|
|
|
|
|
|
|
numStr = noSpace ? "_" : " (";
|
|
|
|
numStr += to_string(num++);
|
|
|
|
if (!noSpace)
|
|
|
|
numStr += ")";
|
|
|
|
|
|
|
|
testPath.insert(extStart, numStr);
|
|
|
|
|
|
|
|
if (!os_file_exists(testPath.c_str())) {
|
|
|
|
strPath = testPath;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2015-07-02 01:00:22 -07:00
|
|
|
static bool CreateAACEncoder(OBSEncoder &res, string &id, int bitrate,
|
|
|
|
const char *name, size_t idx)
|
2015-06-05 16:52:22 -07:00
|
|
|
{
|
2015-07-02 01:00:22 -07:00
|
|
|
const char *id_ = GetAACEncoderForBitrate(bitrate);
|
|
|
|
if (!id_) {
|
|
|
|
id.clear();
|
|
|
|
res = nullptr;
|
|
|
|
return false;
|
2015-06-05 16:52:22 -07:00
|
|
|
}
|
|
|
|
|
2015-07-02 01:00:22 -07:00
|
|
|
if (id == id_)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
id = id_;
|
|
|
|
res = obs_audio_encoder_create(id_, name, nullptr, idx, nullptr);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
obs_encoder_release(res);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-06-05 16:52:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
struct SimpleOutput : BasicOutputHandler {
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
OBSEncoder aacStreaming;
|
|
|
|
OBSEncoder h264Streaming;
|
|
|
|
OBSEncoder aacRecording;
|
|
|
|
OBSEncoder h264Recording;
|
2015-02-06 03:17:33 -08:00
|
|
|
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
string aacRecEncID;
|
|
|
|
string aacStreamEncID;
|
|
|
|
|
|
|
|
string videoEncoder;
|
|
|
|
string videoQuality;
|
|
|
|
bool usingRecordingPreset = false;
|
2016-12-09 14:40:04 -08:00
|
|
|
bool recordingConfigured = false;
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
bool ffmpegOutput = false;
|
|
|
|
bool lowCPUx264 = false;
|
2015-07-02 01:00:22 -07:00
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
SimpleOutput(OBSBasic *main_);
|
|
|
|
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
int CalcCRF(int crf);
|
|
|
|
|
2016-09-26 16:29:33 -07:00
|
|
|
void UpdateStreamingSettings_amd(obs_data_t *settings, int bitrate);
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
void UpdateRecordingSettings_x264_crf(int crf);
|
2016-04-18 00:56:51 -07:00
|
|
|
void UpdateRecordingSettings_qsv11(int crf);
|
2016-05-08 11:21:37 -07:00
|
|
|
void UpdateRecordingSettings_nvenc(int cqp);
|
2016-09-26 16:29:33 -07:00
|
|
|
void UpdateRecordingSettings_amd_cqp(int cqp);
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
void UpdateRecordingSettings();
|
|
|
|
void UpdateRecordingAudioSettings();
|
2015-02-06 03:17:33 -08:00
|
|
|
virtual void Update() override;
|
|
|
|
|
|
|
|
void SetupOutputs();
|
2015-07-02 00:58:28 -07:00
|
|
|
int GetAudioBitrate() const;
|
2015-02-06 03:17:33 -08:00
|
|
|
|
2016-04-18 00:56:51 -07:00
|
|
|
void LoadRecordingPreset_h264(const char *encoder);
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
void LoadRecordingPreset_Lossless();
|
|
|
|
void LoadRecordingPreset();
|
|
|
|
|
2016-04-18 00:56:51 -07:00
|
|
|
void LoadStreamingPreset_h264(const char *encoder);
|
|
|
|
|
2016-12-09 14:40:04 -08:00
|
|
|
void UpdateRecording();
|
|
|
|
bool ConfigureRecording(bool useReplayBuffer);
|
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
virtual bool StartStreaming(obs_service_t *service) override;
|
|
|
|
virtual bool StartRecording() override;
|
2016-12-09 14:40:04 -08:00
|
|
|
virtual bool StartReplayBuffer() override;
|
2016-09-09 07:37:54 -07:00
|
|
|
virtual void StopStreaming(bool force) override;
|
|
|
|
virtual void StopRecording(bool force) override;
|
2016-12-09 14:40:04 -08:00
|
|
|
virtual void StopReplayBuffer(bool force) override;
|
2015-02-06 03:17:33 -08:00
|
|
|
virtual bool StreamingActive() const override;
|
|
|
|
virtual bool RecordingActive() const override;
|
2016-12-09 14:40:04 -08:00
|
|
|
virtual bool ReplayBufferActive() const override;
|
2015-02-06 03:17:33 -08:00
|
|
|
};
|
|
|
|
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
void SimpleOutput::LoadRecordingPreset_Lossless()
|
|
|
|
{
|
|
|
|
fileOutput = obs_output_create("ffmpeg_output",
|
|
|
|
"simple_ffmpeg_output", nullptr, nullptr);
|
|
|
|
if (!fileOutput)
|
|
|
|
throw "Failed to create recording FFmpeg output "
|
|
|
|
"(simple output)";
|
|
|
|
obs_output_release(fileOutput);
|
|
|
|
|
|
|
|
obs_data_t *settings = obs_data_create();
|
2016-02-09 18:46:15 -08:00
|
|
|
obs_data_set_string(settings, "format_name", "avi");
|
2015-09-19 21:21:34 -07:00
|
|
|
obs_data_set_string(settings, "video_encoder", "utvideo");
|
2016-02-09 19:24:44 -08:00
|
|
|
obs_data_set_string(settings, "audio_encoder", "pcm_s16le");
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
|
|
|
|
obs_output_update(fileOutput, settings);
|
|
|
|
obs_data_release(settings);
|
|
|
|
}
|
|
|
|
|
2016-04-18 00:56:51 -07:00
|
|
|
void SimpleOutput::LoadRecordingPreset_h264(const char *encoderId)
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
{
|
2016-04-18 00:56:51 -07:00
|
|
|
h264Recording = obs_video_encoder_create(encoderId,
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
"simple_h264_recording", nullptr, nullptr);
|
|
|
|
if (!h264Recording)
|
|
|
|
throw "Failed to create h264 recording encoder (simple output)";
|
|
|
|
obs_encoder_release(h264Recording);
|
2016-04-18 00:56:51 -07:00
|
|
|
}
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
|
2016-04-18 00:56:51 -07:00
|
|
|
void SimpleOutput::LoadStreamingPreset_h264(const char *encoderId)
|
|
|
|
{
|
|
|
|
h264Streaming = obs_video_encoder_create(encoderId,
|
|
|
|
"simple_h264_stream", nullptr, nullptr);
|
|
|
|
if (!h264Streaming)
|
|
|
|
throw "Failed to create h264 streaming encoder (simple output)";
|
|
|
|
obs_encoder_release(h264Streaming);
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleOutput::LoadRecordingPreset()
|
|
|
|
{
|
|
|
|
const char *quality = config_get_string(main->Config(), "SimpleOutput",
|
|
|
|
"RecQuality");
|
|
|
|
const char *encoder = config_get_string(main->Config(), "SimpleOutput",
|
|
|
|
"RecEncoder");
|
|
|
|
|
|
|
|
videoEncoder = encoder;
|
|
|
|
videoQuality = quality;
|
|
|
|
ffmpegOutput = false;
|
|
|
|
|
|
|
|
if (strcmp(quality, "Stream") == 0) {
|
|
|
|
h264Recording = h264Streaming;
|
|
|
|
aacRecording = aacStreaming;
|
|
|
|
usingRecordingPreset = false;
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else if (strcmp(quality, "Lossless") == 0) {
|
|
|
|
LoadRecordingPreset_Lossless();
|
|
|
|
usingRecordingPreset = true;
|
|
|
|
ffmpegOutput = true;
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else {
|
2016-04-18 00:56:51 -07:00
|
|
|
lowCPUx264 = false;
|
|
|
|
|
|
|
|
if (strcmp(encoder, SIMPLE_ENCODER_X264) == 0) {
|
|
|
|
LoadRecordingPreset_h264("obs_x264");
|
|
|
|
} else if (strcmp(encoder, SIMPLE_ENCODER_X264_LOWCPU) == 0) {
|
|
|
|
LoadRecordingPreset_h264("obs_x264");
|
|
|
|
lowCPUx264 = true;
|
|
|
|
} else if (strcmp(encoder, SIMPLE_ENCODER_QSV) == 0) {
|
|
|
|
LoadRecordingPreset_h264("obs_qsv11");
|
2016-09-26 16:29:33 -07:00
|
|
|
} else if (strcmp(encoder, SIMPLE_ENCODER_AMD) == 0) {
|
|
|
|
LoadRecordingPreset_h264("amd_amf_h264");
|
2016-04-18 16:12:59 -07:00
|
|
|
} else if (strcmp(encoder, SIMPLE_ENCODER_NVENC) == 0) {
|
|
|
|
LoadRecordingPreset_h264("ffmpeg_nvenc");
|
2016-04-18 00:56:51 -07:00
|
|
|
}
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
usingRecordingPreset = true;
|
2016-04-18 00:56:51 -07:00
|
|
|
|
|
|
|
if (!CreateAACEncoder(aacRecording, aacRecEncID, 192,
|
|
|
|
"simple_aac_recording", 0))
|
|
|
|
throw "Failed to create aac recording encoder "
|
|
|
|
"(simple output)";
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
SimpleOutput::SimpleOutput(OBSBasic *main_) : BasicOutputHandler(main_)
|
|
|
|
{
|
2016-04-18 00:56:51 -07:00
|
|
|
const char *encoder = config_get_string(main->Config(), "SimpleOutput",
|
|
|
|
"StreamEncoder");
|
|
|
|
if (strcmp(encoder, SIMPLE_ENCODER_QSV) == 0)
|
|
|
|
LoadStreamingPreset_h264("obs_qsv11");
|
2016-09-26 16:29:33 -07:00
|
|
|
else if (strcmp(encoder, SIMPLE_ENCODER_AMD) == 0)
|
|
|
|
LoadStreamingPreset_h264("amd_amf_h264");
|
2016-04-18 16:12:59 -07:00
|
|
|
else if (strcmp(encoder, SIMPLE_ENCODER_NVENC) == 0)
|
|
|
|
LoadStreamingPreset_h264("ffmpeg_nvenc");
|
2016-04-18 00:56:51 -07:00
|
|
|
else
|
|
|
|
LoadStreamingPreset_h264("obs_x264");
|
2015-02-06 03:17:33 -08:00
|
|
|
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
if (!CreateAACEncoder(aacStreaming, aacStreamEncID, GetAudioBitrate(),
|
2015-07-02 01:00:22 -07:00
|
|
|
"simple_aac", 0))
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
throw "Failed to create aac streaming encoder (simple output)";
|
2015-02-06 03:17:33 -08:00
|
|
|
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
LoadRecordingPreset();
|
|
|
|
|
|
|
|
if (!ffmpegOutput) {
|
2016-12-09 14:40:04 -08:00
|
|
|
bool useReplayBuffer = config_get_bool(main->Config(),
|
2016-12-07 05:21:44 -08:00
|
|
|
"SimpleOutput", "RecRB");
|
2016-12-09 14:40:04 -08:00
|
|
|
if (useReplayBuffer) {
|
2016-12-07 05:21:44 -08:00
|
|
|
const char *str = config_get_string(main->Config(),
|
|
|
|
"Hotkeys", "ReplayBuffer");
|
|
|
|
obs_data_t *hotkey = obs_data_create_from_json(str);
|
2016-12-09 14:40:04 -08:00
|
|
|
replayBuffer = obs_output_create("replay_buffer",
|
2016-12-07 05:21:44 -08:00
|
|
|
Str("ReplayBuffer"), nullptr, hotkey);
|
|
|
|
|
|
|
|
obs_data_release(hotkey);
|
2016-12-09 14:40:04 -08:00
|
|
|
if (!replayBuffer)
|
|
|
|
throw "Failed to create replay buffer output "
|
|
|
|
"(simple output)";
|
|
|
|
obs_output_release(replayBuffer);
|
|
|
|
|
|
|
|
signal_handler_t *signal =
|
|
|
|
obs_output_get_signal_handler(replayBuffer);
|
|
|
|
|
|
|
|
startReplayBuffer.Connect(signal, "start",
|
|
|
|
OBSStartReplayBuffer, this);
|
|
|
|
stopReplayBuffer.Connect(signal, "stop",
|
|
|
|
OBSStopReplayBuffer, this);
|
|
|
|
replayBufferStopping.Connect(signal, "stopping",
|
|
|
|
OBSReplayBufferStopping, this);
|
2016-12-07 05:21:44 -08:00
|
|
|
}
|
|
|
|
|
2016-12-09 14:40:04 -08:00
|
|
|
fileOutput = obs_output_create("ffmpeg_muxer",
|
|
|
|
"simple_file_output", nullptr, nullptr);
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
if (!fileOutput)
|
|
|
|
throw "Failed to create recording output "
|
|
|
|
"(simple output)";
|
|
|
|
obs_output_release(fileOutput);
|
|
|
|
}
|
|
|
|
|
2015-07-03 23:00:21 -07:00
|
|
|
startRecording.Connect(obs_output_get_signal_handler(fileOutput),
|
2015-02-06 03:17:33 -08:00
|
|
|
"start", OBSStartRecording, this);
|
2015-07-03 23:00:21 -07:00
|
|
|
stopRecording.Connect(obs_output_get_signal_handler(fileOutput),
|
2015-02-06 03:17:33 -08:00
|
|
|
"stop", OBSStopRecording, this);
|
2016-06-22 01:47:08 -07:00
|
|
|
recordStopping.Connect(obs_output_get_signal_handler(fileOutput),
|
|
|
|
"stopping", OBSRecordStopping, this);
|
2015-02-06 03:17:33 -08:00
|
|
|
}
|
|
|
|
|
2015-07-02 00:58:28 -07:00
|
|
|
int SimpleOutput::GetAudioBitrate() const
|
|
|
|
{
|
2015-09-21 18:36:26 -07:00
|
|
|
int bitrate = (int)config_get_uint(main->Config(), "SimpleOutput",
|
|
|
|
"ABitrate");
|
|
|
|
|
|
|
|
return FindClosestAvailableAACBitrate(bitrate);
|
2015-07-02 00:58:28 -07:00
|
|
|
}
|
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
void SimpleOutput::Update()
|
|
|
|
{
|
|
|
|
obs_data_t *h264Settings = obs_data_create();
|
|
|
|
obs_data_t *aacSettings = obs_data_create();
|
|
|
|
|
|
|
|
int videoBitrate = config_get_uint(main->Config(), "SimpleOutput",
|
|
|
|
"VBitrate");
|
2015-07-02 00:58:28 -07:00
|
|
|
int audioBitrate = GetAudioBitrate();
|
2015-02-06 03:17:33 -08:00
|
|
|
bool advanced = config_get_bool(main->Config(), "SimpleOutput",
|
|
|
|
"UseAdvanced");
|
2016-04-10 03:10:36 -07:00
|
|
|
bool enforceBitrate = config_get_bool(main->Config(), "SimpleOutput",
|
|
|
|
"EnforceBitrate");
|
2015-02-06 03:17:33 -08:00
|
|
|
const char *custom = config_get_string(main->Config(),
|
|
|
|
"SimpleOutput", "x264Settings");
|
2016-04-18 00:56:51 -07:00
|
|
|
const char *encoder = config_get_string(main->Config(), "SimpleOutput",
|
|
|
|
"StreamEncoder");
|
|
|
|
const char *presetType;
|
|
|
|
const char *preset;
|
|
|
|
|
2016-09-26 16:29:33 -07:00
|
|
|
if (strcmp(encoder, SIMPLE_ENCODER_QSV) == 0) {
|
2016-04-18 00:56:51 -07:00
|
|
|
presetType = "QSVPreset";
|
2016-09-26 16:29:33 -07:00
|
|
|
|
|
|
|
} else if (strcmp(encoder, SIMPLE_ENCODER_AMD) == 0) {
|
|
|
|
presetType = "AMDPreset";
|
|
|
|
UpdateStreamingSettings_amd(h264Settings, videoBitrate);
|
|
|
|
|
|
|
|
} else if (strcmp(encoder, SIMPLE_ENCODER_NVENC) == 0) {
|
2016-04-18 16:12:59 -07:00
|
|
|
presetType = "NVENCPreset";
|
2016-09-26 16:29:33 -07:00
|
|
|
|
|
|
|
} else {
|
2016-04-18 00:56:51 -07:00
|
|
|
presetType = "Preset";
|
2016-09-26 16:29:33 -07:00
|
|
|
}
|
2016-04-18 00:56:51 -07:00
|
|
|
|
|
|
|
preset = config_get_string(main->Config(), "SimpleOutput", presetType);
|
2015-02-06 03:17:33 -08:00
|
|
|
|
2016-05-26 07:54:29 -07:00
|
|
|
obs_data_set_string(h264Settings, "rate_control", "CBR");
|
2015-02-06 03:17:33 -08:00
|
|
|
obs_data_set_int(h264Settings, "bitrate", videoBitrate);
|
|
|
|
|
|
|
|
if (advanced) {
|
|
|
|
obs_data_set_string(h264Settings, "preset", preset);
|
|
|
|
obs_data_set_string(h264Settings, "x264opts", custom);
|
|
|
|
}
|
|
|
|
|
2016-05-08 11:20:51 -07:00
|
|
|
obs_data_set_string(aacSettings, "rate_control", "CBR");
|
2015-02-06 03:17:33 -08:00
|
|
|
obs_data_set_int(aacSettings, "bitrate", audioBitrate);
|
|
|
|
|
2015-03-07 16:32:00 -08:00
|
|
|
obs_service_apply_encoder_settings(main->GetService(),
|
|
|
|
h264Settings, aacSettings);
|
|
|
|
|
2016-04-10 22:53:42 -07:00
|
|
|
if (advanced && !enforceBitrate) {
|
2016-04-10 03:10:36 -07:00
|
|
|
obs_data_set_int(h264Settings, "bitrate", videoBitrate);
|
2016-04-10 22:53:42 -07:00
|
|
|
obs_data_set_int(aacSettings, "bitrate", audioBitrate);
|
|
|
|
}
|
2016-04-10 03:10:36 -07:00
|
|
|
|
2015-04-17 02:48:06 -07:00
|
|
|
video_t *video = obs_get_video();
|
|
|
|
enum video_format format = video_output_get_format(video);
|
|
|
|
|
|
|
|
if (format != VIDEO_FORMAT_NV12 && format != VIDEO_FORMAT_I420)
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
obs_encoder_set_preferred_video_format(h264Streaming,
|
|
|
|
VIDEO_FORMAT_NV12);
|
2015-04-17 02:48:06 -07:00
|
|
|
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
obs_encoder_update(h264Streaming, h264Settings);
|
|
|
|
obs_encoder_update(aacStreaming, aacSettings);
|
2015-02-06 03:17:33 -08:00
|
|
|
|
|
|
|
obs_data_release(h264Settings);
|
|
|
|
obs_data_release(aacSettings);
|
|
|
|
}
|
|
|
|
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
void SimpleOutput::UpdateRecordingAudioSettings()
|
|
|
|
{
|
|
|
|
obs_data_t *settings = obs_data_create();
|
|
|
|
obs_data_set_int(settings, "bitrate", 192);
|
2016-05-08 11:20:51 -07:00
|
|
|
obs_data_set_string(settings, "rate_control", "CBR");
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
|
|
|
|
obs_encoder_update(aacRecording, settings);
|
|
|
|
|
|
|
|
obs_data_release(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CROSS_DIST_CUTOFF 2000.0
|
|
|
|
|
|
|
|
int SimpleOutput::CalcCRF(int crf)
|
|
|
|
{
|
|
|
|
int cx = config_get_uint(main->Config(), "Video", "OutputCX");
|
|
|
|
int cy = config_get_uint(main->Config(), "Video", "OutputCY");
|
|
|
|
double fCX = double(cx);
|
|
|
|
double fCY = double(cy);
|
|
|
|
|
|
|
|
if (lowCPUx264)
|
|
|
|
crf -= 2;
|
|
|
|
|
|
|
|
double crossDist = sqrt(fCX * fCX + fCY * fCY);
|
|
|
|
double crfResReduction =
|
|
|
|
fmin(CROSS_DIST_CUTOFF, crossDist) / CROSS_DIST_CUTOFF;
|
|
|
|
crfResReduction = (1.0 - crfResReduction) * 10.0;
|
|
|
|
|
|
|
|
return crf - int(crfResReduction);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleOutput::UpdateRecordingSettings_x264_crf(int crf)
|
|
|
|
{
|
|
|
|
obs_data_t *settings = obs_data_create();
|
|
|
|
obs_data_set_int(settings, "crf", crf);
|
|
|
|
obs_data_set_bool(settings, "use_bufsize", true);
|
2016-05-08 11:20:51 -07:00
|
|
|
obs_data_set_string(settings, "rate_control", "CRF");
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
obs_data_set_string(settings, "profile", "high");
|
|
|
|
obs_data_set_string(settings, "preset",
|
|
|
|
lowCPUx264 ? "ultrafast" : "veryfast");
|
|
|
|
|
|
|
|
obs_encoder_update(h264Recording, settings);
|
|
|
|
|
|
|
|
obs_data_release(settings);
|
|
|
|
}
|
|
|
|
|
2016-04-18 00:56:51 -07:00
|
|
|
static bool icq_available(obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
obs_properties_t *props = obs_encoder_properties(encoder);
|
|
|
|
obs_property_t *p = obs_properties_get(props, "rate_control");
|
|
|
|
bool icq_found = false;
|
|
|
|
|
|
|
|
size_t num = obs_property_list_item_count(p);
|
|
|
|
for (size_t i = 0; i < num; i++) {
|
|
|
|
const char *val = obs_property_list_item_string(p, i);
|
2016-05-11 13:19:38 -07:00
|
|
|
if (strcmp(val, "ICQ") == 0) {
|
2016-04-18 00:56:51 -07:00
|
|
|
icq_found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_properties_destroy(props);
|
|
|
|
return icq_found;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleOutput::UpdateRecordingSettings_qsv11(int crf)
|
|
|
|
{
|
|
|
|
bool icq = icq_available(h264Recording);
|
|
|
|
|
|
|
|
obs_data_t *settings = obs_data_create();
|
|
|
|
obs_data_set_string(settings, "profile", "high");
|
|
|
|
|
|
|
|
if (icq) {
|
2016-05-11 13:19:38 -07:00
|
|
|
obs_data_set_string(settings, "rate_control", "ICQ");
|
2016-04-18 00:56:51 -07:00
|
|
|
obs_data_set_int(settings, "icq_quality", crf);
|
|
|
|
} else {
|
|
|
|
obs_data_set_string(settings, "rate_control", "CQP");
|
|
|
|
obs_data_set_int(settings, "qpi", crf);
|
|
|
|
obs_data_set_int(settings, "qpp", crf);
|
|
|
|
obs_data_set_int(settings, "qpb", crf);
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_encoder_update(h264Recording, settings);
|
|
|
|
|
|
|
|
obs_data_release(settings);
|
|
|
|
}
|
|
|
|
|
2016-05-08 11:21:37 -07:00
|
|
|
void SimpleOutput::UpdateRecordingSettings_nvenc(int cqp)
|
2016-04-18 16:12:59 -07:00
|
|
|
{
|
|
|
|
obs_data_t *settings = obs_data_create();
|
2016-05-08 11:21:37 -07:00
|
|
|
obs_data_set_string(settings, "rate_control", "CQP");
|
2016-04-18 16:12:59 -07:00
|
|
|
obs_data_set_string(settings, "profile", "high");
|
|
|
|
obs_data_set_string(settings, "preset", "hq");
|
2016-05-08 11:21:37 -07:00
|
|
|
obs_data_set_int(settings, "cqp", cqp);
|
2016-04-18 16:12:59 -07:00
|
|
|
|
|
|
|
obs_encoder_update(h264Recording, settings);
|
|
|
|
|
|
|
|
obs_data_release(settings);
|
|
|
|
}
|
|
|
|
|
2016-09-26 16:29:33 -07:00
|
|
|
void SimpleOutput::UpdateStreamingSettings_amd(obs_data_t *settings,
|
|
|
|
int bitrate)
|
|
|
|
{
|
2016-11-03 12:34:57 -07:00
|
|
|
// Static Properties
|
2017-05-11 04:11:05 -07:00
|
|
|
obs_data_set_int(settings, "Usage", 0);
|
|
|
|
obs_data_set_int(settings, "Profile", 100); // High
|
2017-07-31 18:35:54 -07:00
|
|
|
|
2016-11-03 12:34:57 -07:00
|
|
|
// Rate Control Properties
|
2017-07-28 19:10:50 -07:00
|
|
|
obs_data_set_int(settings, "RateControlMethod", 3);
|
2017-05-11 04:11:05 -07:00
|
|
|
obs_data_set_int(settings, "Bitrate.Target", bitrate);
|
|
|
|
obs_data_set_int(settings, "FillerData", 1);
|
|
|
|
obs_data_set_int(settings, "VBVBuffer", 1);
|
|
|
|
obs_data_set_int(settings, "VBVBuffer.Size", bitrate);
|
2017-07-31 18:35:54 -07:00
|
|
|
|
2016-11-03 12:34:57 -07:00
|
|
|
// Picture Control Properties
|
2017-05-11 04:11:05 -07:00
|
|
|
obs_data_set_double(settings, "KeyframeInterval", 2.0);
|
2017-07-28 19:10:50 -07:00
|
|
|
obs_data_set_int(settings, "BFrame.Pattern", 0);
|
2016-09-26 16:29:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleOutput::UpdateRecordingSettings_amd_cqp(int cqp)
|
|
|
|
{
|
|
|
|
obs_data_t *settings = obs_data_create();
|
|
|
|
|
2016-11-03 12:34:57 -07:00
|
|
|
// Static Properties
|
2017-05-11 04:11:05 -07:00
|
|
|
obs_data_set_int(settings, "Usage", 0);
|
|
|
|
obs_data_set_int(settings, "Profile", 100); // High
|
2016-11-03 12:34:57 -07:00
|
|
|
|
2016-11-16 19:40:49 -08:00
|
|
|
// Rate Control Properties
|
2017-05-11 04:11:05 -07:00
|
|
|
obs_data_set_int(settings, "RateControlMethod", 0);
|
|
|
|
obs_data_set_int(settings, "QP.IFrame", cqp);
|
|
|
|
obs_data_set_int(settings, "QP.PFrame", cqp);
|
|
|
|
obs_data_set_int(settings, "QP.BFrame", cqp);
|
|
|
|
obs_data_set_int(settings, "VBVBuffer", 1);
|
|
|
|
obs_data_set_int(settings, "VBVBuffer.Size", 100000);
|
2016-09-26 16:29:33 -07:00
|
|
|
|
2016-11-03 12:34:57 -07:00
|
|
|
// Picture Control Properties
|
2017-05-11 04:11:05 -07:00
|
|
|
obs_data_set_double(settings, "KeyframeInterval", 2.0);
|
2017-07-28 19:10:50 -07:00
|
|
|
obs_data_set_int(settings, "BFrame.Pattern", 0);
|
2016-09-26 16:29:33 -07:00
|
|
|
|
2016-11-03 12:34:57 -07:00
|
|
|
// Update and release
|
|
|
|
obs_encoder_update(h264Recording, settings);
|
2016-09-26 16:29:33 -07:00
|
|
|
obs_data_release(settings);
|
|
|
|
}
|
|
|
|
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
void SimpleOutput::UpdateRecordingSettings()
|
|
|
|
{
|
2016-04-18 16:12:59 -07:00
|
|
|
bool ultra_hq = (videoQuality == "HQ");
|
|
|
|
int crf = CalcCRF(ultra_hq ? 16 : 23);
|
2016-04-18 00:56:51 -07:00
|
|
|
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
if (astrcmp_n(videoEncoder.c_str(), "x264", 4) == 0) {
|
2016-04-18 00:56:51 -07:00
|
|
|
UpdateRecordingSettings_x264_crf(crf);
|
|
|
|
|
|
|
|
} else if (videoEncoder == SIMPLE_ENCODER_QSV) {
|
|
|
|
UpdateRecordingSettings_qsv11(crf);
|
2016-04-18 16:12:59 -07:00
|
|
|
|
2016-09-26 16:29:33 -07:00
|
|
|
} else if (videoEncoder == SIMPLE_ENCODER_AMD) {
|
|
|
|
UpdateRecordingSettings_amd_cqp(crf);
|
|
|
|
|
2016-04-18 16:12:59 -07:00
|
|
|
} else if (videoEncoder == SIMPLE_ENCODER_NVENC) {
|
2016-05-08 11:21:37 -07:00
|
|
|
UpdateRecordingSettings_nvenc(crf);
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
inline void SimpleOutput::SetupOutputs()
|
|
|
|
{
|
|
|
|
SimpleOutput::Update();
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
obs_encoder_set_video(h264Streaming, obs_get_video());
|
|
|
|
obs_encoder_set_audio(aacStreaming, obs_get_audio());
|
|
|
|
|
|
|
|
if (usingRecordingPreset) {
|
|
|
|
if (ffmpegOutput) {
|
|
|
|
obs_output_set_media(fileOutput, obs_get_video(),
|
|
|
|
obs_get_audio());
|
|
|
|
} else {
|
|
|
|
obs_encoder_set_video(h264Recording, obs_get_video());
|
|
|
|
obs_encoder_set_audio(aacRecording, obs_get_audio());
|
|
|
|
}
|
|
|
|
}
|
2015-02-06 03:17:33 -08:00
|
|
|
}
|
|
|
|
|
2017-07-13 03:57:42 -07:00
|
|
|
const char *FindAudioEncoderFromCodec(const char *type)
|
|
|
|
{
|
|
|
|
const char *alt_enc_id = nullptr;
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
while (obs_enum_encoder_types(i++, &alt_enc_id)) {
|
|
|
|
const char *codec = obs_get_encoder_codec(alt_enc_id);
|
|
|
|
if (strcmp(type, codec) == 0) {
|
|
|
|
return alt_enc_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
bool SimpleOutput::StartStreaming(obs_service_t *service)
|
|
|
|
{
|
|
|
|
if (!Active())
|
|
|
|
SetupOutputs();
|
|
|
|
|
2017-07-13 03:57:42 -07:00
|
|
|
/* --------------------- */
|
|
|
|
|
|
|
|
const char *type = obs_service_get_output_type(service);
|
|
|
|
if (!type)
|
|
|
|
type = "rtmp_output";
|
|
|
|
|
|
|
|
/* XXX: this is messy and disgusting and should be refactored */
|
|
|
|
if (outputType != type) {
|
2017-07-25 19:01:29 -07:00
|
|
|
streamDelayStarting.Disconnect();
|
|
|
|
streamStopping.Disconnect();
|
|
|
|
startStreaming.Disconnect();
|
|
|
|
stopStreaming.Disconnect();
|
|
|
|
|
2017-07-13 03:57:42 -07:00
|
|
|
streamOutput = obs_output_create(type, "simple_stream",
|
|
|
|
nullptr, nullptr);
|
|
|
|
if (!streamOutput)
|
|
|
|
return false;
|
|
|
|
obs_output_release(streamOutput);
|
|
|
|
|
|
|
|
streamDelayStarting.Connect(
|
|
|
|
obs_output_get_signal_handler(streamOutput),
|
|
|
|
"starting", OBSStreamStarting, this);
|
|
|
|
streamStopping.Connect(
|
|
|
|
obs_output_get_signal_handler(streamOutput),
|
|
|
|
"stopping", OBSStreamStopping, this);
|
|
|
|
|
|
|
|
startStreaming.Connect(
|
|
|
|
obs_output_get_signal_handler(streamOutput),
|
|
|
|
"start", OBSStartStreaming, this);
|
|
|
|
stopStreaming.Connect(
|
|
|
|
obs_output_get_signal_handler(streamOutput),
|
|
|
|
"stop", OBSStopStreaming, this);
|
|
|
|
|
2017-07-13 04:04:17 -07:00
|
|
|
const char *codec =
|
|
|
|
obs_output_get_supported_audio_codecs(streamOutput);
|
2017-07-31 18:36:12 -07:00
|
|
|
if (!codec) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-13 04:04:17 -07:00
|
|
|
|
|
|
|
if (strcmp(codec, "aac") != 0) {
|
|
|
|
const char *id = FindAudioEncoderFromCodec(codec);
|
|
|
|
int audioBitrate = GetAudioBitrate();
|
|
|
|
obs_data_t *settings = obs_data_create();
|
|
|
|
obs_data_set_int(settings, "bitrate", audioBitrate);
|
|
|
|
|
|
|
|
aacStreaming = obs_audio_encoder_create(id,
|
|
|
|
"alt_audio_enc", nullptr, 0, nullptr);
|
|
|
|
obs_encoder_release(aacStreaming);
|
|
|
|
if (!aacStreaming)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
obs_encoder_update(aacStreaming, settings);
|
|
|
|
obs_encoder_set_audio(aacStreaming, obs_get_audio());
|
|
|
|
|
|
|
|
obs_data_release(settings);
|
|
|
|
}
|
|
|
|
|
2017-07-13 03:57:42 -07:00
|
|
|
outputType = type;
|
|
|
|
}
|
|
|
|
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
obs_output_set_video_encoder(streamOutput, h264Streaming);
|
|
|
|
obs_output_set_audio_encoder(streamOutput, aacStreaming, 0);
|
2015-02-06 03:17:33 -08:00
|
|
|
obs_output_set_service(streamOutput, service);
|
|
|
|
|
2017-07-13 03:57:42 -07:00
|
|
|
/* --------------------- */
|
|
|
|
|
2015-09-10 19:10:40 -07:00
|
|
|
bool reconnect = config_get_bool(main->Config(), "Output",
|
2015-02-06 03:17:33 -08:00
|
|
|
"Reconnect");
|
2015-09-10 19:10:40 -07:00
|
|
|
int retryDelay = config_get_uint(main->Config(), "Output",
|
2015-02-06 03:17:33 -08:00
|
|
|
"RetryDelay");
|
2015-09-10 19:10:40 -07:00
|
|
|
int maxRetries = config_get_uint(main->Config(), "Output",
|
2015-02-06 03:17:33 -08:00
|
|
|
"MaxRetries");
|
2015-09-06 16:19:53 -07:00
|
|
|
bool useDelay = config_get_bool(main->Config(), "Output",
|
|
|
|
"DelayEnable");
|
|
|
|
int delaySec = config_get_int(main->Config(), "Output",
|
|
|
|
"DelaySec");
|
|
|
|
bool preserveDelay = config_get_bool(main->Config(), "Output",
|
|
|
|
"DelayPreserve");
|
2016-07-29 08:30:54 -07:00
|
|
|
const char *bindIP = config_get_string(main->Config(), "Output",
|
|
|
|
"BindIP");
|
2017-02-21 17:05:45 -08:00
|
|
|
bool enableNewSocketLoop = config_get_bool(main->Config(), "Output",
|
|
|
|
"NewSocketLoopEnable");
|
|
|
|
bool enableLowLatencyMode = config_get_bool(main->Config(), "Output",
|
|
|
|
"LowLatencyEnable");
|
2016-07-29 08:30:54 -07:00
|
|
|
|
|
|
|
obs_data_t *settings = obs_data_create();
|
|
|
|
obs_data_set_string(settings, "bind_ip", bindIP);
|
2017-02-21 17:05:45 -08:00
|
|
|
obs_data_set_bool(settings, "new_socket_loop_enabled",
|
|
|
|
enableNewSocketLoop);
|
|
|
|
obs_data_set_bool(settings, "low_latency_mode_enabled",
|
|
|
|
enableLowLatencyMode);
|
2016-07-29 08:30:54 -07:00
|
|
|
obs_output_update(streamOutput, settings);
|
|
|
|
obs_data_release(settings);
|
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
if (!reconnect)
|
|
|
|
maxRetries = 0;
|
|
|
|
|
2015-09-06 16:19:53 -07:00
|
|
|
obs_output_set_delay(streamOutput, useDelay ? delaySec : 0,
|
|
|
|
preserveDelay ? OBS_OUTPUT_DELAY_PRESERVE : 0);
|
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
obs_output_set_reconnect_settings(streamOutput, maxRetries,
|
|
|
|
retryDelay);
|
|
|
|
|
|
|
|
if (obs_output_start(streamOutput)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-09 14:42:14 -08:00
|
|
|
static void remove_reserved_file_characters(string &s)
|
|
|
|
{
|
|
|
|
replace(s.begin(), s.end(), '/', '_');
|
|
|
|
replace(s.begin(), s.end(), '\\', '_');
|
|
|
|
replace(s.begin(), s.end(), '*', '_');
|
|
|
|
replace(s.begin(), s.end(), '?', '_');
|
|
|
|
replace(s.begin(), s.end(), '"', '_');
|
|
|
|
replace(s.begin(), s.end(), '|', '_');
|
|
|
|
replace(s.begin(), s.end(), ':', '_');
|
|
|
|
replace(s.begin(), s.end(), '>', '_');
|
|
|
|
replace(s.begin(), s.end(), '<', '_');
|
|
|
|
}
|
|
|
|
|
2016-07-04 23:11:24 -07:00
|
|
|
static void ensure_directory_exists(string &path)
|
|
|
|
{
|
|
|
|
replace(path.begin(), path.end(), '\\', '/');
|
|
|
|
|
|
|
|
size_t last = path.rfind('/');
|
|
|
|
if (last == string::npos)
|
|
|
|
return;
|
|
|
|
|
|
|
|
string directory = path.substr(0, last);
|
|
|
|
os_mkdirs(directory.c_str());
|
|
|
|
}
|
|
|
|
|
2016-12-09 14:40:04 -08:00
|
|
|
void SimpleOutput::UpdateRecording()
|
2015-02-06 03:17:33 -08:00
|
|
|
{
|
2016-12-09 14:40:04 -08:00
|
|
|
if (replayBufferActive || recordingActive)
|
|
|
|
return;
|
|
|
|
|
UI: Add recording presets to simple output
So certain high-profile individuals were complaining that it was
difficult to configure recording settings for quality in OBS. So, I
decided to add a very easy-to-use auto-configuration for high quality
encoding -- including lossless encoding. This feature will
automatically configure ideal recording settings based upon a specified
quality level.
Recording quality presets added to simple output:
- Same as stream: Copies the encoded streaming data with no extra usage
hit.
- High quality: uses a higher CRF value (starting at 23) if using x264.
- Indistinguishable quality: uses a low CRF value (starting at 16) if
using x264.
- Lossless will spawn an FFmpeg output that uses huffyuv encoding. If a
user tries to select lossless, they will be warned both via a dialog
prompt and a warning message in the settings window to ensure they
understand that it requires tremendous amounts of free space. It will
always use the AVI file format.
Extra Notes:
- When High/Indistinguishable quality is set, it will allow you to
select the recording encoder. Currently, it just allows you to select
x264 (at either veryfast or ultrafast). Later on, it'll be useful to
be able to set up pre-configured presets for hardware encoders once
more are implemented and tested.
- I decided to allow the use of x264 at both veryfast or ultrafast
presets. The reasoning is two-fold:
1.) ultrafast is perfectly viable even for near indistinguishable
quality as long as it has the appropriate CRF value. It's nice if you
want to record but would like to or need to reduce the impact of
encoding on the CPU. It will automatically compensate for the preset at
the cost of larger file size.
2.) It was suggested to just always use ultrafast, but ultrafast
requires 2-4x as much disk space for the same CRF (most likely due to
x264 compensating for the preset). Providing veryfast is important if
you really want to reduce file size and/or reduce blocking at lower
quality levels.
- When a recording preset is used, a secondary audio encoder is also
spawned at 192 bitrate to ensure high quality audio. I chose 192
because that's the limit of the media foundation aac encoder on
windows, which I want to make sure is used if available due to its
high performance.
- The CRF calculation is based upon resolution, quality, and whether
it's set to ultrafast. First, quality sets the base CRF, 23 for
"good" quality, 16 for "very high" quality. If set to ultrafast,
it'll subtract 2 points from the CRF value to help compensate. Lower
resolutions will also lower the CRF value to help improve higher
details with a smaller pixel ratio.
2015-09-18 22:29:36 -07:00
|
|
|
if (usingRecordingPreset) {
|
|
|
|
if (!ffmpegOutput)
|
|
|
|
UpdateRecordingSettings();
|
|
|
|
} else if (!obs_output_active(streamOutput)) {
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
if (!Active())
|
|
|
|
SetupOutputs();
|
|
|
|
|
2016-12-09 14:40:04 -08:00
|
|
|
if (!ffmpegOutput) {
|
|
|
|
obs_output_set_video_encoder(fileOutput, h264Recording);
|
|
|
|
obs_output_set_audio_encoder(fileOutput, aacRecording, 0);
|
|
|
|
}
|
|
|
|
if (replayBuffer) {
|
|
|
|
obs_output_set_video_encoder(replayBuffer, h264Recording);
|
|
|
|
obs_output_set_audio_encoder(replayBuffer, aacRecording, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
recordingConfigured = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SimpleOutput::ConfigureRecording(bool updateReplayBuffer)
|
|
|
|
{
|
2015-02-06 03:17:33 -08:00
|
|
|
const char *path = config_get_string(main->Config(),
|
|
|
|
"SimpleOutput", "FilePath");
|
2015-05-29 09:45:54 -07:00
|
|
|
const char *format = config_get_string(main->Config(),
|
|
|
|
"SimpleOutput", "RecFormat");
|
2015-11-23 06:36:06 -08:00
|
|
|
const char *mux = config_get_string(main->Config(), "SimpleOutput",
|
|
|
|
"MuxerCustom");
|
2015-11-27 03:14:18 -08:00
|
|
|
bool noSpace = config_get_bool(main->Config(), "SimpleOutput",
|
|
|
|
"FileNameWithoutSpace");
|
2016-03-25 02:43:38 -07:00
|
|
|
const char *filenameFormat = config_get_string(main->Config(), "Output",
|
|
|
|
"FilenameFormatting");
|
|
|
|
bool overwriteIfExists = config_get_bool(main->Config(), "Output",
|
|
|
|
"OverwriteIfExists");
|
2016-12-09 14:42:14 -08:00
|
|
|
const char *rbPrefix = config_get_string(main->Config(), "SimpleOutput",
|
|
|
|
"RecRBPrefix");
|
|
|
|
const char *rbSuffix = config_get_string(main->Config(), "SimpleOutput",
|
|
|
|
"RecRBSuffix");
|
2016-12-07 05:21:44 -08:00
|
|
|
int rbTime = config_get_int(main->Config(), "SimpleOutput",
|
|
|
|
"RecRBTime");
|
|
|
|
int rbSize = config_get_int(main->Config(), "SimpleOutput",
|
|
|
|
"RecRBSize");
|
2015-02-06 03:17:33 -08:00
|
|
|
|
2017-08-06 14:59:03 -07:00
|
|
|
os_dir_t *dir = path && path[0] ? os_opendir(path) : nullptr;
|
2015-02-06 03:17:33 -08:00
|
|
|
|
|
|
|
if (!dir) {
|
2016-08-13 07:36:17 -07:00
|
|
|
if (main->isVisible())
|
2017-05-13 14:06:32 -07:00
|
|
|
OBSMessageBox::information(main,
|
2016-08-13 07:36:17 -07:00
|
|
|
QTStr("Output.BadPath.Title"),
|
|
|
|
QTStr("Output.BadPath.Text"));
|
|
|
|
else
|
|
|
|
main->SysTrayNotify(QTStr("Output.BadPath.Text"),
|
|
|
|
QSystemTrayIcon::Warning);
|
2015-02-06 03:17:33 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_closedir(dir);
|
|
|
|
|
|
|
|
string strPath;
|
|
|
|
strPath += path;
|
|
|
|
|
|
|
|
char lastChar = strPath.back();
|
|
|
|
if (lastChar != '/' && lastChar != '\\')
|
|
|
|
strPath += "/";
|
|
|
|
|
2016-03-25 02:43:38 -07:00
|
|
|
strPath += GenerateSpecifiedFilename(ffmpegOutput ? "avi" : format,
|
|
|
|
noSpace, filenameFormat);
|
2016-07-04 23:11:24 -07:00
|
|
|
ensure_directory_exists(strPath);
|
2016-03-25 02:43:38 -07:00
|
|
|
if (!overwriteIfExists)
|
|
|
|
FindBestFilename(strPath, noSpace);
|
2015-02-06 03:17:33 -08:00
|
|
|
|
|
|
|
obs_data_t *settings = obs_data_create();
|
2016-12-09 14:40:04 -08:00
|
|
|
if (updateReplayBuffer) {
|
2016-12-09 14:42:14 -08:00
|
|
|
string f;
|
|
|
|
|
|
|
|
if (rbPrefix && *rbPrefix) {
|
|
|
|
f += rbPrefix;
|
|
|
|
if (f.back() != ' ')
|
|
|
|
f += " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
f += filenameFormat;
|
|
|
|
|
|
|
|
if (rbSuffix && *rbSuffix) {
|
|
|
|
if (*rbSuffix != ' ')
|
|
|
|
f += " ";
|
|
|
|
f += rbSuffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
remove_reserved_file_characters(f);
|
|
|
|
|
2016-12-07 05:21:44 -08:00
|
|
|
obs_data_set_string(settings, "directory", path);
|
2016-12-09 14:42:14 -08:00
|
|
|
obs_data_set_string(settings, "format", f.c_str());
|
2016-12-07 05:21:44 -08:00
|
|
|
obs_data_set_string(settings, "extension", format);
|
|
|
|
obs_data_set_int(settings, "max_time_sec", rbTime);
|
|
|
|
obs_data_set_int(settings, "max_size_mb",
|
|
|
|
usingRecordingPreset ? rbSize : 0);
|
|
|
|
} else {
|
|
|
|
obs_data_set_string(settings, ffmpegOutput ? "url" : "path",
|
|
|
|
strPath.c_str());
|
|
|
|
}
|
2016-12-09 14:40:04 -08:00
|
|
|
|
2015-11-23 06:36:06 -08:00
|
|
|
obs_data_set_string(settings, "muxer_settings", mux);
|
2015-02-06 03:17:33 -08:00
|
|
|
|
2016-12-09 14:40:04 -08:00
|
|
|
if (updateReplayBuffer)
|
|
|
|
obs_output_update(replayBuffer, settings);
|
|
|
|
else
|
|
|
|
obs_output_update(fileOutput, settings);
|
2015-02-06 03:17:33 -08:00
|
|
|
|
|
|
|
obs_data_release(settings);
|
2016-12-09 14:40:04 -08:00
|
|
|
return true;
|
|
|
|
}
|
2015-02-06 03:17:33 -08:00
|
|
|
|
2016-12-09 14:40:04 -08:00
|
|
|
bool SimpleOutput::StartRecording()
|
|
|
|
{
|
|
|
|
UpdateRecording();
|
|
|
|
if (!ConfigureRecording(false))
|
|
|
|
return false;
|
2017-02-03 20:29:09 -08:00
|
|
|
if (!obs_output_start(fileOutput)) {
|
2017-08-06 15:24:44 -07:00
|
|
|
QString error_reason;
|
|
|
|
const char *error = obs_output_get_last_error(fileOutput);
|
|
|
|
if (error)
|
|
|
|
error_reason = QT_UTF8(error);
|
|
|
|
else
|
|
|
|
error_reason = QTStr("Output.StartFailedGeneric");
|
2017-02-03 20:29:09 -08:00
|
|
|
QMessageBox::critical(main,
|
2017-08-06 15:24:44 -07:00
|
|
|
QTStr("Output.StartRecordingFailed"),
|
|
|
|
error_reason);
|
2016-12-09 14:40:04 -08:00
|
|
|
return false;
|
2017-02-03 20:29:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-09 14:40:04 -08:00
|
|
|
return true;
|
|
|
|
}
|
2015-02-06 03:17:33 -08:00
|
|
|
|
2016-12-09 14:40:04 -08:00
|
|
|
bool SimpleOutput::StartReplayBuffer()
|
|
|
|
{
|
|
|
|
UpdateRecording();
|
|
|
|
if (!ConfigureRecording(true))
|
|
|
|
return false;
|
2017-02-03 20:29:09 -08:00
|
|
|
if (!obs_output_start(replayBuffer)) {
|
|
|
|
QMessageBox::critical(main,
|
|
|
|
QTStr("Output.StartReplayFailed"),
|
|
|
|
QTStr("Output.StartFailedGeneric"));
|
2016-12-09 14:40:04 -08:00
|
|
|
return false;
|
2017-02-03 20:29:09 -08:00
|
|
|
}
|
|
|
|
|
2016-12-09 14:40:04 -08:00
|
|
|
return true;
|
2015-02-06 03:17:33 -08:00
|
|
|
}
|
|
|
|
|
2016-09-09 07:37:54 -07:00
|
|
|
void SimpleOutput::StopStreaming(bool force)
|
2015-02-06 03:17:33 -08:00
|
|
|
{
|
2016-09-09 07:37:54 -07:00
|
|
|
if (force)
|
|
|
|
obs_output_force_stop(streamOutput);
|
|
|
|
else
|
|
|
|
obs_output_stop(streamOutput);
|
2015-09-06 16:19:53 -07:00
|
|
|
}
|
|
|
|
|
2016-09-09 07:37:54 -07:00
|
|
|
void SimpleOutput::StopRecording(bool force)
|
2015-02-06 03:17:33 -08:00
|
|
|
{
|
2016-09-09 07:37:54 -07:00
|
|
|
if (force)
|
|
|
|
obs_output_force_stop(fileOutput);
|
|
|
|
else
|
|
|
|
obs_output_stop(fileOutput);
|
2015-02-06 03:17:33 -08:00
|
|
|
}
|
|
|
|
|
2016-12-09 14:40:04 -08:00
|
|
|
void SimpleOutput::StopReplayBuffer(bool force)
|
|
|
|
{
|
|
|
|
if (force)
|
|
|
|
obs_output_force_stop(replayBuffer);
|
|
|
|
else
|
|
|
|
obs_output_stop(replayBuffer);
|
|
|
|
}
|
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
bool SimpleOutput::StreamingActive() const
|
|
|
|
{
|
|
|
|
return obs_output_active(streamOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SimpleOutput::RecordingActive() const
|
|
|
|
{
|
|
|
|
return obs_output_active(fileOutput);
|
|
|
|
}
|
|
|
|
|
2016-12-09 14:40:04 -08:00
|
|
|
bool SimpleOutput::ReplayBufferActive() const
|
|
|
|
{
|
|
|
|
return obs_output_active(replayBuffer);
|
|
|
|
}
|
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2015-01-26 13:41:22 -08:00
|
|
|
struct AdvancedOutput : BasicOutputHandler {
|
2016-12-21 17:14:24 -08:00
|
|
|
OBSEncoder aacTrack[MAX_AUDIO_MIXES];
|
2015-01-26 13:41:22 -08:00
|
|
|
OBSEncoder h264Streaming;
|
|
|
|
OBSEncoder h264Recording;
|
|
|
|
|
2017-07-13 04:04:17 -07:00
|
|
|
OBSEncoder streamAudioEnc;
|
|
|
|
|
2015-08-18 20:58:24 -07:00
|
|
|
bool ffmpegOutput;
|
2015-01-26 13:41:22 -08:00
|
|
|
bool ffmpegRecording;
|
|
|
|
bool useStreamEncoder;
|
|
|
|
|
2016-12-21 17:14:24 -08:00
|
|
|
string aacEncoderID[MAX_AUDIO_MIXES];
|
2015-07-02 01:00:22 -07:00
|
|
|
|
2015-01-26 13:41:22 -08:00
|
|
|
AdvancedOutput(OBSBasic *main_);
|
|
|
|
|
|
|
|
inline void UpdateStreamSettings();
|
|
|
|
inline void UpdateRecordingSettings();
|
2015-03-07 16:32:00 -08:00
|
|
|
inline void UpdateAudioSettings();
|
2015-01-26 13:41:22 -08:00
|
|
|
virtual void Update() override;
|
|
|
|
|
|
|
|
inline void SetupStreaming();
|
|
|
|
inline void SetupRecording();
|
|
|
|
inline void SetupFFmpeg();
|
|
|
|
void SetupOutputs();
|
2015-07-02 00:58:28 -07:00
|
|
|
int GetAudioBitrate(size_t i) const;
|
2015-01-26 13:41:22 -08:00
|
|
|
|
|
|
|
virtual bool StartStreaming(obs_service_t *service) override;
|
|
|
|
virtual bool StartRecording() override;
|
2016-09-09 07:37:54 -07:00
|
|
|
virtual void StopStreaming(bool force) override;
|
|
|
|
virtual void StopRecording(bool force) override;
|
2015-01-26 13:41:22 -08:00
|
|
|
virtual bool StreamingActive() const override;
|
|
|
|
virtual bool RecordingActive() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
static OBSData GetDataFromJsonFile(const char *jsonFile)
|
|
|
|
{
|
|
|
|
char fullPath[512];
|
|
|
|
|
2015-06-23 19:38:01 -07:00
|
|
|
int ret = GetProfilePath(fullPath, sizeof(fullPath), jsonFile);
|
2015-01-26 13:41:22 -08:00
|
|
|
if (ret > 0) {
|
|
|
|
BPtr<char> jsonData = os_quick_read_utf8_file(fullPath);
|
|
|
|
if (!!jsonData) {
|
|
|
|
obs_data_t *data = obs_data_create_from_json(jsonData);
|
|
|
|
OBSData dataRet(data);
|
|
|
|
obs_data_release(data);
|
|
|
|
return dataRet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
AdvancedOutput::AdvancedOutput(OBSBasic *main_) : BasicOutputHandler(main_)
|
|
|
|
{
|
|
|
|
const char *recType = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"RecType");
|
|
|
|
const char *streamEncoder = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"Encoder");
|
|
|
|
const char *recordEncoder = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"RecEncoder");
|
|
|
|
|
2015-08-18 20:58:24 -07:00
|
|
|
ffmpegOutput = astrcmpi(recType, "FFmpeg") == 0;
|
|
|
|
ffmpegRecording = ffmpegOutput &&
|
|
|
|
config_get_bool(main->Config(), "AdvOut", "FFOutputToFile");
|
2015-01-26 13:41:22 -08:00
|
|
|
useStreamEncoder = astrcmpi(recordEncoder, "none") == 0;
|
|
|
|
|
2015-06-23 19:38:01 -07:00
|
|
|
OBSData streamEncSettings = GetDataFromJsonFile("streamEncoder.json");
|
|
|
|
OBSData recordEncSettings = GetDataFromJsonFile("recordEncoder.json");
|
2015-01-26 13:41:22 -08:00
|
|
|
|
2015-08-18 20:58:24 -07:00
|
|
|
if (ffmpegOutput) {
|
2015-01-26 13:41:22 -08:00
|
|
|
fileOutput = obs_output_create("ffmpeg_output",
|
2014-11-01 13:41:17 -07:00
|
|
|
"adv_ffmpeg_output", nullptr, nullptr);
|
2015-01-26 13:41:22 -08:00
|
|
|
if (!fileOutput)
|
|
|
|
throw "Failed to create recording FFmpeg output "
|
|
|
|
"(advanced output)";
|
2015-05-03 16:55:43 -07:00
|
|
|
obs_output_release(fileOutput);
|
2015-01-26 13:41:22 -08:00
|
|
|
} else {
|
2015-05-28 23:27:06 -07:00
|
|
|
fileOutput = obs_output_create("ffmpeg_muxer",
|
|
|
|
"adv_file_output", nullptr, nullptr);
|
2015-01-26 13:41:22 -08:00
|
|
|
if (!fileOutput)
|
|
|
|
throw "Failed to create recording output "
|
|
|
|
"(advanced output)";
|
2015-05-03 16:55:43 -07:00
|
|
|
obs_output_release(fileOutput);
|
2015-01-26 13:41:22 -08:00
|
|
|
|
|
|
|
if (!useStreamEncoder) {
|
|
|
|
h264Recording = obs_video_encoder_create(recordEncoder,
|
2014-11-01 13:41:17 -07:00
|
|
|
"recording_h264", recordEncSettings,
|
|
|
|
nullptr);
|
2015-01-26 13:41:22 -08:00
|
|
|
if (!h264Recording)
|
|
|
|
throw "Failed to create recording h264 "
|
|
|
|
"encoder (advanced output)";
|
2015-05-03 17:01:38 -07:00
|
|
|
obs_encoder_release(h264Recording);
|
2015-01-26 13:41:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
h264Streaming = obs_video_encoder_create(streamEncoder,
|
2014-11-01 13:41:17 -07:00
|
|
|
"streaming_h264", streamEncSettings, nullptr);
|
2015-01-26 13:41:22 -08:00
|
|
|
if (!h264Streaming)
|
|
|
|
throw "Failed to create streaming h264 encoder "
|
|
|
|
"(advanced output)";
|
2015-05-03 17:01:38 -07:00
|
|
|
obs_encoder_release(h264Streaming);
|
2015-01-26 13:41:22 -08:00
|
|
|
|
2016-12-21 17:14:24 -08:00
|
|
|
for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
|
2015-01-26 13:41:22 -08:00
|
|
|
char name[9];
|
|
|
|
sprintf(name, "adv_aac%d", i);
|
|
|
|
|
2015-07-02 01:00:22 -07:00
|
|
|
if (!CreateAACEncoder(aacTrack[i], aacEncoderID[i],
|
|
|
|
GetAudioBitrate(i), name, i))
|
2015-01-26 13:41:22 -08:00
|
|
|
throw "Failed to create audio encoder "
|
|
|
|
"(advanced output)";
|
|
|
|
}
|
|
|
|
|
2015-07-03 23:00:21 -07:00
|
|
|
startRecording.Connect(obs_output_get_signal_handler(fileOutput),
|
2015-01-26 13:41:22 -08:00
|
|
|
"start", OBSStartRecording, this);
|
2015-07-03 23:00:21 -07:00
|
|
|
stopRecording.Connect(obs_output_get_signal_handler(fileOutput),
|
2015-01-26 13:41:22 -08:00
|
|
|
"stop", OBSStopRecording, this);
|
2016-06-22 01:47:08 -07:00
|
|
|
recordStopping.Connect(obs_output_get_signal_handler(fileOutput),
|
|
|
|
"stopping", OBSRecordStopping, this);
|
2015-01-26 13:41:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdvancedOutput::UpdateStreamSettings()
|
|
|
|
{
|
2015-03-07 16:32:00 -08:00
|
|
|
bool applyServiceSettings = config_get_bool(main->Config(), "AdvOut",
|
|
|
|
"ApplyServiceSettings");
|
|
|
|
|
2015-06-23 19:38:01 -07:00
|
|
|
OBSData settings = GetDataFromJsonFile("streamEncoder.json");
|
2015-03-07 16:32:00 -08:00
|
|
|
|
|
|
|
if (applyServiceSettings)
|
|
|
|
obs_service_apply_encoder_settings(main->GetService(),
|
|
|
|
settings, nullptr);
|
|
|
|
|
2015-04-17 02:48:06 -07:00
|
|
|
video_t *video = obs_get_video();
|
|
|
|
enum video_format format = video_output_get_format(video);
|
|
|
|
|
|
|
|
if (format != VIDEO_FORMAT_NV12 && format != VIDEO_FORMAT_I420)
|
|
|
|
obs_encoder_set_preferred_video_format(h264Streaming,
|
|
|
|
VIDEO_FORMAT_NV12);
|
|
|
|
|
2015-01-26 13:41:22 -08:00
|
|
|
obs_encoder_update(h264Streaming, settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void AdvancedOutput::UpdateRecordingSettings()
|
|
|
|
{
|
2015-06-23 19:38:01 -07:00
|
|
|
OBSData settings = GetDataFromJsonFile("recordEncoder.json");
|
2015-01-26 13:41:22 -08:00
|
|
|
obs_encoder_update(h264Recording, settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdvancedOutput::Update()
|
|
|
|
{
|
|
|
|
UpdateStreamSettings();
|
2015-08-18 20:58:24 -07:00
|
|
|
if (!useStreamEncoder && !ffmpegOutput)
|
2015-01-26 13:41:22 -08:00
|
|
|
UpdateRecordingSettings();
|
2015-03-07 16:32:00 -08:00
|
|
|
UpdateAudioSettings();
|
2015-01-26 13:41:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void AdvancedOutput::SetupStreaming()
|
|
|
|
{
|
|
|
|
bool rescale = config_get_bool(main->Config(), "AdvOut",
|
|
|
|
"Rescale");
|
|
|
|
const char *rescaleRes = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"RescaleRes");
|
|
|
|
unsigned int cx = 0;
|
|
|
|
unsigned int cy = 0;
|
|
|
|
|
2015-03-31 13:48:06 -07:00
|
|
|
if (rescale && rescaleRes && *rescaleRes) {
|
|
|
|
if (sscanf(rescaleRes, "%ux%u", &cx, &cy) != 2) {
|
|
|
|
cx = 0;
|
|
|
|
cy = 0;
|
|
|
|
}
|
2015-01-26 13:41:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
obs_encoder_set_scaled_size(h264Streaming, cx, cy);
|
|
|
|
obs_encoder_set_video(h264Streaming, obs_get_video());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void AdvancedOutput::SetupRecording()
|
|
|
|
{
|
|
|
|
const char *path = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"RecFilePath");
|
2015-11-23 06:36:06 -08:00
|
|
|
const char *mux = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"RecMuxerCustom");
|
2015-01-26 13:41:22 -08:00
|
|
|
bool rescale = config_get_bool(main->Config(), "AdvOut",
|
|
|
|
"RecRescale");
|
|
|
|
const char *rescaleRes = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"RecRescaleRes");
|
2015-05-30 21:45:14 -07:00
|
|
|
int tracks = config_get_int(main->Config(), "AdvOut", "RecTracks");
|
2015-01-26 13:41:22 -08:00
|
|
|
obs_data_t *settings = obs_data_create();
|
|
|
|
unsigned int cx = 0;
|
|
|
|
unsigned int cy = 0;
|
2015-05-30 21:45:14 -07:00
|
|
|
int idx = 0;
|
2015-01-26 13:41:22 -08:00
|
|
|
|
|
|
|
if (useStreamEncoder) {
|
|
|
|
obs_output_set_video_encoder(fileOutput, h264Streaming);
|
|
|
|
} else {
|
2015-03-31 13:48:06 -07:00
|
|
|
if (rescale && rescaleRes && *rescaleRes) {
|
|
|
|
if (sscanf(rescaleRes, "%ux%u", &cx, &cy) != 2) {
|
|
|
|
cx = 0;
|
|
|
|
cy = 0;
|
|
|
|
}
|
2015-01-26 13:41:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
obs_encoder_set_scaled_size(h264Recording, cx, cy);
|
|
|
|
obs_encoder_set_video(h264Recording, obs_get_video());
|
|
|
|
obs_output_set_video_encoder(fileOutput, h264Recording);
|
|
|
|
}
|
|
|
|
|
2015-05-30 21:45:14 -07:00
|
|
|
for (int i = 0; i < MAX_AUDIO_MIXES; i++) {
|
|
|
|
if ((tracks & (1<<i)) != 0) {
|
2015-01-26 13:41:22 -08:00
|
|
|
obs_output_set_audio_encoder(fileOutput, aacTrack[i],
|
2015-05-30 21:45:14 -07:00
|
|
|
idx++);
|
|
|
|
}
|
2015-01-26 13:41:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
obs_data_set_string(settings, "path", path);
|
2015-11-23 06:36:06 -08:00
|
|
|
obs_data_set_string(settings, "muxer_settings", mux);
|
2015-01-26 13:41:22 -08:00
|
|
|
obs_output_update(fileOutput, settings);
|
|
|
|
obs_data_release(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void AdvancedOutput::SetupFFmpeg()
|
|
|
|
{
|
|
|
|
const char *url = config_get_string(main->Config(), "AdvOut", "FFURL");
|
|
|
|
int vBitrate = config_get_int(main->Config(), "AdvOut",
|
|
|
|
"FFVBitrate");
|
2017-02-17 08:25:21 -08:00
|
|
|
int gopSize = config_get_int(main->Config(), "AdvOut",
|
|
|
|
"FFVGOPSize");
|
2015-01-26 13:41:22 -08:00
|
|
|
bool rescale = config_get_bool(main->Config(), "AdvOut",
|
|
|
|
"FFRescale");
|
|
|
|
const char *rescaleRes = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"FFRescaleRes");
|
2015-03-28 00:21:16 -07:00
|
|
|
const char *formatName = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"FFFormat");
|
|
|
|
const char *mimeType = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"FFFormatMimeType");
|
2015-09-16 01:26:48 -07:00
|
|
|
const char *muxCustom = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"FFMCustom");
|
2015-01-26 13:41:22 -08:00
|
|
|
const char *vEncoder = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"FFVEncoder");
|
2015-03-28 00:21:16 -07:00
|
|
|
int vEncoderId = config_get_int(main->Config(), "AdvOut",
|
|
|
|
"FFVEncoderId");
|
2015-01-26 13:41:22 -08:00
|
|
|
const char *vEncCustom = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"FFVCustom");
|
|
|
|
int aBitrate = config_get_int(main->Config(), "AdvOut",
|
|
|
|
"FFABitrate");
|
|
|
|
int aTrack = config_get_int(main->Config(), "AdvOut",
|
|
|
|
"FFAudioTrack");
|
|
|
|
const char *aEncoder = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"FFAEncoder");
|
2015-03-28 00:21:16 -07:00
|
|
|
int aEncoderId = config_get_int(main->Config(), "AdvOut",
|
|
|
|
"FFAEncoderId");
|
2015-01-26 13:41:22 -08:00
|
|
|
const char *aEncCustom = config_get_string(main->Config(), "AdvOut",
|
|
|
|
"FFACustom");
|
|
|
|
obs_data_t *settings = obs_data_create();
|
|
|
|
|
|
|
|
obs_data_set_string(settings, "url", url);
|
2015-03-28 00:21:16 -07:00
|
|
|
obs_data_set_string(settings, "format_name", formatName);
|
|
|
|
obs_data_set_string(settings, "format_mime_type", mimeType);
|
2015-09-16 01:26:48 -07:00
|
|
|
obs_data_set_string(settings, "muxer_settings", muxCustom);
|
2017-02-17 08:25:21 -08:00
|
|
|
obs_data_set_int(settings, "gop_size", gopSize);
|
2015-01-26 13:41:22 -08:00
|
|
|
obs_data_set_int(settings, "video_bitrate", vBitrate);
|
|
|
|
obs_data_set_string(settings, "video_encoder", vEncoder);
|
2015-03-28 00:21:16 -07:00
|
|
|
obs_data_set_int(settings, "video_encoder_id", vEncoderId);
|
2015-01-26 13:41:22 -08:00
|
|
|
obs_data_set_string(settings, "video_settings", vEncCustom);
|
|
|
|
obs_data_set_int(settings, "audio_bitrate", aBitrate);
|
|
|
|
obs_data_set_string(settings, "audio_encoder", aEncoder);
|
2015-03-28 00:21:16 -07:00
|
|
|
obs_data_set_int(settings, "audio_encoder_id", aEncoderId);
|
2015-01-26 13:41:22 -08:00
|
|
|
obs_data_set_string(settings, "audio_settings", aEncCustom);
|
|
|
|
|
|
|
|
if (rescale && rescaleRes && *rescaleRes) {
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int val = sscanf(rescaleRes, "%dx%d", &width, &height);
|
|
|
|
|
|
|
|
if (val == 2 && width && height) {
|
|
|
|
obs_data_set_int(settings, "scale_width", width);
|
|
|
|
obs_data_set_int(settings, "scale_height", height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_output_set_mixer(fileOutput, aTrack - 1);
|
|
|
|
obs_output_set_media(fileOutput, obs_get_video(), obs_get_audio());
|
|
|
|
obs_output_update(fileOutput, settings);
|
|
|
|
|
|
|
|
obs_data_release(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void SetEncoderName(obs_encoder_t *encoder, const char *name,
|
|
|
|
const char *defaultName)
|
|
|
|
{
|
|
|
|
obs_encoder_set_name(encoder, (name && *name) ? name : defaultName);
|
|
|
|
}
|
|
|
|
|
2015-03-07 16:32:00 -08:00
|
|
|
inline void AdvancedOutput::UpdateAudioSettings()
|
2015-01-26 13:41:22 -08:00
|
|
|
{
|
2015-03-07 16:32:00 -08:00
|
|
|
bool applyServiceSettings = config_get_bool(main->Config(), "AdvOut",
|
|
|
|
"ApplyServiceSettings");
|
2015-03-27 12:38:38 -07:00
|
|
|
int streamTrackIndex = config_get_int(main->Config(), "AdvOut",
|
|
|
|
"TrackIndex");
|
2016-12-21 17:14:24 -08:00
|
|
|
obs_data_t *settings[MAX_AUDIO_MIXES];
|
2015-01-26 13:41:22 -08:00
|
|
|
|
2016-12-21 17:14:24 -08:00
|
|
|
for (size_t i = 0; i < MAX_AUDIO_MIXES; i++) {
|
2015-01-26 13:41:22 -08:00
|
|
|
settings[i] = obs_data_create();
|
2015-07-02 00:58:28 -07:00
|
|
|
obs_data_set_int(settings[i], "bitrate", GetAudioBitrate(i));
|
|
|
|
}
|
2015-01-26 13:41:22 -08:00
|
|
|
|
2016-12-21 17:14:24 -08:00
|
|
|
for (size_t i = 0; i < MAX_AUDIO_MIXES; i++) {
|
|
|
|
string cfg_name = "Track";
|
|
|
|
cfg_name += to_string((int)i + 1);
|
|
|
|
cfg_name += "Name";
|
|
|
|
const char *name = config_get_string(main->Config(), "AdvOut",
|
|
|
|
cfg_name.c_str());
|
|
|
|
|
|
|
|
string def_name = "Track";
|
|
|
|
def_name += to_string((int)i + 1);
|
|
|
|
SetEncoderName(aacTrack[i], name, def_name.c_str());
|
|
|
|
}
|
2015-01-26 13:41:22 -08:00
|
|
|
|
2016-12-21 17:14:24 -08:00
|
|
|
for (size_t i = 0; i < MAX_AUDIO_MIXES; i++) {
|
2015-03-27 13:35:43 -07:00
|
|
|
if (applyServiceSettings && (int)(i + 1) == streamTrackIndex)
|
2015-03-07 16:32:00 -08:00
|
|
|
obs_service_apply_encoder_settings(main->GetService(),
|
|
|
|
nullptr, settings[i]);
|
|
|
|
|
2015-01-26 13:41:22 -08:00
|
|
|
obs_encoder_update(aacTrack[i], settings[i]);
|
|
|
|
obs_data_release(settings[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdvancedOutput::SetupOutputs()
|
|
|
|
{
|
|
|
|
obs_encoder_set_video(h264Streaming, obs_get_video());
|
|
|
|
if (h264Recording)
|
|
|
|
obs_encoder_set_video(h264Recording, obs_get_video());
|
2016-12-21 17:14:24 -08:00
|
|
|
for (size_t i = 0; i < MAX_AUDIO_MIXES; i++)
|
|
|
|
obs_encoder_set_audio(aacTrack[i], obs_get_audio());
|
2015-01-26 13:41:22 -08:00
|
|
|
|
|
|
|
SetupStreaming();
|
|
|
|
|
2015-08-18 20:58:24 -07:00
|
|
|
if (ffmpegOutput)
|
2015-01-26 13:41:22 -08:00
|
|
|
SetupFFmpeg();
|
|
|
|
else
|
|
|
|
SetupRecording();
|
|
|
|
}
|
|
|
|
|
2015-07-02 00:58:28 -07:00
|
|
|
int AdvancedOutput::GetAudioBitrate(size_t i) const
|
|
|
|
{
|
2016-12-21 17:14:24 -08:00
|
|
|
static const char *names[] = {
|
2015-07-02 00:58:28 -07:00
|
|
|
"Track1Bitrate", "Track2Bitrate",
|
|
|
|
"Track3Bitrate", "Track4Bitrate",
|
2016-12-21 17:14:24 -08:00
|
|
|
"Track5Bitrate", "Track6Bitrate",
|
2015-07-02 00:58:28 -07:00
|
|
|
};
|
2015-09-21 18:36:26 -07:00
|
|
|
int bitrate = (int)config_get_uint(main->Config(), "AdvOut", names[i]);
|
|
|
|
return FindClosestAvailableAACBitrate(bitrate);
|
2015-07-02 00:58:28 -07:00
|
|
|
}
|
|
|
|
|
2015-01-26 13:41:22 -08:00
|
|
|
bool AdvancedOutput::StartStreaming(obs_service_t *service)
|
|
|
|
{
|
2015-02-14 18:10:39 -08:00
|
|
|
if (!useStreamEncoder ||
|
2015-08-18 20:58:24 -07:00
|
|
|
(!ffmpegOutput && !obs_output_active(fileOutput))) {
|
2015-02-14 18:10:39 -08:00
|
|
|
UpdateStreamSettings();
|
|
|
|
}
|
|
|
|
|
2015-03-07 16:32:00 -08:00
|
|
|
UpdateAudioSettings();
|
|
|
|
|
2015-01-26 13:41:22 -08:00
|
|
|
if (!Active())
|
|
|
|
SetupOutputs();
|
|
|
|
|
2017-07-13 03:57:42 -07:00
|
|
|
/* --------------------- */
|
|
|
|
|
|
|
|
int trackIndex = config_get_int(main->Config(), "AdvOut",
|
|
|
|
"TrackIndex");
|
|
|
|
|
|
|
|
const char *type = obs_service_get_output_type(service);
|
|
|
|
if (!type)
|
|
|
|
type = "rtmp_output";
|
|
|
|
|
|
|
|
/* XXX: this is messy and disgusting and should be refactored */
|
|
|
|
if (outputType != type) {
|
2017-07-25 19:01:29 -07:00
|
|
|
streamDelayStarting.Disconnect();
|
|
|
|
streamStopping.Disconnect();
|
|
|
|
startStreaming.Disconnect();
|
|
|
|
stopStreaming.Disconnect();
|
|
|
|
|
2017-07-13 03:57:42 -07:00
|
|
|
streamOutput = obs_output_create(type, "adv_stream",
|
|
|
|
nullptr, nullptr);
|
|
|
|
if (!streamOutput)
|
|
|
|
return false;
|
|
|
|
obs_output_release(streamOutput);
|
|
|
|
|
|
|
|
streamDelayStarting.Connect(
|
|
|
|
obs_output_get_signal_handler(streamOutput),
|
|
|
|
"starting", OBSStreamStarting, this);
|
|
|
|
streamStopping.Connect(
|
|
|
|
obs_output_get_signal_handler(streamOutput),
|
|
|
|
"stopping", OBSStreamStopping, this);
|
|
|
|
|
|
|
|
startStreaming.Connect(
|
|
|
|
obs_output_get_signal_handler(streamOutput),
|
|
|
|
"start", OBSStartStreaming, this);
|
|
|
|
stopStreaming.Connect(
|
|
|
|
obs_output_get_signal_handler(streamOutput),
|
|
|
|
"stop", OBSStopStreaming, this);
|
|
|
|
|
2017-07-13 04:04:17 -07:00
|
|
|
const char *codec =
|
|
|
|
obs_output_get_supported_audio_codecs(streamOutput);
|
2017-07-31 18:36:12 -07:00
|
|
|
if (!codec) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-13 04:04:17 -07:00
|
|
|
|
|
|
|
if (strcmp(codec, "aac") == 0) {
|
|
|
|
streamAudioEnc = aacTrack[trackIndex - 1];
|
|
|
|
} else {
|
|
|
|
const char *id = FindAudioEncoderFromCodec(codec);
|
|
|
|
int audioBitrate = GetAudioBitrate(trackIndex - 1);
|
|
|
|
obs_data_t *settings = obs_data_create();
|
|
|
|
obs_data_set_int(settings, "bitrate", audioBitrate);
|
|
|
|
|
|
|
|
streamAudioEnc = obs_audio_encoder_create(id,
|
|
|
|
"alt_audio_enc", nullptr,
|
|
|
|
trackIndex - 1, nullptr);
|
|
|
|
if (!streamAudioEnc)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
obs_encoder_update(streamAudioEnc, settings);
|
|
|
|
obs_encoder_set_audio(streamAudioEnc, obs_get_audio());
|
|
|
|
|
|
|
|
obs_data_release(settings);
|
|
|
|
}
|
|
|
|
|
2017-07-13 03:57:42 -07:00
|
|
|
outputType = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_output_set_video_encoder(streamOutput, h264Streaming);
|
2017-07-13 04:04:17 -07:00
|
|
|
obs_output_set_audio_encoder(streamOutput, streamAudioEnc, 0);
|
2017-07-13 03:57:42 -07:00
|
|
|
|
|
|
|
/* --------------------- */
|
|
|
|
|
2015-01-26 13:41:22 -08:00
|
|
|
obs_output_set_service(streamOutput, service);
|
|
|
|
|
2015-09-10 19:10:40 -07:00
|
|
|
bool reconnect = config_get_bool(main->Config(), "Output", "Reconnect");
|
|
|
|
int retryDelay = config_get_int(main->Config(), "Output", "RetryDelay");
|
|
|
|
int maxRetries = config_get_int(main->Config(), "Output", "MaxRetries");
|
2015-09-06 16:19:53 -07:00
|
|
|
bool useDelay = config_get_bool(main->Config(), "Output",
|
|
|
|
"DelayEnable");
|
|
|
|
int delaySec = config_get_int(main->Config(), "Output",
|
|
|
|
"DelaySec");
|
|
|
|
bool preserveDelay = config_get_bool(main->Config(), "Output",
|
|
|
|
"DelayPreserve");
|
2016-07-29 08:30:54 -07:00
|
|
|
const char *bindIP = config_get_string(main->Config(), "Output",
|
|
|
|
"BindIP");
|
2017-02-21 17:05:45 -08:00
|
|
|
bool enableNewSocketLoop = config_get_bool(main->Config(), "Output",
|
|
|
|
"NewSocketLoopEnable");
|
|
|
|
bool enableLowLatencyMode = config_get_bool(main->Config(), "Output",
|
|
|
|
"LowLatencyEnable");
|
2016-07-29 08:30:54 -07:00
|
|
|
|
|
|
|
obs_data_t *settings = obs_data_create();
|
|
|
|
obs_data_set_string(settings, "bind_ip", bindIP);
|
2017-02-21 17:05:45 -08:00
|
|
|
obs_data_set_bool(settings, "new_socket_loop_enabled",
|
|
|
|
enableNewSocketLoop);
|
|
|
|
obs_data_set_bool(settings, "low_latency_mode_enabled",
|
|
|
|
enableLowLatencyMode);
|
2016-07-29 08:30:54 -07:00
|
|
|
obs_output_update(streamOutput, settings);
|
|
|
|
obs_data_release(settings);
|
|
|
|
|
2015-01-26 13:41:22 -08:00
|
|
|
if (!reconnect)
|
|
|
|
maxRetries = 0;
|
|
|
|
|
2015-09-06 16:19:53 -07:00
|
|
|
obs_output_set_delay(streamOutput, useDelay ? delaySec : 0,
|
|
|
|
preserveDelay ? OBS_OUTPUT_DELAY_PRESERVE : 0);
|
|
|
|
|
2015-01-26 13:41:22 -08:00
|
|
|
obs_output_set_reconnect_settings(streamOutput, maxRetries,
|
|
|
|
retryDelay);
|
|
|
|
|
|
|
|
if (obs_output_start(streamOutput)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AdvancedOutput::StartRecording()
|
|
|
|
{
|
2015-08-18 20:58:24 -07:00
|
|
|
const char *path;
|
2016-03-25 02:43:38 -07:00
|
|
|
const char *recFormat;
|
|
|
|
const char *filenameFormat;
|
2015-11-27 03:14:18 -08:00
|
|
|
bool noSpace = false;
|
2016-03-25 02:43:38 -07:00
|
|
|
bool overwriteIfExists = false;
|
2015-08-18 20:58:24 -07:00
|
|
|
|
2015-02-14 18:10:39 -08:00
|
|
|
if (!useStreamEncoder) {
|
2015-08-18 20:58:24 -07:00
|
|
|
if (!ffmpegOutput) {
|
2015-02-14 18:10:39 -08:00
|
|
|
UpdateRecordingSettings();
|
|
|
|
}
|
|
|
|
} else if (!obs_output_active(streamOutput)) {
|
|
|
|
UpdateStreamSettings();
|
|
|
|
}
|
|
|
|
|
2015-03-07 16:32:00 -08:00
|
|
|
UpdateAudioSettings();
|
|
|
|
|
2015-01-26 13:41:22 -08:00
|
|
|
if (!Active())
|
|
|
|
SetupOutputs();
|
|
|
|
|
2015-08-18 20:58:24 -07:00
|
|
|
if (!ffmpegOutput || ffmpegRecording) {
|
|
|
|
path = config_get_string(main->Config(), "AdvOut",
|
|
|
|
ffmpegRecording ? "FFFilePath" : "RecFilePath");
|
2016-03-25 02:43:38 -07:00
|
|
|
recFormat = config_get_string(main->Config(), "AdvOut",
|
2015-08-18 20:58:24 -07:00
|
|
|
ffmpegRecording ? "FFExtension" : "RecFormat");
|
2016-03-25 02:43:38 -07:00
|
|
|
filenameFormat = config_get_string(main->Config(), "Output",
|
|
|
|
"FilenameFormatting");
|
|
|
|
overwriteIfExists = config_get_bool(main->Config(), "Output",
|
|
|
|
"OverwriteIfExists");
|
2015-11-27 03:14:18 -08:00
|
|
|
noSpace = config_get_bool(main->Config(), "AdvOut",
|
|
|
|
ffmpegRecording ?
|
|
|
|
"FFFileNameWithoutSpace" :
|
|
|
|
"RecFileNameWithoutSpace");
|
2015-01-26 13:41:22 -08:00
|
|
|
|
2017-08-06 15:40:20 -07:00
|
|
|
os_dir_t *dir = path && path[0] ? os_opendir(path) : nullptr;
|
2015-01-26 13:41:22 -08:00
|
|
|
|
|
|
|
if (!dir) {
|
2016-08-13 07:36:17 -07:00
|
|
|
if (main->isVisible())
|
2017-05-13 14:06:32 -07:00
|
|
|
OBSMessageBox::information(main,
|
2016-08-13 07:36:17 -07:00
|
|
|
QTStr("Output.BadPath.Title"),
|
|
|
|
QTStr("Output.BadPath.Text"));
|
|
|
|
else
|
|
|
|
main->SysTrayNotify(QTStr("Output.BadPath.Text"),
|
|
|
|
QSystemTrayIcon::Warning);
|
2015-01-26 13:41:22 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_closedir(dir);
|
|
|
|
|
|
|
|
string strPath;
|
|
|
|
strPath += path;
|
|
|
|
|
|
|
|
char lastChar = strPath.back();
|
|
|
|
if (lastChar != '/' && lastChar != '\\')
|
|
|
|
strPath += "/";
|
|
|
|
|
2016-03-25 02:43:38 -07:00
|
|
|
strPath += GenerateSpecifiedFilename(recFormat, noSpace,
|
|
|
|
filenameFormat);
|
2016-07-04 23:11:24 -07:00
|
|
|
ensure_directory_exists(strPath);
|
2016-03-25 02:43:38 -07:00
|
|
|
if (!overwriteIfExists)
|
|
|
|
FindBestFilename(strPath, noSpace);
|
2015-01-26 13:41:22 -08:00
|
|
|
|
|
|
|
obs_data_t *settings = obs_data_create();
|
2015-08-18 20:58:24 -07:00
|
|
|
obs_data_set_string(settings,
|
|
|
|
ffmpegRecording ? "url" : "path",
|
|
|
|
strPath.c_str());
|
2015-01-26 13:41:22 -08:00
|
|
|
|
|
|
|
obs_output_update(fileOutput, settings);
|
|
|
|
|
|
|
|
obs_data_release(settings);
|
|
|
|
}
|
|
|
|
|
2017-02-03 20:29:09 -08:00
|
|
|
if (!obs_output_start(fileOutput)) {
|
2017-08-06 15:24:44 -07:00
|
|
|
QString error_reason;
|
|
|
|
const char *error = obs_output_get_last_error(fileOutput);
|
|
|
|
if (error)
|
|
|
|
error_reason = QT_UTF8(error);
|
|
|
|
else
|
|
|
|
error_reason = QTStr("Output.StartFailedGeneric");
|
2017-02-03 20:29:09 -08:00
|
|
|
QMessageBox::critical(main,
|
|
|
|
QTStr("Output.StartRecordingFailed"),
|
2017-08-06 15:24:44 -07:00
|
|
|
error_reason);
|
2017-02-03 20:29:09 -08:00
|
|
|
return false;
|
2015-01-26 13:41:22 -08:00
|
|
|
}
|
|
|
|
|
2017-02-03 20:29:09 -08:00
|
|
|
return true;
|
2015-01-26 13:41:22 -08:00
|
|
|
}
|
|
|
|
|
2016-09-09 07:37:54 -07:00
|
|
|
void AdvancedOutput::StopStreaming(bool force)
|
2015-01-26 13:41:22 -08:00
|
|
|
{
|
2016-09-09 07:37:54 -07:00
|
|
|
if (force)
|
|
|
|
obs_output_force_stop(streamOutput);
|
|
|
|
else
|
|
|
|
obs_output_stop(streamOutput);
|
2015-09-06 16:19:53 -07:00
|
|
|
}
|
|
|
|
|
2016-09-09 07:37:54 -07:00
|
|
|
void AdvancedOutput::StopRecording(bool force)
|
2015-01-26 13:41:22 -08:00
|
|
|
{
|
2016-09-09 07:37:54 -07:00
|
|
|
if (force)
|
|
|
|
obs_output_force_stop(fileOutput);
|
|
|
|
else
|
|
|
|
obs_output_stop(fileOutput);
|
2015-01-26 13:41:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AdvancedOutput::StreamingActive() const
|
|
|
|
{
|
|
|
|
return obs_output_active(streamOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AdvancedOutput::RecordingActive() const
|
|
|
|
{
|
|
|
|
return obs_output_active(fileOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2015-02-06 03:17:33 -08:00
|
|
|
BasicOutputHandler *CreateSimpleOutputHandler(OBSBasic *main)
|
|
|
|
{
|
|
|
|
return new SimpleOutput(main);
|
|
|
|
}
|
2015-01-26 13:41:22 -08:00
|
|
|
|
|
|
|
BasicOutputHandler *CreateAdvancedOutputHandler(OBSBasic *main)
|
|
|
|
{
|
|
|
|
return new AdvancedOutput(main);
|
|
|
|
}
|