如何在iPhone中捕捉视频

时间:2021-09-11 19:00:34

I am creating application for video app in iPhone, but I don't know how to capture a video in iPhone; and I want to store them in SQLite database, but I have one problem: can I save direct video in SQLite database? 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? Please help in this problem.

我正在iPhone中创建视频应用程序的应用程序,但我不知道如何在iPhone中捕获视频;我想将它们存储在SQLite数据库中,但我有一个问题:我可以在SQLite数据库中保存直接视频吗?是可能的,还是我必须存储视频的路径?如果我必须在SQLite数据库中保存路径,那么我该怎么做呢?请帮忙解决这个问题。

2 个解决方案

#1


16  

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.
You will have "MobileCoreServices/MobileCoreServices.h" to run this code.

只有iPhone 3GS及以上版本支持视频录制。因此,您应首先检查是否支持录制,然后使用以下代码启动为属性设置所需值的摄像机。您将拥有“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.

希望这可以帮助。

#2


3  

You would be able to store the video data in sqlite as raw data BUT I would strongly recommend AGAINST this. The performance would be awful. Better to save the video to the documents directory and then a path to that in the DB.

你可以将视频数据存储在sqlite中作为原始数据但是我强烈建议反对这个。表现太糟糕了。最好将视频保存到文档目录,然后将路径保存到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,它使管理持久性变得更加容易...下载我的核心数据教程的源代码,因为它包含一个很好的存储服务包装器...这里的教程

#1


16  

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.
You will have "MobileCoreServices/MobileCoreServices.h" to run this code.

只有iPhone 3GS及以上版本支持视频录制。因此,您应首先检查是否支持录制,然后使用以下代码启动为属性设置所需值的摄像机。您将拥有“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.

希望这可以帮助。

#2


3  

You would be able to store the video data in sqlite as raw data BUT I would strongly recommend AGAINST this. The performance would be awful. Better to save the video to the documents directory and then a path to that in the DB.

你可以将视频数据存储在sqlite中作为原始数据但是我强烈建议反对这个。表现太糟糕了。最好将视频保存到文档目录,然后将路径保存到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,它使管理持久性变得更加容易...下载我的核心数据教程的源代码,因为它包含一个很好的存储服务包装器...这里的教程