react-native-video-processing icon indicating copy to clipboard operation
react-native-video-processing copied to clipboard

How do i know the video orientation before trimming?

Open chai86 opened this issue 5 years ago • 4 comments

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  
/>  

chai86 avatar Feb 17 '20 20:02 chai86

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

maomeiqi avatar Feb 19 '20 02:02 maomeiqi

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

chai86 avatar Feb 19 '20 11:02 chai86

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

maomeiqi avatar Feb 25 '20 08:02 maomeiqi

我已经使用了该功能,因此我的图像在选定的秒内也不准确 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.

Lohins avatar Feb 27 '20 20:02 Lohins