【发布时间】:2011-04-13 13:48:59
【问题描述】:
似乎是,自从 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 作为结果
这是我对缓冲区进行编码的方法:
- (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,结果缓冲区为空。
谢谢。
【问题讨论】: