DEV Community

Cover image for How to compress a large video without losing quality using FFmpeg with Termux
Sixtus Anyanwu
Sixtus Anyanwu

Posted on

How to compress a large video without losing quality using FFmpeg with Termux

Here is the Video Tutorial if you don't like reading.

https://m.youtube.com/watch?v=w4Hz0Kh0NXE&feature=youtu.be

If you are a content creator like me you will understand the pain and data it takes to upload 1GB of video which is probably about 20 minutes long or so.
You usually get this problem if you are recording on a device with a high refresh rate.

I have been searching all through the internet for a perfect solution that will be able to compress some of the video content which I create for YouTube without losing quality and alas, I was able to bump into ffmpeg.

With this tool, I was able to compress a 250mb video to just 14mb!!
Without losing quality and fast too! So let's get started.

What is ffmpeg?

FFmpeg is an open-source video and audio editor tool that can cut, chop, join, mux, and transcode almost any media format.

It is also a very reliable method of performing automated video processing.

Prerequisites

To get started you need to have the following:

  • An android phone (Android 10 and above)
  • Termux App

Installing termux

Termux is an application that allows you to run Linux commands and applications on your smartphone without needing to install a Linux distro. It contains lots of features which you will find interesting.

To download termux follow this link.
Download and install the app on your phone and then run the below commands.

pkg upgrade

To install ffmpeg, run:

pkg install ffmpeg

A storage access permission is required for Termux in order for it to be able to access shared storage (such as /sdcard or /storage/emulated/0). Since it is not required for the program to operate normally, access to it is not provided automatically, and the user is not prompted to authorize it when the application is started.

Now, grant permission to Termux to access your storage device by running.

termux-setup-storage

Next, navigate into the folder that has your large video file which you want to compress.

$ cd storage/shared/AzRecorderFree/

Then run the below command:

ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4

Replace "input.mp4" with the name of your large video file.
You can also replace the output name with something else, doesn't matter.

It will take a couple of minutes for FFmpeg to run the conversion.

Enjoy.

Top comments (2)

Collapse
 
1day1codeline profile image
1Day1CodeLine

It’s pretty cool solve problem but I am a bit the fact that is not available on IOS 😄
Thank’s to you it’s awesome 👏🏻

Collapse
 
sparklesix profile image
Sixtus Anyanwu

So sorry about that. Guess its one of the few perks of Andriod. 😅