Termux is probably the best terminal emulator available for Android. Apart from being a terminal emulator, it also provides its own isolated Linux environment and offers a wide variety of pre-built Linux packages. These packages can be downloaded and installed through the APT tool (Advanced Package Tool), known from Debian and Ubuntu desktop Linux distributions. Today we’ll see how we can convert media files using FFmpeg and Termux.
There are many exciting things that an Android user can do with Termux. One of them is using FFmpeg, the swiss army knife of media manipulation tools on Linux, to convert media (audio and video) to different formats. Although a plethora of media converter apps are already available on the Google Play Store, this console based solution gives full control over the codec parameters and enables conversions between the 100+ different file formats supported by FFmpeg.
Convert Media Files Using FFmpeg and Termux
Here is what you need to do to easily convert your media files using FFmpeg and Termux:
1. Install Termux App
[googleplay url=”https://play.google.com/store/apps/details?id=com.termux”/]2. Install the FFmpeg package
- Open the Termux app from the launcher. You will be introduced to a console environment.
- Enter the following command:
pkg install -y ffmpeg
3. Enable Storage Access for Termux
By default, Termux does not have access to the Android storage. To enable access to storage, enter the following command in the app’s console:
termux-setup-storage
If you are on Android 6.0 or later, a popup will show asking for permissions. Click Allow.
After the command exits, Internal shared storage will be accessible under ~/storage.
Currently (8/2017), Termux does not support accessing external storage. You will need to place the files you are willing to edit on the internal shared storage of your device.
Also read:ย Google Assistant Shortcuts – Everything You Need To Know
4. Convert your media files
The steps above only need to be carried out once. After that, you can open the Termux app, navigate to the media location and use the FFmpeg command to convert your media files.
For example, let’s convert a FLAC audio file found under the music folder on the internal shared storage of the device.
- To get to the folder, we will give the following command:
cd ~/storage/music
- The following command will show a list of the files under the music directory:
ls
The file we need to convert for this tutorial is myfile.flac.
- The following command will convert the file to Ogg format, using the opus codec:
ffmpeg -i myfile.flac -c:a opus myfile.ogg
The new file will be saved in the same directory as the original.
Recommended for you:ย How to Convert Videos into GIFs on PC and Android
Let’s take a look at the previous command:
The parameter after -i (myfile.flac) is the input file name
The last parameter (myfile.ogg) is the output filename. The filename extension (.ogg) instructs the FFmpeg tool to use the Ogg Open File Format.
The parameter after -c:a is the codec to be used for audio encoding. On video files, a similar parameter should also be given for the video codec. This should be given in the form -c:v video_codec.
In another example, to convert an mp4 video named original_video.mp4 to MKVย file format named converted_video using h264 encoding for video and ac3 encoding for audio, the command should turn into something like:
ffmpeg -i original_video.mp4 -c:a ac3 -c:v h264 converted_video.mkv
You can find out the codec names (to put next to -c:a and -c:v) and file formats supported by FFmpeg using the following commands:
ffmpeg -formats
ffmpeg -codecs
Each supported format and codec can have the letter “D”, “E” or both next to it. “D” stands for decoding support (FFmpeg can convert from this format/codec) and “E” stands for encoding (FFmpeg can convert to this format/codec).
You can learn more about the possible parameters of the FFmpeg command line by reading its Official Documentation.
Finally, for advanced users, each codec has its own configurable options, which can be changed from the command line. To find all the properties for each codec, take a look at the FFmpeg Codecs Documentation.
Notice
FFmpeg uses software codec implementations. All work will be done on the application processor. In some cases (for example conversions of HD videos, with high bit-rates), the process might take really long and the device responsiveness might drop. This depends on the device capabilities.
Read next:ย Download YouTube Videos on Android with youtube-dl Commands
Join The Discussion: