Compress and Convert Videos with Command Line

Vladimir Vovk - Jul 14 - - Dev Community

ffmpeg

Often we have videos of different formats and resolutions from our phones and cameras, and also, from our friends and family. Sometimes these videos are uncompressed, so they take up much space.

There are many methods how we can solve this problem. But here, I would like to tell you about FFmpeg. It is a free and open-source tool available for all major operating systems. FFmpeg is fast and gives good results in compression, changing formats, and resolution.

To compress our favorite cats.mov video and convert it to mp4 format we need to run:

ffmpeg -i cats.mov cats.mp4
Enter fullscreen mode Exit fullscreen mode

Pretty easy, right? The only downside of this command is that ffmpeg does not give us user-friendly UI. There are no progress bar or estimated time to finish.

ffmpeg

menc

Introducing menc (media encoder) a small "wrapper" utility around ffmpeg which gives a nicer UI and can help to process several files more easily.

To compress the same cats.mov video with menc we need to run:

npx menc cats.mov
Enter fullscreen mode Exit fullscreen mode

menc

It will use the mp4 format by default and create a cats.mp4 file in the same folder.

Please ensure you have Node.js installed on your machine.

If you want to extract audio or change resolution it can be done with the --format argument. For example, the following command will compress our video and change the resolution to full HD.

npx menc -f fhd cats.mov
Enter fullscreen mode Exit fullscreen mode

You can find all supported formats with --help argument.

npx menc --help
Enter fullscreen mode Exit fullscreen mode

menc --help

To convert several files we can use the wildcard character. For example, if we have more than one mov file we can process them all with only one command:

npx menc *.mov
Enter fullscreen mode Exit fullscreen mode

And if we want to write results into a separate my_compressed_mp4_files folder we can do that with the --dir argument.

npx menc -d my_compressed_mp4_files *.mov
Enter fullscreen mode Exit fullscreen mode

Please try menc, give it a star 🌟, and happy hacking! 💻

Credits

Photo by Alan Alves on Unsplash

. . . . . . . . . . . . .
Terabox Video Player