gpt4 book ai didi

iPhone ffmpeg 开发人员使用 libav 将 AMR 解码为 ACC 编解码器

转载 作者:行者123 更新时间:2023-12-04 22:51:18 25 4
gpt4 key购买 nike

似乎是,自从 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,结果缓冲区为空。

谢谢。

最佳答案

所以,我找到了所有解决方案,现在我的媒体播放器类可以播放 RTSP 音频和视频。我知道使用从 AMR 到 AAC 的解码不是一个好主意,因为资源使用情况,最好播放 RAW 缓冲区,您可以使用允许从 AMR 获取 RAW 缓冲区的解码方式获得。我有一个很好的示例(实际上,我必须进行小的重构:))如何播放 RTSP 流,如果他们介意提供电子邮件,我准备与 ppl 分享它:)。另外,我有 LIBAV、AMR_NB 和 AAC 编码器的通用二进制(armv6、armv7、i386)。

谢谢。

关于iPhone ffmpeg 开发人员使用 libav 将 AMR 解码为 ACC 编解码器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5650372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com