我可以使用视频工具箱框架将从相机设备捕获的视频压缩为 h264 格式,但是当我尝试在 VLC 播放器中播放该 h264 文件时,我听不到视频的音频。我认为音频压缩也应该用代码来完成。
但是我怎么没有找到任何资源呢?
最佳答案
您可以通过这种方式解码录制的视频:-
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
关于objective-c - 如何使用 VideoToolbox 将音频和视频一起编码为 h264 格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39784291/