Using FFmpeg to convert media to H.264

Are you using an open-source media server like Plex, Jellyfin, or Kodi and having trouble with file playback on some movie formats? Use FFmpeg to convert unusable formats to high-quality H.264 files quickly. FFmpeg is perfect for media servers running on low-powered CPUs or single-board computers like the Raspberry Pi.

Use Case

In my use case, I have an extensive movie collection that I stream on my home network via Plex. However, I was going on a 4-month trip, and I wanted to take my movie collection and set it up at my new location, allowing my friends to stream my content as we would share the same network. I needed to have a small footprint, and I did not want to use my Plex Pass account for all my friends. I decided to use an 8TB hard drive, which I copied my collection to, a single-board computer (Raspberry Pi), and the open-source media server software Jellyfin.

Jellyfin is a GREAT customizable interface, and it was fun to put together and learn about all the awesome plugins and extras it can do. I am not writing a tutorial on setting up Jellyfin, but I will post how I customized and set up this portable media server later. I don’t think I will be giving up my home Plex Media Server set up, as I have a lot of time invested (and money) in this now, but if I started over, I would consider Jellyfin at the top of the list.

Plex seems to do an excellent job of ensuring it can playback almost all audio and video codecs. My movie collection has many different file formats, such as: avi, mp4, mkv, etc. not all of these formats were playable on other media servers. Servers like Kodi and Jellyfin seem to have limitations on their supported file types. However, converting the files to the new lightweight media players was a good option for me. To do this, I used the compute of the single-board computer to convert the files to H.264 using ffmpeg.

What is FFmpeg

FFmpeg is a super-fast command-line tool that converts multimedia files between formats. FFmpeg can decode, encode, transcode, mux, demux, stream, filter, and play anything. It supports the most obscure ancient formats up to the cutting edge. It is also highly portable: FFmpeg compiles and runs across Linux, Mac OS X, Microsoft Windows, the BSDs, etc. You can learn more about it here: https://ffmpeg.org/ and get a deeper dive into the versatility and depth of what this open-source tool can provide.

Conversion Process

If you don’t have FFmpeg installed, it is a quick install. I installed FFmpeg on my Linux machine, and it is as simple as:

sudo apt install ffmpeg

Or via Snap:

sudo snap install ffmpeg

If you want to install it on Windows or Mac, then visit https://ffmpeg.org/download.html for details. Additionally, you will want a .7z decompression program like 7zip or WinRAR.

Converting your media files is as simple as this:

ffmpeg -i input.avi output.mp4 

In my case, I needed to get deeper into the format, preset, and audio codecs to ensure high-quality play on a single-board computer for H.264. I used the following:

ffmpeg -i '3 Days Gone (2008).avi' -c:v libx264 -crf 19 -preset slow -c:a aac -b:a 192k -ac 2 '3 Days Gone (2008).mp4'

What’s this doing? This command uses FFmpeg to take the input file: 3 days ago.avi using the -c:v tag to specify video streaming and its codec libx264. The constant rate factor (crf 19) is a specification for lossless. Selecting a slow preset will provide better compression. Finally, I specify the audio codec and its bit rate along with the new filename and format. This wiki will also help understand the FFmpeg options used in converting to H.264: https://trac.ffmpeg.org/wiki/Encode/H.264

Here are some screenshots of the conversion process:

Command Screenshot

Conversion Example

Conversion Process 2Conversion Process 3Can I use a program like handbrake? You can. FFmpeg is a quick, lightweight command line process that does not need a separate application installation and can run directly on the media server to convert your files. I use it for existing files on my media server. If I downloaded new content, the ripping software could do both simultaneously.

This post is a straightforward overview of quickly converting existing media files. Have fun with it! FFmpeg has outstanding capabilities and can do much more than the simple conversion outlined above.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.