相关疑难解决方法(0)

以mp4格式录制,保存和/或转换视频?

我有以下问题 - 我正在尝试创建一个记录视频的应用程序,然后将其保存到相机胶卷,之后我将该视频上传到网络.问题是唯一支持的格式是"mp4",但我的视频是"mov".

所以我的问题是如何以"mp4"格式从相机保存视频,或将其保存在"mov"中,然后将其转换为"mp4".

这是我的代码:

  • 这是我打开相机的方式:

    picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.delegate = self;
    picker.showsCameraControls = YES;
    picker.allowsEditing = YES;
    picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
    [self presentViewController:picker animated:YES completion:nil];
    
    Run Code Online (Sandbox Code Playgroud)
  • 这是我保存视频的方式:

    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
    
    if (CFStringCompare ((__bridge_retained CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo)
    {
        NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
        videoURL = info[UIImagePickerControllerMediaURL];
    
        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(moviePath))
        {
            UISaveVideoAtPathToSavedPhotosAlbum(moviePath, self, nil, nil);
        }
    }
    [nextScreenButton setTitle:@"????????" forState:UIControlStateNormal];
    [self dismissViewControllerAnimated:YES completion:nil];
    
    Run Code Online (Sandbox Code Playgroud)

提前致谢!

iphone video xcode mp4 ios

16
推荐指数
2
解决办法
3万
查看次数

如何将.movpkg转换为mp4

我正在通过使用流式传输视频(.m3u8) AVPlayer

let url = URL(string: "http:myUrl.m3u8")
let player = AVPlayer(url: url!)

let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = videoView.bounds
playerLayer.backgroundColor = UIColor.purple.cgColor
videoView.layer.addSublayer(playerLayer)

player.play()
Run Code Online (Sandbox Code Playgroud)

我需要将流视频保存到图库。我注意到在下面的委托中保存了缓存视频路径。

func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didFinishDownloadingTo location: URL) {
        // Do not move the asset from the download location
        UserDefaults.standard.set(location.relativePath, forKey: "assetPath")

    }
Run Code Online (Sandbox Code Playgroud)

当我尝试使用以下代码从UserDefaults获取网址路径时,

let path = UserDefaults.standard.value(forKey: "assetPath")
Run Code Online (Sandbox Code Playgroud)

结果是:

图书馆/com.apple.UserManagedAssets.s9Giec/video_streaming_title_3E90DD91830B8992.movpkg

我在此问题的答案中找到.movpkg文件夹结构

扩展名为“ '.movpkg' 如何将视频转换为mp4并保存到图库”。

注意

  • movpkg文件包含.frag文件。如果有任何答案可以将.frag文件转换为mp4文件,则可以接受。

  • 我可以AVAsset.movpkgURL 创建一个,因此问题“如何将AVAsset转换为mp4文件”的答案也可以接受。

对于想要帮助的人,我在这里创建了一个仓库

https://github.com/trungducc/stackoverflow/tree/movpkg-to-mp4 …

objective-c http-live-streaming ios swift

10
推荐指数
1
解决办法
2715
查看次数

Swift - AVAssetExportSession exportSession.exportAsynchronously 完成处理程序未调用

我在我的项目中使用了此链接和以下代码,但 AVAssetExportSession - exportAsynchronously 方法完成处理程序在我的项目中不会调用:

堆栈链接

func encodeVideo(at videoURL: URL, completionHandler: ((URL?, Error?) -> ())?)  {
        let avAsset = AVURLAsset(url: videoURL, options: nil)
        
        let startDate = Date()
        
        //Create Export session
        guard let exportSession = AVAssetExportSession(asset: avAsset, presetName: AVAssetExportPresetPassthrough) else {
            completionHandler?(nil, nil)
            return
        }
        
        //Creating temp path to save the converted video
        let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL
        let filePath = documentsDirectory.appendingPathComponent("rendered-Video.mp4")
        
        //Check if the file already exists then remove the previous file
        if FileManager.default.fileExists(atPath: filePath.path) { …
Run Code Online (Sandbox Code Playgroud)

xcode swift

2
推荐指数
1
解决办法
1358
查看次数

标签 统计

ios ×2

swift ×2

xcode ×2

http-live-streaming ×1

iphone ×1

mp4 ×1

objective-c ×1

video ×1