【问题标题】:AVURLAsset cannot find video trackAVURLAsset 找不到视频轨道
【发布时间】:2014-10-15 05:46:33
【问题描述】:

我使用UIVideoEditorController 修剪视频。编辑后,在代表中,我尝试将视频与其他媒体重新混合。但是,[AVURLAsset trackWithMediaType:] 无法找到视频轨道。代码如下:

- (void)video:(NSString*)videoPath didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo {
    NSURL *videoURL = [NSURL URLWithString:videoPath];
    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
    if(asset == nil) {
      NSLog(@"Cannot create AVURLAsset");
      return;
    } else {
      NSLog(@"Asset: %@", asset);
    }

    if([asset tracksWithMediaType:AVMediaTypeVideo].count == 0) {
      NSLog(@"No Video Track");
      return;
    } else if([asset tracksWithMediaType:AVMediaTypeAudio].count == 0) {
      NSLog(@"No Audio Track");
      return;
    }
    // Follow up codes hidden intentionally
}

控制台日志打印:

2014-10-15 13:35:45.913 TestVideoTrim[3278:1191544] Asset: <AVURLAsset: 0x178229e00, URL = /private/var/mobile/Containers/Data/Application/96E7C0FF-92EB-44F7-8E35-B29FD0E58302/tmp/trim.EC3FB214-9907-411D-B3A3-75 ... 41E5.MOV>
2014-10-15 13:35:45.981 TestVideoTrim[3278:1191544] No Video Track

但是,当我转到照片应用程序并播放修剪后的视频时,视频与音频一起播放得很好。找不到视频轨道可能是什么原因?

附言委托函数的NSError返回null,表示编辑视频时没有出错。

【问题讨论】:

    标签: ios video avfoundation uivideoeditorcontroller


    【解决方案1】:

    替换

    NSURL *videoURL = [NSURL URLWithString:videoPath];
    

    NSURL *videoURL = [NSURL fileURLWithPath:videoPath];
    

    【讨论】:

      猜你喜欢
      • 2019-02-23
      • 1970-01-01
      • 1970-01-01
      • 2014-10-16
      • 2021-12-20
      • 2011-10-07
      • 2020-12-27
      • 2012-10-02
      相关资源
      最近更新 更多