ffmpegfs Is A FUSE-Based Filesystem For Transcoding Video And Audio On The Fly When Opened

I recently stumbled across ffmpegfs and found it to be quite useful, so I thought I'd make a post about it, especially since there are no other articles about it.

ffmpegfs auto transcoding

ffmpegfs is a free and open source FUSE-based read-only transcoding filesystem which converts audio and video formats on the fly when opened and read. It supports many formats, including MP4, WebM, OGG, MP3, OPUS, MOV, ProRes (a MOV container for Apple Prores video & PCM audio) and WAV, among others.

This is useful in case you have many files in your media collection that can't be directly played by some hardware or software (e.g. DaVinci Resolve, which has limited codecs support in the free Linux version) - instead of transcoding the whole media collection you could use ffmpegfs to transcode the files on the fly, when they are accessed / played. You may also use this to easily transcode files: just drop some files in the folder that you've used as an input directory for ffmpegfs, then copy the files from the ffmpegfs output folder and the resulted files will be transcoded to the format you've specified for ffmpegfs.

ffmpegfs is written in C and C++ and makes use of the FUSE libraries. It also needs FFmpeg to work. Libav was also supported, but is currently disabled because it seems it does not work properly. The Libav support may be dropped soon.

This is how this tool works. The ffmpegfs command mounts the directory IN_DIR (which contains your media collection) on OUT_DIR. Accessing OUT_DIR shows the contents of IN_DIR, with all supported media files transparently renamed and transcoded to one of the supported target formats upon access.

ffmpegfs features:

  • Smart transcoding can create different output formats for video and audio files. For example, video files can be converted to MOV and audio files to AIFF. Specify the video and audio file type separated by a + sign (e.g.: --desttype=mov+aiff)
  • "Auto copy" performs intelligent stream copy, e.g., if transcoding a transport stream that already represents a H264 video and/or AAC audio stream it would be possible to simply repackage it to a mp4 container without recoding. Autocopy options: OFF (never copy streams, transcode always), MATCH (copy stream if target supports codec), MATCHLIMIT (same as MATCH, only copy if target is not larger, transcode otherwise), STRICT (copy stream if codec matches desired target, transcode otherwise), and STRICTLIMIT (same as STRICT, only copy if target is not larger, transcode otherwise)
  • Built-in transcoding profiles optimized for web browser like Firefox, MS Edge and IE 11+, Chrome, Safari, Opera or Maxthon
  • Specify video and audio bitrate, video width and height, deinterlace, enable album art into output file, and more
  • Cache with various options
  • DVD / Blu-ray support
  • Specify the number of transcoder threads

Microsoft Windows support is planned for future versions.

Other FFmpeg-related articles from Linux Uprising that you might like:

Let's take a look at a few ffmpegfs examples.

#1 Use ffmpegfs to transcode all videos from the ~/Videos folder to ~/ffmpegfs into WebM (allow_other allows all users, including root, to access the files; ro mounts it as read only):

ffmpegfs --desttype=webm ~/Videos/Movies ~/ffmpegfs -o allow_other,ro

By default, --desttype is set to mp4.

Note that the allow_other FUSE option by default can only be used by root. You must either run ffmpegfs as root or better add user_allow_other to /etc/fuse.conf.

#2 Use ffmpegfs to transcode all music files from ~/Music using ~/ffmpegfs as the output directory, to MP3 with an audio bitrate of 256K:

ffmpegfs --audiobitrate=256K --desttype=mp3 ~/Music ~/ffmpegfs2 -o allow_other,ro

#3 Transcode all video files from ~/media to MOV and all audio files from the same folder to AIFF, to ~/transcoded as the output folder, with the log level set to DEBUG (the log messages are outputted to stderr by default in debug mode), and with the case residing in /tmp/cache:

ffmpegfs --desttype=mov+aiff --log_maxlevel=DEBUG --cachepath=/tmp/cache ~/media ~/transcoded

You may also mount the filesystem via /etc/fstab. For more on using ffmpegfs, see its help (ffmpegfs --help) and man page (man ffmpegfs). You can also visit its online documentation, though note that some bits are outdated.

Install ffmpegfs

ffmpegfs is not available in the official repositories for most Linux distributions. Debian recently added ffmpegfs to the Bullseye and Sid repositories, and as a result, this package is now also available in the Ubuntu 20.04 repositories and on Linux distributions based on it, like Pop!_OS 20.04. Install it on these Linux distributions from the repositories:

sudo apt install ffmpegfs

For Arch Linux and Manjaro, you can get ffmpegfs from the Arch User Repository (AUR), where it's available as either the latest stable version or the latest code from Git.

On other Linux distributions you'll need to install it from source. See the official installation instructions for details.