[Libav-user] Issue with decoding APE files

Nicolas George george at nsup.org
Fri Aug 7 12:55:53 CEST 2015


Le decadi 20 thermidor, an CCXXIII, Michał Kurowski a écrit :
> I'm developing a mobile music player and I'm planning to use ffmpeg for
> some of the audio decoding. The decoder has been written some time ago,
> but it seems to work ok (music plays without issues). Except for APE
> files. The result is as if the decoder was seeking ~0.8 second forward
> after reading each packet, so that a 4 minute track plays in a couple of
> seconds. Decoding of one stereo 96kHz APE file results in frames with
> 18432 bytes of data each (4608 samples, or 48 ms), but the consecutive
> timestamps are as follows:

> 		ret = av_read_frame(af->mFormatCtx, &(af->mPacket));
> 		if (ret < 0)
> 		{
> 			return ret;
> 		}
> 
> 	    if (af->mPacket.stream_index == af->mAudioStream)
> 	    {
> 	            avcodec_get_frame_defaults(frame);
> 	            got_frame = 0;
> 	            ret = avcodec_decode_audio4(af->mCodecCtx, frame, &got_frame, &(af->mPacket));
> 	            if (ret < 0)
> 	            {
> 	                continue;
> 	            }
> 
> 	            if (got_frame)
> 	            {
> 	            	af->mTimestamp = (float)(af->mPacket.pts * af->mDTimebase);
> 	            	return 0;
> 	            }
> 	    }
> 	     av_free_packet(&(af->mPacket));
> 	}

Unlike video packets, audio packets can decode into multiple frames: you
have to get the return value of avcodec_decode_audio4(), remove that many
bytes from the beginning of the packet, and re-call avcodec_decode_audio4()
until all the packet have been consumed.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20150807/e2016a53/attachment.sig>


More information about the Libav-user mailing list