gpt4 book ai didi

iOS - 在设备上修剪 mp4

转载 作者:行者123 更新时间:2023-11-28 06:55:11 25 4
gpt4 key购买 nike

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

AVAssetReaderOutput 目前不支持压缩输出

有没有办法通过 AVAssetReader 从磁盘读取 MP4?

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
}
}
}
}

最佳答案

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

关于iOS - 在设备上修剪 mp4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33831141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com