GPUImageMovieWriter-录制视频的两端偶尔出现黑帧 [英] GPUImageMovieWriter - occasional black frames at either ends of the recorded video

查看:74
本文介绍了GPUImageMovieWriter-录制视频的两端偶尔出现黑帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有录音应用程序实现,用户可以点击录音"按钮开始/停止录音.我可以使用基本的 GPUImageVideoCamera 来实现此目的,并将输出设置为 GPUImageView GPUImageMovieWriter .

50%的情况下,录制的剪辑的两端两端都有一对(或单个)黑框,有时是两个.该实现非常简单,但是无论如何都在这里.

  gpuImageView = [[GPUImageView分配] initWithFrame:cameraView.frame];gpuImageView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill;[cameraView addSubview:gpuImageView];videoCamera = [[GPUImageVideoCamera分配] initWithSessionPreset:AVCaptureSessionPresetHigh cameraPosition:(usingBackCamera)吗?AVCaptureDevicePositionBack:AVCaptureDevicePositionFront];[videoCamera addTarget:gpuImageView];[videoCamera addTarget:movieWriter];videoCamera.audioEncodingTarget = movieWriter;[videoCamera startCameraCapture];double delayToStartRecording = 0.5;dispatch_time_t startTime = dispatch_time(DISPATCH_TIME_NOW,delayToStartRecording * NSEC_PER_SEC);dispatch_after(startTime,dispatch_get_main_queue(),^(void){NSLog(@开始记录");[movieWriter startRecording];}); 

然后使用以下命令停止记录(而实时摄像机继续显示在 GPUImageView 上.

  [movieWriter finishRecording]; 

其他人有没有遇到过这种情况和/或找到了避免黑框的解决方案?我无法暂停/恢复相机拍摄,因此无法确保无缝的用户体验.

解决方案

通常,发生这种情况是因为队列在获取任何视频帧之前正在将音频写入文件.很难从实现中分辨出来,但是如果您确定要写入文件的第一件事是视频帧,并且在写入第一个视频帧之后才写入任何音频,那么您将不会有任何黑帧./p>

I have recording app implementation where user can tap the "record" button to start/stop recording. I achieve this with a basic GPUImageVideoCamera with output set to a GPUImageView as well as a GPUImageMovieWriter.

50% of the time, the recorded clip ends up with a couple (or a single) black frame at either ends, sometimes both. The implementation is fairly straightforward, but here is it anyway.

gpuImageView = [[GPUImageView alloc] initWithFrame:cameraView.frame];
gpuImageView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill;

[cameraView addSubview:gpuImageView];

videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPresetHigh cameraPosition:(usingBackCamera) ? AVCaptureDevicePositionBack : AVCaptureDevicePositionFront];

[videoCamera addTarget:gpuImageView];
[videoCamera addTarget:movieWriter];
videoCamera.audioEncodingTarget = movieWriter;
[videoCamera startCameraCapture];

double delayToStartRecording = 0.5;
dispatch_time_t startTime = dispatch_time(DISPATCH_TIME_NOW, delayToStartRecording * NSEC_PER_SEC);
        dispatch_after(startTime, dispatch_get_main_queue(), ^(void){
            NSLog(@"Start recording");
            [movieWriter startRecording];
        });

And then stop the recording with the following (while the live camera continues to show up on GPUImageView.

[movieWriter finishRecording];

Has anyone else experienced this and/or found a solution to avoid black frames? I cannot pause/resume camera capture so to ensure seamless user experience.

解决方案

Typically when this happens it's because the queue is writing audio to the file before it gets any video frames. Hard to tell from your implementation, but if you make sure the first thing you write to the file is a video frame and don't write any audio until after the first video frame is written, you won't have any black frames.

这篇关于GPUImageMovieWriter-录制视频的两端偶尔出现黑帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆