[Libav-user] avcodec_decode_audio4

David martin vilanew at gmail.com
Fri Mar 16 11:27:49 CET 2012


Hi,
I'm trying to play the sound and video of a streaming video but the 
function avcodec_decode_audio4 keeps returning 0. Do you know why ??? I 
also realized that i only get one frame decoded which i guess is the first.

Here are the steps I have done

void packet_queue_init(PacketQueue *q)
int packet_queue_put(PacketQueue *q, AVPacket *pkt)
int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block) { //get 
AVPacketList
audio_callback(void *userdata, Uint8 *stream, int len) {
audio_decode_frame ---> returns no data


Video is oK;
Audio -> no audio

 >output
Playing... video.mpeg
[mpeg @ 0x9fc9980] max_analyze_duration 5000000 reached at 5000000
Input #0, mpeg, from '-f':
   Duration: 00:00:09.96, start: 1.000000, bitrate: 595 kb/s
     Stream #0:0[0x1e0]: Video: mpeg1video, yuv420p, 640x360 [SAR 1:1 
DAR 16:9], 104857 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc
     Stream #0:1[0x1c0]: Audio: mp2, 44100 Hz, 2 channels, s16, 128 kb/s
Video Codec found :mpeg1video
Audio Codec found :mp2
Video Codec initialized !!!
Audio Codec initialized !!!
Width:640
height:360
Running on platform:Linux
Using software rendering
INFO: +++++ INIT DONE +++++
Using audio driver: pulseaudio
Packet queue initialized
Calling audiocallback
Sent data buffer:134529440
Decoding Frame
no data
no data
no data
no data
....
Video end reached and read correctly
Goodbye
 > ~/workspace/test1/Release $

//Here is the function that returns no data.
int audio_decode_frame(AVCodecContext *aCodecCtx, uint8_t *audio_buf, 
int buf_size) { // decode audio

	printf("Decoding Frame\n");
	//printf("Codec Name:%s",aCodecCtx->codec_name);
	static AVPacket pkt;
	static uint8_t *audio_pkt_data = NULL;
	static int audio_pkt_size = 0;

   int len1, data_size;

   for(;;) {
     while(audio_pkt_size > 0) {
       data_size = buf_size;
       len1 = avcodec_decode_audio4(aCodecCtx, (int16_t *)audio_buf, 
&data_size, audio_pkt_data);

       if(len1 < 0) {
     	  printf("Skipping frame\n");
     /* if error, skip frame */
     audio_pkt_size = 0;
     break;
       }

       audio_pkt_data += len1;
       audio_pkt_size -= len1;
       pkt.pts = AV_NOPTS_VALUE;

       if(data_size <= 0) {
     /* No data yet, get more frames */
     printf("no data\n");
     continue;
       }
       /* We have data, return it and come back for more later */

       return data_size;
     }
     if(pkt.data)
       av_free_packet(&pkt);

     if(quit) {
       return -1;
     }

     if(packet_queue_get(&audioq, &pkt, 1) < 0) {
     	printf("No packet\n");
       return -1;
     }
     audio_pkt_data = pkt.data;
     audio_pkt_size = pkt.size;
   }
   printf("End of Decoding Frame\n");
}




More information about the Libav-user mailing list