rffmpeg: remote SSH FFmpeg wrapper tool
Find a file
Joshua Boniface f317fd6ef7 Add README
2019-10-19 18:10:05 -04:00
README.md Add README 2019-10-19 18:10:05 -04:00
rffmpeg.py Add initial rffmpeg 2019-10-19 17:54:20 -04:00
rffmpeg.yml.sample Add initial rffmpeg 2019-10-19 17:54:20 -04:00

rffmpeg

rffmpeg is a remote FFmpeg wrapper used to execute FFmpeg commands on a remote server via SSH. It is most useful in situations involving media servers such as Jellyfin (our reference user), where one might want to perform transcoding actions with FFmpeg on a remote machine or set of machines to better handle the load.

Usage

  1. Create the directory /etc/rffmpeg.

  2. Copy the rffmpeg.yml.sampel file to /etc/rffmpeg/rffmpeg.yml and edit it to suit your needs.

  3. Install rffmpeg.py somewhere useful, for instance at /usr/local/bin/rffmpeg.py.

  4. Edit your media program to use the rffmpeg.py binarry instead of the standard ffmpeg binary.

  5. Profit!

Full setup

This example setup is the one I use for rffmpeg, involving a Jellyfin server (jf1) and a remote transcode server (gpu1).

  1. Prepare the remote transcode server. This involves the following steps:

  2. Install any required tools or programs to make use of hardware transcoding. This is optional if you only plan to use software (i.e. CPU) transcoding.

  3. Create a temporary transcoding directory somewhere on the system. Ideally, this should be fast scratch storage with no persistence required. In my case I use a pair of RAID-0 SSDs, though you could use a ramdisk if you have sufficient RAM. For my purposes, I put this directory at /var/transcode and mount my SSD RAID there.

  4. Create a user to accept SSH connections in and run the FFmpeg commands. I use a user called jellyfin with a home directory of /var/lib/jellyfin, identical to the user that is created by the Jellyfin server itself - this is important for the directory layout to work.

  5. Ensure the temporary transcoding directory is owned by the new user.

  6. Create a symlink from the user's home directory to the temporary transcoding directory. This much match the Jellyfin file layout to preserve paths. For insance, if your transcoding-temp directory on the Jellyfin server is at /var/lib/jellyfin/transcoding-temp, the symlink must exist at the same location on the transcode server.

  7. Similarly to the transcoding directory, ensure your media volume is mounted on the transcode server at the same location as on the Jellyfin server.

  8. Install an FFmpeg binary, in my case the jellyfin-ffmpeg package, on the transcode server.

  9. Install the NFS kernel server, and set up an export of your temporary transcoding directory such that the Jellyfin server can mount it.

  10. On your Jellyfin server, create a new SSH private keypair owned by the Jellyfin service user.

  11. Install the public key of the new SSH private keypair under the remote user on the transcode server. Verify that SSH is successful from the Jellyfin server to the transcode server as the selected user.

  12. Install the NFS client, and mount the temporary transcoding directory from the remote server to your transcoding-temp directory as set in Jellyfin.

  13. Install the rffmpeg program as detailed above.

  14. In Jellyfin, set the rffmpeg.py binary as your "FFmpeg path".

  15. Try running a transcode and verifying that the rffmpeg program works as expected. The flow should be:

    1. Jelyfin calls rffmpeg.py with the expected arguments.

    2. FFmpeg begins running on the transcode server; the file paths should all be valid there as they would be on the Jellyfin machine.

    3. The FFmpeg process writes the output files to the NFS-exported temporary transcoding directory.

    4. Jelyfin reads the output files from the NFS-mounted temporary transcoding directory and plays back normally.