我写了一个循环来使用扩展音频文件服务将我的应用程序生成的pcm音频数据编码到aac.编码同步地在后台线程中进行,而不是实时进行.
对于ios 4和i,ipad 1和iphone 3gs/4的编码完美无缺.然而,对于双核设备(iphone 4s,ipad 2),第三次调用ExtAudioFileWrite会使编码线程崩溃,没有堆栈跟踪,也没有错误代码.
这是有问题的代码:
数据格式
AudioStreamBasicDescription AUCanonicalASBD(Float64 sampleRate,
UInt32 channel){
AudioStreamBasicDescription audioFormat;
audioFormat.mSampleRate = sampleRate;
audioFormat.mFormatID = kAudioFormatLinearPCM;
audioFormat.mFormatFlags = kAudioFormatFlagsAudioUnitCanonical;
audioFormat.mChannelsPerFrame = channel;
audioFormat.mBytesPerPacket = sizeof(AudioUnitSampleType);
audioFormat.mBytesPerFrame = sizeof(AudioUnitSampleType);
audioFormat.mFramesPerPacket = 1;
audioFormat.mBitsPerChannel = 8 * sizeof(AudioUnitSampleType);
audioFormat.mReserved = 0;
return audioFormat;
}
AudioStreamBasicDescription MixdownAAC(void){
AudioStreamBasicDescription audioFormat;
audioFormat.mSampleRate = 44100.0;
audioFormat.mFormatID = kAudioFormatMPEG4AAC;
audioFormat.mFormatFlags = kMPEG4Object_AAC_Main;
audioFormat.mChannelsPerFrame = 2;
audioFormat.mBytesPerPacket = 0;
audioFormat.mBytesPerFrame = 0;
audioFormat.mFramesPerPacket = 1024;
audioFormat.mBitsPerChannel = 0;
audioFormat.mReserved = 0;
return …Run Code Online (Sandbox Code Playgroud) 当我设置视频格式MPEG-2(常数值8)TS和音频格式ACC(常数值3)时,它仅以ACC格式记录视频而没有音频.但它没有给出任何错误.我试过三星Galaxy Tab(Honeycomb).因为MPEG-2TS支持Android 3.0版以上版本.如果我使用默认的视频和音频格式,它可以正常工作.我怎样才能做到这一点.请帮忙.
if(mCamera == null) {
mCamera = Camera.open();
mCamera.unlock();
}
if(mMediaRecorder == null) mMediaRecorder = new MediaRecorder();
mMediaRecorder.setPreviewDisplay(surface);
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(8);
mMediaRecorder.setOutputFile("/mnt/sdcard/temp.ts");
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mMediaRecorder.setVideoSize(640, 480);
mMediaRecorder.setVideoEncodingBitRate(500000);
mMediaRecorder.setAudioEncodingBitRate(44100);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setMaxDuration(-1);
mMediaRecorder.prepare();
Run Code Online (Sandbox Code Playgroud) 我正在做一个应用程序,它从mediapicker获取歌曲并将其保存到我的应用程序.我想减小文件的大小,但我有一个名为"AACConverter"的样本,我测试应用程序,但它没有减少文件大小.任何人帮助我解决这个问题.
- (IBAction)convert:(id)sender {
if ( ![TPAACAudioConverter AACConverterAvailable] ) {
[[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Converting audio", @"")
message:NSLocalizedString(@"Couldn't convert audio: Not supported on this device", @"")
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"OK", @""), nil] autorelease] show];
return;
}
// Initialise audio session, and register an interruption listener, important for AAC conversion
if ( !checkResult(AudioSessionInitialize(NULL, NULL, interruptionListener, self), "initialise audio session") ) {
[[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Converting audio", @"")
message:NSLocalizedString(@"Couldn't initialise audio session!", @"")
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(@"OK", @""), nil] autorelease] show];
return;
}
// Set up an …Run Code Online (Sandbox Code Playgroud) 我有直接来自音频编码器的AAC-LC音频流.
它是一个原始流,没有ADTS标头,没有容器数据,因为我想在它到达时直接传输编码音频.(在文件保存之前).
我想确定输入编码的原始AAC流中的帧边界/帧长度/分组长度.(AAC具有可变的数据包长度.)
我可以搜索任何固定的帧头/模式,以便我可以确定帧边界吗?
AAC可以吗?
提前感谢您的宝贵意见.
我正在努力捕获并将音频流传输到RTMP服务器.我在MacOS下工作(在Xcode中),所以为了捕获音频样本缓冲区我使用AVFoundation-framework.但是对于编码和流媒体,我需要使用ffmpeg-API和libfaac编码器.因此输出格式必须是AAC(用于支持iOS设备上的流播放).
我遇到了这样的问题:音频捕获设备(在我的案例中是罗技相机)为我提供了512个LPCM样本的样本缓冲区,我可以选择16000,24000,36000或48000 Hz的输入采样率.当我将这512个样本提供给AAC编码器(配置为适当的采样率)时,我听到一个缓慢而抽搐的音频(在每帧之后看起来像是沉默的骰子).
我想通了(也许我错了),libfaac编码器只接受1024个样本的音频帧.当我将输入采样率设置为24000并在编码之前将输入采样缓冲区重采样为48000时,我获得1024个重采样样本.将这些1024个样本编码到AAC后,我听到输出声音正确.但是,当输出采样率必须为48000 Hz时,我的网络摄像头会在缓冲区中为任何输入采样率生成512个样本.所以我需要在任何情况下进行重采样,重新采样后我不会在缓冲区中获得1024个样本.
有没有办法在ffmpeg-API功能中解决这个问题?
我将不胜感激任何帮助.
PS:我想我可以累积重采样缓冲区,直到样本数变为1024,然后对其进行编码,但这是流,因此会产生时间戳和其他输入设备的麻烦,并且这种解决方案不合适.
当前问题出自[问题]中描述的问题:如何使用从CMSampleBufferRef(AVFoundation)获得的数据填充音频AVFrame(ffmpeg)?
这是一个带有音频编解码器配置的代码(还有视频流,但视频工作正常):
/*global variables*/
static AVFrame *aframe;
static AVFrame *frame;
AVOutputFormat *fmt;
AVFormatContext *oc;
AVStream *audio_st, *video_st;
Init ()
{
AVCodec *audio_codec, *video_codec;
int ret;
avcodec_register_all();
av_register_all();
avformat_network_init();
avformat_alloc_output_context2(&oc, NULL, "flv", filename);
fmt = oc->oformat;
oc->oformat->video_codec = AV_CODEC_ID_H264;
oc->oformat->audio_codec = AV_CODEC_ID_AAC;
video_st = NULL;
audio_st = NULL;
if (fmt->video_codec != AV_CODEC_ID_NONE)
{ //… /*init video codec*/}
if (fmt->audio_codec != AV_CODEC_ID_NONE) {
audio_codec= avcodec_find_encoder(fmt->audio_codec);
if (!(audio_codec)) {
fprintf(stderr, "Could …Run Code Online (Sandbox Code Playgroud) 我设法录制MP3用VLC 2.1.5上的MacOSX 10.9.2使用下面的命令:
./VLC -vvv qtsound://AppleHDAEngineInput:1B,0,1,0:1 --sout "#transcode{acodec=mp3,ab=128}:standard{access=file,mux=mp3,dst=~/Desktop/Recording.mp3}"
Run Code Online (Sandbox Code Playgroud)
但是我需要记录AAC音频,每次使用AAC设置时,文件都是203字节并且坏了,可能只有标头被写入.某些mux/filetype组合产生0字节文件或根本不产生任何文件.我使用了这个命令:
./VLC -vvv qtsound://AppleHDAEngineInput:1B,0,1,0:1 --sout "#transcode{acodec=mp4a,ab=128}:standard{access=file,mux=ts,dst=~/Desktop/Recording.mp4}"
Run Code Online (Sandbox Code Playgroud)
任何可以在终端上使用VLC工作和记录AAC音频的命令都将非常感激.谢谢!
更新:
我设法从这个命令开始:
./VLC -vvv qtsound://Internal\ microphone --sout "#transcode{acodec=mp4a,ab=128}:standard{access=file,mux=mp4,dst=~/Desktop/Recording.mp4}"
Run Code Online (Sandbox Code Playgroud)
但是当它试图编码它时告诉:
[aac @ 0x10309e000]编码器'aac'是实验性的,但实验编解码器未启用,如果要使用它,请添加'-strict -2'.[0x100469c30] avcodec编码器错误:无法打开编码器
所以看起来我应该添加它
-strict -2
修复它的命令的参数.不幸的是,此参数适用于ffmpeg,而VLC无法识别它.您是否知道如何为VLC启用实验性AAC编码器?
我在使用 FFmpeg 进行 acc 编码时遇到问题。我有 au mp4 文件和 aac 音频。我试图用 ffmpeg 复制音频。在源 mp4 文件中,第一个音频噪声出现在 0.30 秒处。使用 转换后ffmpeg -i inputfile.mp4 -c:a copy outputfile.aac,得到的文件是错误的,第一个音频噪音出现在 0.32 秒。文件的持续时间也不一样。
当我强制编码器使用 libfaac 时,它可以工作,但文件太大。
那么为什么在使用默认编码器 (aac, libfdk_aac) 时它不起作用?请注意,当我从大胆转换时会出现同样的事情。
非常感谢
我想在我的应用程序中实现SIP调用,我需要解决的第一个问题是将带有ADTS标头的压缩AAC格式的音频转换为线性PCM.
我的输入数据是具有不同帧大小的ADTS帧的NSArray.每个帧都是NSMutableData类型.每个帧具有相同的格式和采样率,唯一的区别是帧大小.
我尝试实现Igor Rotaru 为此问题建议的示例代码,但无法使其工作.
现在我的代码看起来像这样.首先,我配置AudioConverter:
- (void)configureAudioConverter {
AudioStreamBasicDescription inFormat;
memset(&inFormat, 0, sizeof(inFormat));
inputFormat.mBitsPerChannel = 0;
inputFormat.mBytesPerFrame = 0;
inputFormat.mBytesPerPacket = 0;
inputFormat.mChannelsPerFrame = 1;
inputFormat.mFormatFlags = kMPEG4Object_AAC_LC;
inputFormat.mFormatID = kAudioFormatMPEG4AAC;
inputFormat.mFramesPerPacket = 1024;
inputFormat.mReserved = 0;
inputFormat.mSampleRate = 22050;
AudioStreamBasicDescription outputFormat;
memset(&outputFormat, 0, sizeof(outputFormat));
outputFormat.mSampleRate = inputFormat.mSampleRate;
outputFormat.mFormatID = kAudioFormatLinearPCM;
outputFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
outputFormat.mBytesPerPacket = 2;
outputFormat.mFramesPerPacket = 1;
outputFormat.mBytesPerFrame = 2;
outputFormat.mChannelsPerFrame = 1;
outputFormat.mBitsPerChannel = 16;
outputFormat.mReserved = 0;
AudioClassDescription *description = [self
getAudioClassDescriptionWithType:kAudioFormatMPEG4AAC
fromManufacturer:kAppleSoftwareAudioCodecManufacturer]; …Run Code Online (Sandbox Code Playgroud) 这是为了尝试理解 aac 文件结构
为简单起见,我们可以假设 m4a 文件仅包含 aac 音频(即没有视频)
我正在比较 m4a 文件和使用 faac 库从 m4a 文件生成的 aac 文件
两个文件的字节级对比截图如下:
上半部分是m4a文件,下半部分是aac文件
对于第一帧,从下部开始,AAC ADTS 标头是,FF F9 4C 80 12 3F FC从这里和这里开始,实际的 aac 音频数据应该有 138 字节
从下半部分我们可以看到来自 的字节与上窗口中的数据块(绿色部分)相 DE匹配80
我假设我已经在 m4a 文件中找到了实际 aac 音频数据存储位置的偏移量。我虽然21 4C ...上面的窗口中的字节包含了下一帧 aac 音频的所有字节,如果我们看下面的窗口,我们确实可以看到... a3 80(下面的窗口中绿色部分的末尾)后面是另一个 ADTS 标头(FF F9 4C 80 12 1F FC,表示下一个 aac 帧中的音频数量应为 137 字节)
然而,从aac文件中读取的字节与预期的m4a文件中的字节不匹配,如下图所示:
它们匹配到某个点,但之后的一切看起来都是随机的。
m4a 文件和从它创建的相应 aac 文件在字节级别上有什么关系?
主要目标是能够修改这个 …