0

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 并播放修剪后的视频时,视频与音频一起播放得很好。找不到视频轨道的原因可能是什么?

ps委托函数的NSErrorreturns null,表示编辑视频时没有出错。

4

1 回答 1

3

代替

NSURL *videoURL = [NSURL URLWithString:videoPath];

NSURL *videoURL = [NSURL fileURLWithPath:videoPath];
于 2015-09-29T09:45:28.410 回答