avformat/iamf_writer: fix setting num_samples_per_frame for OPUS

As per section 3.11.1 of the IAMF spec, the sample rate used in Codec Config
for Opus shall be 48kHz, regardless of the original sample rate used during
encoding.

Signed-off-by: James Almer <jamrial@gmail.com>
master
James Almer 2 weeks ago
parent 95217872ad
commit 76049d1c45
  1. 16
      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));

Loading…
Cancel
Save