diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c index f15dabcb3e..467f839baf 100644 --- a/libavformat/iamf_writer.c +++ b/libavformat/iamf_writer.c @@ -112,9 +112,17 @@ static int fill_codec_config(IAMFContext *iamf, const AVStreamGroup *stg, int j, ret = 0; codec_config->codec_id = st->codecpar->codec_id; - codec_config->sample_rate = st->codecpar->sample_rate; codec_config->codec_tag = st->codecpar->codec_tag; - codec_config->nb_samples = st->codecpar->frame_size; + switch (codec_config->codec_id) { + case AV_CODEC_ID_OPUS: + codec_config->sample_rate = 48000; + codec_config->nb_samples = av_rescale(st->codecpar->frame_size, 48000, st->codecpar->sample_rate); + break; + default: + codec_config->sample_rate = st->codecpar->sample_rate; + codec_config->nb_samples = st->codecpar->frame_size; + break; + } populate_audio_roll_distance(codec_config); if (st->codecpar->extradata_size) { codec_config->extradata = av_memdup(st->codecpar->extradata, st->codecpar->extradata_size); @@ -183,9 +191,9 @@ static int add_param_definition(IAMFContext *iamf, AVIAMFParamDefinition *param, } if (codec_config) { if (!param->duration) - param->duration = codec_config->nb_samples; + param->duration = av_rescale(codec_config->nb_samples, param->parameter_rate, codec_config->sample_rate); if (!param->constant_subblock_duration) - param->constant_subblock_duration = codec_config->nb_samples; + param->constant_subblock_duration = av_rescale(codec_config->nb_samples, param->parameter_rate, codec_config->sample_rate); } param_definition = av_mallocz(sizeof(*param_definition));