@@ -1115,6 +1115,8 @@ int ff_iamf_write_audio_frame(const IAMFContext *iamf, AVIOContext *pb,
1115
1115
{
1116
1116
uint8_t header [MAX_IAMF_OBU_HEADER_SIZE ];
1117
1117
PutBitContext pbc ;
1118
+ const IAMFAudioElement * audio_element ;
1119
+ IAMFCodecConfig * codec_config ;
1118
1120
AVIOContext * dyn_bc ;
1119
1121
const uint8_t * side_data ;
1120
1122
uint8_t * dyn_buf = NULL ;
@@ -1124,22 +1126,21 @@ int ff_iamf_write_audio_frame(const IAMFContext *iamf, AVIOContext *pb,
1124
1126
audio_substream_id + IAMF_OBU_IA_AUDIO_FRAME_ID0 : IAMF_OBU_IA_AUDIO_FRAME ;
1125
1127
int ret ;
1126
1128
1129
+ audio_element = get_audio_element (iamf , audio_substream_id );
1130
+ if (!audio_element )
1131
+ return AVERROR (EINVAL );
1132
+ codec_config = ff_iamf_get_codec_config (iamf , audio_element -> codec_config_id );
1133
+ if (!codec_config )
1134
+ return AVERROR (EINVAL );
1135
+
1127
1136
if (!pkt -> size ) {
1128
- const IAMFAudioElement * audio_element ;
1129
- IAMFCodecConfig * codec_config ;
1130
1137
size_t new_extradata_size ;
1131
1138
const uint8_t * new_extradata = av_packet_get_side_data (pkt ,
1132
1139
AV_PKT_DATA_NEW_EXTRADATA ,
1133
1140
& new_extradata_size );
1134
1141
1135
1142
if (!new_extradata )
1136
1143
return AVERROR_INVALIDDATA ;
1137
- audio_element = get_audio_element (iamf , audio_substream_id );
1138
- if (!audio_element )
1139
- return AVERROR (EINVAL );
1140
- codec_config = ff_iamf_get_codec_config (iamf , audio_element -> codec_config_id );
1141
- if (!codec_config )
1142
- return AVERROR (EINVAL );
1143
1144
1144
1145
av_free (codec_config -> extradata );
1145
1146
codec_config -> extradata = av_memdup (new_extradata , new_extradata_size );
@@ -1160,6 +1161,14 @@ int ff_iamf_write_audio_frame(const IAMFContext *iamf, AVIOContext *pb,
1160
1161
discard_padding = AV_RL32 (side_data + 4 );
1161
1162
}
1162
1163
1164
+ if (codec_config -> codec_id == AV_CODEC_ID_OPUS ) {
1165
+ // IAMF's num_samples_to_trim_at_start is the same as Opus's pre-skip.
1166
+ skip_samples = pkt -> dts < 0
1167
+ ? av_rescale (- pkt -> dts , 48000 , pkt -> time_base .den )
1168
+ : 0 ;
1169
+ discard_padding = av_rescale (discard_padding , 48000 , pkt -> time_base .den );
1170
+ }
1171
+
1163
1172
ret = avio_open_dyn_buf (& dyn_bc );
1164
1173
if (ret < 0 )
1165
1174
return ret ;
0 commit comments