react-native-vision-camera
react-native-vision-camera copied to clipboard
✨ Output Bitrate Modification
What feature or enhancement are you suggesting?
In react-native-camera we had the ability to change the video bitrate. This is particularly useful if you're using the component to send the video up to a server on a poor connection.
See attached documentation for how it worked there(videoBitrate prop): https://react-native-camera.github.io/react-native-camera/docs/api#method-type-1
Places in their code this was able to be modified: https://github.com/react-native-camera/react-native-camera/blob/v4.2.1/ios/RN/RNCamera.m#L1207-L1215 https://github.com/react-native-camera/react-native-camera/blob/v4.2.1/android/src/main/java/com/google/android/cameraview/Camera2.java#L1422
What Platforms whould this feature/enhancement affect?
iOS, Android
Alternatives/Workarounds
You could do post processing on the device using FFMpeg but that seems like a poor idea if you can modify the bitrate during recording.
Additional information
- [X] I agree to follow this project's Code of Conduct
- [X] I searched for similar feature requests in this repository and found none.
Hi! Yes, this should probably be possible very easily on iOS since I am using my own custom file writer, as opposed to RNCamera which just uses the default iOS file writer.
Not sure how I can achieve it on Android for now.
Hi @mrousavy, Is there any way for now to achieve this(bitrate modification) on android ?
Could this be why "medium" preset still has large videos for android and not iOS?
For a 1 minute video, its around 12mb for ios, 140mb for android
Unfortunately we had to revert back to RNCamera because we can't get the android video size down, hopefully someone can help out with setting the bit rate for Android in future 🙂
https://github.com/react-native-camera/react-native-camera/blob/master/android/src/main/java/com/google/android/cameraview/Camera1.java
The old RNCamera android code looks like it handles bitrate no problem.
But when looking at documentation for the newer API used in this library...
https://github.com/react-native-camera/react-native-camera/blob/master/android/src/main/java/com/google/android/cameraview/Camera1.java
It looks like the API isn't even ready yet, @mrousavy do you think you jumped a gun a little on that? Bitrate setting is extremely important, and I don't want a customer waiting for their video to be reencoded all over again because of a shortcoming of the new API.
Wait... I may have found something
https://developer.android.com/reference/kotlin/androidx/camera/core/impl/VideoCaptureConfig
I've almost lost my mind reading the new androidX documentation, apparently it was possible to manipulate bitrate using VideoCaptureConfig and VideoCapture.Builder, but they seem to have blocked that and only allow these STUPID preset QualitySelector things.
I can't describe how much I hate the Android development team, I can't believe that they would actually make it impossible to touch bitrate settings when recording a video. God I'm so angry
Ok from what I understand, the AndroidX Camera library is limited in what it can do. The Camera2 API is NOT deprecated, and was implemented fine in react-native-camera.
https://github.com/react-native-camera/react-native-camera/blob/master/android/src/main/java/com/google/android/cameraview/Camera2.java
I'm going to fork and move to that API for finer control including bitrate, because the 'medium' and 'high' presets on android are creating huge video files requiring the use of react-native-compressor to help fix (but with processing delays introduced).
I don't know if you @mrousavy want your repo to move in this direction (from what I understand it would only provide benefits to the devs here but you may know something I don't), or I just stick with my fork.
@jpike88 do share your library here in this thread. we are also facing the same issue, the video size is too large and we have to compress it before uploading. earlier we had used react-native-compressor but it increased our apk size a lot.
Also you can use https://github.com/Tourenathan-G5organisation/SiliCompressor, which use mediaCodec api to compress the video. But the only problem with this library is that it take a lots of time to compress. eg, for 2 min video it take 4 min compression time and it changes from device to device.
hello, any news on this one? we need to reduce android file size during recording, because all other methods requires post processing time which could be huge burden for the app.
any help would be appreciated, thanks.
@mrousavy @jpike88
@jpike88 I just saw your comments now:
It looks like the API isn't even ready yet, @mrousavy do you think you jumped a gun a little on that?
No;
Bitrate setting is extremely important, and I don't want a customer waiting for their video to be reencoded all over again because of a shortcoming of the new API.
Sure! If it's that important for you/your business/your clients, reach out to me over email or Twitter and we can work a way out so I can work on that! :) I have discounted hourly rates for open-source work.
I've almost lost my mind reading the new androidX documentation
I feel 'ya. iOS is even more tricky.
Ok from what I understand, the AndroidX Camera library is limited in what it can do
Exactly.
The Camera2 API is NOT deprecated, and was implemented fine in react-native-camera.
It is not, as of now at least. Camera1 is deprecated. The benefit of CameraX is that it abstracts a lot of things away and makes basic Camera usage way easier than it was on Camera2 (as there was a sh*t ton of boilerplate code and things breaking that require user error handling), and also it supports Camera1 too.
If I use Camera2, all devices that are Camera1 based won't work.
BUT: We are working on VisionCamera V3 ✨. VisionCamera V3 will have a ton of cool changes:
- Write-back Frame Processors (Draw anything onto the Frame, in realtime, using Skia straight from JS!)
- Fabric/TurboModule (speed improvements, sync methods so you can await
startRecording
, maybe get aPhotoHostObject
to skip file write attakePhoto
, and aconvertViewCoordinatesToCameraCoordinates(..)
func) - CameraX -> Camera2 rewrite <-- this is what you'd be interested in (solves a ton of errors with no devices, formats, blackscreens, and we can easily impl. bitrate there.)
- Potential VisionCamera declarative device/format API redesign (Builder approach? not sure yet, but should simplify device/format selection drastically)
If you want to read more about that, check out this GIST I made to explain everything in greater detail.
We are focusing on write-back frame processors first, then Camera2 rewrite. I am currently just doing a proof of concept in my free time, and to actually work on that (since this is a huge project, and I have a company to run lol) we need the budget. So contact me if you're interested in that becoming reality we need companies to support us and help fund the development of this.
✌️
Sure! If it's that important for you/your business/your clients, reach out to me over email or Twitter and we can work a way out so I can work on that! :)
Hi! We are using VisionCamera V3 and would like to get the file size down so the video can be uploaded quickly over cellular. We're recording in H265 at the lowest resolution iOS allows, but the file size is still too large for weaker connections. Bitrate control is something we are very interested in.
I saw #1555 , is this something you're still working on? What would it take to get this feature?
@techied sure, I can implement this as consultancy service. DM me on Twitter (@mrousavy) or send me an email to discuss details :)
See #1882 ;)