numandev1 / react-native-compressor

🗜️Compress Image, Video, and Audio same like Whatsapp 🚀✨
MIT License
883 stars 85 forks source link

Adjust 16mb minimum compression size for react-native-compressor@0.5.6 #57

Closed emmbyiringiro closed 2 years ago

emmbyiringiro commented 2 years ago

Some developers start to use this package within the expo. Unfortunately, Expo still uses an old version of React Native up to React Native 0.64.3.

Can you remove this condition https://github.com/Shobbak/react-native-compressor/blob/dd5c106522461005acd89d6f679c0ef2f96fdd74/ios/Video/VideoCompressor.swift#L205

and old version users can benefit from that patch.

xuanhieupd commented 2 years ago

+1

numandev1 commented 2 years ago

@emmbyiringiro @xuanhieupd today I am busy with office work. hope I will add this tomorrow. thanks

emmbyiringiro commented 2 years ago

Start from Expo SDK 42, the Expo team release a new service that makes the Expo app support a native module.

Expo community has no built-i media compression package. This package is the one that is a great candidate as It has an easy setup and API to work with.

I expect many Expo users to adopt this.

I wish I can help more unfortunately I don't have a background in native development.

You can read more about Expo native build here

https://docs.expo.dev/build/setup/

numandev1 commented 2 years ago

@emmbyiringiro @xuanhieupd can you check 0.5.8

yarn add react-native-compressor@0.5.8
emmbyiringiro commented 2 years ago

Thanks for the patch. I have another issue or I'm doing wrong something.

By default, the video size for compression is 640. When I record video with camera on android, the camera record video with width:480 and height:640 dimensions.

I was expecting this video to be compressed on to default of 640. Unfortunately, the app crash and I need to lower video compression to either 480 or 360.

I guess that the logic should check if the size is less than or equal so provide compression size.

I

numandev1 commented 2 years ago

@emmbyiringiro can you confirm, in 0.5.8 version minimumFileSizeForCompress is working or not? so i can write this version in docs

numandev1 commented 2 years ago

@emmbyiringiro can you send me the video, so I can check that video on my side?

emmbyiringiro commented 2 years ago

I investigate the issue and I found that all videos you want to compress must have a video size great than maxSize otherwise it will crash.

For example, if you have a video like this https://sample-videos.com/video123/mp4/360/big_buck_bunny_360p_1mb.mp4 which has width 640 and height 360 and you set maxSize to 640 this will crash.

Even if video size 640 is equal maxSize. The device cameras sometimes record large video sizes which require be optimized.

In this situation, both video size and maxSize are equal but the app crashes.

emmbyiringiro commented 2 years ago

@emmbyiringiro can you confirm, in 0.5.8 version minimumFileSizeForCompress is working or not? so i can write this version in docs

I installed but it crashed with Native module not found error.

I'm using Expo SDK 42 which uses React Native 0.63 .

You can read more about this Expo Native module integration https://blog.expo.dev/introducing-custom-development-clients-5a2c79a9ddf8

emmbyiringiro commented 2 years ago

@emmbyiringiro can you confirm, in 0.5.8 version minimumFileSizeForCompress is working or not? so i can write this version in docs

I installed but it crashed with Native module not found error.

I'm using Expo SDK 42 which uses React Native 0.63 .

You can read more about this Expo Native module integration https://blog.expo.dev/introducing-custom-development-clients-5a2c79a9ddf8

This issue happen on android

numandev1 commented 2 years ago

@emmbyiringiro can you check 0.5.9 version. I have added support for the expo. you can read docs

yarn add react-native-compressor@0.5.9

Add the Compressor plugin to your Expo config (app.json, app.config.json or app.config.js):

{
  "name": "my app",
  "plugins": ["react-native-compressor"]
}
numandev1 commented 2 years ago

I investigate the issue and I found that all videos you want to compress must have a video size great than maxSize otherwise it will crash.

For example, if you have a video like this https://sample-videos.com/video123/mp4/360/big_buck_bunny_360p_1mb.mp4 which has width 640 and height 360 and you set maxSize to 640 this will crash.

Even if video size 640 is equal maxSize. The device cameras sometimes record large video sizes which require be optimized.

In this situation, both video size and maxSize are equal but the app crashes.

i will investigate this tonight

emmbyiringiro commented 2 years ago

@emmbyiringiro can you check 0.5.9 version. I have added support for the expo. you can read docs

yarn add react-native-compressor@0.5.9

Add the Compressor plugin to your Expo config (app.json, app.config.json or app.config.js):

{
  "name": "my app",
  "plugins": ["react-native-compressor"]
}

Have tested this package with Expo 42. I tried and result in this error.

[TypeError: null is not an object (evaluating 'NativeVideoCompressor.compress')

It seems that EXPO SDK 42 does not register native module

numandev1 commented 2 years ago

@emmbyiringiro after the above steps, can you run these three commands and test them?

expo prebuild

eas build

yarn ios
numandev1 commented 2 years ago

@emmbyiringiro closing this because I have fixed it and released the 0.5.9 version. you can open another issue for the expo if you want