How to detect selected Media is Time-Lapse, Slow-Motion or .mp4
Asked Answered
K

1

11

Creating an application for image and video processing, where app requirement is set device Orientation according to selected video content orientation from the gallery. So I have used some line of code to get selected media current orientation kindly check Below code for orientation get from selected content.

var video_orientation: UIInterfaceOrientation {
    guard let transform = tracks(withMediaType: AVMediaType.video).first?.preferredTransform else {
        return .portrait
    }
    switch (transform.tx, transform.ty) {
    case (0, 0):
        return .landscapeLeft
    case (videoFirstFrameSize.width, videoFirstFrameSize.height):
        return .landscapeRight
    case (0, videoFirstFrameSize.width):
        return .portraitUpsideDown
    default:
        return .portrait
    }
}

Now, the problem is when user select video (slow-Mo, Normal) from Gallery its working fine. But when user select Time-Lapse video from gallery orientation going to changed, I have done too many research related to get orientation also have create many experiment and then finally I got some solution, and the solution is if we selected Time-lapse we need to pass AVMediaType.timecode in video type but now the problem is, how should I set it on selected assets. Any help is really appreciable and will save my life :P but its going little frustrating.

NOTE:- var video_orientation Is the Extension property of AVAssets

Kalil answered 14/12, 2017 at 9:16 Comment(9)
For SloMo you can check below link :https://mcmap.net/q/831566/-getting-slow-motion-meta-data-from-captured-video-in-iosWithstand
medium.com/@xcadaverx/avfoundation-cmtimemapping-c3521d4da6b1Repression
hi @Md.IbrahimHassan thanks for answer and i agreed with your suggestion, theoretically it is good to understand but practically can you please suggest some line of code..Kalil
I was actually trying to work on this issue but I had used UIImagePickerViewController I will try it using PHAssets and let you know. BTW its a very interesting question.Repression
Please and thanks in advance for your effortsKalil
@Sumitsingh you should work on frame rate it might helps you.Mesnalty
@RB1509 thanks for the idea I was working on this R&D from last 3 weeks but did't get the perfect solution.Kalil
you need to work with timerange and framerate. if possible than share you research code i will definitely helps you.Mesnalty
please check this link and set / get FPS of video. https://mcmap.net/q/831567/-ios-avplayer-get-fpsMesnalty
R
4

Here is the code how you can detect media type easily.

enum AssetType {
    case photo
    case video
    case livePhoto
    case sloMo
    case timeLapse
    case burst
    case gif
}

func getMediaType(asset : PHAsset)-> AssetType? {
        if asset.mediaType == .image {
            if asset.representsBurst {
                return .burst
            } else if asset.playbackStyle == .imageAnimated {
                return .gif
            } else if (asset.mediaType == PHAssetMediaType.image && ((asset.mediaSubtypes.rawValue & PHAssetMediaSubtype.photoLive.rawValue) != 0)) {
                return .livePhoto
            } else {
                return .photo
            }
        } else if asset.mediaType == .video {
            if (asset.mediaType == PHAssetMediaType.video && ((asset.mediaSubtypes.rawValue & PHAssetMediaSubtype.videoTimelapse.rawValue) != 0)) {
                return .timeLapse
            } else if (asset.mediaType == PHAssetMediaType.video && ((asset.mediaSubtypes.rawValue & PHAssetMediaSubtype.videoHighFrameRate.rawValue) != 0)) {
                return .sloMo
            } else {
                return .video
            }
        } else {
            return nil
        }
    }

Reportage answered 22/1, 2023 at 6:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.