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

Anton Shekhovtsov shekh.anton at gmail.com
Fri Jan 23 12:20:08 CET 2015

I used swresample only to convert format but it looks simple as brick to
me. You can feed any amount of data in and get any amount out, something
like this (pseudocode):

  int n = src_size-src_pos;
  if(n==0) break;

  const uint8_t* src[32];
  const uint8_t* dst[32];
  {for(int i=0; i<frame->channels; i++){
    src[i] = frame->extended_data[i] + src_pos*src_linesize;
    dst[i] = buf_data[i] + dst_pos*dst_linesize;

  int r = swr_convert(swr, dst, dst_size-dst_pos, src, n);
  if(!r) break;
  dst_pos += r;
  src_pos += n;
  if(dst_pos>=out_packet_size) handle_output();

No need to know anything about format except its bytes per sample:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20150123/b8241c0c/attachment.html>

More information about the Libav-user mailing list