|
| 1 | +// |
| 2 | +// AVAssetTrack Timecode Read Tests.swift |
| 3 | +// TimecodeKit • https://github.com/orchetect/TimecodeKit |
| 4 | +// © 2022 Steffan Andrews • Licensed under MIT License |
| 5 | +// |
| 6 | + |
| 7 | +// AVAssetReader is unavailable on watchOS so we can't support any AVAsset operations |
| 8 | +#if shouldTestCurrentPlatform && canImport(AVFoundation) && !os(watchOS) |
| 9 | + |
| 10 | +import XCTest |
| 11 | +@testable import TimecodeKit |
| 12 | +import AVFoundation |
| 13 | + |
| 14 | +class AVAssetTrack_TimecodeRead_Tests: XCTestCase { |
| 15 | + override func setUp() { } |
| 16 | + override func tearDown() { } |
| 17 | + |
| 18 | + // MARK: - Start/Duration/End Timecode |
| 19 | + |
| 20 | + func testReadTimecodeRange_23_976fps() throws { |
| 21 | + let frameRate: TimecodeFrameRate = ._23_976 |
| 22 | + let url = try TestResource.timecodeTrack_23_976_Start_00_58_40_00.url() |
| 23 | + let asset = AVAsset(url: url) |
| 24 | + let track = try XCTUnwrap(asset.tracks.first) |
| 25 | + |
| 26 | + let correctStart = try TCC().toTimecode(at: frameRate) |
| 27 | + let correctEnd = try TCC(m: 24, s: 10, f: 19, sf: 03) |
| 28 | + .toTimecode(at: frameRate, format: [.showSubFrames]) |
| 29 | + |
| 30 | + // even though it's a timecode track, its timeRange property relates to overall timeline of the asset, |
| 31 | + // so its start is 0. |
| 32 | + // print(track.timeRange) |
| 33 | + // start: CMTime(value: 0, timescale: 1000, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0) |
| 34 | + // duration: CMTime(value: 1452244, timescale: 1000, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0) |
| 35 | + |
| 36 | + // auto-detect frame rate |
| 37 | + do { |
| 38 | + let tcRange = try track.timecodeRange() |
| 39 | + XCTAssertEqual(tcRange.lowerBound, correctStart) |
| 40 | + XCTAssertEqual(tcRange.upperBound, correctEnd) |
| 41 | + } |
| 42 | + |
| 43 | + // manually supply frame rate |
| 44 | + do { |
| 45 | + let tcRange = try track.timecodeRange(at: frameRate) |
| 46 | + XCTAssertEqual(tcRange.lowerBound, correctStart) |
| 47 | + XCTAssertEqual(tcRange.upperBound, correctEnd) |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + func testReadDurationTimecode_23_976fps() throws { |
| 52 | + let frameRate: TimecodeFrameRate = ._23_976 |
| 53 | + let url = try TestResource.timecodeTrack_23_976_Start_00_58_40_00.url() |
| 54 | + let asset = AVAsset(url: url) |
| 55 | + let track = try XCTUnwrap(asset.tracks.first) |
| 56 | + |
| 57 | + // duration |
| 58 | + let correctDur = try TCC(m: 24, s: 10, f: 19, sf: 03) |
| 59 | + .toTimecode(at: frameRate, format: [.showSubFrames]) |
| 60 | + |
| 61 | + // auto-detect frame rate |
| 62 | + XCTAssertEqual(try track.durationTimecode(), correctDur) |
| 63 | + // manually supply frame rate |
| 64 | + XCTAssertEqual(try track.durationTimecode(at: frameRate), correctDur) |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +#endif |
0 commit comments