简体   繁体   English

如何在 iPhone 中捕捉视频

[英]how to capture video in iPhone

I am creating application for video app in iPhone, but I don't know how to capture a video in iPhone;我正在为 iPhone 中的视频应用程序创建应用程序,但我不知道如何在 iPhone 中捕获视频; and I want to store them in SQLite database, but I have one problem: can I save direct video in SQLite database?我想将它们存储在 SQLite 数据库中,但我有一个问题:我可以将直接视频保存在 SQLite 数据库中吗? Is is possible, or I have to store path of video?是可能的,还是我必须存储视频路径? If I have to save path in SQLite database, then how can I do this?如果我必须在 SQLite 数据库中保存路径,那么我该怎么做? Please help in this problem.请帮助解决这个问题。

Only iPhone 3GS and above support video recording.so you should first check if recording is supported and then start camera with desired values set for properties,using following code.只有 iPhone 3GS 及更高版本支持视频录制。所以您应该首先检查是否支持录制,然后使用以下代码为属性设置所需的值启动相机。
You will have "MobileCoreServices/MobileCoreServices.h" to run this code.您将拥有“MobileCoreServices/MobileCoreServices.h”来运行此代码。

            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {              
                UIImagePickerController *videoRecorder = [[UIImagePickerController alloc]init];         
                NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:videoRecorder.sourceType];
                NSLog(@"Available types for source as camera = %@", sourceTypes);
                if (![sourceTypes containsObject:(NSString*)kUTTypeMovie] ) {
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil 
                                                                    message:@"Device Not Supported for video Recording."                                                                       delegate:self 
                                                          cancelButtonTitle:@"Yes" 
                                                          otherButtonTitles:@"No",nil];
                    [alert show];
                    [alert release];
                    return;
                }
                videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
                videoRecorder.mediaTypes = [NSArray arrayWithObject:(NSString*)kUTTypeMovie];           
                videoRecorder.videoQuality = UIImagePickerControllerQualityTypeLow;
                videoRecorder.videoMaximumDuration = 120;
                videoRecorder.delegate = self;
                self.recorder_ = videoRecorder;                 
                [videoRecorder release];
                [self presentModalViewController:self.recorder_ animated:YES];                  
            }

Then you should implement following delegate method to save the captured video.Storing video path in SQL/coredata would be ideal instead of storing entire video file in it.然后您应该实现以下委托方法来保存捕获的视频。将视频路径存储在 SQL/coredata 中是理想的,而不是将整个视频文件存储在其中。

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
 if ([type isEqualToString:(NSString *)kUTTypeVideo] || 
    [type isEqualToString:(NSString *)kUTTypeMovie]) { // movie != video
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
    NSData *videoData = [NSData dataWithContentsOfURL:videoUrl];
    NSString *videoStoragePath;//Set your video storage path to this variable
    [videoData writeToFile:videoStoragePath atomically:YES];
    //You can store the path of the saved video file in sqlite/coredata here.
}
}

Hope this helps.希望这可以帮助。

You would be able to store the video data in sqlite as raw data BUT I would strongly recommend AGAINST this.您可以将 sqlite 中的视频数据作为原始数据存储,但我强烈建议您不要这样做。 The performance would be awful.表现会很糟糕。 Better to save the video to the documents directory and then a path to that in the DB.最好将视频保存到文档目录,然后保存到数据库中的路径。

If you are working with sqlite then you should look at CoreData, it makes managing persistence a lot easier... download the source code for my core data tutorial as it contains a nice storage service wrapper... tutorial here如果您正在使用 sqlite,那么您应该查看 CoreData,它使管理持久性变得更加容易......下载我的核心数据教程的源代码,因为它包含一个很好的存储服务包装器...... 教程在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM