【问题标题】:Creating a AVAsset with a HTTP NSURL使用 HTTP NSURL 创建 AVAsset
【发布时间】:2013-08-09 02:15:07
【问题描述】:

我正在尝试合并两个包含视频参考的NSURLs。其中一个 url 指向 AWS 上的视频,另一个指向本地存储的视频。我的导出代码有效,因为我已经尝试使用两个本地视频,但是每当我尝试合并 HTTP url 和本地 url 时,我都会收到此错误:Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on this server." UserInfo=0x155d2f20 {NSUnderlyingError=0x155b4f60 "The operation couldn’t be completed. No such file or directory", NSLocalizedDescription=The requested URL was not found on this server.} 这是创建 AVAsset 的代码:

AVAsset *firstAsset = [AVAsset assetWithURL:awsURL];

AVAssetExportSession 是否需要使用本地网址?

【问题讨论】:

    标签: iphone ios objective-c avfoundation


    【解决方案1】:

    @MichaelScaria,非常感谢您发布您的发现,我在这上面呆了大约 3 天。下面是我尝试从本地 url 和远程 url 获取 AVAssets 时的完整解决方案

    + (AVAsset*)getAVAssetFromRemoteUrl:(NSURL*)url 
    {   
        if (!NSTemporaryDirectory())
        {
           // no tmp dir for the app (need to create one)
        }
    
        NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
        NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"temp"] URLByAppendingPathExtension:@"mp4"];
        NSLog(@"fileURL: %@", [fileURL path]);
    
        NSData *urlData = [NSData dataWithContentsOfURL:url];
        [urlData writeToURL:fileURL options:NSAtomicWrite error:nil];
    
        AVAsset *asset = [AVAsset assetWithURL:fileURL];
        return asset;
    }
    + (AVAsset*)getAVAssetFromLocalUrl:(NSURL*)url
    {
        AVURLAsset *asset = [AVAsset assetWithURL:url];
        return asset;
    }
    

    【讨论】:

      【解决方案2】:

      我将在线网址保存到一个临时目录,并使用临时网址合并视频,它工作。

          NSData *urlData = [NSData dataWithContentsOfURL:initalURL];
          [urlData writeToFile:path options:NSAtomicWrite error:nil]
      

      【讨论】:

        【解决方案3】:

        也许您需要改用AVURLAsset 或其他子类?来自文档:

        您经常使用 AVURLAsset(AVAsset 的具体子类)实例化资产,其中 NSURL 引用视听媒体资源,例如流(包括 HTTP 实时流)、QuickTime 电影文件、MP3 文件和其他类型的文件。您还可以使用其他具体子类来实例化资产,这些子类以有用的方式扩展视听媒体的基本模型,就像 AVComposition 对时间编辑所做的那样。

        【讨论】:

        • 我已经尝试过使用 AVURLAsset,但我发布了我的问题的解决方案。
        猜你喜欢
        • 1970-01-01
        • 2015-04-23
        • 1970-01-01
        • 2015-12-16
        • 1970-01-01
        • 2011-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多