[Libav-user] Muxing example and audio resampling
Nuno Santos
nuno.santos at imaginando.pt
Mon Aug 1 00:18:00 EEST 2022
Hi,
I’m trying to mux an audio stream at 192 KHz. The audio codec is AAC which is limited to 96 KHz. Since, this codec is not compatible with 192 KHz, the maximum 96 KHz will be used and the result is an incorrect audio stream. I have based my code on the muxing.c example:
https://ffmpeg.org/doxygen/trunk/muxing_8c-example.html
This example initialises a sample rate converter at open_audio function. As per my understanding, the sample rate converter is used in the write_audio_frame function in order to convert the input audio stream sample rate into the codec sample rate. However, in the open_audio function, during the sample rate converter initialisation:
av_opt_set_int <https://ffmpeg.org/doxygen/trunk/group__opt__set__funcs.html#ga3adf7185c21cc080890a5ec02c2e56b2> (ost <https://ffmpeg.org/doxygen/trunk/vaapi__transcode_8c.html#a3e44252189bdae5212c5d1171bcd7cf4>->swr_ctx, "in_sample_rate", c <https://ffmpeg.org/doxygen/trunk/undefined_8txt.html#a12d8853991e25cc8d069554379c29ef6>->sample_rate, 0);
av_opt_set_int <https://ffmpeg.org/doxygen/trunk/group__opt__set__funcs.html#ga3adf7185c21cc080890a5ec02c2e56b2> (ost <https://ffmpeg.org/doxygen/trunk/vaapi__transcode_8c.html#a3e44252189bdae5212c5d1171bcd7cf4>->swr_ctx, "out_sample_rate", c <https://ffmpeg.org/doxygen/trunk/undefined_8txt.html#a12d8853991e25cc8d069554379c29ef6>->sample_rate, 0);
The input sample rate is the same as the output sample rate. Trying to change the input sample rate to match the audio stream sample rate results in a assertion fail in write_audio_frame function:
av_assert0 <https://ffmpeg.org/doxygen/trunk/avassert_8h.html#aae204192396f78cc8c5cd7ad5c57c23f>(dst_nb_samples == frame <https://ffmpeg.org/doxygen/trunk/filter__design_8txt.html#a48ad71a5b40cdd5f23c601f33665a953>->nb_samples);
What is correct way of taking advantage of the already existing sample rate converter in order to have the audio stream that is being generated at 192khz, being encoded at 96Khz?
Thanks in advance!
Best regards,
Nuno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20220731/1a469550/attachment.htm>
More information about the Libav-user
mailing list