[Ffmpeg-devel] how to decode RTP packet containing mp3 data
sanjay kumar gupta
Wed Feb 21 18:26:08 CET 2007
Helix server in LAN is streaming mp3 file and I am receiving the RTP packets.
I would like to decode this RTP packets data and get the decoded buffer and its length so that I can play this decoded data using SDL library.
I have a program which plays mp3 locally. To play mp3 file locally, I needed format context and codec context pointers. Piece of code used to decode the local audio file is given below.
But in case of RTP packet containing mp3 data.
how to get the pFormatCtx. can we get the stream info as with local file as it is needed to get the pCodecCtx which in turn used to get the codec id.
Any example code or document would be helpful.
Thanks in advance for help.
// Register all formats and codecs
// Open video file
if(av_open_input_file(&pFormatCtx, argv/*mp3 file name*/, NULL, 0, NULL)!=0)
return -1; // Couldn't open file
// Retrieve stream information
return -1; // Couldn't find stream information
// Find the first video stream
for(i=0; i<pFormatCtx->nb_streams; i++)
if(audioStream == -1)
return -1; // Didn't find a video/audio stream
// Get a pointer to the codec context for the video stream
// Find the decoder for the video stream
return -1; // Codec not found
// Open codec
return -1; // Could not open codec
while(av_read_frame(pFormatCtx, &packet)>= 0 )
// Is this a packet from the audio stream?
// Decode audio frame
len=avcodec_decode_audio(pCodecCtx, outBuf, &outBufSize, packet.data, packet.size);
if (len < 0)
printf("Error while decoding\n");
//send this decoded audio to SDL.
// Free the packet that was allocated by av_read_frame
Thanks & Regards,
More information about the ffmpeg-devel