我正在尝试创建应用程序,在其中我可以在录制过程中从设备上的不同摄像机录制视频。例如。用户从前置摄像头按下“开始录制”按钮,5 秒录制后用户按下“切换摄像头”按钮,应用程序将视频源从前置摄像头更改为后置摄像头并继续录制。对于相机切换,我使用下一个代码:
NSError *error;
AVCaptureDeviceInput *newVideoInput;
AVCaptureDevicePosition currentCameraPosition = [[videoInput device] position];
if (currentCameraPosition == AVCaptureDevicePositionBack)
{
currentCameraPosition = AVCaptureDevicePositionFront;
}
else
{
currentCameraPosition = AVCaptureDevicePositionBack;
}
AVCaptureDevice *backFacingCamera = nil;
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices)
{
if ([device position] == currentCameraPosition)
{
backFacingCamera = device;
}
}
newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:backFacingCamera error:&error];
if (newVideoInput != nil)
{
[_captureSession beginConfiguration];
[_captureSession removeInput:videoInput];
if ([_captureSession canAddInput:newVideoInput])
{
[_captureSession addInput:newVideoInput];
videoInput = newVideoInput;
}
else
{
[_captureSession addInput:videoInput];
}
//captureSession.sessionPreset = oriPreset;
[_captureSession commitConfiguration];
}
_inputCamera = backFacingCamera;
在此应用程序更改视频源并继续编写之后,但是...音频/视频不同步...有人可以解决这个问题吗?
谢谢你。