[Libav-user] Converting audio sample buffer format

Brad O'Hearne brado at bighillsoftware.com
Mon Feb 25 07:39:10 CET 2013


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. 

Help is greatly appreciated!

Thanks, 

Brad

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: AudioProcessingSnippet.txt
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130224/4db48dc8/attachment.txt>


More information about the Libav-user mailing list