Skip to content

publish

Function · tgrtmp 0.3.0

Publish source to url with key and hand back a Player. The source can be a path, an open binary file, or a live byte stream (any .read(n) handle that only grows, such as a downloader's output). A live source cannot be paused from the outside; it keeps producing. By default (buffer_size=0) nothing is buffered: pause freezes the picture, and resume jumps to the live edge. Give buffer_size some bytes and the source is drained into a rolling window instead, so a pause holds its point while the live edge keeps filling it, like a DVR. Tuning buffer_size: it is how far behind the live edge you can afford to be. The held time is roughly buffer_size / bitrate, e.g. 48 MB holds about five minutes of a 1.3 Mbps stream or one minute of 6 Mbps. A pause that outlives the window resumes from the oldest buffered data and says so in the log. With loop=True a finite source restarts from the beginning at EOF instead of holding its last frame: a movie becomes an endless channel. Each pass continues the same stream timeline, so viewers see one uninterrupted stream; player.stats["loops"] counts the passes. player.stats is one dict with everything a dashboard needs (position, paused, muted, connected, bitrate_kbps, frames_sent, ...), and player.bitrate_kbps is the stream throughput on its own. The extra options go to the Player (freeze_interval, lookahead_ms, verify_tls, and on_connection, which is called as on_connection(player, connected) whenever a session goes live or drops).

publish()(
  source: ,
  url: ,
  key: ,
  buffer_size: = 0,
  log: = None,
  options:
) → <class 'tgrtmp.player.Player'>