尝试使用MonoTouch / iPhone 5s录制120fps视频时崩溃

时间:2013-12-02 09:34:37

标签: c# ios iphone xamarin.ios avfoundation

我正试图在MonoTouch中实现以高帧率录制视频的能力(自iOS 7起可用)。在Apple文档之后,我们列举了可用的视频格式:

 AV.AVCaptureDeviceFormat highSpeedFormat = null;
 m_captureSession.BeginConfiguration();

 double requestedFrameRate = 120;

   for (int i = 0; i < avVideoCaptureDevice.Formats.Length; i++)
   {
     AV.AVCaptureDeviceFormat format = avVideoCaptureDevice.Formats[i];
     CM.CMFormatDescription fd = format.FormatDescription;
     Media.Logger.Log(string.Format("format = {0}", format));
     Media.Logger.Log(string.Format("dim = {0}x{1}", fd.VideoDimensions.Width, fd.VideoDimensions.Height));

     for (int j = 0; j < format.VideoSupportedFrameRateRanges.Length; j++)
     {
       AV.AVFrameRateRange range = format.VideoSupportedFrameRateRanges[j];
       Media.Logger.Log(string.Format("   range: {0}", range));

       if (System.Math.Abs(requestedFrameRate - range.MaxFrameRate) <= 1.0 && fd.VideoDimensions.Width == 1280)
       {
         Media.Logger.Log(">>>> found a matching format");
         highSpeedFormat = format;
       }
     }
   }

一旦我们找到了所需的高帧速率格式,我们将其设置为视频捕获设备,如下所示:

 if (highSpeedFormat != null)   
 {   
  NS.NSError error;  
  avVideoCaptureDevice.LockForConfiguration(out error);  
  avVideoCaptureDevice.ActiveFormat = highSpeedFormat;   
  CM.CMTime frameDuration = new CM.CMTime(1,requestedFrameRate);  
  avVideoCaptureDevice.ActiveVideoMaxFrameDuration = frameDuration;  
  avVideoCaptureDevice.UnlockForConfiguration();   
 }

此代码在iPhone 5上运行正常,我们可以在此设备上录制60fps视频。但是,在iPhone 5S上,它大部分时间都在以下行崩溃:

avVideoCaptureDevice.ActiveFormat = highSpeedFormat;

堆栈追踪:

0   libsystem_kernel.dylib          0x39ea41fc __pthread_kill + 8
1   libsystem_pthread.dylib         0x39f0ba4f pthread_kill + 55
2   libsystem_c.dylib               0x39e55029 abort + 73
3   EasyCaptureMonoTouch            0x0161ff8d 0x27000 + 23039885
4   EasyCaptureMonoTouch            0x0162a9fd 0x27000 + 23083517
5   libsystem_platform.dylib        0x39f06721 _sigtramp + 41
6   CoreFoundation                  0x2f4c4b9b CFEqual + 231
7   CoreMedia                       0x2fae1a07 CMFormatDescriptionEqual + 23
8   AVFoundation                    0x2e4d7b6d -[AVCaptureDeviceFormat isEqual:] + 105
9   CoreFoundation                  0x2f4cf9ef -[NSArray containsObject:] + 163
10  AVFoundation                    0x2e48d69f -[AVCaptureFigVideoDevice setActiveFormat:] + 143

有时,崩溃发生在稍后的类似堆栈跟踪(在录制期间,setActiveFormat也被称为):

0   libsystem_kernel.dylib 0x39a641fc __pthread_kill + 8
1   libsystem_pthread.dylib 0x39acba4f pthread_kill + 55
2   libsystem_c.dylib 0x39a15029 abort + 73
3   EasyCaptureMonoTouch 0x017a5685 0xec000 + 23828101
4   EasyCaptureMonoTouch 0x017b00f5 0xec000 + 23871733
5   libsystem_platform.dylib 0x39ac6721 _sigtramp + 41
6   libobjc.A.dylib 0x394b59d7 realizeClass(objc_class*) + 219
7   libobjc.A.dylib 0x394b59d7 realizeClass(objc_class*) + 219
8   libobjc.A.dylib 0x394b7793 lookUpImpOrForward + 71
9   libobjc.A.dylib 0x394b0027 _class_lookupMethodAndLoadCache3 + 31
10  libobjc.A.dylib 0x394afdf7 _objc_msgSend_uncached + 23
11  CoreFoundation 0x2f084b9b CFEqual + 231
12  CoreMedia 0x2f6a1a07 CMFormatDescriptionEqual + 23
13  AVFoundation 0x2e097b6d -[AVCaptureDeviceFormat isEqual:] + 105
14  CoreFoundation 0x2f08f9ef -[NSArray containsObject:] + 163
15  AVFoundation  0x2e04d69f -[AVCaptureFigVideoDevice setActiveFormat:] + 143
16  Foundation 0x2faa5149 _NSSetObjectValueAndNotify + 93
17  AVFoundation 0x2e04d2ef -[AVCaptureFigVideoDevice _setActiveFormatAndFrameRatesForResolvedOptions:sendingFrameRatesToFig:] + 91
18  AVFoundation 0x2e06245d -[AVCaptureSession _buildAndRunGraph] + 365
19  AVFoundation  0x2e05c23b -[AVCaptureSession addInput:] + 899

我们怀疑MonoTouch绑定中的实现错误,或者是错误配置/ 64位问题?有人有想法吗?

1 个答案:

答案 0 :(得分:0)

根据:

http://forums.xamarin.com/discussion/10864/crash-when-trying-to-record-120fps-video-with-monotouch-iphone-5s#latest

这是Xamarin.iOS中的一个错误,它将被修复(它们没有正确保留CMFormatDescription)。