[Libav-user] Converting audio sample buffer format

Paul B Mahol onemda at gmail.com
Mon Feb 25 09:30:48 CET 2013

On 2/25/13, Brad O'Hearne <brado at bighillsoftware.com> wrote:
> On Feb 18, 2013, at 3:50 PM, Carl Eugen Hoyos <cehoyos at ag.or.at> wrote:
>> While I have _no_ idea what the "flv audio codec" could
>> be, please use either the aconvert filter or libswresample
>> directly to convert from one audio format to another.
> This has turned out to be much more difficult than expected. To review, I'm
> trying to take samples captured from QTKit (Apple's QuickTime library) and
> resample them to an appropriate format for streaming with FFmpeg. The audio
> data received from QTKit capture is a data structured contained within
> QTSampleBuffer, which has the following description:
> Linear PCM, 32 bit little-endian floating point, 2 channels, 44100 Hz
> After reading various ffmpeg source, it appears that this maps to the
> AV_SAMPLE_FMT_FLT sample format (though note I've also tried
> AV_SAMPLE_FMT_FLTP -- with the same result). The output sample format that I
> need to resample to is AV_SAMPLE_FMT_S16.
> I have successfully created the resample context, allocated both source and
> destination data arrays, and filled the source array with the QTSampleBuffer
> data. But the actual conversion is failing, specifically the line:
> // convert to destination format
> returnVal = swr_convert(resamplerCtx,
>                         &destinationData,
>                         destinationNumberOfSamples,
>                         (const uint8_t **)&sourceData,
>                         sourceNumberOfSamples);
> is completely crashing the app with an EXC_ARITHMETIC error, which is
> generally an indication of a divide by zero error. I have attached a more
> extensive code snippet so that you can see how I've gone about this. Note
> I've changed sample formats, changed between default (0) and no alignment
> (1) on the data array allocations, with no change -- the conversion still
> fails. In the call above, both the destination and source number of samples
> are 512, the same number of samples that are coming over on the
> QTSampleBuffer object.
> Does anyone have any idea what might be causing this? The app is just
> outright crashing inside the swr_convert function, giving me almost no clue
> what the problem is.

Without looking at exact code I'm playing lottery here.

> Help is greatly appreciated!
> Thanks,
> Brad

More information about the Libav-user mailing list