![](/img/trans.png)
[英]How to stream and convert live video into mp-4. How to use FFMPEG?
[英]How to use AVCaptureSession to stream live preview video, then take a photo, then return to streaming
我有一個應用程序,在拍攝靜態照片之前創建自己的實時預覽。 應用程序需要對圖像數據運行一些處理,因此無法依賴AVCaptureVideoPreviewLayer。 使用Apple的示例代碼,使初始流工作進展順利。 當我嘗試切換到更高質量的圖像拍攝快照時出現問題。 響應按鈕按下,我嘗試重新配置會話以拍攝全分辨率照片。 我嘗試了很多變化,但這是我最新的例子(仍然不起作用):
- (void)sessionSetupForPhoto
{
[session beginConfiguration];
session.sessionPreset = AVCaptureSessionPresetPhoto;
AVCaptureStillImageOutput *output = [[[AVCaptureStillImageOutput alloc] init] autorelease];
for (AVCaptureOutput *output in [session outputs]) {
[session removeOutput:output];
}
if ([session canAddOutput:output]){
[session addOutput:output];
} else {
NSLog(@"Not able to add an AVCaptureStillImageOutput");
}
[session commitConfiguration];
}
我一直在commitConfiguration行之后收到一條錯誤消息,如下所示:(也就是說,我收到AVCaptureSessionRuntimeErrorNotification發送給我的注冊觀察者)
收到錯誤:NSConcreteNotification 0x19d870 {name = AVCaptureSessionRuntimeErrorNotification; object =; userInfo = {AVCaptureSessionErrorKey =“Error Domain = AVFoundationErrorDomain Code = -11800 \\”操作無法完成。 (AVFoundationErrorDomain錯誤-11800。)\\“UserInfo = 0x19d810 {}”;
XCode中的文檔表面上提供了有關錯誤編號(-11800)的更多信息,“AVErrorUnknown - 錯誤原因未知。”;
以前我也嘗試過調用stopRunning和startRunning,但是在觀看WWDC Session 409之后不再這樣做了,不鼓勵這樣做。 當我停止並開始時,我得到一個不同的錯誤消息-11819,它對應於“AVErrorMediaServicesWereReset - 操作無法完成,因為媒體服務變得不可用。”,這比簡單的“未知”要好得多,但不一定更有幫助。
它成功添加了AVCaptureStillImageOutput(即,不發出日志消息)。
我正在測試iPhone 3g(w / 4.1)和iPhone 4。
這個調用發生在主線程中,這也是我原來的AVCaptureSession設置發生的地方。
如何避免錯誤? 如何切換到更高的分辨率拍攝照片?
謝謝!
由於您正在處理來自AVCaptureSession的視頻數據,我假設您在調用sessionSetupForPhoto之前已將AVCaptureVideoDataOutput連接到它。
如果是這樣,你能詳細說明你在captureOutput中做了什么:didOutputSampleBuffer : ? 無法看到更多內容,我猜測刪除舊輸出並隨后設置照片質量預設可能存在問題。
此外,刪除輸出時用作迭代器的輸出變量隱藏靜止圖像輸出 。 不是問題,但它使代碼更難閱讀。
無需切換會話。 只需在初始化時將AVCaptureStillImageOutput
添加到會話中,並在要捕獲圖像時調用以下內容並相應地使用CMSampleBufferRef
:
captureStillImageAsynchronouslyFromConnection:videoConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error)
{
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.