obs-ffmpeg: Add Opus audio encoder
This commit is contained in:
parent
d2ffd0fdd2
commit
fa611dcd76
@ -1,5 +1,6 @@
|
||||
FFmpegOutput="FFmpeg Output"
|
||||
FFmpegAAC="FFmpeg Default AAC Encoder"
|
||||
FFmpegOpus="FFmpeg Opus Encoder"
|
||||
Bitrate="Bitrate"
|
||||
Preset="Preset"
|
||||
RateControl="Rate Control"
|
||||
|
@ -62,6 +62,12 @@ static const char *aac_getname(void *unused)
|
||||
return obs_module_text("FFmpegAAC");
|
||||
}
|
||||
|
||||
static const char *opus_getname(void *unused)
|
||||
{
|
||||
UNUSED_PARAMETER(unused);
|
||||
return obs_module_text("FFmpegOpus");
|
||||
}
|
||||
|
||||
static void enc_destroy(void *data)
|
||||
{
|
||||
struct enc_encoder *enc = data;
|
||||
@ -126,7 +132,7 @@ static void init_sizes(struct enc_encoder *enc, audio_t *audio)
|
||||
#endif
|
||||
|
||||
static void *enc_create(obs_data_t *settings, obs_encoder_t *encoder,
|
||||
const char *type)
|
||||
const char *type, const char *alt)
|
||||
{
|
||||
struct enc_encoder *enc;
|
||||
int bitrate = (int)obs_data_get_int(settings, "bitrate");
|
||||
@ -139,6 +145,11 @@ static void *enc_create(obs_data_t *settings, obs_encoder_t *encoder,
|
||||
enc->codec = avcodec_find_encoder_by_name(type);
|
||||
enc->type = type;
|
||||
|
||||
if (!enc->codec && alt) {
|
||||
enc->codec = avcodec_find_encoder_by_name(alt);
|
||||
enc->type = alt;
|
||||
}
|
||||
|
||||
blog(LOG_INFO, "---------------------------------");
|
||||
|
||||
if (!enc->codec) {
|
||||
@ -169,12 +180,13 @@ static void *enc_create(obs_data_t *settings, obs_encoder_t *encoder,
|
||||
int cur_rate = enc->context->sample_rate;
|
||||
int closest = 0;
|
||||
|
||||
while (rate) {
|
||||
while (*rate) {
|
||||
int dist = abs(cur_rate - *rate);
|
||||
int closest_dist = abs(cur_rate - closest);
|
||||
|
||||
if (dist < closest_dist)
|
||||
closest = *rate;
|
||||
rate++;
|
||||
}
|
||||
|
||||
if (closest)
|
||||
@ -214,7 +226,12 @@ fail:
|
||||
|
||||
static void *aac_create(obs_data_t *settings, obs_encoder_t *encoder)
|
||||
{
|
||||
return enc_create(settings, encoder, "aac");
|
||||
return enc_create(settings, encoder, "aac", NULL);
|
||||
}
|
||||
|
||||
static void *opus_create(obs_data_t *settings, obs_encoder_t *encoder)
|
||||
{
|
||||
return enc_create(settings, encoder, "libopus", "opus");
|
||||
}
|
||||
|
||||
static bool do_encode(struct enc_encoder *enc,
|
||||
@ -328,3 +345,18 @@ struct obs_encoder_info aac_encoder_info = {
|
||||
.get_extra_data = enc_extra_data,
|
||||
.get_audio_info = enc_audio_info
|
||||
};
|
||||
|
||||
struct obs_encoder_info opus_encoder_info = {
|
||||
.id = "ffmpeg_opus",
|
||||
.type = OBS_ENCODER_AUDIO,
|
||||
.codec = "opus",
|
||||
.get_name = opus_getname,
|
||||
.create = opus_create,
|
||||
.destroy = enc_destroy,
|
||||
.encode = enc_encode,
|
||||
.get_frame_size = enc_frame_size,
|
||||
.get_defaults = enc_defaults,
|
||||
.get_properties = enc_properties,
|
||||
.get_extra_data = enc_extra_data,
|
||||
.get_audio_info = enc_audio_info
|
||||
};
|
||||
|
@ -13,6 +13,7 @@ extern struct obs_output_info ffmpeg_output;
|
||||
extern struct obs_output_info ffmpeg_muxer;
|
||||
extern struct obs_output_info replay_buffer;
|
||||
extern struct obs_encoder_info aac_encoder_info;
|
||||
extern struct obs_encoder_info opus_encoder_info;
|
||||
extern struct obs_encoder_info nvenc_encoder_info;
|
||||
|
||||
static DARRAY(struct log_context {
|
||||
@ -148,6 +149,7 @@ bool obs_module_load(void)
|
||||
obs_register_output(&ffmpeg_muxer);
|
||||
obs_register_output(&replay_buffer);
|
||||
obs_register_encoder(&aac_encoder_info);
|
||||
obs_register_encoder(&opus_encoder_info);
|
||||
if (nvenc_supported()) {
|
||||
blog(LOG_INFO, "NVENC supported");
|
||||
obs_register_encoder(&nvenc_encoder_info);
|
||||
|
Loading…
x
Reference in New Issue
Block a user