bhu*_*uga 5 avfoundation avcapturesession
我正在尝试构建一些可以在 Mac 上实时捕获视频源并写出预先分段的 mp4 块的东西。它适用于某些相机,但不适用于其他相机。
设置如下。
一个AVCaptureVideoDataOutput有一个AVCaptureVideoDataOutputSampleBufferDelegate。
dispatch_queue_t sampleQueue = dispatch_queue_create("samples", NULL);
[videoOutput setSampleBufferDelegate: delegate queue: sampleQueue];
Run Code Online (Sandbox Code Playgroud)
输出还涉及AVCaptureSession保存到文件并显示预览,并且一切正常。
在委托中,我有一个AVAssetWriterInput. 它是这样设置的:
NSDictionary
*videoFormat = [NSDictionary dictionaryWithObjectsAndKeys:
// Format options
AVVideoCodecH264, AVVideoCodecKey,// h264
[NSNumber numberWithInt: width], AVVideoWidthKey,
[NSNumber numberWithInt: height], AVVideoHeightKey,
// Encoder options
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: theQuality*1024], AVVideoAverageBitRateKey,// 256kbps
[NSNumber numberWithInt: 30], AVVideoMaxKeyFrameIntervalKey,// write at least one keyframe every 30 frames
nil], AVVideoCompressionPropertiesKey,
nil],
video = [[AVAssetWriterInput assetWriterInputWithMediaType: AVMediaTypeVideo outputSettings: videoFormat] retain];
[video setExpectsMediaDataInRealTime: YES];
Run Code Online (Sandbox Code Playgroud)
有一种方法可以使用此委托写入文件:
writer = [[AVAssetWriter assetWriterWithURL: url fileType: AVFileTypeMPEG4 error: &error] retain];
[writer setShouldOptimizeForNetworkUse: YES];
[writer addInput: video];
Run Code Online (Sandbox Code Playgroud)
现在在captureData委托的回调方法中,我在其中处理采样数据的缓冲区,我这样做:
if([video isReadyForMoreMediaData])
[video appendSampleBuffer: sampleBuffer];
Run Code Online (Sandbox Code Playgroud)
伟大的!这适用于我的 facetime 相机。现在我插入 BlackMagic Intensity 并使用它。
在这一行:
[video appendSampleBuffer: sampleBuffer];
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
*** -[AVAssetWriterInput appendSampleBuffer:] Input buffer must be in an uncompressed format when outputSettings is not nil
Run Code Online (Sandbox Code Playgroud)
我玩过videoOutput设置,无济于事。文档似乎提到这是无法压缩的东西。像:
// not all at the same time, of course.
videoOutput.videoSettings = nil;
videoOutput.videoSettings = [NSDictionary dictionaryWithObject:@"avc1" forKey:AVVideoCodecKey];
Run Code Online (Sandbox Code Playgroud)
最好的部分是,如果我禁用输出中的所有编码内容,它会告诉我不支持传递编码。甜的。
幸运的是,谷歌搜索此错误消息会导致零命中。如果有人能在这里指出我的解决方案,我很想知道我做错了什么。
| 归档时间: |
|
| 查看次数: |
2076 次 |
| 最近记录: |