Decoding AAC Audio Stream

Examples and samples for those who develop software with FFmpeg.
Post Reply
cesareof
Posts: 5
Joined: Wed Dec 28, 2011 10:10 pm

Decoding AAC Audio Stream

Post by cesareof » Tue Jan 17, 2017 10:39 pm

Trying to connect an RTMP stream and read audio from it and work with the audio obtained. And I am struggling. I am able to do this with video without a problem, grabbing and converting each video frame to mjpeg but audio is not working:

This is the basic function, read a frame, decode frame and do something with the resulting audio:

Code: Select all

..
..
while( av_read_frame( stream->pFormatCtx, &packet) >= 0 )
{
        if(packet.stream_index==nAudioStream)	
	{
		int frameFinished=0;
		int nResult = avcodec_send_packet(pIn_AudioCodecCtx, &packet);
		if( nResult == 0 )
			nResult = avcodec_receive_frame( pIn_AudioCodecCtx, pFrame );
		if( nResult == 0 )
		{
			int nRet = 0;
			FILE *fOut;
			if( fopen_s( &fOut, "..\\testout2.pcm", "a+" ) == 0 )
			{
			         int data_size = av_samples_get_buffer_size(NULL, pIn_AudioCodecCtx->channels, pFrame->nb_samples, pIn_AudioCodecCtx->sample_fmt, 1);
				fwrite( pFrame->data[i], 1, data_size, fOut);
				fclose(fOut);
			}
                }
        }
}
I am able to read frames, and decode frames okay, not sure how to handle the resulting decoded frame though. In the code example I have put here I am just trying to store it as a raw audio, but I have tried encoding the resulting frame to MP3 with no success. This is a live stream that has no definite end, it basically reads until it hits EOF.

Any help pointing me in the right direction would be greatly appreciated.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest