[Libav-user] swr_convert crashed when convert format S16P to FLTP

hemiao hemiao_1990 at 126.com
Sat Jan 11 10:15:32 CET 2014


I think i got the reason. I converts the audio to planar format, but 
frame->data[1] is NULL.

> I have checked ffmpeg and doc/examples/resampling.c, both of them 
> works fine.  I have reviewed my code many times, but unfortunatlly get 
> no result.
>
> int AudioDecoder::doDecode()
> {
>     AVPacket * packet = &mPacket;
>     int decoded_size = 0;
>     int got_frame = 0;
>     int ret;
>
>     if (!mFrame) {
>         mFrame = av_frame_alloc();
>     }
>
>     avcodec_get_frame_defaults(mFrame);
>     while (1) {
>         if (mPacketSize > 0) {
>             ret = avcodec_decode_audio4(mCodecCtx, mFrame, &got_frame, 
> packet);
>             if (ret < 0) {
>                 fprintf(stderr, "decode audio failed: %s.\n", 
> av_err2str(ret));
>                 continue;
>             }
>
>             if (!got_frame) {
>                 mPacketSize = 0;
>                 continue;
>             }
>
>             mPacketSize -= ret;
>             decoded_size = av_samples_get_buffer_size(NULL, 
> mCodecCtx->channels,
>                     mFrame->nb_samples, (enum 
> AVSampleFormat)mFrame->format, 1);
>             if (mChannelLayout != mOutChannelLayout ||
>                     mSampleFmt != mOutSampleFmt ||
>                     mSampleRate != mOutSampleRate)
>             {
>                 if (!mSwrCtx) {
>                     mSwrCtx = swr_alloc_set_opts(mSwrCtx, 
> mOutChannelLayout /* 3 */, mOutSampleFmt /* fltp */,
>                             mOutSampleRate /* 44100 */, mChannelLayout 
> /* 3 */, mSampleFmt /*s16p */, mSampleRate /* 44100 */, 0, NULL);
>                     int err = swr_init(mSwrCtx);
>                     if (err < 0) {
>                         av_log(NULL, AV_LOG_ERROR, "swr init failed: 
> %s.\n", av_err2str(err));
>                         exit(1);
>                     }
>                 }
>
>                 uint8_t * out[] = { mData };
>                 int out_count = sizeof(mData) / 
> av_get_channel_layout_nb_channels(mOutChannelLayout) /
> av_get_bytes_per_sample(mSampleFmt);
>                 ret = swr_convert(mSwrCtx, out, out_count, (const 
> uint8_t **)mFrame->extended_data,
>                                 mFrame->nb_samples);
>                 if (ret < 0) {
>                     av_log(NULL, AV_LOG_ERROR, "swr convert failed: 
> %s.\n", av_err2str(ret));
>                     exit(1);
>                 }
>                 decoded_size = ret * 
> av_get_channel_layout_nb_channels(mOutChannelLayout) *
>                         av_get_bytes_per_sample(mOutSampleFmt);
>                 mAudioBuffer = mData;
>                 if (ret == out_count) {
>                     av_log(NULL, AV_LOG_INFO, "audio buffer too 
> small.\n");
>                 }
>             } else {
>                 mAudioBuffer = mFrame->data[0];
>             }
>
>             return decoded_size;
>         }
>
>         if (packet->data) {
>             av_free_packet(packet);
>         }
>
>         ret = av_read_frame(mFmtCtx, packet);
>         if (ret < 0) {
>             fprintf(stdout, "read packet failed: %s.\n", 
> av_err2str(ret));
>         }
>         if (packet->stream_index != mStreamIndex) {
>             continue;
>         }
>         mPacketSize += packet->size;
>     }
>
>     return -1;     //shouldn't be here
> }
>
>
>> On date Thursday 2014-01-09 23:05:43 +0800, hemiao encoded:
>>> hi,everyone
>>>
>>> my audio source file's format is s16p. when i use swr_convert function
>>> to convert it to fltp or dblp, the function crashed, without return
>>> value or error message.
>>> but when i convert it to flt or dbl, it works fine. so why?
>> Please open a ticket if you're able to consistently reproduce the
>> error. Are you able to reproduce the issue with ffmpeg or with
>> doc/examples/resampling.c?
>
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user




More information about the Libav-user mailing list