### Initialize Timecode from AVAsset Start, Duration, or End Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Initialize Timecode from an AVAsset's start, duration, or end using `.avAsset()` with appropriate options. ```swift Timecode(.avAsset(AVAsset(), .start), at: .fps24) Timecode(.avAsset(AVAsset(), .duration), at: .fps24) Timecode(.avAsset(AVAsset(), .end), at: .fps24) ``` -------------------------------- ### Custom Timecode Comparison with Timeline Start Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Comparison-and-Sort.md Compares two Timecode instances considering a non-zero timeline start. This is useful for timelines that do not begin at 00:00:00:00. The result is a ComparisonResult. ```swift let timecode1: Timecode let timecode2: Timecode let start: Timecode let result = timecode1.compare(to: timecode2, timelineStart: start) // result is a ComparisonResult of orderedAscending, orderedSame, or orderedDescending ``` -------------------------------- ### Get Default Timecode String Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-String.md Get the timecode string from a Timecode instance using default formatting options. ```swift try Timecode(.components(h: 01, m: 00, s: 00, f: 05), at: .fps29_97d) .stringValue() // == "01:00:00;00" ``` -------------------------------- ### Read Start Timecode Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeAV/Documentation.docc/AVAsset-Timecode-Track.md Read the start timecode of the video. The frame rate can be auto-detected or explicitly provided. This method throws an error if frame rate information is not available. ```swift // read start timecode, auto-detecting frame rate let startTimecode = try await asset.startTimecode() // read start timecode, forcing a known frame rate let startTimecode = try await asset.startTimecode(at: .fps29_97) ``` -------------------------------- ### Define Start and End Timecodes Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Range-and-Strideable.md Define the start and end timecodes for range and stride operations. Ensure the frame rate is consistent. ```swift let startTC = try Timecode(.string("01:00:00:00"), at: .fps24) let endTC = try Timecode(.string("01:00:00:10"), at: .fps24) ``` -------------------------------- ### Initialize Timecode from AVAsset Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode.md Initialize Timecode by extracting time values (start, end, or duration) from an AVFoundation AVAsset. ```swift // AVFoundation AVAsset: read .start, .end or .duration timecode of a movie .avAsset(AVAsset(...), .start) ``` -------------------------------- ### Export Mutable Movie Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeAV/Documentation.docc/AVAsset-Timecode-Track.md Save the modified mutable movie to a new file using AVAssetExportSession. This example uses the passthrough preset for QuickTime movies. ```swift let exportSession = AVAssetExportSession( asset: mutableMovie, presetName: AVAssetExportPresetPassthrough ) let url = URL( ... ) try await exportSession.export(to: url, as: .mov) ``` -------------------------------- ### Get Timecode String Value for Filename Compatibility Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md The `stringValueFileNameCompatible` property is removed. Use `stringValue(format: [.filenameCompatible])` to get a filename-compatible string representation. ```swift timecode.stringValue(format: [.filenameCompatible]) ``` -------------------------------- ### Arithmetic Operators for Timecode Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Math.md Demonstrates the use of arithmetic operators (+, -, *, /) for performing calculations between Timecode objects and Double values. This snippet shows how to add, subtract, multiply, and divide timecodes, and how to get a Double result from timecode division. ```swift let tc1 = try Timecode(.string("01:00:00:00"), at: .fps23_976) let tc2 = try Timecode(.string("00:02:00:00"), at: .fps23_976) (tc1 + tc2).stringValue() // == "01:02:00:00" (tc1 - tc2).stringValue() // == "00:58:00:00" (tc1 * 2.0).stringValue() // == "02:00:00:00" (tc1 / 2.0).stringValue() // == "00:30:00:00" tc1 / tc2 // == 30.0 ``` -------------------------------- ### Get Feet+Frames Value from Timecode Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Conversions.md Converts a Timecode value to its feet and frames representation. Requires a frame rate. ```swift try Timecode(.string("01:00:00:00"), at: .fps23_976) .feetAndFramesValue // 5400+00 ``` -------------------------------- ### Get Audio Samples Value from Timecode Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Conversions.md Calculates the total number of audio samples represented by a Timecode value at a given frame rate and sample rate. ```swift try Timecode(.string("01:00:00:00"), at: .fps24) .samplesValue(sampleRate: 48000) // == 172800000 ``` -------------------------------- ### Get Absolute Interval Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Interval.md Retrieve the absolute value of the timecode interval, ignoring its sign. ```swift let tc = try Timecode(.components(h: 1), at: .fps24) let interval = TimecodeInterval(tc, .positive) // 01:00:00:00 interval.absoluteInterval // 01:00:00:00 let interval = TimecodeInterval(tc, .negative) // -01:00:00:00 interval.absoluteInterval // 01:00:00:00 ``` -------------------------------- ### Get Rational Value from Timecode Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Rational-Numbers-and-CMTime.md Retrieve the elapsed time of a Timecode object as a rational fraction. ```swift try Timecode(.components(h: 00, m: 01, s: 03, f: 29), at: .fps29_97) .rationalValue // == Fraction(1920919, 30000) ``` -------------------------------- ### Get Real-World Time Value from Timecode Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Conversions.md Calculates the elapsed real-world wall time in seconds for a given Timecode value at a specific frame rate. ```swift try Timecode(.string("01:00:00:00"), at: .fps23_976) .realTimeValue // == 3603.6 as TimeInterval (Double) ``` -------------------------------- ### Get Total Frame Count from Timecode Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Conversions.md Calculates the total number of frames represented by a Timecode value at a specific frame rate. ```swift try Timecode(.components(h: 1), at: .fps23_976) .frameCount // == 86400 ``` -------------------------------- ### Get Timecode String Value with Sub-Frames Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md The `stringValue` property is now a method. Use `stringValue(format:)` and pass `.showSubFrames` to include sub-frame information. ```swift // 1.x API let timecode = try Timecode(TCC(h: 1, m: 0, s: 0, f: 0, sf: 50), at: ._24) timecode.stringValue // "01:00:00:00" timecode.stringFormat = [.showSubFrames] timecode.stringValue // "01:00:00:00.50" // New API let timecode = try Timecode(.components(h: 1, m: 0, s: 0, f: 0, sf: 50), at: .fps24) timecode.stringValue() // "01:00:00:00" timecode.stringValue(format: [.showSubFrames]) // "01:00:00:00.50" ``` -------------------------------- ### Replace or Add Timecode Track Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeAV/Documentation.docc/AVAsset-Timecode-Track.md Replace an existing timecode track or add a new one to an AVMutableMovie. Specify the start timecode, frame rate, and file type. ```swift // replace existing timecode track if it exists, otherwise add a new timecode track try await mutableMovie.replaceTimecodeTrack( startTimecode: Timecode(.components(h: 0, m: 59, s: 58, f: 00), at: .fps29_97), fileType: .mov ) ``` -------------------------------- ### Using TimecodeSortComparator with Timeline Context Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Comparison-and-Sort.md Sorts a collection of Timecode instances using a SortComparator configured with a specific timeline start. This enables sorting based on a custom timeline origin and order. ```swift let start = try Timecode(.string("01:00:00:00"), at: .fps24) let comparator = TimecodeSortComparator(timelineStart: start) // ascending let comparator = TimecodeSortComparator(order: .reverse, timelineStart: start) // descending let timeline: [Timecode] = [ ... ] let sorted = timeline.sorted(using: comparator) ``` -------------------------------- ### Checking Sort Order with Timeline Context Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Comparison-and-Sort.md Checks if an array of Timecode instances is sorted according to a specific timeline start. This method is useful for verifying sort order in custom timeline scenarios. The default order to check is ascending. ```swift let timeline: [Timecode] = [ ... ] let start = try Timecode(.string("01:00:00:00"), at: .fps24) let isSorted: Bool = timeline.isSorted(timelineStart: start) // ascending let isSorted: Bool = timeline.isSorted(order: .reverse, timelineStart: start) // descending ``` -------------------------------- ### Sorting Timecode Collections with Timeline Context Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Comparison-and-Sort.md Sorts an array of Timecode instances considering a specific timeline start. This allows sorting based on a custom timeline origin. The default order is ascending. ```swift let timeline: [Timecode] = [ ... ] let start = try Timecode(.string("01:00:00:00"), at: .fps24) let sorted = timeline.sorted(timelineStart: start) // ascending let sorted = timeline.sorted(order: .reverse, timelineStart: start) // descending ``` -------------------------------- ### Initialize AVAsset Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeAV/Documentation.docc/AVAsset-Timecode-Track.md Create an AVAsset instance to work with. ```swift let asset = AVAsset( ... ) ``` -------------------------------- ### Build DocC Preview Source: https://github.com/orchetect/swift-timecode/blob/main/Docs/README.md Run this script from the terminal within the repo directory to build a cached preview of the documentation. Resolve any warnings and commit changes before proceeding. ```bash build-docc-cached-preview.sh ``` -------------------------------- ### Navigate to Generated Docs Source: https://github.com/orchetect/swift-timecode/blob/main/Docs/README.md After the build script completes, use the output path to navigate to the generated documentation directory. This path will be printed to the console. ```bash cd /var/folders/pk/3smbhvrd0p701_rpq3t0c_2r0000gn/T/tmp.Oq9smpNmnD/docs-webroot/swift-timecode ``` -------------------------------- ### Initialize Timecode with Samples and Sample Rate Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Initialize Timecode using `.samples(samples:sampleRate:)` for audio sample-based timecodes. ```swift Timecode(.samples(123.0, sampleRate: 48000), at: .fps24) ``` -------------------------------- ### Initialize Timecode with Properties Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Initialize a Timecode instance using direct property parameters, similar to TimecodeKit 1.x. ```swift let timecode = try Timecode( .components(h: 1, m: 0, s: 0, f: 0), at: .fps24, base: .max80SubFrames, limit: .max24Hours ) ``` -------------------------------- ### Initialize VideoFrameRate from Rational Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Rational-Numbers-and-CMTime.md Initialize a VideoFrameRate from a rational fraction representing either the duration of a single frame or the frames per second. Interlaced attributes must be supplied separately. ```swift // fraction representing the duration of 1 frame VideoFrameRate(frameDuration: Fraction(1001, 30000), interlaced: false) // == .fps29_97p // fraction representing the fps VideoFrameRate(rate: Fraction(30000, 1001), interlaced: false) // == .fps29_97p ``` -------------------------------- ### Initialize Timecode from Audio Samples Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode.md Create a Timecode instance from a number of elapsed audio samples and the sample rate in Hz. ```swift // elapsed audio samples at a given sample rate in Hz .samples(123456789, sampleRate: 48000) ``` -------------------------------- ### Initialize Timecode with Real Time Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Use `.realTime(seconds:)` to initialize Timecode with a duration in seconds. ```swift Timecode(.realTime(seconds: 123.0), at: .fps24) ``` -------------------------------- ### Arithmetic Methods for Timecode Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Math.md Illustrates how to use arithmetic methods (add, subtract, multiply, divide) for in-place mutation and returning new Timecode instances. It shows how to apply validation rules like .wrapping during operations. ```swift var tc1 = try Timecode(.string("01:00:00:00"), at: .fps23_976) var tc2 = try Timecode(.string("00:00:02:00"), at: .fps23_976) // in-place mutation try tc1.add(tc2) try tc1.add(tc2, by: .wrapping) // using result validation rule // return a new instance let tc3 = try tc1.adding(tc2) let tc3 = try tc1.adding(tc2, by: .wrapping) // using result validation rule ``` -------------------------------- ### Open Docs Folder in Finder Source: https://github.com/orchetect/swift-timecode/blob/main/Docs/README.md Once inside the generated docs directory, use this command to open the folder in Finder for easy access. ```bash open . ``` -------------------------------- ### Initialize Timecode with Feet and Frames Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Use `.feetAndFrames()` to initialize Timecode with feet and frames values. ```swift Timecode(.feetAndFrames(feet: 60, frames: 10), at: .fps24) ``` -------------------------------- ### Initialize Timecode with Components Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Use `.components(h:m:s:f:)` for initializing Timecode with hour, minute, second, and frame components. ```swift Timecode(.components(h: 1, m: 0, s: 0, f: 0), at: .fps24) ``` -------------------------------- ### Initialize Timecode from Real Time Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode.md Initialize Timecode by converting elapsed real time in seconds. ```swift // real time (wall clock) elapsed in seconds .realTime(seconds: 4723.241579) ``` -------------------------------- ### Initialize Timecode with Zero Components Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Migrate from `Timecode(TCC(), at: ._24)` to `Timecode(.zero, at: .fps24)` for initializing with zero time values. ```swift Timecode(.zero, at: .fps24) ``` -------------------------------- ### Initialize Timecode with Rational Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Initialize Timecode using the `.rational()` initializer with numerator and denominator. ```swift Timecode(.rational(60, 1), at: .fps24) ``` -------------------------------- ### Import Entire SwiftTimecode Library Source: https://github.com/orchetect/swift-timecode/blob/main/README.md Import the entire SwiftTimecode library to access all features (core, AV, UI) on Apple platforms or just core on Linux. ```swift // on Apple platforms, imports Core/AV/UI. // on Linux, imports Core. import SwiftTimecode ``` -------------------------------- ### Initialize Timecode from Feet and Frames Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode.md Create a Timecode instance using a traditional Feet+Frames reference. Supports integer feet and frames, string format, or a FeetAndFrames struct. ```swift // traditional Feet+Frames reference .feetAndFrames(feet: 60, frames: 10) .feetAndFrames("60+10") .feetAndFrames(FeetAndFrames(feet: 60, frames: 10)) // also accepts struct instance ``` -------------------------------- ### Import Individual SwiftTimecode Targets Source: https://github.com/orchetect/swift-timecode/blob/main/README.md Import specific SwiftTimecode targets as needed for your project. ```swift import SwiftTimecodeCore // core value types import SwiftTimecodeAV // AVFoundation extensions import SwiftTimecodeUI // UI components ``` -------------------------------- ### Import Individual SwiftTimecode Modules Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/Getting-Started.md Import specific modules from the library if only certain functionalities are needed. This includes core, AV, and UI components. ```swift import SwiftTimecodeCore import SwiftTimecodeAV import SwiftTimecodeUI ``` -------------------------------- ### Create Timecode from Audio Samples Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Conversions.md Initializes a Timecode object from a total number of audio samples, specifying the sample rate and frame rate. ```swift try Timecode(.samples(172800000, sampleRate: 48000), at: .fps24) ``` -------------------------------- ### Initialize TimecodeFrameRate from Rational Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Rational-Numbers-and-CMTime.md Initialize a TimecodeFrameRate from a rational fraction representing either the duration of a single frame or the frames per second. Drop-frame attributes must be supplied separately. ```swift // fraction representing the duration of 1 frame TimecodeFrameRate(frameDuration: Fraction(1001, 30000), drop: false) // == .fps29_97 // fraction representing the fps TimecodeFrameRate(rate: Fraction(30000, 1001), drop: false) // == .fps29_97 ``` -------------------------------- ### Initialize Timecode with Custom Properties Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode.md Initialize Timecode with a custom set of properties, including frame rate, subframe base, and upper limit, using the `using:` overload. ```swift let properties = Timecode.Properties( rate: .fps23_976, base: .max100SubFrames, limit: .max24Hours ) let tc = try Timecode(.string("01:00:00:00"), using: properties) ``` -------------------------------- ### Validate Timecode Initialization (Clamping) Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Use the `by: .clamping` parameter to initialize Timecode with values that will be clamped to valid ranges. ```swift // 1.x API Timecode(clamping: "01:00:00:00", at: ._24) // New API Timecode(.string("01:00:00:00"), at: .fps24, by: .clamping) ``` -------------------------------- ### Initialize Timecode from Rational Fraction Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode.md Initialize Timecode using a rational fraction, commonly found in formats like Final Cut Pro XML or AAF. Accepts raw numerator/denominator or a Fraction struct. ```swift // rational time fraction (ie: Final Cut Pro XML, or AAF) .rational(1920919, 30000) .rational(Fraction(1920919, 30000)) // also accepts struct instance ``` -------------------------------- ### Initialize Timecode from String Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode.md Create a Timecode instance from a string representation. Supports formats including days and subframes. ```swift // timecode string .string("01:00:00:00") .string("2 01:00:00:00.00") // days and subframes allowed ``` -------------------------------- ### Validate Timecode Initialization (Wrapping) Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Use the `by: .wrapping` parameter to initialize Timecode with values that will wrap around valid ranges. ```swift // 1.x API Timecode(wrapping: "01:00:00:00", at: ._24) // New API Timecode(.string("01:00:00:00"), at: .fps24, by: .wrapping) ``` -------------------------------- ### Filename Compatible Timecode String Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-String.md Format the timecode string to be filename-friendly by passing the .filenameCompatible option. ```swift try Timecode(.components(h: 01, m: 05, s: 20, f: 10, sf: 08), at: .fps29_97d) .stringValue(format: [.filenameCompatible]) // == "01-05-20-10.08" ``` -------------------------------- ### Initialize Timecode with Properties Struct Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Construct and pass a Timecode.Properties struct to initialize a new Timecode instance. This struct encapsulates rate, base, and limit. ```swift // construct a Timecode.Properties instance // and pass it to a new Timecode instance let properties = Timecode.Properties( rate: .fps24, base: .max80SubFrames, limit: .max24Hours ) let timecode = Timecode( .components(h: 1, m: 0, s: 0, f: 0), using: properties ) ``` ```swift // it can also be fetched using the `properties` property and used to // construct a new Timecode with the same properties let newTimecode = Timecode( .components(h: 2, m: 0, s: 0, f: 0), using: timecode.properties ) ``` -------------------------------- ### Initialize Timecode from Rational Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Rational-Numbers-and-CMTime.md Initialize a Timecode object from a rational fraction representing elapsed time. Returns the string representation of the timecode. ```swift try Timecode(.rational(Fraction(1920919, 30000)), at: .fps29_97) .stringValue() // == "00:01:03;29" ``` -------------------------------- ### Initialize Timecode with String Value Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Time values are now passed as static wrappers to Timecode initializers. Use `.string()` for string initialization. ```swift // 1.x API Timecode("01:00:00:00", at: ._24) // New API Timecode(.string("01:00:00:00"), at: .fps24) ``` -------------------------------- ### Initialize Timecode with Combined Frames and Sub-Frames Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Use `.frames(frames:subFrames:)` to initialize Timecode with combined frame and sub-frame values. ```swift Timecode(.frames(123, subFrames: 50), at: .fps24) ``` -------------------------------- ### Initialize Timecode with Components Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode.md Create a Timecode instance using discrete component values like hours, minutes, seconds, and frames. Supports days and subframes, and can also accept a Components struct instance. ```swift // zero timecode (00:00:00:00) .zero // timecode component values .components(h: 01, m: 00, s: 00, f: 00) .components(d: 00, h: 01, m: 00, s: 00, f: 00, sf: 00) // days and subframes allowed .components(Timecode.Components(h: 1)) // also accepts struct instance ``` -------------------------------- ### Initialize Timecode with CMTime Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Use `.cmTime()` to initialize Timecode from a CMTime object. ```swift Timecode(.cmTime(CMTime()), at: .fps24) ``` -------------------------------- ### Initialize Timecode with Frames Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Initialize Timecode directly with a total number of frames using the `.frames()` initializer. ```swift Timecode(.frames(1234), at: .fps24) ``` -------------------------------- ### Initialize Timecode with Sub-Frames as Unit Interval Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Initialize Timecode with sub-frames represented as a unit interval using `.frames(frames:subFramesUnitInterval:)`. ```swift Timecode(.frames(123, subFramesUnitInterval: 0.5), at: .fps24) ``` -------------------------------- ### Create Timecode from Real-World Time Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Conversions.md Initializes a Timecode object from an elapsed real-world time interval in seconds. Requires a frame rate. ```swift try Timecode(.realTime(seconds: 3603.6), at: .fps23_976) ``` -------------------------------- ### Create Timecode from String Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Conversions.md Initializes a Timecode object from a string representation. Requires a frame rate for context. ```swift try Timecode(.string("01:00:00:00"), at: .fps23_976) ``` -------------------------------- ### Import SwiftTimecode Umbrella Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/Getting-Started.md Import all modules in the library to your app project or Swift package using an umbrella import. ```swift import SwiftTimecode ``` -------------------------------- ### Create Timecode from Feet+Frames Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Conversions.md Initializes a Timecode object from feet and frames components or a string representation. Requires a frame rate. ```swift try Timecode(.feetAndFrames(feet: 5400, frames: 0), at: .fps23_976) // feet+frames string → timecode try Timecode(.feetAndFrames("5400+00"), at: .fps23_976) ``` -------------------------------- ### Set Frame Rate for Timecode Initialization Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode.md Specify the frame rate for a Timecode instance during initialization using the `at:` overload. ```swift let tc = try Timecode(.string("01:00:00:00"), at: .fps23_976) ``` -------------------------------- ### Construct TimecodeInterval with Timecode Instance Method Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Interval.md Construct a TimecodeInterval using the interval() method on a Timecode instance. ```swift let tc = try Timecode(.components(h: 1), at: .fps24) let interval = tc.interval(.negative) ``` -------------------------------- ### Initialize Timecode from CMTime Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode.md Create a Timecode instance from an AVFoundation CMTime object. ```swift // AVFoundation CMTime .cmTime(CMTime(value: 1920919, timescale: 30000)) ``` -------------------------------- ### Validate Timecode Initialization (Throwing) Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md The default Timecode initializer now throws if the time value is invalid. Use `try` to handle potential errors. ```swift // 1.x API try Timecode("01:00:00:00", at: ._24) // New API try Timecode(.string("01:00:00:00"), at: .fps24) ``` -------------------------------- ### Show Days in Timecode String Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-String.md Enable the display of days in the timecode string by passing the .alwaysShowDays option. ```swift try Timecode(.components(h: 01, m: 00, s: 00, f: 00), at: .fps24) .stringValue(format: [.alwaysShowDays]) // == "0 01:00:00:00" ``` -------------------------------- ### Initialize Timecode by Flattening an Interval Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Use `.interval(flattening:)` to initialize Timecode by flattening a TimecodeInterval. ```swift Timecode(.interval(flattening: TimecodeInterval)) ``` -------------------------------- ### Add SwiftTimecode Dependency to Xcode Project Source: https://github.com/orchetect/swift-timecode/blob/main/README.md Add the SwiftTimecode package to an Xcode app project using the provided URL. ```swift https://github.com/orchetect/swift-timecode ``` -------------------------------- ### Show Subframes in Timecode String Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-String.md Enable the display of subframes in the timecode string by passing the .showSubFrames option. ```swift try Timecode(.components(h: 01, m: 00, s: 00, f: 00, sf: 05), at: .fps29_97d) .stringValue(format: [.showSubFrames]) // == "01:00:00;00.05" ``` -------------------------------- ### SwiftUI View for Timecode List with Transferable Support Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Encoding.md Demonstrates a SwiftUI view that supports copying and pasting lists of Timecode objects. It utilizes `.copyable` and `.pasteDestination` modifiers for clipboard operations and `.dropDestination` for drag-and-drop. ```swift struct TimecodeListView: View { @State var model: [Timecode] @State var selection: Timecode var body: some View { List(selection: $selection) { ForEach(model) { item in Text(item.stringValue()).tag(item) } .dropDestination(for: Timecode.self) { items, location in add(items: items) return true } } .copyable([selection]) .pasteDestination(for: Timecode.self) { items in add(items: items) } } func add(items: [Timecode]) { for item in items { // Here is where you can validate pasted timecode before accepting it. // See the `validate()` method inline help or Encoding section in the // documentation for details. let validatedTimecode = TimecodeField.validate(pastedTimecode: item, ... ) // Timecode's default `Identifiable` implementation uses self // which means we cannot have two identical timecodes in a SwiftUI array if !model.contains(validatedTimecode) { model.append(validatedTimecode) } } } } ``` -------------------------------- ### SwiftUI Copy and Paste Commands for Timecode Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Encoding.md Implement `.onCopyCommand` and `.onPasteCommand` in a SwiftUI View to enable copying Timecode instances to the pasteboard and pasting them back. This snippet demonstrates how to generate NSItemProviders for copying and how to decode them when pasting. ```swift struct TimecodeListView: View { @State var model: [Timecode] @State var selection: Timecode var body: some View { List(selection: $selection) { ForEach(model) { item in Text(item.stringValue()).tag(item) } } .onCopyCommand { selection.itemProviders() } .onPasteCommand(of: [.timecode]) { itemProviders in Task { try await add(itemFrom: itemProviders) } } } func add(itemFrom itemProviders: [NSItemProvider]) async throws { // Provide default properties in case only a timecode string is present, // which could be the case if the user copies a plain-text timecode string // from another application. If the timecode data on the pasteboard was // originally created using Timecode's `itemProviders()` method or its // `Transferable` representation, then these properties will be ignored, // as the pasteboard will contain lossless data with which to decode to // the new Timecode instance. let properties = model.last?.properties ?? Timecode.Properties(rate: .fps24) let timecode = try await Timecode( from: itemProviders, propertiesForString: properties ) // Here is where you can validate pasted timecode before accepting it. // See the `validate()` method inline help or Encoding section in the // documentation for details. let validatedTimecode = TimecodeField.validate(pastedTimecode: timecode, ... ) // Finally, accept the pasted timecode // Timecode's default `Identifiable` implementation uses self // which means we cannot have two identical timecodes in a SwiftUI array if !model.contains(validatedTimecode) { model.append(validatedTimecode) } } } ``` -------------------------------- ### Create Timecode from Frame Count Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Conversions.md Initializes a Timecode object from a frame count, optionally including subframes or a fractional frame count. Requires a frame rate. ```swift try Timecode(.frames(86400), at: .fps23_976) // frame number + subframes → timecode try Timecode(.frames(86400, subFrames: 25), at: .fps23_976) // frame number + subframes unit interval as Double → timecode try Timecode(.frames(86400.25), at: .fps23_976) // frame number + subframes unit interval → timecode try Timecode(.frames(86400, subFramesUnitInterval: 0.25), at: .fps23_976) ``` -------------------------------- ### Construct TimecodeInterval Directly Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Interval.md Construct a TimecodeInterval directly using a Timecode instance and a sign. ```swift let tc = try Timecode(.components(h: 1), at: .fps24) let interval = TimecodeInterval(tc, .negative) ``` -------------------------------- ### Configure Timecode NSFormatter for Real-time Validation Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Validation.md Sets up a Timecode.TextFormatter to process user-entered timecode strings in real-time, optionally highlighting invalid components. Assign this formatter to an NSTextField. ```swift // set up formatter let properties = Timecode.Properties( rate: .fps23_976, base: .max80SubFrames, limit: .max24Hours ) let formatter = Timecode.TextFormatter( using: properties stringFormat: [.showSubFrames], showsValidation: true, // enable invalid component highlighting invalidAttributes: [.backgroundColor: NSColor.red] ) // assign formatter to a TextField UI object, for example let textField = NSTextField() textField.formatter = formatter ``` -------------------------------- ### Clamp Timecode to Valid Range Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode.md Initialize Timecode with values that might be out of bounds, using `.clamping` to ensure the resulting timecode adheres to the specified frame rate and upper limit. ```swift // clamp full timecode to valid range Timecode(.components(h: 26, m: 00, s: 00, f: 00), at: .fps24, by: .clamping) .stringValue() // == "23:59:59:23" // clamp individual timecode component values to valid values if they are out-of-bounds Timecode(.components(h: 01, m: 00, s: 85, f: 50), at: .fps24, by: .clampingEach) .stringValue() // == "01:00:59:23" ``` -------------------------------- ### Standard Timecode Comparison Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Comparison-and-Sort.md Compares two Timecode instances using standard comparison operators. Ensure Timecode instances are initialized correctly. ```swift try Timecode(.string("01:00:00:00"), at: .fps24) == Timecode(.string("01:00:00:00"), at: .fps24) // == true try Timecode(.string("00:59:50:00"), at: .fps24) < Timecode(.string("01:00:00:00"), at: .fps24) // == true try Timecode(.string("00:59:50:00"), at: .fps24) > Timecode(.string("01:00:00:00"), at: .fps24) // == false ``` -------------------------------- ### Validate Timecode Initialization (Allowing Invalid) Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Use the `by: .allowingInvalid` parameter to initialize Timecode with potentially invalid raw values. ```swift // 1.x API Timecode(rawValues: "01:00:00:00", at: ._24) // New API Timecode(.string("01:00:00:00"), at: .fps24, by: .allowingInvalid) ``` -------------------------------- ### Create Mutable Movie Copy Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeAV/Documentation.docc/AVAsset-Timecode-Track.md Create a mutable copy of an AVMovie to modify its timecode tracks. ```swift let movie = AVMovie( ... ) guard let mutableMovie = movie.mutableCopy() as? AVMutableMovie else { ... } ``` -------------------------------- ### Update Index HTML for Redirection Source: https://github.com/orchetect/swift-timecode/blob/main/Docs/README.md Edit the root-level index.html file in the 'docs' branch to include a meta refresh tag. This redirects users to the documentation subpath upon loading the index page. ```html
``` -------------------------------- ### Initialize Timecode from Frame Count Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode.md Initialize Timecode using a total frame count, optionally including subframes. Supports whole frames, subframes, and floating-point subframe values, as well as a FrameCount struct. ```swift // frame number (total elapsed frames) .frames(10000) // whole frames .frames(10000, subFrames: 20) // whole frames + subframes .frames(10000.25) // (Double) whole frames + float subframes .frames(10000, subFramesUnitInterval: 0.25) // whole frames + float subframes .frames(Timecode.FrameCount(...)) // also accepts struct instance ``` -------------------------------- ### Add SwiftTimecode Dependency to Swift Package Source: https://github.com/orchetect/swift-timecode/blob/main/README.md Add the SwiftTimecode package as a dependency in your Swift package's Package.swift file. ```swift let package = Package( dependencies: [ .package(url: "https://github.com/orchetect/swift-timecode", from: "3.1.0") ], targets: [ .target( dependencies: [ .product(name: "SwiftTimecode", package: "swift-timecode") ] ) ] ) ``` -------------------------------- ### Validate Timecode Components Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Validation.md Demonstrates non-granular and granular validation of timecode components. Use granular validation to allow invalid values and inspect which components are invalid. ```swift // example: // 1 hour and 20 minutes ARE valid at 23.976 fps, // but 75 seconds and 60 frames are NOT valid // non-granular validation try Timecode(.components(h: 1, m: 20, s: 75, f: 60), at: .fps23_976) // == throws error; cannot form a valid timecode // granular validation // `allowingInvalid` allows invalid values; does not throw errors so 'try' is not needed let timecode = Timecode( .components(h: 1, m: 20, s: 75, f: 60), at: .fps23_976, by: .allowingInvalid ) timecode.isValid // == false timecode.invalidComponents // == [.seconds, .frames] ``` -------------------------------- ### Check Timecode Containment in Range Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Range-and-Strideable.md Verify if a given Timecode falls within a defined range. This is useful for boundary checks. ```swift (startTC...endTC).contains(try Timecode(.string("01:00:00:05"), at: .fps24)) // == true (startTC...endTC).contains(try Timecode(.string("01:05:00:00"), at: .fps24)) // == false ``` -------------------------------- ### Wrap Timecode Around Valid Range Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode.md Initialize Timecode with values that might exceed the valid range, using `.wrapping` to continuously cycle the timecode values around the clock. ```swift // wrap around clock continuously if entire timecode overflows or underflows Timecode(.components(h: 26, m: 00, s: 00, f: 00), at: .fps24, by: .wrapping) .stringValue() // == "02:00:00:00" Timecode(.components(h: 23, m: 59, s: 59, f: 24), at: .fps24, by: .wrapping) .stringValue() // == "00:00:00:00" ``` -------------------------------- ### Iterate Through Timecode Range Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Range-and-Strideable.md Loop through each frame within a Timecode range. This is useful for processing every frame sequentially. ```swift for tc in startTC...endTC { print(tc) } ``` -------------------------------- ### Validating Pasted Timecode Against Local Context Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Encoding.md Shows how to validate a pasted Timecode instance against local properties and policies using `TimecodeField.validate`. This is useful for constraining pasted timecode to a specific frame rate, subframes base, and upper limit. ```swift @TimecodeState private var timecode: Timecode // pass in the `Timecode` instance received from the pasteboard // from the `pasteDestination()` or `onPasteCommand()` view modifiers: func validate(pastedTimecode: Timecode) { guard let newTimecode = TimecodeField.validate( pastedTimecode: pastedTimecode, localTimecodeProperties: timecode.properties, pastePolicy: .preserveLocalProperties, validationPolicy: .enforceValid ) else { return } timecode = newTimecode } ``` -------------------------------- ### Convert Timecode to String Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Conversions.md Formats a Timecode value into its string representation. The format depends on the Timecode's components and frame rate. ```swift try Timecode(.components(h: 1), at: .fps23_976) .stringValue() // == "01:00:00:00" ``` -------------------------------- ### Construct TimecodeInterval with Unary Operators Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Interval.md Construct a TimecodeInterval using the unary '+' or '-' operators on a Timecode instance. ```swift let interval = try -Timecode(.components(h: 1), at: .fps24) // negative let interval = try +Timecode(.components(h: 1), at: .fps24) // positive ``` -------------------------------- ### Using TimecodeSortComparator for Sorting Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Comparison-and-Sort.md Sorts a collection of Timecode instances using a dedicated SortComparator. The comparator can be configured for ascending or reverse order. ```swift let comparator = TimecodeSortComparator() // ascending let comparator = TimecodeSortComparator(order: .reverse) // descending let timeline: [Timecode] = [ ... ] let sorted = timeline.sorted(using: comparator) ``` -------------------------------- ### Iterate Through Timecode Range with Stride Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Range-and-Strideable.md Iterate over a Timecode range with a specified frame interval. Use this to process frames at specific steps. ```swift for tc in stride(from: startTC, to: endTC, by: 5) { print(tc) } ``` -------------------------------- ### Access and Set Timecode Components Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode.md Retrieve or modify individual timecode components (days, hours, minutes, seconds, frames, subFrames) directly as instance properties. Changes to components update the timecode value. ```swift let tc = try Timecode(.string("01:12:20:05"), at: .fps23_976) // get tc.days // == 0 tc.hours // == 1 tc.minutes // == 12 tc.seconds // == 20 tc.frames // == 5 tc.subFrames // == 0 // set tc.hours = 5 tc.stringValue() // == "05:12:20:05" ``` -------------------------------- ### Set Timecode on Existing Instance Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecode/Documentation.docc/TimecodeKit-1-Migration-Guide.md Use the refactored `set()` methods to modify an existing Timecode instance. These methods accept various value sources and validation rules, mirroring initializer overloads. ```swift var timecode = Timecode(.zero, at: .fps24) try timecode.set(.realTime(seconds: 123.0)) timecode.set(.frames(1234), by: .wrapping) ``` -------------------------------- ### Construct TimecodeInterval Between Two Timecodes Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Interval.md Construct a TimecodeInterval representing the duration between two Timecode instances. ```swift let interval = timecode1.interval(to: timecode2) ``` -------------------------------- ### Sorting Timecode Collections Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Comparison-and-Sort.md Sorts an array of Timecode instances in ascending or descending order. The default order is ascending. ```swift let timeline: [Timecode] = [ ... ] let sorted = timeline.sorted() // ascending let sorted = timeline.sorted(ascending: false) // descending ``` -------------------------------- ### Convert Timecode to Another Frame Rate Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Conversions.md Converts a Timecode value from its current frame rate to a new one. Ensure the target frame rate is compatible. ```swift try Timecode(.string("01:00:00;00"), at: .fps29_97d) .converted(to: .fps29_97) // == 00:59:56:12 ``` -------------------------------- ### Checking if Timecode Collections are Sorted Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Comparison-and-Sort.md Checks if an array of Timecode instances is sorted in ascending or descending order. The default order to check is ascending. ```swift let timeline: [Timecode] = [ ... ] let isSorted: Bool = timeline.isSorted() // ascending let isSorted: Bool = timeline.isSorted(ascending: false) // descending ``` -------------------------------- ### Read Timecode Frame Rate Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeAV/Documentation.docc/AVAsset-Timecode-Track.md Auto-detect and read the movie's frame rate. This method throws an error if frame rate information is not available in the video file. ```swift let frameRate = try await asset.timecodeFrameRate() // ie: .fps29_97 ``` -------------------------------- ### Timecode Component Values Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Components.md Accessors for the individual timecode component values. ```APIDOC ## ``Timecode`` ### Description Primitive storage type for timecode component values. ### Topics #### Component Values - ``days`` - ``hours`` - ``minutes`` - ``seconds`` - ``frames`` - ``subFrames`` #### Initializer - ``init(d:h:m:s:f:sf:)`` #### Static Constructors - ``zero`` - ``random(using:)`` - ``random(in:)`` #### Array - ``init(_:)-63n08`` - ``array`` #### Dictionary - ``init(_:)-38swh`` - ``dictionary`` #### Validation - ``isWithinValidDigitCounts(at:base:)`` - ``validRange(of:using:)`` - ``validRange(of:at:base:limit:)`` - ``ComponentRanges`` ``` -------------------------------- ### Format Invalid Timecode Components with NSAttributedString Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Validation.md Generates an NSAttributedString that highlights invalid timecode components with specified attributes. Useful for displaying user-input or parsed timecode with visual feedback. ```swift let timecode = Timecode( .components(h: 1, m: 20, s: 75, f: 60), at: .fps23_976, by: .allowingInvalid ) let attrString = timecode.nsAttributedString( invalidAttributes: [.foregroundColor: NSColor.red] ) ``` ```swift // set text's background color to red instead of its foreground color let invalidAttr: [NSAttributedString.Key: Any] = [ .backgroundColor: NSColor.red ] // set custom font and font size for the entire string let defaultAttr: [NSAttributedString.Key: Any] = [ .font: NSFont.systemFont(ofSize: 16) ] let timecode = Timecode( .components(h: 1, m: 20, s: 75, f: 60), at: .fps23_976, by: .allowingInvalid ) let attrString = timecode.nsAttributedString( invalidAttributes: invalidAttr, defaultAttributes: defaultAttr ) ``` -------------------------------- ### Flatten Timecode Interval Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Interval.md Flatten a timecode interval by wrapping it around the 24-hour limit if it's negative. ```swift let tc = try Timecode(.components(h: 1), at: .fps24) let interval = TimecodeInterval(tc, .positive) // 01:00:00:00 interval.flattened() // 01:00:00:00 let interval = TimecodeInterval(tc, .negative) // -01:00:00:00 interval.flattened() // 23:00:00:00 ``` -------------------------------- ### Read Duration as Timecode Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeAV/Documentation.docc/AVAsset-Timecode-Track.md Read the video duration expressed as elapsed timecode. The frame rate can be auto-detected or explicitly provided. This method throws an error if frame rate information is not available. ```swift // read video duration expressed as timecode let durationTimecode = try await asset.durationTimecode() // read video duration expressed as timecode, forcing a known frame rate let durationTimecode = try await asset.durationTimecode(at: .fps29_97) ``` -------------------------------- ### Read End Timecode Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeAV/Documentation.docc/AVAsset-Timecode-Track.md Read the end timecode of the video. The frame rate can be auto-detected or explicitly provided. This method throws an error if frame rate information is not available. ```swift // read end timecode, auto-detecting frame rate let endTimecode = try await asset.endTimecode() // read end timecode, forcing a known frame rate let endTimecode = try await asset.endTimecode(at: .fps29_97) ``` -------------------------------- ### Display Validated Timecode in SwiftUI Source: https://github.com/orchetect/swift-timecode/blob/main/Sources/SwiftTimecodeCore/Documentation.docc/Timecode-Validation.md Uses the TimecodeText SwiftUI view to display timecode and apply validation styling. The .timecodeValidationStyle modifier can be used to visually indicate invalid components. ```swift @TimecodeState var timecode = Timecode( .components(h: 1, m: 20, s: 75, f: 60), at: .fps23_976, by: .allowingInvalid ) var body: some View { TimecodeText(timecode) .timecodeValidationStyle(.red) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.