[Libav-user] Problems decoding mp3 files

b.mcdonagh at sky.com b.mcdonagh at sky.com
Mon Apr 28 02:16:19 CEST 2014


AVCodecContext *inputAudioContextz= NULL;

AVFormatContext*    inputAudioFormat= NULL; 


I do call av_register_all before the code I sent you (sorry should have said that).

I have removed the lines which were setting the muxer values but it didn't help.

Here's the new code in case it helps.

int ret= avformat_open_input(&inputAudioFormat, filename, NULL, NULL);
if(ret < 0)
{
qDebug() << "couldn't open input file for audio ";
exit(1);
}
inputAudioContextz = inputAudioFormat->streams[0]->codec;
inputAudioContextz->codec =  avcodec_find_decoder(inputAudioContextz->codec_id);

if (avcodec_open2(inputAudioContextz, inputAudioContextz->codec, NULL) < 0) {
fprintf(stderr, "could not open codec\n");
exit(1);
}

AVPacket pkt;
av_init_packet( &pkt ); //tried both leaving this line in and commenting it out neither help
qDebug() << "b4 while read frame";
while (av_read_frame( inputAudioFormat, &pkt ) >= 0) //crashes here
{
qDebug() << "after while read frame";
if(pkt.stream_index == 0)
{


if(decoded_frame)
av_frame_unref(decoded_frame);

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

int rv = avcodec_decode_audio4(inputAudioContextz, decoded_frame, &got_frame, &pkt);
qDebug() << "result decodeframe" <<rv;;
}
}


Thanks again for your time.
On Monday, 28 April 2014, 1:02, Gonzalo Garramuno <ggarra13 at gmail.com> wrote:
 
On 27/04/14 20:54, b.mcdonagh at sky.com wrote:
> 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)
>
     What are inputAudioFormat and
 inputAudioContextz?  Also did you 
call av_register_all() before?
>         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);
You shouldn't need to initialize the audio context when demuxing. Leave 
all values at their default.

> inputAudioCodec = (AVCodec*)inputAudioContextz->codec;
This
 definitively looks wrong.

>
> if (!inputAudioCodec) {
> fprintf(stderr, "no codec not found\n");
> exit(1);
> }
> if (avcodec_open2(inputAudioContextz, inputAudioContextz->codec, NULL) 
> < 0) {
> fprintf(stderr, "could not open codec\n");
> exit(1);
> }
>
Here you would start with av_read_frame()


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


More information about the Libav-user mailing list