1

我以为我可以使用 anAVAssetReader/Writer来修剪 MP4,但是当我尝试阅读音频(还没有尝试过视频)时,我得到了这个:

AVAssetReaderOutput does not currently support compressed output

有什么方法可以通过磁盘读取 MP4AVAssetReader吗?

let asset: AVAsset = AVAsset(URL: NSURL(fileURLWithPath: filePath))
        let audioTrack: AVAssetTrack = asset.tracksWithMediaType(AVMediaTypeAudio)[0]
        let audioTrackOutput: AVAssetReaderOutput = AVAssetReaderTrackOutput(track: audioTrack, outputSettings:
        [AVFormatIDKey: NSNumber(unsignedInt: kAudioFormatMPEG4AAC)])

        if let reader = try? AVAssetReader(asset: asset) {
            if reader.canAddOutput(audioTrackOutput) {
                reader.addOutput(audioTrackOutput)
            }
            reader.startReading()

            var done = false
            while (!done) {
                let sampleBuffer: CMSampleBufferRef? = audioTrackOutput.copyNextSampleBuffer()
                if (sampleBuffer != nil) {
                    print("buffer")
                    //process
                } else {
                    if (reader.status == AVAssetReaderStatus.Failed) {
                        print("Error: ")
                        print(reader.error)
                    } else {
                        done = true
                    }
                }
            }
        }
4

1 回答 1

1

AVAssetExportSession 是解决方案。SCassetExportSession效果更好。

于 2015-11-24T02:53:15.113 回答