I use UIImagePickerController to edit video and cut it,
I create it like this:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
[imagePicker setVideoQuality:UIImagePickerControllerQualityType640x480];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = #[(__bridge NSString *)kUTTypeMovie, (__bridge NSString *)kUTTypeVideo, (__bridge NSString *)kUTTypeMPEG4];
imagePicker.allowsEditing = YES;
[self.navigationController presentViewController:imagePicker animated:YES completion:nil];
but unfortunately in delegate method that is called I cant get start and end editing time - to save edited video:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
[picker dismissViewControllerAnimated:YES completion:^{
}];
NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
if ([type isEqualToString:(NSString *)kUTTypeVideo] ||
[type isEqualToString:(NSString *)kUTTypeMovie]) { // movie != video
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSNumber *start = [info objectForKey:#"_UIImagePickerControllerVideoEditingStart"];
NSNumber *end = [info objectForKey:#"_UIImagePickerControllerVideoEditingEnd"];
}
in my case start and end is nil. I have no idea how to get this information. Could you please advice how to get it?
Thank you in advance for any help.
I just check your code and run and i found that _UIImagePickerControllerVideoEditingStart and _UIImagePickerControllerVideoEditingEnd return only captured video from camera but if you are select video from your PhotoLibrary you did not get this two key in info dictionary:
If you are using imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; then you will get following info dictionary log:
UIImagePickerControllerMediaType = "public.movie";
UIImagePickerControllerMediaURL = "file:///private/var/mobile/Containers/Data/Application/BCBE6A30-1A92-41BB-8734-BFF052E416DE/tmp/trim.59737F15-FC2A-4EB7-89AE-DF3831089657.MOV";
UIImagePickerControllerReferenceURL = "assets-library://asset/asset.MOV?id=87E3E50A-1DBF-449F-8BE3-AB36E718D82C&ext=MOV";
If you are using imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; then you will get following info dictionary log:
UIImagePickerControllerMediaType = "public.movie";
UIImagePickerControllerMediaURL = "file:///private/var/mobile/Containers/Data/Application/611D33A4-61F4-4CD0-934D-C0EFF82B75AC/tmp/capture/capturedvideo.MOV";
"_UIImagePickerControllerVideoEditingEnd" = "2.360877976190476";
"_UIImagePickerControllerVideoEditingStart" = "1.360505952380952";
So at the end with UIImagePickerControllerSourceTypePhotoLibrary UIImagePickerController wont provide a _UIImagePickerControllerVideoEditingStart and _UIImagePickerControllerVideoEditingEnd key. so you can get its duration by using AVURLAsset like following code that assume start Time is 0 and end time is full duration.
AVURLAsset *Asset = [AVURLAsset assetWithURL:videoURL];
CMTime duration = [Asset duration];
int fullduration = ceil(duration.value/duration.timescale);
Related
I have problem in recording the video.After recording the video I am not having sound of the video.My coding is below.
- (void)StartVideo
{
self.imagePickerController = [[UIImagePickerController alloc] init];
_imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];
_imagePickerController.videoQuality = UIImagePickerControllerQualityTypeMedium;
_imagePickerController.videoMaximumDuration = 10;
_imagePickerController.allowsEditing = NO;
_imagePickerController.showsCameraControls = NO;
_imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
_imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
if(!self.CameraLvingVCLayer)
{
self.CameraLvingVCLayer = [[CameraFaceLivingCreditViewController alloc] init];
self.CameraLvingVCLayer.delegate = self;
}
_imagePickerController.cameraOverlayView = self.CameraLvingVCLayer.view;
_imagePickerController.navigationBarHidden = YES;
_imagePickerController.toolbarHidden = YES;
_imagePickerController.delegate = self;
[self presentViewController:_imagePickerController animated:YES completion:nil]; }
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:#"public.movie"])
{
NSURL* mediaURL = [info objectForKey:UIImagePickerControllerMediaURL];
if(mediaURL)
{
NSString *moviePath = [mediaURL path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath))
{
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
}
}
}
}
There's no sound in my recording video,why? Please Go through my coding and give the solution for this.
Please help me
This question already has answers here:
Send image to server as binary data
(2 answers)
Closed 9 years ago.
I want to upload image from UIImagePickerController.
I want to post my image to server from my iPad library.
I am not able to send the image to server. Any other options to do this?
I am doing this:
-(void)method_OpenImagePickerLibrary{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image=[info objectForKey:UIImagePickerControllerEditedImage];
SelectPickerimageView.image=image;
NSData *imageData = UIImagePNGRepresentation(image);
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
// Here is the file path for the image
filepath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:#"imagename.png"]];
[imageData writeToFile:filepath options:NSDataWritingAtomic error:nil];
[self dismissModalViewControllerAnimated:YES];
}
-(void)MethodUploadImage{
NSString *ftpUrl=#"ftp://yourftp Url";
NSString *strPortNumber=#"port Number";
NSString *strurlUpload=[NSString stringWithFormat:#"%#:%#",ftpUrl,strPortNumber];
NSString *getfilePath = filepath;
SCRFTPRequest *ftpRequest = [[SCRFTPRequest alloc] initWithURL:[NSURL URLWithString:strurlUpload] toUploadFile:getfilePath];
ftpRequest.username = #"Username";
ftpRequest.password = #"password";
ftpRequest.delegate = self;
/*
ftpRequest.didFinishSelector = #selector(uploadFinished:);
ftpRequest.didFailSelector = #selector(uploadFailed:);
ftpRequest.willStartSelector = #selector(uploadWillStart:);
ftpRequest.didChangeStatusSelector = #selector(requestStatusChanged:);
ftpRequest.bytesWrittenSelector = #selector(uploadBytesWritten:);*/
[ftpRequest startRequest];
}
These commented lines are giving me errors
Error 1: Undeclared selector
Error 2: Property
didFinishSelector,didFailSelector,willStartSelector,didChangeStatusSelector,bytesWrittenSelector
not found on SCRFtprequest delegate
Any idea or suggestion would be highly welcome.
Try using AFNetworking. It will surely make your life much easier.
I am working on an application that needs its user to upload a photo for him, using iphone, how can i implement this : when click on the image in my personal information page, the gallery is opend to choose a photo. when the photo is chosen it must appear instead of the previous one (at first it is the default pic). Notice that, the path of this photo or the photo itself(i do not know) must be stored in the DataBase for the next login. Moreover, this photo must be transferred to the server in order to be shown on the website when the same user login on the web.
I did it using the following code, i can choose a photo but when i save the path i could not load the pic again. it is a white box !! there is no photo !!
-(void) pickPhoto
{
UIImagePickerController *picker ;
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
else
{
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self presentViewController:picker animated:YES completion:nil];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *img = [info objectForKey:UIImagePickerControllerEditedImage];
if(!img)
img = [info objectForKey:UIImagePickerControllerOriginalImage];
NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [docDirPath stringByAppendingPathComponent:#"myImage.png"];
NSLog (#"File Path = %#", filePath);
UIButton *btn = (UIButton *)[self.tableView viewWithTag:2013];
[btn setBackgroundImage:img forState:UIControlStateNormal];
database= [[connectToDB alloc] init];
[database setDelegate:self];
[database saveUserPic:filePath ForUser:user.userId];
[self dismissViewControllerAnimated:YES completion:nil];
}
now to load the pic :
UIImage *img;
if(pic != nil)
img=[UIImage imageWithContentsOfFile:pic];
else
img= [UIImage imageNamed:#"business_userL.png"];
Any Help will be appreciated.!
UIImagePickerControllerReferenceURL will return reference to local storage of your selected image.
NSURL* localUrl = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];
Now you can save this url in your database.
To retrieve the image : display image from URL retrieved from ALAsset in iPhone
Iam trying to capture video using front camera in ios and convert that into sequence of images I am trying to use avassetimagegenerator for that . Iam new to AV Foundation please help me in this , thanks .
First present an UIImagePickerController
- (void)presentVideoPicker {
UIImagePickerController *anImagePicker = [[UIImagePickerController alloc] init];
anImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
anImagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
anImagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie, nil];
anImagePicker.allowsEditing = YES;
anImagePicker.delegate = self;
UIPopoverController *aPopoverController = [[[UIPopoverController alloc] initWithContentViewController:anImagePicker] autorelease];
[aPopoverController presentPopoverFromRect:self.view.frame inView:[[self view] window]
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
Capture the Video in UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *aMediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([aMediaType isEqualToString:(NSString *)kUTTypeMovie]) {
NSURL *aVideoURL = [info objectForKey:UIImagePickerControllerMediaURL];
[self readMovie:aVideoURL];
// If you want the Duration fo the Video, Use this
AVPlayerItem *aPlayerItem = [AVPlayerItem playerItemWithURL:aVideoURL];
CMTime aDuration = aPlayerItem.duration;
float anInSeconds = CMTimeGetSeconds(aDuration);
NSInteger aDuration = nearbyintf(anInSeconds);
}
}
Now code for the Method you called in the Delegate - (void) readMovie:(NSURL *)url
Refer this link:
http://www.7twenty7.com/blog/2010/11/video-processing-with-av-foundation
...
Once you generate the CVImageBuffer for an Image,
Refer
how to convert a CVImageBufferRef to UIImage
to convert it to UIImage
In my app, If user selects an image from camera roll to use as a compnay logo (added to a final pdf) it can take the attached file size from 8mb (with no image) to 29mb in some cases. This is a problem when user emails the file as its lager than most servers will allow for attachement sizes
- (IBAction)schemeLogoPressed:(id)sender {
LogCmd();
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = NO;
[self.editController presentModalViewController:imagePicker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
DebugLog(#"info dict: %#", info);
[picker dismissModalViewControllerAnimated:YES];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
self.schemeLogo.backgroundColor = [UIColor whiteColor];
self.schemeLogo.image = image;
NSData *imageData1 = UIImagePNGRepresentation(image);
NSString *path1 = [ICUtils pathForDocument:#"schemeLogo.png"];
[imageData1 writeToFile:path1 atomically:NO];
Is there anything I can do to optimise the picked image size?
Change this line:
NSData *imageData1 = UIImagePNGRepresentation(image);
to:
NSData *imageData1 = UIImageJPEGRepresentation(image, 0.9f);
the second parameter (0.9 float) is the quality. Higher number, higher quality. from 0.0 to 1.0