瀏覽代碼

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.
Norihiro Kamae 3 年之前
父節點
當前提交
685f8297e4
共有 2 個文件被更改,包括 6 次插入1 次删除
  1. 4 0
      plugins/obs-ffmpeg/ffmpeg-mux/ffmpeg-mux.c
  2. 2 1
      plugins/obs-ffmpeg/obs-ffmpeg-mux.c

+ 4 - 0
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;

+ 2 - 1
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);