2
似乎是,自iOS 4.3发布以来,AudioQueue的AMR支持已经消失。我不能使用从旧的方式从RSTP服务器接收到的音频帧:iPhone ffmpeg开发使用libav从AMR解码到ACC编解码器
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,结果缓冲区为空。
谢谢。
我想玩mms流。已成功编译libMMS和ffmpeg到我的项目中。但我不知道如何从缓冲区转换为iPhone播放的mp3或arc格式。你能否提供示例代码将wma转换为其他格式? – 2011-09-26 16:37:18
实际上,我使用相机流并将AMR格式转换为RAW缓冲区,然后将其播放为WAV格式。它工作得很好。 iPhone支持AAC没有任何问题。我不确定是否可以将文件附加到我的回复中,因为在之前的文章中,我将LIBAV二进制文件链接到我的Dropbox,版主删除了它。如果您可以提供您的电子邮件地址,那么我可以向您发送我的播放器课程来进行调查。 – VictorT 2011-09-27 15:37:51