gpt4 book ai didi

ios - 如何将我们的iOS设备中存储或捕获的.mov文件转换为.mp4格式?

转载 作者:行者123 更新时间:2023-12-01 16:49:33 26 4
gpt4 key购买 nike

我正在开发该应用程序,该应用程序在ios设备上执行时可以正常运行,但是在播放从Android设备中从应用程序上传的视频时,.mov格式不支持。

我的代码可以正常工作,但需要.mp4格式的视频

-(void)openLibrary
{
cameraUI = [[UIImagePickerController alloc] init];
[cameraUI setDelegate:self];

[cameraUI setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
[cameraUI setAllowsEditing:YES];
cameraUI.tabBarController.tabBar.backgroundColor = [UIColor whiteColor];
[self presentViewController:cameraUI animated:YES completion:nil];

}

- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {

if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;


cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;

// Displays a control that allows the user to choose movie capture
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];

// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;

cameraUI.delegate = delegate;

[controller presentViewController:cameraUI animated:YES completion:nil];
return YES;
}
- (void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info {

NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];

[self dismissViewControllerAnimated:YES completion:nil];

// Handle a movie capture

if (CFStringCompare (( CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {
NSUserDefaults *def =[NSUserDefaults standardUserDefaults];
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
videoPath =[NSString stringWithFormat:@"%@/xyz.mov",docDir];


if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath))
{
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
[videoData writeToFile:videoPath atomically:NO];

[def setValue:videoPath forKey:@"videoPath"];

}
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[info objectForKey:UIImagePickerControllerMediaURL]];
CMTime duration = playerItem.duration;
float seconds = CMTimeGetSeconds(duration);
NSLog(@"seconds : %f",seconds);
if (seconds > 10) {
[def removeObjectForKey:@"videoPath"];
_lblVideo.hidden = TRUE;
[self.view makeToast:@"Select video which is less than 10 seconds" duration:2.0 position:@"center"];

}
else
{
_lblVideo.hidden = FALSE;
NSLog(@"Length is not greater than 10");
[self.view makeToast:@"Word is ready for posting" duration:2.0 position:@"center"];
}
}

}

好吧,我正在寻找一个好的解决方案,而不是根本无法使用的扩展更改解决方案。

最佳答案

当您保存录制的视频时,请如下手动更改.mp4

//您的loaca目录

NSArray *dirPaths;
NSString *docsDir;

dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString* mp4FilePath = [docsDir stringByAppendingPathComponent:@"recordedVideo.mp4"];

关于ios - 如何将我们的iOS设备中存储或捕获的.mov文件转换为.mp4格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17162615/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com