Command#

Pure logic: decide what to do with a file and build the ffmpeg command.

remote_compression.command.FORBIDDEN_CHARS = {'\n', '\r', '!', '"', '$', '%', '&', ';', '<', '>', '^', '`', '|'}#

Characters banned from remote command lines (cmd.exe expansion, redirections, separators, sh substitutions). Remote paths are hex names generated by us, and option tokens are fixed ASCII, so hitting this guard means a programming error.

class remote_compression.command.FfmpegPlan(tokens: tuple)[source]#

A ready-to-run ffmpeg command with SOURCE/TARGET placeholders.

tokens#

Full argv, with SOURCE and TARGET each appearing exactly once.

Type:

tuple of str

argv(source, target)[source]#

Substitute placeholders and return the local execution form.

Parameters:
  • source (Path or str) – Input file.

  • target (Path or str) – Output file.

Returns:

Argument list for subprocess.run() (never a shell).

Return type:

list of str

command(r_source, r_target, binary=None)[source]#

Substitute placeholders and return the remote execution form.

Parameters:
  • r_source (str) – Remote input path, relative to the SFTP home (e.g. .rcomp/<hex>.mp4).

  • r_target (str) – Remote output path, same convention.

  • binary (str, optional) – Explicit ffmpeg path replacing the leading ffmpeg token (remote_ffmpeg setting). Subject to the same safety guards.

Returns:

A single command line safe for both POSIX shells and cmd.exe.

Return type:

str

Raises:

ValueError – If any token or path is non-ASCII or contains a forbidden character. The original file name never travels through a remote shell (only through SFTP), so this cannot be triggered by user data.

class remote_compression.command.Plan(todo: bool, transcode: bool, resize: bool, warnings: tuple = ())[source]#

What has to be done for a given file.

todo#

Whether any work is needed. A compliant file is never remuxed.

Type:

bool

transcode#

Whether the video codec must change.

Type:

bool

resize#

Whether the video must be downscaled.

Type:

bool

warnings#

Human-readable warnings (e.g. a subtitle stream that will be dropped).

Type:

tuple of str

remote_compression.command.SOURCE = '{source}'#

Sentinel tokens substituted at execution time.

remote_compression.command.build_ffmpeg_command(info, settings)[source]#

Build the full ffmpeg command for a file.

Parameters:
  • info (MediaInfo) – Probe result for the file.

  • settings (Settings) – Target settings.

Returns:

Command with placeholders, usable locally (FfmpegPlan.argv()) or remotely (FfmpegPlan.command()).

Return type:

FfmpegPlan

Notes

-nostats -progress pipe:1 replaces the stderr chatter with a machine-readable key=value stream on stdout: it feeds the progress bar and doubles as the liveness heartbeat for remote execution.

remote_compression.command.evaluate(info, settings)[source]#

Decide what has to be done for a file.

Parameters:
  • info (MediaInfo) – Probe result for the file.

  • settings (Settings) – Target settings.

Returns:

Work description. todo is True iff a transcode or a resize is needed; a compliant file is never remuxed to the target container.

Return type:

Plan

remote_compression.command.subtitle_args(subtitles)[source]#

Build the subtitle handling arguments for an mkv target.

Parameters:

subtitles (tuple of SubtitleStream) – Subtitle streams of the source.

Returns:

  • list of str – ffmpeg tokens: per stream, copy when mkv accepts the codec as-is, srt conversion for pure-text codecs (mov_text), and an unmap for anything else. Collapsed to a single -c:s when uniform.

  • tuple of str – One warning per dropped stream.