I am trying to use UIVideoEditorController to edit my video, but it seems to lose my video resolution. My original video was 720 x 1280, but after using the UIVideoEditorController, the quality becomes 360 x 640.
I tried to set the videoQuality to be UIImagePickerControllerQualityTypeHigh or even UIImagePickerControllerQualityTypeIFrame1280x720, but that doesn't help.
I am working on the iPad and here are my code:
self.editorController = [[[UIVideoEditorController alloc] init] autorelease];
self.editorController.videoPath = self.tempVideoPath;
self.editorController.delegate = self;
self.editorController.videoQuality = UIImagePickerControllerQualityTypeHigh;
CKLog(#"%d", self.editorController.videoQuality);
self.popOverController = [[[UIPopoverController alloc] initWithContentViewController:self.editorController] autorelease];
self.popOverController.delegate = self;
self.popOverController.popoverContentSize = CGSizeMake(700, 700);
[self.popOverController presentPopoverFromRect:CGRectMake(0, 0, 1, 1) inView:self.videoView permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
According to the UIVideoEditorController documentation:
A UIVideoEditorController object, or video editor, manages the
system-supplied user interface for trimming video frames from the
start and end of a previously recorded movie as well as reencoding to
lower quality...
The UIVideoEditorController class has a property called videoQuality. It allows us to choose the video quality when saving the trimmed video. (The default value is UIImagePickerControllerQualityTypeLow)
UIImagePickerControllerQualityTypeHigh uses the highest-quality video recording supported for the active camera on the device. It looks much better, but still seems to lose a little of the original resolution.
Related
I'm trying to implement a video recorder view controller that will be embedded inside of another view controller.
I implemented a MPMoviePlayedViewController, but that takes up the whole screen and is not what I want. I followed this tutorial, but did not get the results I was looking for - http://www.appcoda.com/video-recording-playback-ios-programming/
tl;dr - Is it possible to record a video without taking up the whole screen? How would one go about implementing that?
Try using the UIContainerView. It allows one UIViewController and its views to be displayed in a container of your desired size. Similar to a UITabBarController, which displays its child view controllers in a specified part of the screen, not the whole screen.
For examples and documentation, check out Apple's (hopefully secure) Developer site.
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html
You can use AVFoundation to if you need more control see this link to the apple documentation.
First setup your AVCaptureSession with an AVCaptureDevice, AVCaptureInput, and an AVCaptureVideoPreviewLayer.
Second create the view you want to display the output in and add it to your view controller
AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetHigh;
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *videoInput= [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:nil];
[session addInput:videoInput];
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
UIView *videoDisplay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
previewLayer.frame = videoDisplay.bounds;
[videoDisplay.layer addSublayer:previewLayer];
[session startRunning];
I'm working on an app that allows image capture, but not video capture, but I can't figure out how to remove the photo/video toggle from a UIImagePickerView. This is the code I'm working with, taken from Apple's documentation:
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose picture or
// movie capture, if both are available:
cameraUI.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;
cameraUI.delegate = self;
[self presentModalViewController:cameraUI animated:YES];
I'd like to keep all the camera controls EXCEPT the photo/video switch. Thanks!
Or remove this line:
cameraUI.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
The default value for cameraUI.mediaTypes is "kUTTypeImage". See the documentation.
You just have to set the mediaType property of UIImagePickerController to only contain images, the one you are using there is used to assign all available media types..you can read about it here, if you arent sure what the types are you can always output them to console and then just set that array with the appropriate one (to allow only pictures)
I want to make an app where users can create funny stick figure animations.
It would be cool if it is possible to export them as video. Can I "draw" video frames frame by frame and render them into a H.264 or other video format?
The length will be between 2 seconds and 5 minutes. I heared a while back that there is a framework to edit video but in my case I really need to create a video from scratch. What are my options?
You might need to use a multimedia framework which provides more lower level control, like gstreamer or ffmeg.
Alternately, you can create an MJPEG and figure out a way to transcode it.
Yes, you can examine :
CEMovieMaker
Usage:
UIImage *frameImg = <Some Image>;
NSDictionary *settings = [CEMovieMaker videoSettingsWithCodec:AVVideoCodecTypeH264
withWidth:source.size.width
andHeight:source.size.height
];
///
CEMovieMaker * movieMaker = [[CEMovieMaker alloc] initWithSettings:settings];
/// Complete video
[movieMaker createMovieFromImages:[self.movieImages copy] withCompletion:^(NSURL *fileURL){
//AVPlayerViewController or
MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[playerController.view setFrame:self.view.bounds];
[self presentMoviePlayerViewControllerAnimated:playerController];
[playerController.moviePlayer prepareToPlay];
[playerController.moviePlayer play];
[self.view addSubview:playerController.view];
}];
Hey I was wondering how I can access the front facing camera. Maybe there's some guide for it?
But I don't want all buttons etc. I just want to access the from facing camera, I don't ant the button to take a photo or anything like that.
You can access the front facing camera like:
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
Check out the UIImagePickerController Class Reference
Just set the cameraDevice property of UIImagePickerController to UIImagePickerControllerCameraDeviceFront. But you should check if the device is available.
You should initiate an AVCaptureSession and specify which AVCaptureDevice to use ( AVCaptureDevicePositionFront in your case).
Start looking for the AVCaptureSession documentation and you should have a better understanding of what to do.
Well, what "Khushbu Shah" said is right. however actually the isCameraDeviceAvailable is available only ios 4 and above. Just to ensure that you opened the front camera only if it is there, the right code block to be used is as follows.
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
if([UIImagePickerController respondsToSelector:#selector(isCameraDeviceAvailable:)])
{ //check if iphone 4 and above
if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront])
{
ipc.cameraDevice=UIImagePickerControllerCameraDeviceFront;
}
}
}
[ipc release];
First thing you need to do is to detect if your device has got front-facing camera. For that you need to iterate through the video devices.
Try this method of UIImagePickerController:
+ (BOOL)isCameraDeviceAvailable:(UIImagePickerControllerCameraDevice)cameraDevice
This is a class method and UIImagePickerControllerCameraDevice can take two values:
- UIImagePickerControllerCameraDeviceRear
- UIImagePickerControllerCameraDeviceFront
Example code:
if( [UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceFront]){
// do something
}
I am writing a simple video uploader application on iPhone 3GS where I first direct the user to photos album, and then select the video to share or upload. I am using the UIImagePickerController in the following way:
videoPickerCtrl = [[UIImagePickerController alloc] init];
videoPickerCtrl.delegate = self;
videoPickerCtrl.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
videoPickerCtrl.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:videoPickerCtrl.sourceType];
videoPickerCtrl.allowsImageEditing = NO;
videoPickerCtrl.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
[window addSubview:videoPickerCtrl.view];
But I can see that once the controller is invoked, there is a disturbing video trimming interface that is presented. Once I press "choose", the video is always trimmed no matter whether I touch the trimming controls or not. Is there any way to get around this trimming interface and directly get the path of the video file ?
You should set allowsEditing = NO; instead of allowsImageEditing = NO; (which has been deprecated in 3.1). Then, the trimming interface should not appear unless the selected movie is longer than 10 minutes (from the docs: "Maximum movie duration is 10 minutes. If a user picks a movie that is longer in duration than 10 minutes, they are forced to trim it before saving it.").
Interesting problem. This is just for information should anyone else be looking at this. On iPad OS 3.2 I have found some problems retrieving video, although the picker works and I can select video from albums and not just from the camera roll.
Here's my working code frag
The call
NSArray *mediaTypesAllowed = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[picker setMediaTypes:mediaTypesAllowed];
picker.delegate = self;
picker.allowsEditing = NO;
picker.wantsFullScreenLayout = YES;
if(!IsEmpty(self.editBackgroundPopover)){
[self.editBackgroundPopover setContentViewController:picker animated:YES];
}
And here is the delegate method
imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self.editBackgroundPopover dismissPopoverAnimated:true];
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
//not production code, do not use hard coded string in real app
if ( [ mediaType isEqualToString:#"public.image" ]) {
NSLog(#"Picked a photo");
}
//not production code, do not use hard coded string in real app
else if ( [ mediaType isEqualToString:#"public.movie" ]){
NSLog(#"Picked a movie at URL %#", [info objectForKey:UIImagePickerControllerMediaURL]);
NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(#"> %#", [url absoluteString]);
}
[[picker self] dismissModalViewControllerAnimated:YES];
}
However the video URL which I retrieve from the picker has the form
file:/localhost/private/var/mobile/Applications/C6FAC491-D27D-45A6-B805-951727ED2CEC/tmp/-Tmp-/trim.KOzqps.MOV
So it looks to me that the Video might be being processed through the trimming code even if I'm selecting the video as a whole. Note also that the movie, originally of type m4v when I loaded it through iTunes is of type MOV, which is of course unplayable on the device! I did try playing the URL but I received an alert saying "This kind of movie can't be played"
I don't quite understand what Apple is playing at here, the API appears not to really be usable as a way of loading and playing video from the photo library.
Hopefully IOS 4 will be more forthcoming, but for my iPad app, that's still months away.
Ok so I got it working long back after carefully looking at SDK docs. I am able to get videos from Camera Roll directory on my 3GS. But I can not find any way in which UIImagePickerController can choose video from directories other than Camera Roll(for instance, device's Photo Library where the user syncs videos through iTunes). Is there any standard way in SDK to do that ?