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

How do i know the video orientation before trimming? #267

Open chai86 opened 4 years ago

chai86 commented 4 years ago

How do i know the selected video's orientation as it comes in to be trimmed? I want to know whether to load the video portrait or landscape in VideoPlayer

<VideoPlayer
          rotate={true/false}   // use this prop to rotate video if it captured in landscape mode  
/>  
maomeiqi commented 4 years ago

Have you used this method? ProcessingManager.getPreviewForSecond() The images I get here are not accurate,Can you help me

chai86 commented 4 years ago

I have used that function, my images are also not accurate for the selected second

maomeiqi commented 4 years ago

我已经使用了该功能,因此我的图像在选定的秒内也不准确 What a pity, but thank you anyway

Lohins commented 4 years ago

我已经使用了该功能,因此我的图像在选定的秒内也不准确 What a pity, but thank you anyway

Idk if this fit your need. I write a swift function and expose it to JS:

  @objc func getVideoOrientationFromAsset(asset : AVAsset) -> UIImage.Orientation {
    let videoTrack: AVAssetTrack? = asset.tracks(withMediaType: AVMediaType.video)[0]
    let size = videoTrack!.naturalSize

    let txf: CGAffineTransform = videoTrack!.preferredTransform

    if (size.width == txf.tx && size.height == txf.ty) {
      return UIImage.Orientation.left;
    } else if (txf.tx == 0 && txf.ty == 0) {
      return UIImage.Orientation.right;
    } else if (txf.tx == 0 && txf.ty == size.width) {
      return UIImage.Orientation.down;
    } else {
      return UIImage.Orientation.up;
    }
  }

Pass in the local path of the video.

Since I can't find a lib to detect the video orientation, and the react-native-video-processing does actually sometimes treat vertical/horizontal as the same.