小编kal*_*los的帖子

此代码通过AVAssetWriter和AVAssetWriterInputs写入视频+音频不起作用.为什么?

我一直在尝试使用AVAssetWriter和AVAssetWriterInputs编写视频+音频.

我在这个论坛上看了很多人说他们能够做到这一点,但这对我不起作用.如果我只是写视频,那么代码就能很好地完成它的工作.当我添加音频时,输出文件已损坏且无法再现.

这是我的代码的一部分:

设置AVCaptureVideoDataOutput和AVCaptureAudioDataOutput:

NSError *error = nil;

// Setup the video input
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo];
// Create a device input with the device and add it to the session.
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
// Setup the video output
_videoOutput = [[AVCaptureVideoDataOutput alloc] init];
_videoOutput.alwaysDiscardsLateVideoFrames = NO;
_videoOutput.videoSettings =
[NSDictionary dictionaryWithObject:
[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];     

// Setup the audio input
AVCaptureDevice *audioDevice     = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeAudio];
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error ];     
// Setup the …
Run Code Online (Sandbox Code Playgroud)

iphone audio video avassetwriter

63
推荐指数
2
解决办法
4万
查看次数

标签 统计

audio ×1

avassetwriter ×1

iphone ×1

video ×1