twitchstream.outputvideo

This file contains the classes used to send videostreams to Twitch

class twitchstream.outputvideo.TwitchBufferedOutputStream(*args, **kwargs)[source]

This stream makes sure a steady framerate is kept by buffering frames. Make sure not to have too many frames in buffer, since it will increase the memory load considerably!

Adding frames is thread safe.

get_audio_buffer_state()[source]

Find out how many audio fragments are left in the buffer. The buffer should never run dry, or audio and video will go out of sync. Likewise, the more filled the buffer, the higher the memory use and the delay between you putting your frame in the stream and the frame showing up on Twitch.

:return integer estimate of the number of audio fragments left.

get_video_frame_buffer_state()[source]

Find out how many video frames are left in the buffer. The buffer should never run dry, or audio and video will go out of sync. Likewise, the more filled the buffer, the higher the memory use and the delay between you putting your frame in the stream and the frame showing up on Twitch.

:return integer estimate of the number of video frames left.

send_audio(left_channel, right_channel, frame_counter=None)[source]

Add the audio samples to the stream. The left and the right channel should have the same shape.

Parameters:
  • left_channel (numpy array with shape (k, ) containing values between -1.0 and 1.0. l can be any integer) – array containing the audio signal.
  • right_channel (numpy array with shape (k, ) containing values between -1.0 and 1.0. l can be any integer) – array containing the audio signal.
  • frame_counter (int) – frame position number within stream. Provide this when multi-threading to make sure frames don’t switch position
send_video_frame(frame, frame_counter=None)[source]

send frame of shape (height, width, 3) with values between 0 and 1

Parameters:
  • frame (numpy array with shape (height, width, 3) containing values between 0.0 and 1.0) – array containing the frame.
  • frame_counter (int) – frame position number within stream. Provide this when multi-threading to make sure frames don’t switch position
class twitchstream.outputvideo.TwitchOutputStream(twitch_stream_key, width=640, height=480, fps=30.0, ffmpeg_binary='ffmpeg', enable_audio=False, verbose=False)[source]

Initialize a TwitchOutputStream object and starts the pipe. The stream is only started on the first frame.

Parameters:
  • twitch_stream_key
  • width (int) – the width of the videostream (in pixels)
  • height (int) – the height of the videostream (in pixels)
  • fps (float) – the number of frames per second of the videostream
  • enable_audio (boolean) – whether there will be sound or not
  • ffmpeg_binary (String) – the binary to use to create a videostream This is usually ffmpeg, but avconv on some (older) platforms
  • verbose (boolean) – show ffmpeg output in stdout
reset()[source]

Reset the videostream by restarting ffmpeg

send_audio(left_channel, right_channel)[source]

Add the audio samples to the stream. The left and the right channel should have the same shape. Raises an OSError when the stream is closed.

Parameters:
  • left_channel (numpy array with shape (k, ) containing values between -1.0 and 1.0. k can be any integer) – array containing the audio signal.
  • right_channel (numpy array with shape (k, ) containing values between -1.0 and 1.0. k can be any integer) – array containing the audio signal.
send_video_frame(frame)[source]

Send frame of shape (height, width, 3) with values between 0 and 1. Raises an OSError when the stream is closed.

Parameters:frame (numpy array with shape (height, width, 3) containing values between 0.0 and 1.0) – array containing the frame.
class twitchstream.outputvideo.TwitchOutputStreamRepeater(*args, **kwargs)[source]

This stream makes sure a steady framerate is kept by repeating the last frame when needed.

Note: this will not generate a stable, stutter-less stream!
It does not keep a buffer and you cannot synchronize using this stream. Use TwitchBufferedOutputStream for this.
send_audio(left_channel, right_channel)[source]

Add the audio samples to the stream. The left and the right channel should have the same shape.

Parameters:
  • left_channel (numpy array with shape (k, ) containing values between -1.0 and 1.0. k can be any integer) – array containing the audio signal.
  • right_channel (numpy array with shape (k, ) containing values between -1.0 and 1.0. k can be any integer) – array containing the audio signal.
send_video_frame(frame)[source]

Send frame of shape (height, width, 3) with values between 0 and 1.

Parameters:frame (numpy array with shape (height, width, 3) containing values between 0.0 and 1.0) – array containing the frame.