갤러리에서 비디오를 선택하면 .MOV로 선택된 파일 확장명을 얻고 있으므로 .MP4로 변환하려고합니다. 이 경우에. 어떤 생각이라도 있으면 도와주세요..MOV를 .MP4로 변환 갤러리에서 선택하거나 카메라에서 녹화
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
selectedVideoURL = info[UIImagePickerControllerMediaURL];
if([picker sourceType] == UIImagePickerControllerSourceTypeCamera)
{
NSURL *videoURL=info[UIImagePickerControllerMediaURL];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];
[library writeVideoAtPathToSavedPhotosAlbum:videoURL completionBlock:^(NSURL *assetURL, NSError *error)
{
//here is your URL : assetURL
NSLog(@"url is%@",assetURL);
// here in debugger it shows as assets.MOV i want .MP4
PHFetchResult<PHAsset*> *assets = [PHAsset fetchAssetsWithALAssetURLs:@[assetURL]
options:nil];
PHAsset *asset1 = assets.firstObject;
[[PHImageManager defaultManager] requestAVAssetForVideo:asset1 options:nil resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
if ([asset isKindOfClass:[AVURLAsset class]]) {
AVURLAsset* urlAsset = (AVURLAsset*)asset;
NSNumber *size;
[urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
NSLog(@"size video of camera %f",[size floatValue]/(1024.0*1024.0)); //size is 43.703005
NSData *data = [NSData dataWithContentsOfURL:urlAsset.URL];
NSLog(@"length of camera %f",[data length]/(1024.0*1024.0)); // data size is 43.703005
sizeofVideo=[size floatValue]/(1024.0*1024.0);
NSLog(@"sizeofVideo arvin %f",sizeofVideo);
if (!sizeofVideo>50.00) {
selectedVideoURL=nil;
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Alert" message:@"size of video exist 50MB" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
attachnoteLbl.text=[NSString stringWithFormat:@"Attach Note:0"];
}
attachnoteLbl.text=[NSString stringWithFormat:@"Attach Note:1"];
}
}];
}];
}
내가 생각 .MP4에 파일 확장자 from.MOV을 삭제하여 다음과 같은 방법을 시도했지만 worked.So을 din't 한은 갤러리 나 카메라에서 선택 동안에 만 구걸로 변환해야합니다.
-(void)afnetworking{
NSString *videoUrl=[selectedVideoURL path];
if(videoUrl){
NSString *videoName = [[videoUrl lastPathComponent]stringByDeletingPathExtension];
NSData *videoData = [NSData dataWithContentsOfURL:selectedVideoURL];
[bodyData appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSString *tmpfileinfo = [NSString stringWithFormat:@"Content-Disposition: form-data; name=\"video_clip\"; filename=\"%@.mp4\"\r\n",videoName];
[bodyData appendData:[tmpfileinfo dataUsingEncoding:NSUTF8StringEncoding]];
[bodyData appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[bodyData appendData:[NSData dataWithData:videoData]];
}
http://stackoverflow.com/questions/5015050/equivalent-for-stringbydeletingpathextension-for-an-array http://stackoverflow.com/questions/1098957/objective-c-extract-filename-from-path -string – vicky