Search code examples
react-nativeffmpegvideo-compression

What is the fastest method to compress videos before sending in React Native Chatting app


So my question is mainly in the title, I'm working on a chatting app and I have to compress the videos before sending to the database (firebase storage). All I could find till now is ffmpeg, but the issue is that it's taking tremendous amount of time to compress videos, for a 10 sec video it would take like a minute, and i was astonished how fast it's done in whatsapp.. so is there any other method to compress videos faster? Or does changing the ffmpeg command make an acceptable difference? the currently used command is "-y -i ${rVideoUrl} -c:v libx264 -crf 28 -preset ultrafast ${finalVideo}"


Solution

  • One of the methods to decrease the compression time by a good margin was to set the resolution of the output video to a low resolution, by using "-vf scale=426:240", so the whole command became "-y -i ${inputVideo} -c:v libx264 -crf 28 -vf scale=426:240 -preset ultrafast ${outputVideo}", or you can use "-1" instead of 426 or 240, the -1 will tell ffmpeg to automatically choose the correct height in relation to the provided width to preserve the aspect ratio. -1 can also be used for width if you provide a given height. You can check more details regarding the "-1" here