我可以使用视频工具箱框架将从相机设备捕获的视频压缩为h264格式,但当我尝试在VLC播放器中播放该h264文件时,我无法听到视频的音频。我认为音频压缩也应该在代码中完成。
但是为什么我没有找到任何资源呢?
发布于 2019-04-16 15:05:04
你可以这样解码你录制的视频:
func encodeReocrdedVideoToH264(url:URL) {
let anAsset = AVAsset.init(url: url)// Your source AVAsset movie in HEVC format //
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
let outputURL = documentsURL?.appendingPathComponent("recording.mp4")
// These settings will encode using H.264.
let preset = AVAssetExportPresetHighestQuality
let outFileType = AVFileType.mov
AVAssetExportSession.determineCompatibility(ofExportPreset: preset, with: anAsset, outputFileType: outFileType) { (isCompatible) in
if !isCompatible {
print("AVAssetExportSession Not Compatible")
return
}
}
guard let export = AVAssetExportSession(asset: anAsset, presetName: preset) else {
return
}
export.outputFileType = outFileType
export.outputURL = outputURL
export.exportAsynchronously { () -> Void in
// Handle export results.
print("exportAsynchronously Succesuffully")
}
}你可以在outputURL上看到你的编码视频。
欲了解更多信息,请访问Apple's doc
发布于 2017-01-17 09:26:17
按照我自己的赏金。请参考这个很棒的问题答案和评论:
Compute PTS and DTS correctly to sync audio and video ffmpeg C++。
尽管那里的解决方案是用C++实现的,但是逻辑可以移植到IOS,就像我在我自己的iOS项目中实现的那样。
https://stackoverflow.com/questions/39784291
复制相似问题