Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将iOS设备中存储或捕获的.mov文件转换为.mp4格式?_Ios_Video - Fatal编程技术网

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

如何将iOS设备中存储或捕获的.mov文件转换为.mp4格式?,ios,video,Ios,Video,我正在开发该应用程序,该应用程序在ios设备上运行时运行良好,但在Android设备上播放应用程序上传的视频时,格式为.mov不支持 我有代码,工作正常,但需要在.mp4格式的视频 -(void)openLibrary { cameraUI = [[UIImagePickerController alloc] init]; [cameraUI setDelegate:self]; [cameraUI setSourceType:UIImagePickerControll

我正在开发该应用程序,该应用程序在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"];
        }
    }

}
-(void)openLibrary
{
cameraUI=[[UIImagePickerController alloc]init];
[cameraUI setDelegate:self];
[cameraUI setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
cameraUI.mediaTypes=[[NSArray alloc]initWithObjects:(NSString*)KuttypeMoine,nil];
[cameraUI setAllowsEditing:是];
cameraUI.tabBarController.tabBar.backgroundColor=[UIColor whiteColor];
[self-presentViewController:cameraUI动画:是完成:无];
}
-(BOOL)startCameraControllerFromViewController:(UIViewController*)控制器
usingDelegate:(id)delegate{
如果(([UIImagePickerController]资源类型可用:
UIImagePickerControllerSourceTypeCamera]==否)
||(委托==零)
||(控制器==零)
返回否;
cameraUI=[[UIImagePickerController alloc]init];
cameraUI.sourceType=UIImagePickerControllerSourceTypeCamera;
//显示允许用户选择电影捕获的控件
cameraUI.mediaTypes=[[NSArray alloc]initWithObjects:(NSString*)KuttypeMoine,nil];
//隐藏用于移动和缩放图片的控件,或用于
//剪辑电影。若要显示控件,请使用“是”。
cameraUI.allowsEditing=否;
cameraUI.delegate=代表;
[controller presentViewController:cameraUI动画:是完成:无];
返回YES;
}
-(无效)imagePickerController:(UIImagePickerController*)选择器
didFinishPickingMediaWithInfo:(NSDictionary*)信息{
NSString*mediaType=[info objectForKey:UIImagePickerControllerMediaType];
[自我解除视图控制器激活:是完成:无];
//处理电影拍摄
if(CFStringCompare((CFStringRef)mediaType,kUTTypeMovie,0)=KCFComparequalto){
NSUserDefaults*def=[NSUserDefaults standardUserDefaults];
NSString*docDir=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)对象索引:0];
NSString*moviePath=[[info-objectForKey:UIImagePickerControllerMediaURL]路径];
videoPath=[NSString stringWithFormat:@“%@/xyz.mov”,docDir];
if(UIVideoAtPath与SavedPhotosAlbum(moviePath))兼容)
{
NSURL*videoURL=[info-objectForKey:UIImagePickerControllerMediaURL];
NSData*videoData=[NSData DATA with contents sofURL:videoURL];
[视频数据写入文件:视频路径原子:否];
[def setValue:videoPath forKey:@“videoPath”];
}
AVPlayerItem*playerItem=[AVPlayerItem playerItemWithURL:[info-objectForKey:UIImagePickerController-DiaUrl]];
CMTime duration=playerItem.duration;
浮动秒数=CMTimeGetSeconds(持续时间);
NSLog(@“秒:%f”,秒);
如果(秒>10){
[def removeObjectForKey:@“videoPath”];
_lblVideo.hidden=TRUE;
[self.view makeToast:@“选择少于10秒的视频”持续时间:2.0位置:@“中心”];
}
其他的
{
_lblVideo.hidden=FALSE;
NSLog(@“长度不大于10”);
[self.view makeToast:@“Word已准备好发布”持续时间:2.0位置:@“中心”];
}
}
}

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

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

//你的loaca目录

NSArray *dirPaths;
NSString *docsDir;

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

这正是我所做的,并且没有像你能读到我问题的最后一行那样工作…但是谢谢你的回答…试着让它不值得一个没有任何价值的建议,也许这会有所帮助