【问题标题】:Crash when trying to record 120fps video with MonoTouch / iPhone 5s尝试使用 MonoTouch / iPhone 5s 录制 120fps 视频时崩溃
【发布时间】:2013-12-17 23:05:30
【问题描述】:

我正在尝试在 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 位问题?有人有想法吗?

【问题讨论】:

    标签: c# ios iphone xamarin.ios avfoundation


    【解决方案1】:

    根据:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-08
      • 2019-08-13
      • 1970-01-01
      • 2014-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多