[Libav-user] Audio sample rate conversion and fixed frame size

Ove Bjelke-Holtermann oveb at defteros.com
Thu Jan 22 21:10:16 CET 2015


Uing filters (anull if no actual filter is needed; with abuffer and
abuffersink) instead of a manual swr_convert is making life easier.

rough idea of how to deal with the abuffer/abuffersink is here:
https://www.ffmpeg.org/doxygen/2.2/filter_audio_8c-example.html

av_buffersink_set_frame_size(...) will do the re-packaging into fixed
packet sizes for you, including a correct last packet on flushing.
Supplying the proper format descriptions on abuffer (your source) and
abuffersink (your output format) will also make the filter graph take
care of all required format conversions.

Maybe a bit heavy for something simple but very convenient.




On Wed, Jan 21, 2015 at 3:31 AM, Max Vlasov <max.vlasov at gmail.com> wrote:
> Hi,
>
> When sample rate conversion is needed, one can face another problem. Some
> codecs reports they don't have CODEC_CAP_VARIABLE_FRAME_SIZE capability so
> accept only some fixed frame size buffers with an exception for the last
> block. I tried to find a working example, but it seems they often lack full
> support for such cases. Obviously one may cache converter results and output
> by necessary blocks, but this involves supporting several buffers for planar
> data and knowing exact format.
>
> With own experiment I tried to do the following:
> 1) For the required dest_frames use infamous formula
>   av_rescale_rnd(swr_get_delay(...) + inp_frames,...
> trying to detect the number of input frames (inp_frames here) necessary for
> at least dest_frames (src_frames). Either with binary search or just by
> using an incrementer
> 2) call swr_convert with src_frames as the number of input frames, but pass
> exactly dest_frames as output. So the converter have to cache some input
> frames since I limited the output buffer.
>
> The approach worked at least for some cases, but there are problems I faced:
> - I have to use much larger dest_frames (currently it is twice as large).
> Otherwise sometimes swr_convert reports making several bytes less than I
> requested (1535 instead of 1536). I suspect this is because swr_get_delay is
> approximate in most cases. The question is whether should I fix this
> multiplier (x2) or use some other approach for this detection.
> - I can not figure out how correctly get the last cached frames from the
> converter and not violate the rule for frame_size (it should have the same
> size with every step except the last one). When I fed the last input bytes,
> I probably already get non-standard output so another call with Null and 0
> as input will produce extra non-standard block.
>
> Any help will be appreciated
>
> Thanks,
>
> Max
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>


More information about the Libav-user mailing list