On Feb 18, 2013, at 3:50 PM, Carl Eugen Hoyos <[email protected]> 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
CODE SNIPPET - PROCESSING AN AUDIO FRAME
// get the codec context
AVCodecContext *codecCtx = _audioStream->codec;
// source variables
int64_t sourceChannelLayout = AV_CH_LAYOUT_STEREO;
int sourceSampleRate = 44100;
enum AVSampleFormat sourceSampleFormat = AV_SAMPLE_FMT_FLT;
int sourceNumberOfChannels =
av_get_channel_layout_nb_channels(sourceChannelLayout);
int sourceLineSize = 0;
int sourceNumberOfSamples = (int)sampleBuffer.numberOfSamples;
uint8_t *sourceData = NULL;
// destination variables
int64_t destinationChannelLayout = AV_CH_LAYOUT_STEREO;
int destinationSampleRate = 44100;
enum AVSampleFormat destinationSampleFormat = _outputSampleFormat;
int destinationNumberOfChannels =
av_get_channel_layout_nb_channels(destinationChannelLayout);
int destinationLineSize = 0;
int destinationNumberOfSamples = (int)av_rescale_rnd(sourceNumberOfSamples,
destinationSampleRate, sourceSampleRate, AV_ROUND_UP);
uint8_t *destinationData = NULL;
// resample the audio to convert to a format that FFmpeg can use
// allocate a resampler context
static struct SwrContext *resamplerCtx;
resamplerCtx = swr_alloc_set_opts(NULL,
destinationChannelLayout,
destinationSampleFormat,
destinationSampleRate,
sourceChannelLayout,
sourceSampleFormat,
sourceSampleRate,
0,
NULL);
if (resamplerCtx == NULL)
{
// handle error
}
// allocate the source samples buffer
int returnVal = av_samples_alloc(&sourceData,
&sourceLineSize,
sourceNumberOfChannels,
sourceNumberOfSamples,
sourceSampleFormat,
1);
if (returnVal < 0)
{
// handle error
}
// allocate the destination samples buffer
returnVal = av_samples_alloc(&destinationData,
&destinationLineSize,
destinationNumberOfChannels,
destinationNumberOfSamples,
destinationSampleFormat,
1);
if (returnVal < 0)
{
// handle error
}
// fill the source samples buffer
returnVal = av_samples_fill_arrays(&sourceData,
&sourceLineSize,
sampleBuffer.bytesForAllSamples,
sourceNumberOfChannels,
sourceNumberOfSamples,
sourceSampleFormat,
1);
if (returnVal < 0)
{
// handle error
}
// convert to destination format
returnVal = swr_convert(resamplerCtx,
&destinationData,
destinationNumberOfSamples,
(const uint8_t **)&sourceData,
sourceNumberOfSamples);
*** The above line crashes with an EXC_ARITHMETIC error, generally the result
of divide by 0
_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user