From 685f8297e406a4ef56e5be2f06268c9526c2cb3c Mon Sep 17 00:00:00 2001 From: Norihiro Kamae Date: Thu, 23 Dec 2021 21:09:50 +0900 Subject: [PATCH] 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. --- plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c | 4 ++++ plugins/obs-ffmpeg/obs-ffmpeg-mux.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c index a6b97ed20..c07e22abe 100644 --- a/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c +++ b/plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c @@ -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; diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-mux.c b/plugins/obs-ffmpeg/obs-ffmpeg-mux.c index fc573463a..d82e2cd94 100644 --- a/plugins/obs-ffmpeg/obs-ffmpeg-mux.c +++ b/plugins/obs-ffmpeg/obs-ffmpeg-mux.c @@ -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);