当我从Gallery中选择一个视频时,我选择的文件扩展名为.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"];
}
}];
}];
}
我已尝试通过以下方式删除.MOV到.MP4的文件扩展名但是没有工作。所以我认为只有在从图库或相机中选择时才需要将其转换为乞讨。
-(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]];
}