How to Use FFmpeg in Termux to Convert Video Files
How to Use FFmpeg in Termux to Convert Video Files
Want to turn your Android phone into a capable video conversion and compression tool? You can. With Termux and FFmpeg, you don't need a desktop computer to transcode media. Whether you're freeing up storage, prepping a clip for social media, or converting a raw recording to MP4, the command line gives you full control over the process.
This guide covers exactly how to set up and use FFmpeg in Termux — from installation to real conversion commands, compression, and fixing the errors people hit most often.
Quick Summary: FFmpeg in Termux
- What is it? FFmpeg is a widely used command-line tool for processing multimedia files. Termux is a terminal emulator that gives Android a real Linux command-line environment.
- Does it run locally? Yes — once installed, FFmpeg runs entirely offline using your phone's CPU.
- Main benefit: Full control over resolution, bitrate, codecs, and container formats, without ads or uploading your files anywhere.
What Is FFmpeg and Why Run It in Termux?
FFmpeg is a standard tool for processing video and audio — it handles decoding, encoding, transrating, muxing, demuxing, streaming, and filtering. Many popular media players and editing tools rely on its libraries under the hood.
Termux brings a Linux environment to Android without requiring root access. Combined with FFmpeg, you get genuinely capable media processing on your phone. Unlike many free video converter apps that add watermarks or cap your export resolution, running FFmpeg directly in Termux means no ads, no hidden limits, and everything stays on your device.
Prerequisites and Setup
Before running your first conversion command, get your environment ready. If you haven't installed Termux yet, start with our guide on how to install Termux on Android — install from F-Droid or GitHub, since these are the official, actively maintained sources (the Google Play Store build has historically lagged behind or gone unmaintained).
Installing FFmpeg
Open Termux and run the following commands to update your packages and install FFmpeg:
pkg update && pkg upgrade -y
pkg install ffmpeg -y
Installation time depends on your internet speed and device. Once it finishes, verify it worked:
ffmpeg -version
If you see build configuration details and a list of supported codecs, you're ready to go. If the package won't install at all, see our guide on fixing "Unable to Locate Package" errors in Termux.
How to Use FFmpeg in Termux: Basic Conversions
To convert files, Termux needs access to your phone's storage. If it doesn't have access yet, run:
termux-setup-storage
This creates a storage folder in your Termux home directory, and your internal storage becomes accessible at ~/storage/shared/. For a full walkthrough of how Termux storage access works, see our Termux storage guide.
Converting an MKV File to MP4
Suppose you have a video called input.mkv in your Download folder and want an MP4 version:
ffmpeg -i ~/storage/shared/Download/input.mkv ~/storage/shared/Download/output.mp4
Here's what each part does:
ffmpeg— calls the program.-i [path]— specifies the input file.- The final path — tells FFmpeg where to save the converted file and what to name it.
Compressing Video with FFmpeg in Termux
File sizes get out of hand quickly, especially with 4K recordings. To shrink a file for sharing or storage without destroying quality, use the CRF (Constant Rate Factor) method with the H.264 codec:
ffmpeg -i ~/storage/shared/Download/large_video.mp4 -vcodec libx264 -crf 28 ~/storage/shared/Download/compressed_video.mp4
Real Use-Case Example
Say you have an 800MB family video and need to send it through a messaging app with a strict file size limit. Running the compression command above will shrink it significantly.
What does -crf 28 mean?
- CRF values range from 0 to 51 for libx264.
- Lower values mean better quality and larger files.
- Higher values mean lower quality and smaller files.
- A value of 23 is libx264's default balance, while 28 gives noticeably stronger compression with quality that's still acceptable for casual mobile viewing.
Termux FFmpeg vs. Android GUI Converter Apps
Should you use a graphical app or stick to the terminal? Here's a straightforward comparison.
| Feature | Termux FFmpeg | Standard Android Video Converters |
|---|---|---|
| Cost & ads | Free, open-source, no ads | Often free with ads or paywalls |
| Watermarks | None | Common on free tiers |
| Customization | Extensive — codecs, bitrates, filters | Limited to preset toggles |
| Learning curve | Requires typing commands | Tap-and-go interface |
| Privacy | Fully local processing | Some apps upload files to remote servers |
Troubleshooting Common FFmpeg Errors in Termux
1. "Permission denied"
Cause: Termux doesn't have access to your device's shared storage yet.
Fix: Run termux-setup-storage and tap "Allow" on the permission prompt. If you still hit permission issues, our Termux storage permission fix guide covers this in more depth. Double-check your paths point to ~/storage/shared/.
2. "No such file or directory"
Cause: A typo in the filename, or the file is in a different folder than you think.
Fix: Run ls ~/storage/shared/Download/ (or whichever folder applies) to confirm the exact filename and extension before running your command.
3. Process killed unexpectedly (out of memory)
Cause: Android can terminate heavy background processes when RAM runs low, which happens often when transcoding large 1080p or 4K files on budget phones. In some cases repeated crashes can also point to a broader Termux stability issue — see our guide on fixing Termux black screen or crash problems if this happens outside of heavy encoding too.
Fix: Close background apps before running the command, encode shorter clips, or use a faster preset to reduce memory and CPU pressure.
Tips for Faster Conversions on Mobile
- Keep your screen on during long encodes. Android aggressively throttles background CPU tasks, so keep Termux in the foreground while large files process.
- Use faster software presets when needed. By default, Termux's FFmpeg build encodes using the CPU (software encoding) rather than your phone's hardware video encoder — true hardware-accelerated encoding via Android's MediaCodec is experimental and inconsistent across devices in Termux's FFmpeg build. If a compression is too slow, a flag like
-preset ultrafastspeeds up CPU encoding at the cost of a larger output file, rather than turning on hardware acceleration. - Trim before converting. If you only need part of a long video, trim it first with FFmpeg's
-ssand-toflags to save significant processing time.
Frequently Asked Questions
Can I use FFmpeg in Termux offline?
Yes. Once the initial package download is complete, FFmpeg runs entirely offline on your device — no internet connection is needed to convert or compress files.
Does using FFmpeg in Termux require root access?
No. Termux runs in a user-space sandbox, so you can install packages and convert videos without rooting your device.
How do I stop a running FFmpeg process?
Press Ctrl + C in your Termux session to cancel the active command immediately.
Conclusion
Video conversion on your phone opens up real flexibility once you're comfortable with a few commands. Running an FFmpeg in Termux compression command takes only a few seconds once you know the syntax, and you keep full ownership of your files without watermarks or slow cloud converters.
Want to build on this? Check out our guide on essential Termux commands for beginners to get more comfortable navigating the terminal, or learn how to download YouTube videos using Termux if you want source clips to convert.
Join the conversation