简体   繁体   English

iOS录制视频第一帧是黑色的

[英]iOS record video first frame is black

I'm made a record video app, but the first frame always be black.我制作了一个录制视频应用程序,但第一帧总是黑色的。

I use:我用:

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection 

and assetWriter to write sample buffer.和 assetWriter 写入样本缓冲区。

I found that the first sample buffer is mediaType:'soun', does it is the problem.我发现第一个示例缓冲区是mediaType:'soun',是不是有问题。

How should I do我该怎么办

I had the same problem.我有同样的问题。 And I think first sample buffer being "sound" should be the problem.我认为第一个样本缓冲区是“声音”应该是问题所在。 What I tried to do is to ignore the first sample buffer if it's sound.我试图做的是忽略第一个样本缓冲区,如果它是合理的。 Wait until the first "video" sample buffer comes in and then do the AVAssetWriter startWriting thing.等到第一个“视频”样本缓冲区进来,然后执行 AVAssetWriter startWriting 操作。 I solved my problem by doing this.我通过这样做解决了我的问题。

Thanks for the reply @ethanchli, it helped me, so I decided to add some details.感谢@ethanchli 的回复,它帮助了我,所以我决定添加一些细节。

First, try uninstalling the AVCaptureAudioDataOutputSampleBufferDelegate extension if you are not using it, because it runs the same function with AVCaptureVideoDataOutputSampleBufferDelegate extension.首先,如果您不使用 AVCaptureAudioDataOutputSampleBufferDelegate 扩展,请尝试卸载它,因为它运行与 AVCaptureVideoDataOutputSampleBufferDelegate 扩展相同的功能。

func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection){}

Or if you need audioSamleBoofer :)或者,如果您需要 audioSamleBoofer :)

Try this - Check orientation support which exist only in video connection.试试这个 - 检查仅存在于视频连接中的方向支持。

    if connection.isVideoOrientationSupported {
        // Work with video samle boofer
    } else {
        // Work with audio sample boofer audio
    }
    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM