AVURLAsset无法找到视频轨道

时间:2014-10-15 05:46:34

标签: ios video avfoundation uivideoeditorcontroller

我使用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

然而,当我去Photo App并播放修剪过的视频时,视频可以很好地播放音频。可能是无法找到视频轨道的原因?

P.S。委托功能NSError返回null,表示编辑视频时没有发生错误。

1 个答案:

答案 0 :(得分:2)

替换

NSURL *videoURL = [NSURL URLWithString:videoPath];

NSURL *videoURL = [NSURL fileURLWithPath:videoPath];