mirror of
https://github.com/samsonjs/SJSAssetExportSession.git
synced 2026-03-25 08:45:50 +00:00
Make the test more thorough and move color stuff to video composition
This commit is contained in:
parent
750b77210c
commit
6319aaaad1
1 changed files with 22 additions and 9 deletions
|
|
@ -17,13 +17,16 @@ final class ExportSessionTests {
|
|||
let filename = "ExportSessionTests_testEncode_\(timestamp).mp4"
|
||||
let destinationURL = URL.temporaryDirectory.appending(component: filename)
|
||||
defer { _ = try? FileManager.default.removeItem(at: destinationURL) }
|
||||
|
||||
let size = CGSize(width: 1280, height: 720)
|
||||
let duration = CMTime(seconds: 1, preferredTimescale: 600)
|
||||
let videoComposition = try await AVMutableVideoComposition.videoComposition(withPropertiesOf: sourceAsset)
|
||||
videoComposition.renderSize = size
|
||||
videoComposition.renderScale = 1
|
||||
videoComposition.frameDuration = CMTime(value: 1, timescale: 30)
|
||||
videoComposition.colorPrimaries = AVVideoColorPrimaries_ITU_R_709_2
|
||||
videoComposition.colorTransferFunction = AVVideoTransferFunction_ITU_R_709_2
|
||||
videoComposition.colorYCbCrMatrix = AVVideoYCbCrMatrix_ITU_R_709_2
|
||||
|
||||
try await ExportSession.export(
|
||||
asset: sourceAsset,
|
||||
audioMix: nil,
|
||||
|
|
@ -41,11 +44,6 @@ final class ExportSessionTests {
|
|||
AVVideoAverageBitRateKey: NSNumber(value: 1_000_000),
|
||||
AVVideoProfileLevelKey: AVVideoProfileLevelH264HighAutoLevel as String,
|
||||
] as [String: any Sendable],
|
||||
AVVideoColorPropertiesKey: [
|
||||
AVVideoColorPrimariesKey: AVVideoColorPrimaries_ITU_R_709_2,
|
||||
AVVideoTransferFunctionKey: AVVideoTransferFunction_ITU_R_709_2,
|
||||
AVVideoYCbCrMatrixKey: AVVideoYCbCrMatrix_ITU_R_709_2,
|
||||
],
|
||||
],
|
||||
timeRange: CMTimeRange(start: .zero, duration: duration),
|
||||
to: destinationURL,
|
||||
|
|
@ -54,9 +52,24 @@ final class ExportSessionTests {
|
|||
|
||||
let asset = AVURLAsset(url: destinationURL)
|
||||
#expect(try await asset.load(.duration) == duration)
|
||||
try #require(await asset.loadTracks(withMediaType: .video).count == 1)
|
||||
let videoTrack = try #require(try await asset.loadTracks(withMediaType: .video).first)
|
||||
#expect(try await videoTrack.load(.naturalSize) == size)
|
||||
// Audio
|
||||
try #require(try await asset.loadTracks(withMediaType: .audio).count == 1)
|
||||
let audioTrack = try #require(await asset.loadTracks(withMediaType: .audio).first)
|
||||
let audioFormat = try #require(await audioTrack.load(.formatDescriptions).first)
|
||||
#expect(audioFormat.mediaType == .audio)
|
||||
#expect(audioFormat.mediaSubType == .mpeg4AAC)
|
||||
#expect(audioFormat.audioChannelLayout?.numberOfChannels == 2)
|
||||
#expect(audioFormat.audioStreamBasicDescription?.mSampleRate == 44_100)
|
||||
// Video
|
||||
try #require(await asset.loadTracks(withMediaType: .video).count == 1)
|
||||
let videoTrack = try #require(await asset.loadTracks(withMediaType: .video).first)
|
||||
#expect(try await videoTrack.load(.naturalSize) == size)
|
||||
print(try await videoTrack.load(.formatDescriptions))
|
||||
let videoFormat = try #require(await videoTrack.load(.formatDescriptions).first)
|
||||
#expect(videoFormat.mediaType == .video)
|
||||
#expect(videoFormat.mediaSubType == .h264)
|
||||
#expect(videoFormat.extensions[.colorPrimaries] == .colorPrimaries(.itu_R_709_2))
|
||||
#expect(videoFormat.extensions[.transferFunction] == .transferFunction(.itu_R_709_2))
|
||||
#expect(videoFormat.extensions[.yCbCrMatrix] == .yCbCrMatrix(.itu_R_709_2))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue