我有在Objective-C中运行时创建,配置和启动视频捕获会话的代码,没有任何问题。我移植样品C#和MonoTouch的4.0.3,并有几个问题,这里是代码:使用MonoTouch在iOS中捕获视频
void Initialize()
{
// Create notifier delegate class
captureVideoDelegate = new CaptureVideoDelegate(this);
// Create capture session
captureSession = new AVCaptureSession();
captureSession.SessionPreset = AVCaptureSession.Preset640x480;
// Create capture device
captureDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);
// Create capture device input
NSError error;
captureDeviceInput = new AVCaptureDeviceInput(captureDevice, out error);
captureSession.AddInput(captureDeviceInput);
// Create capture device output
captureVideoOutput = new AVCaptureVideoDataOutput();
captureSession.AddOutput(captureVideoOutput);
captureVideoOutput.VideoSettings.PixelFormat = CVPixelFormatType.CV32BGRA;
captureVideoOutput.MinFrameDuration = new CMTime(1, 30);
//
// ISSUE 1
// In the original Objective-C code I was creating a dispatch_queue_t object, passing it to
// setSampleBufferDelegate:queue message and worked, here I could not find an equivalent to
// the queue mechanism. Also not sure if the delegate should be used like this).
//
captureVideoOutput.SetSampleBufferDelegatequeue(captureVideoDelegate, ???????);
// Create preview layer
previewLayer = AVCaptureVideoPreviewLayer.FromSession(captureSession);
previewLayer.Orientation = AVCaptureVideoOrientation.LandscapeRight;
//
// ISSUE 2:
// Didn't find any VideoGravity related enumeration in MonoTouch (not sure if string will work)
//
previewLayer.VideoGravity = "AVLayerVideoGravityResizeAspectFill";
previewLayer.Frame = new RectangleF(0, 0, 1024, 768);
this.View.Layer.AddSublayer(previewLayer);
// Start capture session
captureSession.StartRunning();
}
#endregion
public class CaptureVideoDelegate : AVCaptureVideoDataOutputSampleBufferDelegate
{
private VirtualDeckViewController mainViewController;
public CaptureVideoDelegate(VirtualDeckViewController viewController)
{
mainViewController = viewController;
}
public override void DidOutputSampleBuffer (AVCaptureOutput captureOutput, CMSampleBuffer sampleBuffer, AVCaptureConnection connection)
{
// TODO: Implement - see: http://go-mono.com/docs/index.aspx?link=T%3aMonoTouch.Foundation.ModelAttribute
}
}
问题1: 不知道如何在SetSampleBufferDelegatequeue方法正确使用委托。还没有找到一个等效的机制dispatch_queue_t对象,在Objective-C中正常工作以传递第二个参数。
问题2: 我在MonoTouch库中找不到任何VideoGravity枚举,不知道传递一个具有常量值的字符串是否可行。
我有寻找任何线索来解决这个问题,但没有明确的样本。任何有关如何在MonoTouch中执行相同操作的示例或信息都将不胜感激。
非常感谢。
的在Init结尾的StartLiveDecoding函数并没有做太多的工作,只需调用 //启动视频捕捉 captureSession.StartRunning(); – 2011-05-10 17:22:30
谢谢,这意味着MonoTouch支持一种解决方案。问题#2的答案在那里,但仍不知道您的dispatchQueue是如何创建的。我猜avBufferDelegate是一个从委托类下降的类的实例。剩下的问题与dispatchQueue有关。非常感谢Pavel,缓冲区转换不成问题。 – 2011-05-10 21:53:37
托管创建捕获会话工作,其中一个问题是尝试使用SetSampleBufferDelegatequeue而不是SetSampleBufferDelegateAndQueue(不知道有什么区别)。但是现在我遇到了一个问题,预览中的图像会在几帧后冻结,但是如果我在DidOutputSampleBuffer中放置了断点,那么在该断点中停止执行时,预览图层中的图像会继续显示正常。我想它必须做我创建调度队列的方式。有关如何正确设置调度队列的任何线索?感谢任何帮助。 – 2011-05-11 13:16:01