When a pipe symbol is introduced in any ffmpeg flag bash tries to pipe
the output to the second half of the command instead of passing it to
ffmpeg. Therefore it is necessary to escape
Fall back to using the local ffmpeg binary (at the same path as the
remote system) if we are unable to reach a remote server. Prevents
rffmpeg from getting stuck if it can find no valid remote servers.
Allow rffmpeg to determine if a host is "bad", i.e. if the SSH
connection times out or fails, for instance due to an unreachable host
down for maintenance. In such a case, instead of exiting abruptly, we
will mark the host as "bad" in the current state file, and then retry
the whole process, skipping the bad hosts. If other rffmpeg processes
start while the current one is still running, they will also treat the
host as "bad", until the original process ends at which point the
statefile marking it bad will be removed and it will be retried by
future processes. This helps ensure that redundancy of transcode hosts
can actually be achieved, as before if the first host was down, the
process would simply fail, retry, and then fail again if the down host
was first in the list.
This required some major refactoring of the code, including
functionalizing various elements of the process as well as adding an
infinite loop to the main execution in order to keep looping through
hosts after marking one as bad.
Without the full path, various alternative uses of ffmpeg (e.g. subtitle
extraction, image extraction) were not working. Recommend exporting the
entire Jellyfin data directory instead and make note that changing path
locations may alter this. Also includes some other tweaks to make this
work (e.g. putting the ssh public key step earlier in the NFS export).
This caused some issues with ffprobe if the remote command ever sends
something to stderr (which then gets sent to stdout locally, causing
format issues).
However, from some testing, this was original though needed to ensure
the 'q' sent to FFmpeg was sent directly over the pipe, but this seems
to not be required (any longer?).
From top to bottom:
1. Use dict comprehension instead of try/catch
2. Never output anything to stdout; this breaks Jellyfin's parsing
3. Print more helpful debug messages including PID
4. Fix broken handling of full command paths vs. basenames
5. Use stdout=stdout for ffprobe
6. Only quote arguments that need it (bad shell chars)