[Libav-user] Decoding RTP streams with FFMpeg

Thomas Mair thomas.mair at ifi.lmu.de
Tue Apr 5 14:20:50 CEST 2011


Hello,

I am using FFMpeg to decode RTP streams specified by a SDP file. 
Specifically I have the following SDP file:

v=0
o=- 15079605070653109974 15079605070653109974 IN IP4 lap-mair
s=Unnamed
i=N/A
c=IN IP4 10.153.199.134
t=0 0
a=tool:vlc 1.1.4
a=recvonly
a=type:broadcast
a=charset:UTF-8
m=audio 1234 RTP/AVP 96
b=AS:16
b=RR:0
a=rtpmap:96 mpeg4-generic/48000/2
a=fmtp:96 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=1190; 
SizeLength=13; IndexLength=3; IndexDeltaLength=3; Profile=1;
m=video 1236 RTP/AVP 97
b=AS:32
b=RR:0
a=rtpmap:97 H264/90000
a=fmtp:97 
packetization-mode=1;profile-level-id=64000c;sprop-parameter-sets=Z2QADKwkpAeCP6wEQAAAAwBAAAAFI8UKkg==,aMvMsiw=;

FFMpeg first probes the streams and then starts playing them. However 
after a few seconds of playback it stops getting video packets and only 
gets audio packets. I have tried to figure out where the video packets 
are lost, but I could not find it. The funny thing is, when i do not 
decode audio packets i will get the video packets just fine. I am 
wondering if avcodec_decode_audio3 sets some strange options that breaks 
the receiving of the video packets. The code I am using is the following:

// Open video file
int ert = av_open_input_file(&format_ctx, file, NULL, 0, NULL);
	if(ert!=0){
		return; // Couldn't open file
	}

// Retrieve stream information
     ert = av_find_stream_info(ctx->format_ctx);
	if(ert<0){
	    return; // Couldn't find stream information
	}

// PREPARE VIDEO
// Find the first video stream
video_stream=-1;
int i;
for(i=0; i<ctx->format_ctx->nb_streams; i++)
	  if(&format_ctx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) {
	    	video_stream=i;
	    	break;
	    }

   ctx->audio_stream=-1;
   for(i=0; i<ctx->format_ctx->nb_streams; i++)
	      if(&format_ctx->streams[i]->codec->codec_type==CODEC_TYPE_AUDIO) {
	      	audio_stream=i;
	      	break;
	  }

.......

while(1){

         av_init_packet(&packet);

         // Read frames and put them into the queue
         if(av_read_frame(ctx->format_ctx, &packet)<0) {
             continue;
         }

         // Is this a packet from the video stream?
         if(packet.stream_index==video_stream) {
             queue_put(ctx->video_queue, &packet);
         }else if(packet.stream_index == audio_stream){
             decoded_buf = (uint16_t *)audio_buf;


             int read = 0;
             // get packet from queue
             while(packet.size > 0){
                 audio_buf_size = AVCODEC_MAX_AUDIO_FRAME_SIZE * 2 - read;

                 len1 = avcodec_decode_audio3(ctx->audio_codec_ctx, 
decoded_buf, &audio_buf_size, &packet);

                 if(len1 < 0) {
                     // if error, skip frame
                     break;
                 }
                 packet.data += len1;
                 packet.size -= len1;
                 decoded_buf += audio_buf_size;
                 read += audio_buf_size;
             }
         }
     }


I have tried to solve the problem for several days now but I could not 
come up with a solution. When i use the same code to play a local video 
file the video playback works just fine.

Any hints on a solution for the problem are appreciated.

Thanks
Thomas


More information about the Libav-user mailing list