Progress#

Console output: logging, and tqdm bars fed by the ffmpeg -progress stream.

class remote_compression.progress.BatchBar(total, enabled=True)[source]#

Whole-batch bar: one tick per file, with status counters as postfix.

Parameters:
  • total (int) – Number of files in the batch.

  • enabled (bool) – Draw the bar.

advance(summary)[source]#

Tick one file and refresh the counters from a BatchSummary.

class remote_compression.progress.FileBar(name, duration=None, enabled=True)[source]#

Per-file encode bar: seconds encoded out of the file duration.

Parameters:
  • name (str) – File name (bar label).

  • duration (float, optional) – Total duration in seconds; without it the bar shows raw progress.

  • enabled (bool) – Draw the bar (disable on non-TTY or --no-progress).

remote_compression.progress.LOG_RETENTION_DAYS = 30#

Age (days) beyond which per-run log files are purged at startup.

class remote_compression.progress.ProgressStream(callback=None)[source]#

Incremental parser of the ffmpeg -progress stream.

Feed it arbitrary text chunks (they may split lines anywhere); it tracks the encoded position in seconds and the encoding speed, and invokes callback at the end of each progress block (the progress= line, ~2 per second).

Parameters:

callback (callable, optional) – Called with the stream itself after each progress block.

seconds#

Current output position, in seconds (never negative).

Type:

float

speed#

Encoding speed factor (e.g. 1.19), when known.

Type:

float, optional

feed(chunk)[source]#

Consume one decoded chunk of -progress output.

class remote_compression.progress.TqdmHandler(level=0)[source]#

Logging handler routed through tqdm.tqdm.write() so bars stay intact.

emit(record)[source]#

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

remote_compression.progress.bars_enabled(no_progress=False)[source]#
Returns:

Whether progress bars should be drawn: not explicitly disabled, and stderr is a real terminal.

Return type:

bool

remote_compression.progress.human_size(n)[source]#
Parameters:

n (int) – Byte count.

Returns:

Human-readable size.

Return type:

str

Examples

>>> human_size(0)
'0 B'
>>> human_size(2048)
'2.0 KB'
>>> human_size(3 * 1024**3)
'3.0 GB'
remote_compression.progress.logs_dir()[source]#
Returns:

Directory of the per-run log files.

Return type:

Path

remote_compression.progress.parse_progress_line(line)[source]#

Parse one line of ffmpeg -progress output.

Parameters:

line (str) – A key=value line.

Returns:

(key, value), or None for anything else.

Return type:

tuple or None

Examples

>>> parse_progress_line('out_time_us=4520000')
('out_time_us', '4520000')
>>> parse_progress_line('speed=1.19x')
('speed', '1.19x')
>>> parse_progress_line('not a progress line') is None
True
remote_compression.progress.setup_logging(verbosity=0)[source]#

Configure the rcomp logger: console handler at the requested verbosity, plus a DEBUG file handler on a fresh per-run file (parallel rcomp processes never share a log file, so there is no rotation and no locking).

Parameters:

verbosity (int) – Negative for quiet (warnings only), 0 for normal (one line per file), positive for verbose (full commands, ffmpeg stderr).