obs-ffmpeg: Set frame_size for audio codec parameter

This commit fixes an issue that the last audio packet is sometimes not
written into mp4 format. Since libavformat internally calculates the
packet duration from the frame_size specified in the codec parameter, it
is necessary to set frame_size.
This commit is contained in:
Norihiro Kamae 2021-12-23 21:09:50 +09:00 committed by Jim
parent d1b87e1642
commit 685f8297e4
2 changed files with 6 additions and 1 deletions

View File

@ -100,6 +100,7 @@ struct audio_params {
char *name;
int abitrate;
int sample_rate;
int frame_size;
int channels;
};
@ -220,6 +221,8 @@ static bool get_audio_params(struct audio_params *audio, int *argc,
return false;
if (!get_opt_int(argc, argv, &audio->sample_rate, "audio sample rate"))
return false;
if (!get_opt_int(argc, argv, &audio->frame_size, "audio frame size"))
return false;
if (!get_opt_int(argc, argv, &audio->channels, "audio channels"))
return false;
return true;
@ -446,6 +449,7 @@ static void create_audio_stream(struct ffmpeg_mux *ffm, int idx)
context->bit_rate = (int64_t)ffm->audio[idx].abitrate * 1000;
context->channels = ffm->audio[idx].channels;
context->sample_rate = ffm->audio[idx].sample_rate;
context->frame_size = ffm->audio[idx].frame_size;
context->sample_fmt = AV_SAMPLE_FMT_S16;
context->time_base = stream->time_base;
context->extradata = extradata;

View File

@ -169,8 +169,9 @@ static void add_audio_encoder_params(struct dstr *cmd, obs_encoder_t *aencoder)
dstr_copy(&name, obs_encoder_get_name(aencoder));
dstr_replace(&name, "\"", "\"\"");
dstr_catf(cmd, "\"%s\" %d %d %d ", name.array, bitrate,
dstr_catf(cmd, "\"%s\" %d %d %d %d ", name.array, bitrate,
(int)obs_encoder_get_sample_rate(aencoder),
(int)obs_encoder_get_frame_size(aencoder),
(int)audio_output_get_channels(audio));
dstr_free(&name);