shahen94 / react-native-video-processing

Native Video editing/trimming/compressing :movie_camera: library for React-Native
https://shahen94.github.io/react-native-video-processing/
MIT License
1.25k stars 326 forks source link

Issue trimming portrait videos rotates the videos to landscape on IOS #285

Closed kevmmdev closed 4 years ago

kevmmdev commented 4 years ago

Current Behavior

When I recently updated the react native to 0.62.2 from 0.61.5, I started to have this issue with portrait videos being rotated to landscape and this only happens only on IOS. I am using the ProcessingManager.trim function.

Expected Behavior

Trim the videos but the portrait videos shout not be rotated to landscape

Your Environment

software version
react-native-video-processing 1.20.0
react-native 0.62.2
node 12.13.1
kevmmdev commented 4 years ago

okay so with zero knowledge in swift, and by desperate call. I was able to create a quick fix for this issue which honestly I don't totally understand entirely, just copied some bits of codes from the crop function and boomerang and saw there about a quick fix with videos rotating.

        let composition = AVMutableComposition()
        let track = composition.addMutableTrack(withMediaType: .video, preferredTrackID: Int32(kCMPersistentTrackID_Invalid))
        let videoOrientation = self.getVideoOrientationFromAsset(asset: asset)

        if ( videoOrientation == .up  ) {
          var transforms: CGAffineTransform?
          transforms = track?.preferredTransform
          transforms = CGAffineTransform(rotationAngle: 0)
          transforms = transforms?.concatenating(CGAffineTransform(rotationAngle: CGFloat(90.0 * .pi / 180)))
          track?.preferredTransform = transforms!
        }
        else if ( videoOrientation == .down ) {
          var transforms: CGAffineTransform?
          transforms = track?.preferredTransform
          transforms = CGAffineTransform(rotationAngle: 0)
          transforms = transforms?.concatenating(CGAffineTransform(rotationAngle: CGFloat(270.0 * .pi / 180)))
          track?.preferredTransform = transforms!
        }
        else if ( videoOrientation == .left ) {
          var transforms: CGAffineTransform?
          transforms = track?.preferredTransform
          transforms = CGAffineTransform(rotationAngle: 0)
          transforms = transforms?.concatenating(CGAffineTransform(rotationAngle: CGFloat(180.0 * .pi / 180)))
          track?.preferredTransform = transforms!
        }

that in RNVideoTrimmer.swift on the function trim

gmansour09 commented 4 years ago

okay so with zero knowledge in swift, and by desperate call. I was able to create a quick fix for this issue which honestly I don't totally understand entirely, just copied some bits of codes from the crop function and boomerang and saw there about a quick fix with videos rotating.

       let track = composition.addMutableTrack(withMediaType: .video, preferredTrackID: Int32(kCMPersistentTrackID_Invalid))

        let videoOrientation = self.getVideoOrientationFromAsset(asset: asset)

        if ( videoOrientation == .up || videoOrientation == .down ) {
          var transforms: CGAffineTransform?
          transforms = track?.preferredTransform
          transforms = CGAffineTransform(rotationAngle: 0)

            transforms = transforms?.concatenating(CGAffineTransform(rotationAngle: CGFloat(90.0 * .pi / 180)))
            track?.preferredTransform = transforms!
        }

that in RNVideoTrimmer.swift on the function trim

@electricfeel1979 your a life saver I spent all day trying to figure this out. Works great thanks!

kevmmdev commented 4 years ago

okay so with zero knowledge in swift, and by desperate call. I was able to create a quick fix for this issue which honestly I don't totally understand entirely, just copied some bits of codes from the crop function and boomerang and saw there about a quick fix with videos rotating.

       let track = composition.addMutableTrack(withMediaType: .video, preferredTrackID: Int32(kCMPersistentTrackID_Invalid))

        let videoOrientation = self.getVideoOrientationFromAsset(asset: asset)

        if ( videoOrientation == .up || videoOrientation == .down ) {
          var transforms: CGAffineTransform?
          transforms = track?.preferredTransform
          transforms = CGAffineTransform(rotationAngle: 0)

            transforms = transforms?.concatenating(CGAffineTransform(rotationAngle: CGFloat(90.0 * .pi / 180)))
            track?.preferredTransform = transforms!
        }

that in RNVideoTrimmer.swift on the function trim

@electricfeel1979 your a life saver I spent all day trying to figure this out. Works great thanks!

@gmansour09 I updated the code, since the previous fix was still rotating unusual video orientations. That one fixed all of the issues. This is just a temporary fix, I have no knowledge with swift. I hope someone will be able to fix this officially.

wehriam commented 4 years ago

See #299

shahen94 commented 4 years ago

PR is merged, releasing new version.

kevmmdev commented 4 years ago

Just saw that this was solved, and my exact fixed was used :)

krupalikevadiya commented 3 years ago

It is not worked for all type of videos..can you please suggest me any other way to solve it.