内容简介:Apple在ObjectiveC中有一个示例项目AVCam,可以处理这些事情.我个人使用这个
我设法编写一些打开相机并预览视频的代码.我现在想从输出中捕获帧,发送到理想编码为H.264的服务器
这就是我所得到的:
import UIKit import AVFoundation class ViewController: UIViewController { let captureSession = AVCaptureSession() var previewLayer : AVCaptureVideoPreviewLayer? // If we find a device we'll store it here for later use var captureDevice : AVCaptureDevice? override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. captureSession.sessionPreset = AVCaptureSessionPresetHigh let devices = AVCaptureDevice.devices() // Loop through all the capture devices on this phone for device in devices { // Make sure this particular device supports video if (device.hasMediaType(AVMediaTypeVideo)) { // Finally check the position and confirm we've got the back camera if(device.position == AVCaptureDevicePosition.Back) { captureDevice = device as? AVCaptureDevice if captureDevice != nil { println("Capture device found") beginSession() } } } } } func beginSession() { var err : NSError? = nil captureSession.addInput(AVCaptureDeviceInput(device: captureDevice, error: &err)) if err != nil { println("error: \(err?.localizedDescription)") } previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) self.view.layer.addSublayer(previewLayer) previewLayer?.frame = self.view.layer.frame captureSession.startRunning() } }
这可以成功打开相机,我可以预览镜头.
我发现这个Objective C代码看起来像得到输出,但是我不知道如何将它转换成swift.它使用AVCaptureVideoDataOutput,AVAssetWriter,AVAssetWriterInput和AVAssetWriterInputPixelBufferAdaptor将帧写入H.264编码的电影文件.
Can use AVCaptureVideoDataOutput and AVCaptureMovieFileOutput at the same time?
有人可以帮助您转换它,还是给我指点如何将框架从我当前的代码中取出?
Apple在ObjectiveC中有一个示例项目AVCam,可以处理这些事情.
Here’s 关于在Swift中使用AVCamera的另一个问题.
我个人使用这个 https://github.com/alex-chan/AVCamSwift ,没关系.我只需要将其转换为Xcode中的最新Swift语法,并且工作正常.
另一个建议是使用您发现的ObjectiveC代码并将其导入到Swift代码中,通过桥接头.
代码日志版权声明:
翻译自:http://stackoverflow.com/questions/26197992/get-output-from-avcapturesession-in-swift-to-send-to-server
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- awk 获取指定列的内容进行判断输出
- 在Android界面上显示和获取Logcat日志输出的方法
- php – 在命令中调用console命令,并在Symfony2中获取输出
- 2. Python中的基本输入、输出、格式化输出
- console 输出对象
- 多种格式数据输出
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Design systems
Not all design systems are equally effective. Some can generate coherent user experiences, others produce confusing patchwork designs. Some inspire teams to contribute to them, others are neglected. S......一起来看看 《Design systems》 这本书的介绍吧!