[Libav-user] Audio sample rate conversion and fixed frame size
Max Vlasov
max.vlasov at gmail.com
Wed Jan 21 12:31:14 CET 2015
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20150121/38827d90/attachment.html>
More information about the Libav-user
mailing list