当我从图库中选择一个视频时,我选择的文件扩展名为 .MOV,因此想将其转换为 .MP4 进行研究,但在这种情况下不知道如何做到这一点。如果你有任何想法,请帮忙。
- (void)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)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<HAsset*> *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]];
}
查看这个库。希望这可以解决您的问题。 https://github.com/Darktt/DTVideoConverter
关于ios - 将 .MOV 转换为 .MP4,同时从图库中选择或从相机录制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37832277/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |