我正在使用 AVFoundation 录制视频并将其发送到服务器。每当服务器使用我录制的视频时,它都会返回内部服务器错误。但是当我上传一些不是我录制的虚拟视频时,它上传成功。添加下面的代码。
let documentsPath = NSURL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])
let logsPath = documentsPath.appendingPathComponent(GlobalVar.interVCode)
if !FileManager.default.fileExists(atPath: (logsPath?.absoluteString)!){
do {
try FileManager.default.createDirectory(at: logsPath!, withIntermediateDirectories: true, attributes: nil)
} catch let error as NSError {
NSLog("Unable to create directory \(error.debugDescription)")
}
}
let outputURL: URL = (self.applicationDocumentsDirectory().appendingPathComponent(GlobalVar.interVCode)?.appendingPathComponent("\(questionId)").appendingPathExtension("mp4"))!
self.camera.startRecording(withOutputUrl: outputURL, didRecord:
{(camera, outputURL, error) in
})
使用自定义相机控制器 LLSimpleCamera 开始录制。下面是开始录制的代码。
- (void)startRecordingWithOutputUrl:(NSURL *)url didRecord:(void (^)(LLSimpleCamera *camera, NSURL *outputFileUrl, NSError *error))completionBlock
{
// check if video is enabled
if(!self.videoEnabled) {
NSError *error = [NSError errorWithDomain:LLSimpleCameraErrorDomain
code:LLSimpleCameraErrorCodeVideoNotEnabled
userInfo:nil];
[self passError:error];
return;
}
if(self.flash == LLCameraFlashOn) {
[self enableTorch:YES];
}
// set video orientation
for(AVCaptureConnection *connection in [self.movieFileOutput connections]) {
for (AVCaptureInputPort *port in [connection inputPorts]) {
// get only the video media types
if ([[port mediaType] isEqual:AVMediaTypeVideo]) {
if ([connection isVideoOrientationSupported]) {
[connection setVideoOrientation:[self orientationForConnection]];
}
}
}
}
self.didRecordCompletionBlock = completionBlock;
[self.movieFileOutput startRecordingToOutputFileURL:url recordingDelegate:self];
}
非常感谢帮助。