我从rtmp中解码出了音频流,怎么用audioqueue播放呢

lttzwz 2013-08-28 10:31:12
PCM实时音频流怎样播放?
我现在有ffmpeg解码出来的pcm实时音频数据,但是不知道应该怎样播放,请教一下怎么用audioqueue播实时音频流呢?想把ffmpeg解码出来的PCM包直接扔给AudioQueue进行播放

int VoiceErrorCode = 0;
av_register_all(); //注册所有可解码类型
AVFormatContext *pInFmtCtx=NULL; //文件格式
AVCodecContext *pInCodecCtx=NULL; //编码格式
if (av_open_input_file(&pInFmtCtx, [voicePath cStringUsingEncoding:NSASCIIStringEncoding], NULL, 0, NULL)!=0) //获取文件格式
printf("av_open_input_file error\n");
if (av_find_stream_info(pInFmtCtx) < 0) //获取文件内音视频流的信息
printf("av_find_stream_info error\n");
unsigned int j;
// Find the first audio stream
int audioStream = -1;
for (j=0; j<pInFmtCtx->nb_streams; j++) //找到音频对应的stream
{
if (pInFmtCtx->streams[j]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
{
audioStream = j;
break;
}
}
if (audioStream == -1)
{
printf("input file has no audio stream\n");
return VoiceErrorCode; // Didn't find a audio stream
}

printf("audio stream num: %d\n",audioStream);
pInCodecCtx = pInFmtCtx->streams[audioStream]->codec; //音频的编码上下文
AVCodec *pInCodec = NULL;

pInCodec = avcodec_find_decoder(pInCodecCtx->codec_id); //根据编码ID找到用于解码的结构体
if (pInCodec == NULL)
{
printf("error no Codec found\n");
VoiceErrorCode =-1 ; // Codec not found
}

if(avcodec_open(pInCodecCtx, pInCodec)<0)//将两者结合以便在下面的解码函数中调用pInCodec中的对应解码函数
{
printf("error avcodec_open failed.\n");
VoiceErrorCode= -1; // Could not open codec
}
static AVPacket Packet;
printf(" bit_rate = %d \r\n", pInCodecCtx->bit_rate);
printf(" sample_rate = %d \r\n", pInCodecCtx->sample_rate);
printf(" channels = %d \r\n", pInCodecCtx->channels);
printf(" code_name = %s \r\n", pInCodecCtx->codec->name);
printf(" block_align = %d\n",pInCodecCtx->block_align);
...全文
488 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lam_Co 2015-11-09
  • 打赏
  • 举报
回复
AudioQueueEnqueueBuffer 推进缓冲区
lhx546920268 2013-09-25
  • 打赏
  • 举报
回复
请问怎么把数据填入缓冲区,函数AudioFileReadPackets 只能从文件中把数据读入缓冲区,有没有其他方法把data 填入 audioQueueBuffer
程序尸 2013-09-09
  • 打赏
  • 举报
回复
学习中,期待指导,,
bluesky_03 2013-09-06
  • 打赏
  • 举报
回复
创建缓冲区并绑定给audioqueue,使用start/pause等函数控制播放。主要的工作应该是围绕缓冲区展开,比如填充数据,计算缓冲进度,等待填充等。从解码到播放,这里面有一套交互逻辑要写(比如解码一帧后通知播放器,播放器填充缓冲区,决定是否start等)。 解码到的pcm,如果放在内存,要考虑到如果解码线程一直在跑而播放可能暂停了,那pcm数据会占很大的内存,需要控制。如果pcm数据写到文件,会方便控制,只是在运行时占用的磁盘空间大一点(启动程序时,可以先删除掉文件)。
lttzwz 2013-09-04
  • 打赏
  • 举报
回复
期待指导,,,
lttzwz 2013-08-28
  • 打赏
  • 举报
回复
[voicePath cStringUsingEncoding:NSASCIIStringEncoding]是rtmp得地址 打印出来得信息是 bit_rate = 48000 sample_rate = 22050 channels = 1 code_name = mp3 block_align = 0

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧