Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VideoTrimmer with .mov has wrong size #410

Closed
boboxiaodd opened this issue Oct 25, 2019 · 10 comments
Closed

VideoTrimmer with .mov has wrong size #410

boboxiaodd opened this issue Oct 25, 2019 · 10 comments

Comments

@boboxiaodd
Copy link
Contributor

Describe the bug
when select a video with .mov type, VideoTrimmer has black area
select an mp4 file ,it's correct

Screenshots
image

Environment (please complete the following information):

  • Device: [e.g. iPhone6] iPhone 11
  • OS: [e.g. iOS8.1] 13.2
  • Xcode Version [e.g. 9.4.1] 11.1
  • Swift Version [e.g. 4.1] 5.1

Installation Type

  • Cocoapods

Additional context
Add any other context about the problem here.

@s4cha
Copy link
Member

s4cha commented Jan 2, 2020

@boboxiaodd, indeed. This seems to happen on iCloud videos on my side. I'm going to rollback into git to see when this has been introduced.

@s4cha
Copy link
Member

s4cha commented Jan 6, 2020

Rolling back doesn't help. the bug is there as well. After testing it seems to happen on videos whose mediaFormat (helper below) isvide/avc1. vide/hvc1 work well. I don't know (yet) why recent (local?) videos are in vide/hvc1 format while older (iCloud?) videos are in vide/avc1

extension AVAssetTrack {
    var mediaFormat: String {
        var format = ""
        let descriptions = self.formatDescriptions as! [CMFormatDescription]
        for (index, formatDesc) in descriptions.enumerated() {
            // Get String representation of media type (vide, soun, sbtl, etc.)
            let type =
                CMFormatDescriptionGetMediaType(formatDesc).toString()
            // Get String representation media subtype (avc1, aac, tx3g, etc.)
            let subType =
                CMFormatDescriptionGetMediaSubType(formatDesc).toString()
            // Format string as type/subType
            format += "\(type)/\(subType)"
            // Comma separate if more than one format description
            if index < descriptions.count - 1 {
                format += ","
            }
        }
        return format
    }
}
 
extension FourCharCode {
    // Create a String representation of a FourCC
    func toString() -> String {
        let bytes: [CChar] = [
            CChar((self >> 24) & 0xff),
            CChar((self >> 16) & 0xff),
            CChar((self >> 8) & 0xff),
            CChar(self & 0xff),
            0
        ]
        let result = String(cString: bytes)
        let characterSet = CharacterSet.whitespaces
        return result.trimmingCharacters(in: characterSet)
    }
}

@s4cha
Copy link
Member

s4cha commented Jan 7, 2020

Somehow this only happens on iOS 13 on my side, not 0n iOS 12.
Clues are stacking...

  • Only happens under iOS 13
  • Only happens to vide/avc1 format

@LiborZa
Copy link

LiborZa commented Jan 7, 2020

@s4cha Did you find out where is the issue and how to fix this?

@rbecharast-chwy
Copy link

I have the same issue And this happen to me on iOS 12 and 13. Any solutions? Thanks

@s4cha
Copy link
Member

s4cha commented Jan 7, 2020

Well, I just found the fix after 2 days of extensive search... 🥂
Setting videosOptions.deliveryMode = .highQualityFormat line 71 of LibraryMediaManager.swift fixes it on my side.
The reason (I assume) is that other delivery modes grab degraded versions of the video (from iCloud for example) and the crop fails since the videos dimensions returned by requestAVAsset are actually lower than the original video, which breaks the cropping logic.
It actually makes sense to go get the full resolution video before cropping as to not loose any quality.
@LiborZa, @rodribech20 could you try the fix and let me know if this fixes works for you ?
PS: Be sure to test on an actual device as simulator tests proved unreliable in my case.

@rbecharast-chwy
Copy link

rbecharast-chwy commented Jan 7, 2020

Hi @s4cha, I added the code line and now it is working!!! Thank you very much!

@s4cha
Copy link
Member

s4cha commented Jan 8, 2020

@rodribech20 Thanks a ton for confirming the fix on you end. I will let you know when it's live :)

@s4cha
Copy link
Member

s4cha commented Jan 9, 2020

@boboxiaodd
Copy link
Contributor Author

good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants