Ios 将VTCompressionSession中的压缩帧与音频数据混合到MPEG2-TS容器中,以进行网络流传输
我正在从事一个项目,该项目涉及从iOS8中的VTCompressionSession中获取H.264编码的帧,将它们与来自麦克风的实时AAC或PCM音频混合到一个可播放的MPEG2-TS中,并以最小的延迟(即:(几乎)无缓冲)通过套接字实时传输 在观看了iOS8中新VideoToolbox的演示并进行了一些研究之后,我想可以安全地假设:Ios 将VTCompressionSession中的压缩帧与音频数据混合到MPEG2-TS容器中,以进行网络流传输,ios,audio,video-streaming,h.264,muxer,Ios,Audio,Video Streaming,H.264,Muxer,我正在从事一个项目,该项目涉及从iOS8中的VTCompressionSession中获取H.264编码的帧,将它们与来自麦克风的实时AAC或PCM音频混合到一个可播放的MPEG2-TS中,并以最小的延迟(即:(几乎)无缓冲)通过套接字实时传输 在观看了iOS8中新VideoToolbox的演示并进行了一些研究之后,我想可以安全地假设: 您从VTCompressionSession获得的编码帧不是附录B格式,因此我需要以某种方式对其进行转换(到目前为止我看到的所有解释都太模糊,因此我不确定如何
- 您从VTCompressionSession获得的编码帧不是附录B格式,因此我需要以某种方式对其进行转换(到目前为止我看到的所有解释都太模糊,因此我不确定如何进行转换(即:将“3或4字节头替换为长度头”))
- 从VTCompressionSession获得的编码帧实际上是一个基本流。因此,首先我需要将它们转换为打包的基本流,然后才能对其进行多路复用
- 我还需要来自麦克风数据的AAC或PCM基本流(我认为PCM会更容易,因为不涉及编码)。我也不知道怎么做
- 为了多路复用打包的基本流,我还需要一些库,比如libmpegts。或者ffmpeg(通过使用libavcodec和libavformat库)
AVCaptureDevice *microphone = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
_audioInput = [AVCaptureDeviceInput deviceInputWithDevice:microphone error:&error];
if (_audioInput == nil) {
NSLog(@"Couldn't open microphone %@: %@", microphone, error);
return NO;
}
_audioProcessingQueue = dispatch_queue_create("audio processing queue", DISPATCH_QUEUE_SERIAL);
_audioOutput = [[AVCaptureAudioDataOutput alloc] init];
[_audioOutput setSampleBufferDelegate:self queue:_audioProcessingQueue];
NSDictionary *audioOutputSettings = @{
AVFormatIDKey: @(kAudioFormatMPEG4AAC),
AVNumberOfChannelsKey: @(1),
AVSampleRateKey: @(44100.),
AVEncoderBitRateKey: @(64000),
};
_audioWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio outputSettings:audioOutputSettings];
_audioWriterInput.expectsMediaDataInRealTime = YES;
if(![_writer canAddInput:_audioWriterInput]) {
NSLog(@"Couldn't add audio input to writer");
return NO;
}
[_writer addInput:_audioWriterInput];
[_captureSession addInput:_audioInput];
[_captureSession addOutput:_audioOutput];
- (void)audioCapture:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
/// sampleBuffer contains encoded aac samples.
}
我猜你已经在为你的相机使用AVCaptureSession了;您可以对麦克风使用相同的捕获会话。您确定来自捕获会话的样本缓冲区已进行AAC编码吗?我看到您正在使用压缩设置设置AVAssetWriterInput,但它似乎没有连接到任何东西。。。据我所知,音频输出只会向学员提供未压缩的音频样本,不是吗?是的,我确认我可以从AVAssetWriterInput获取AAC样本(我之所以如此确定,是因为我花了两天时间包装音频转换器,就在我完成时,我注意到我可以更改输出设置,它会给我AAC。不过,这个答案中的代码与该项目中的代码不完全相同;不记得使其工作的确切配置)。@RodrigoSieiro啊,我可能使用了-[AVCaptureAudioDataOutput audioSettings],仅在Mac OS上可用:(我现在正在iOS上手动使用AudioConverter,不确定是否有更简单的方法。