想要获取我拍摄的视频

时间:2012-11-01 15:21:29

标签: iphone ios avfoundation

我使用AVFoundation创建了一个相机,现在我想要我的视频回来,所以我可以将它上传到我的服务器上,我该怎么做?

我正在使用MKNetworkKit在服务器上上传视频。

我得到这样的输出:

file://localhost/private/var/mobile/Applications/4B2E02E5-3EE2-493E-8ECF-4B1DA29B9387/tmp/output.mov

1 个答案:

答案 0 :(得分:1)

我已经通过一些帮助找到了它的代码。

- (void)              captureOutput:(AVCaptureFileOutput *)captureOutput
didFinishRecordingToOutputFileAtURL:(NSURL *)anOutputFileURL
                    fromConnections:(NSArray *)connections
                              error:(NSError *)error
{

   videodata = [NSData dataWithContentsOfURL:outputFileURL];

   //NSLog(@"output file url is :%@",anOutputFileURL);

    NSLog(@"output video data size is:%d", videodata.length);




    if ([[self delegate] respondsToSelector:@selector(recorder:recordingDidFinishToOutputFileURL:error:)]) {
        [[self delegate] recorder:self recordingDidFinishToOutputFileURL:anOutputFileURL error:error];
    }

    //NSLog(@"captureOutput is: %@",captureOutput);
    // NSLog(@"anOutputFileURL is: %@",anOutputFileURL);


    //videoPath = [NSString stringWithContentsOfURL:anOutputFileURL encoding:NSUTF8StringEncoding error:nil];



    //videoPath = [anOutputFileURL absoluteString];

    //videoURL = anOutputFileURL;
   // videodata = captureOutput;
   // NSLog(@"video path is: %@",videodata);


    UIAlertView *message = [[UIAlertView alloc] initWithTitle:nil
                                                       message:@"Do you want to upload this content to the yes stream network ?"
                                                      delegate:self
                                             cancelButtonTitle:nil
                                             otherButtonTitles:@"Yes",@"No",nil];
    [message show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if([title isEqualToString:@"Yes"])
    {
        NSLog(@"Yes was selected.");



        self.flUploadEngine = [[fileUploadEngine alloc] initWithHostName:@"manektech.net" customHeaderFields:nil];

        NSMutableDictionary *postParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                           @"testApp", @"appID",
                                           nil];      
        self.flOperation = [self.flUploadEngine postDataToServer:postParams path:@"/dilipvideotest/savefile.php"];

        [self.flOperation addData:videodata forKey:@"uploadfile" mimeType:@"video/mov" fileName:@"output.mov" ];





        [self.flOperation onCompletion:^(MKNetworkOperation *operation) {

            NSLog(@"response string is : %@", [operation responseString]);


            /*   
             This is where you handle a successful 200 response
             */
        }     
                               onError:^(NSError *error) {
                                   NSLog(@"error : %@", error);
                                   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                                   message:[error localizedDescription]
                                                                                  delegate:nil
                                                                         cancelButtonTitle:@"Dismiss"
                                                                         otherButtonTitles:nil];
                                   [alert show];        
                               }];



        [self.flUploadEngine enqueueOperation:self.flOperation ];

    }
    else if([title isEqualToString:@"No"])
    {
        NSLog(@"No was selected.");
        //[self readMovie:outputFileURL];
    }
}