Are there any examples for using swr_convert_frame() to resample audio instead of swr_convert()? My code currently looks like (using cgo):
if averr := C.swr_convert_frame(swrctx, outframe, inframe); averr < 0 {
return av_err("swr_convert_frame", averr)
}
encodeFrame(outFrame)
if delay := C.swr_get_delay(swrctx, C.int64_t(outframe.sample_rate)); delay > 0 {
if averr := C.swr_convert_frame(swrctx, outframe, nil); averr < 0 {
return av_err("swr_convert_frame", averr)
}
encodeFrame(outFrame)
}
However the output frame has more samples than the encoder's configured frame_size for libopus. If I shrink the max nb_samples on the AVFrame, then it passes the encoder but I have to manually set the pts resulting in multiple frames with the same pts, even when following this outline, for example.
I tried setting it according to out_pts = swr_next_pts(ctx, in_pts) however this doesn't seem to correctly calculate the pts and libopus produces some incorrect dts numbers.
Is there an example for correctly using swr_convert_frame that correctly sets the pts for the encoder? Based on the API provided, it seems like it would also produce incomplete frames?