[Libav-user] Problems decoding mp3 files

b.mcdonagh at sky.com b.mcdonagh at sky.com
Mon Apr 28 01:54:22 CEST 2014

I've had a look at your code, thanks. It seems you are using av_read_frame which for me crashes with mp3 files as previously described.

I have just quickly written some code which has the crashes in when I run it - I hope this can help somebody to point me in the right direction. It crashes on av_read_frame or (find_stream_info - if i uncomment it out)

        int ret= avformat_open_input(&inputAudioFormat, filename, NULL, NULL);
//yyy = avformat_find_stream_info(inputAudioFormat, NULL);
//qDebug() << " crashes above line if not commented out ...after find stream info inputAudioFormat res=" << yyy;

inputAudioContextz = inputAudioFormat->streams[0]->codec;
inputAudioContextz->strict_std_compliance = -2;
inputAudioContextz->bit_rate = 64000;//inputAudioFormat->streams[0]->codec->bit_rate;
inputAudioContextz->channels = 2;
inputAudioContextz->request_channel_layout = AV_CH_LAYOUT_STEREO;
inputAudioContextz->sample_rate = 44100;//inputAudioFormat->streams[0]->codec->sample_rate;
inputAudioContextz->codec =  avcodec_find_decoder(inputAudioContextz->codec_id);
inputAudioCodec = (AVCodec*)inputAudioContextz->codec;

if (!inputAudioCodec) {
fprintf(stderr, "no codec not found\n");
if (avcodec_open2(inputAudioContextz, inputAudioContextz->codec, NULL) < 0) {
fprintf(stderr, "could not open codec\n");

AVPacket pkt;
  av_init_packet( &pkt );
      qDebug() << "b4 while read frame";
  while (av_read_frame( inputAudioFormat, &pkt ) >= 0) {
  qDebug() << "after while read frame";
    if(pkt.stream_index == 0)


  if (!(decoded_frame = avcodec_alloc_frame()))
  fprintf(stderr, "Could not allocate audio frame\n");

  int rv = avcodec_decode_audio4(inputAudioContextz, decoded_frame, &got_frame, &pkt);
  qDebug() << "result decodeframe" <<rv;;
On Monday, 28 April 2014, 0:09, Gonzalo Garramuno <ggarra13 at gmail.com> wrote:
On 27/04/14 20:03, b.mcdonagh at sky.com wrote:
> Thank you for your response Gonzalo.

Maybe my code sample in http://sourceforge.net/projects/mrviewer will 
help you out.  You should look at the file called CMedia_audio.cpp and 
The viewer plays mp3 and has never needed to call the routines you mention.

Libav-user mailing list
Libav-user at ffmpeg.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20140428/c65acb94/attachment.html>

More information about the Libav-user mailing list