这似乎是因为,自从iOS 4.3发布以来,AudioQueue的AMR支持已经消失了。我不能用旧方法使用从RSTP服务器接收的音频帧:
audioFormat.mFormatID = kAudioFormatAMR;
int err = AudioQueueNewOutput(&audioFormat, MyAudioQueueOutputCallback, self, NULL, kCFRunLoopCommonModes, 0, &audioQueue);
结果,我在最后一个字符串中收到了一个错误。
也许有人知道如何将AMR AVPacket解码成原始缓冲区,并使用LIBAV使用AAC或MP3对其进行编码?
我试着用
avcodec_decode_audio3
它可以工作,我可以得到原始的缓冲区,但是当我尝试用
avcodec_encode_audio
我的结果是0
这是我对buffer进行编码的方法:
- (AVPacket) encodeRawFrame:(const short *) in_buffer withSize:(unsigned int) in_buf_byte_size
{
AVPacket res;
AVCodec *codec;
AVCodecContext *c= NULL;
int count, out_size, outbuf_size, frame_byte_size;
uint8_t *outbuf;
avcodec_init();
avcodec_register_all();
printf("Audio encoding\n");
codec = avcodec_find_encoder(CODEC_ID_AAC);
if (!codec) {
fprintf(stderr, "codec not found\n");
return res;
}
c= avcodec_alloc_context();
c->bit_rate = 64000;
c->sample_rate = 24000;
c->channels = 2;
if (avcodec_open(c, codec) < 0)
{
fprintf(stderr, "could not open codec\n");
}
else
{
frame_byte_size=c->frame_size*2*2;
count = in_buf_byte_size/frame_byte_size;
fprintf(stderr, "Number of frames: %d\n", count);
outbuf_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
outbuf = (uint8_t*) malloc(outbuf_size);
out_size = avcodec_encode_audio(c, outbuf, outbuf_size, &in_buffer[frame_byte_size*i]);
if(out_size >= 0)
{
res.size = outbuf_size;
res.data = malloc(outbuf_size);
}
free(outbuf);
}
avcodec_close(c);
av_free(c);
return res;
}
编码后,"out_size“始终为0,结果缓冲区为空。
谢谢。
发布于 2011-09-02 21:25:54
所以,我找到了所有的解决方案,现在我的媒体播放器类可以播放RTSP音频和视频了。我知道从AMR解码到AAC不是一个好主意,因为资源占用,最好播放原始缓冲区,你可以使用解码方法从AMR获得原始缓冲区。我有一个很好的示例(实际上,我必须做一些小的重构:)如何播放RTSP流,如果人们介意提供电子邮件:),我准备与他们分享它。另外,我有通用的二进制(armv6,armv7,i386)的LIBAV,AMR_NB和AAC编码器。
谢谢。
https://stackoverflow.com/questions/5650372
复制相似问题