<tfoot id='uN1M6'></tfoot>
    • <bdo id='uN1M6'></bdo><ul id='uN1M6'></ul>
      <legend id='uN1M6'><style id='uN1M6'><dir id='uN1M6'><q id='uN1M6'></q></dir></style></legend>
    1. <small id='uN1M6'></small><noframes id='uN1M6'>

        <i id='uN1M6'><tr id='uN1M6'><dt id='uN1M6'><q id='uN1M6'><span id='uN1M6'><b id='uN1M6'><form id='uN1M6'><ins id='uN1M6'></ins><ul id='uN1M6'></ul><sub id='uN1M6'></sub></form><legend id='uN1M6'></legend><bdo id='uN1M6'><pre id='uN1M6'><center id='uN1M6'></center></pre></bdo></b><th id='uN1M6'></th></span></q></dt></tr></i><div id='uN1M6'><tfoot id='uN1M6'></tfoot><dl id='uN1M6'><fieldset id='uN1M6'></fieldset></dl></div>

        使用 AVFoundation 框架 iPhone 录制视频?

        Video Recording using AVFoundation Framework iPhone?(使用 AVFoundation 框架 iPhone 录制视频?)

        1. <i id='CJJBO'><tr id='CJJBO'><dt id='CJJBO'><q id='CJJBO'><span id='CJJBO'><b id='CJJBO'><form id='CJJBO'><ins id='CJJBO'></ins><ul id='CJJBO'></ul><sub id='CJJBO'></sub></form><legend id='CJJBO'></legend><bdo id='CJJBO'><pre id='CJJBO'><center id='CJJBO'></center></pre></bdo></b><th id='CJJBO'></th></span></q></dt></tr></i><div id='CJJBO'><tfoot id='CJJBO'></tfoot><dl id='CJJBO'><fieldset id='CJJBO'></fieldset></dl></div>

              <bdo id='CJJBO'></bdo><ul id='CJJBO'></ul>

                <tbody id='CJJBO'></tbody>
            • <legend id='CJJBO'><style id='CJJBO'><dir id='CJJBO'><q id='CJJBO'></q></dir></style></legend>

              <small id='CJJBO'></small><noframes id='CJJBO'>

                  <tfoot id='CJJBO'></tfoot>
                  本文介绍了使用 AVFoundation 框架 iPhone 录制视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在借助 WWDC 2010 AVCamDemo 示例.在应用程序中,我需要从 iPhone 的前置摄像头录制视频,但由于我所在的地方没有新的 iPhone 4,我无法正确测试代码.

                  I'm developing an application with the help of sample code from the WWDC 2010 AVCamDemo example. In the app I need to record a video from the front camera of iPhone, but since the new iPhone 4 is not available at my place I am not able to test the code properly.

                  如果有人能提醒我我的方向是否正确,我将非常感激.当我设置 AVCaptureSession 时,我可以在 iPhone 3G(升级到 iOS 4.1)上测试的有限代码崩溃,如下面的代码所示:

                  I would be really thankful if someone can give me a heads up whether I'm going in the right direction or not. The limited code I could test on my iPhone 3G (upgraded to iOS 4.1) crashes when I set the AVCaptureSession, as shown in the code below:

                  - (void)recordVideo
                  {
                      NSLog(@"video recording on");
                  
                      AVCaptureDevice *videoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
                      AVCaptureDeviceInput *videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:videoCaptureDevice error:nil];  
                      AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
                  
                      [movieFileOutput release];
                  
                      AVCaptureSession *session = [[AVCaptureSession alloc] init];
                      [session addInput:videoInput];
                      [session addOutput:movieFileOutput];
                      [self setSession:session]; // crashes
                  
                      if (![session isRunning])
                      {
                          [self performSelector:@selector(startRecording) withObject:nil afterDelay:1.0];
                          [session startRunning];
                      }
                  }
                  
                  
                  - (void)startRecording
                  {
                  
                      AVCaptureConnection *videoConnection = [playVideo connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self movieFileOutput] connections]];
                  
                      if ([videoConnection isVideoOrientationSupported]) {
                          [videoConnection setVideoOrientation:[self orientation]]; 
                      }
                  
                      [[self movieFileOutput] startRecordingToOutputFileURL:[self tempFileURL]
                                                          recordingDelegate:self];
                  }
                  
                  
                  - (void) stopRecording
                  {
                      NSLog(@"stop recording");
                      [[self movieFileOutput] stopRecording];
                  }
                  
                  - (NSURL *) tempFileURL
                  {
                  
                      NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"output.mov"];
                      NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath];
                      NSFileManager *fileManager = [NSFileManager defaultManager];
                      if ([fileManager fileExistsAtPath:outputPath]) {
                          NSLog(@"file saved");
                      }
                      [outputPath release];
                      return [outputURL autorelease];
                  }
                  
                  + (AVCaptureConnection *)connectionWithMediaType:(NSString *)mediaType fromConnections:(NSArray *)connections;
                  {
                      for ( AVCaptureConnection *connection in connections ) {
                          for ( AVCaptureInputPort *port in [connection inputPorts] ) {
                              if ( [[port mediaType] isEqual:mediaType] ) {
                                  return [[connection retain] autorelease];
                              }
                          }
                      }
                      return nil;
                  }
                  
                  - (void)captureOutput:(AVCaptureFileOutput *)captureOutput
                  didStartRecordingToOutputFileAtURL:(NSURL *)fileURL
                                     fromConnections:(NSArray *)connections
                  {
                  
                  }
                  
                  - (void)captureOutput:(AVCaptureFileOutput *)captureOutput
                  didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
                                      fromConnections:(NSArray *)connections
                                                error:(NSError *)error
                  {
                      ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
                  
                      if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputFileURL])
                      {
                          [library writeVideoAtPathToSavedPhotosAlbum:outputFileURL
                                                      completionBlock:^(NSURL *assetURL, NSError *error)];
                      }
                  
                      [library release];       
                  }
                  

                  推荐答案

                  movieFileOutput 分配后立即释放.(第 9 行)

                  movieFileOutput is released immediately after it has been allocated. (line 9)

                  这篇关于使用 AVFoundation 框架 iPhone 录制视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  EAAccessory/EASession teardown during background(EAAccessory/EASession 在后台拆除)
                  Getting an NSArray of a single attribute from an NSArray(从 NSArray 获取单个属性的 NSArray)
                  ImageIO: lt;ERRORgt; JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?(ImageIO:lt;错误gt;JPEG 损坏的 JPEG 数据:iphone 数据段过早结束 - 如何捕捉到这个?)
                  Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                  MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)
                  How to add and get the values from .plist in iOS(如何在 iOS 中从 .plist 添加和获取值)

                  <legend id='pn9rU'><style id='pn9rU'><dir id='pn9rU'><q id='pn9rU'></q></dir></style></legend>
                    <i id='pn9rU'><tr id='pn9rU'><dt id='pn9rU'><q id='pn9rU'><span id='pn9rU'><b id='pn9rU'><form id='pn9rU'><ins id='pn9rU'></ins><ul id='pn9rU'></ul><sub id='pn9rU'></sub></form><legend id='pn9rU'></legend><bdo id='pn9rU'><pre id='pn9rU'><center id='pn9rU'></center></pre></bdo></b><th id='pn9rU'></th></span></q></dt></tr></i><div id='pn9rU'><tfoot id='pn9rU'></tfoot><dl id='pn9rU'><fieldset id='pn9rU'></fieldset></dl></div>
                        <tbody id='pn9rU'></tbody>
                        <bdo id='pn9rU'></bdo><ul id='pn9rU'></ul>
                          <tfoot id='pn9rU'></tfoot>

                          1. <small id='pn9rU'></small><noframes id='pn9rU'>