我必须将视频从 iPhone 实时发送到服务器。我创建捕获会话并使用 AVCaptureMovieFileOutput。
NSError *error = nil;
captureSession = [[AVCaptureSession alloc] init];
// find, attach devices
AVCaptureDevice *muxedDevice = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeMuxed];
if (muxedDevice) {
NSLog (@"got muxedDevice");
AVCaptureDeviceInput *muxedInput = [AVCaptureDeviceInput deviceInputWithDevice:muxedDevice
error:&error];
if (muxedInput) {
[captureSession addInput:muxedInput];
}
} else {
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo];
if (videoDevice) {
NSLog (@"got videoDevice");
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice
error:&error];
if (videoInput) {
[captureSession addInput: videoInput];
}
}
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeAudio];
if (audioDevice) {
NSLog (@"got audioDevice");
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice
error:&error];
if (audioInput) {
[captureSession addInput: audioInput];
}
}
}
// create a preview layer from the session and add it to UI
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
previewLayer.frame = view.layer.bounds;
previewLayer.videoGravity = AVLayerVideoGravityResizeAspect;
previewLayer.orientation = AVCaptureVideoOrientationPortrait;
[view.layer addSublayer:previewLayer];
// create capture file output
captureMovieOutput = [[AVCaptureMovieFileOutput alloc] init];
if (! captureMovieURL) {
captureMoviePath = [[self getMoviePathWithName:MOVIE_FILE_NAME] retain];
captureMovieURL = [[NSURL alloc] initFileURLWithPath:captureMoviePath];
}
NSLog (@"recording to %@", captureMovieURL);
[captureSession addOutput:captureMovieOutput];
使用ffmpeg对元数据进行编码,可能比AVAssetExportSession更好。但是ffmpeg编码比AVAssetExportSession困难得多;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)