SessionVideoSegment

@objcMembers
public class SessionVideoSegment : NSObject, Codable

For more information see Session documentation.

Segment Size

  • The pixel dimensions of the original video. Does not take into account the preferredTransform.

    Declaration

    Swift

    public internal(set) var naturalSize: CGSize { get }
  • The pixel dimensions of the original video with the preferredTransform taken into account.

    Declaration

    Swift

    public var actualSize: CGSize { get }

Rotation and Cropping

  • The preferredTransform takes into account any rotation that should be made to the video segment.

    If the video segment originally came with a preferredTransform, it will be set here.

    90° rotation increments made by the EditController will also be reflected here.

    Default value: .identity

    Declaration

    Swift

    public var preferredTransform: CGAffineTransform { get set }
  • The cropRect defines which region of the video segment should be in the final video.

    The cropRect is placed inside the video segment after the preferredTransform is applied. The video segment size will be the actualSize and the origin is top left corner. The cropRect is in pixels.

    A warning will be produced if the width/height ratio of the cropRect does not match the width/height ratio of the video renderSize.

    The easiest way to set this is by retrieving a cropRect from the suggestedCropRect() function.

    Default value: nil

    Declaration

    Swift

    public var cropRect: CGRect? { get set }
  • This returns a suggested cropRect for the segment. The returned cropRect will always touch two opposite edges of the segment actualSize and will be centered inside. The cropRect width/height ratio will match the video renderSize width/height ratio.

    Declaration

    Swift

    public func suggestedCropRect() -> CGRect

Current Filters

  • All active filters not including the primaryFilter. The EditController Adjust tab will place filters here.

    The filters in this array will be applied to only this segment and in ascending order.

    Declaration

    Swift

    public var filters: [SessionFilter] { get set }

Durations

  • The start time of the video segment after it has been trimmed.

    .zero corresponds with a start time at the beginning of the video segment.

    Speed is not factored into this time.

    Precondition

    Cannot be greater than duration and cannot be negative.

    Default value: .zero

    Declaration

    Swift

    public var trimStartTime: CMTime { get set }
  • The duration of the video segment after it has been trimmed.

    This is the duration of video to play after the trimStartTime.

    Speed is not factored into this time.

    Precondition

    Cannot be greater than duration - trimStartTime and cannot be negative.

    Default value: duration

    Declaration

    Swift

    public var trimDuration: CMTime { get set }
  • The final duration of the video segment after it has been trimmed and speed multipliers divided in.

    Default value: trimDuration \ speedMultiplier \ SessionVideo speedMultiplier

    Declaration

    Swift

    public var renderDuration: CMTime { get }
  • The original duration of the video segment. Originates from the timeRange of the original AVAsset.

    Declaration

    Swift

    public internal(set) var duration: CMTime { get }
  • The framerate for the video segment. Originates from the minFrameDuration of the original AVAsset.

    For example, a frameDuration of 1/30th of a second CMTime(value: 1, timescale: 30) would be a 30fps video segment.

    Will be CMTime(value: 1, timescale: 30) if the minFrameDuration of the AVAsset is not known or cannot be calculated.

    Declaration

    Swift

    public var frameDuration: CMTime { get set }

Speed

  • The playback speed for the current segment.

    Precondition

    Must be greater than zero.

    Note

    The speed of the whole video can be set with SessionVideo speedMultiplier instead.

    For example:

    A value of 2 with result in 2x faster playback speed.

    A value of .5 will result .5x slower playback speed.

    A value of 1 will result in normal playback speed.

    Default value: 1

    Declaration

    Swift

    public var speedMultiplier: Double { get set }

Location Data

  • If the video segment came from the users Photo Library and there was location information associated, this will be set.

    See the documentation for CLLocation.

    Default value: nil

    Declaration

    Swift

    public var location: CLLocation?
  • If the video segment came from the users Photo Library and there was location information associated, this will be equal to the latitude value of the location coordinate.

    The latitude is in degrees. Positive values indicate latitudes north of the equator. Negative values indicate latitudes south of the equator.

    Default value: self.location?.coordinate.latitude

    Declaration

    Swift

    public var latitude: Double? { get }
  • If the video segment came from the users Photo Library and there was location information associated, this will be equal to the longitude value of the location coordinate.

    The longitude is in degrees. Measurements are relative to the zero meridian, with positive values extending east of the meridian and negative values extending west of the meridian.

    Default value: self.location?.coordinate.longitude

    Declaration

    Swift

    public var longitude: Double? { get }

Export Status

  • The URL location of the final video segment file after it has been exported. There will only be a file here after an export has been completed for the individual segment. You may move, copy or delete this file. See VideoExporter for more information.

    Declaration

    Swift

    public var exportedVideoURL: URL { get }
  • The UTC date when the last successful video segment export started.

    Declaration

    Swift

    public internal(set) var dateExported: Date? { get }
  • Indicates if the export was completed for the individual segment.

    If the sessions dateModified is an older date than the video segments dateExported, this will be false. In other words, if you export the video segment this will become true but if you then make modifications to the video segment this will flip back to false. The exportedVideoURL file must also exist for this to be true.

    Declaration

    Swift

    public var isExported: Bool { get }

Generating Thumbnails

  • Retrieves a thumbnail for the video segment. Thumbnails do not include filters, unless you manually pass a SessionFilter to this function.

    If the thumbnail has not been retrieved before it will be generated and cached. If it has been retrieved before, it will be pulled from cache. Cache persists after restart.

    Declaration

    Swift

    public func requestThumbnail(boundingSize: CGSize, contentMode: ContentMode, filter: SessionFilter? = nil, completion: @escaping ((UIImage?) -> Void))

    Parameters

    boundingSize

    The size in pixels you would like to restrict the thumbnail to. The maximum size you can request is 400x400 pixels.

    contentMode

    The contentMode will control how the thumbnail is filled or fit into the size. Content will not be clipped to bounds.

    filter

    An optional SessionFilter to apply to the thumbnail.

    completion

    Called when the thumbnail has been retrieved.

  • Clears the thumbnail cache.

    Declaration

    Swift

    public func invalidateThumbnails()

Generating Frames

  • Generates an image from the video segment frame at the specified time. Does not include filters. Blocks the current thread until complete.

    Declaration

    Swift

    public func generateFrame(time: CMTime, cropped: Bool, maximumSize: CGSize? = nil) -> UIImage?

    Parameters

    time

    The requested time in the video segment from which the image should be generated. Relative to the video segment duration, not trimDuration. This value must be within a .zero to duration range.

    cropped

    Set this to true if the cropRect should be taken into account when generating the image.

    maximumSize

    The maximum size in pixels of the image to generate. Images will be fit within this bounding box. If no bounding box is provided the image size will match the video renderSize if cropped is true. If cropped is false the image size will match the video segment actualSize.