Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Easy streaming using FFmpeg to YouTube Live, Periscope, Facebook Live, Twitch, ...

Project Description

.. image::

.. image::

.. image::
:alt: Python versions (PyPI)

.. image::
:alt: Distribution format (PyPI)

.. image::
:alt: Maintainability

Python scripted livestreaming using FFmpeg

Streams to one or **multiple** streaming sites simultaneously.
FFmpeg is used from Python ``subprocess`` to stream to Facebook Live, YouTube Live, Periscope, Twitch, Mixer, Ustream, Vimeo and more for streaming broadcasts.
The Python scripts compute good streaming parameters, and emit the command used so you can just copy and paste in the future if you wish.
Works on any OS (Mac, Linux, Windows).
Uses an ``.ini`` file to adjust all parameters.

.. image:: doc/logo.png
:alt: PyLivestream diagram showing screen capture or webcam simultaneously livestreaming to multiple services.

:FFmpeg: >= 3.0 required
:Python: >= 3.5 required

.. contents::


python -m pip install -e .

You can skip past this section to "stream start" if it's confusing.
The defaults might work to get you started.

The ``stream.ini`` file contains parameters relevant to your stream.
The ``[DEFAULT]`` section has parameters that can be overriden for each site, if desired.

* ``screencap_origin``: origin (upper left corner) of screen capture region in pixels.
* ``screencap_res``: resolution of screen capture (area to capture, starting from origin)
* ``screencap_fps``: frames/sec of screen capture
* ``webcam_res``: webcam resolution -- find from ``v4l2-ctl --list-formats-ext`` or webcam spec sheet.
* ``webcam_fps``: webcam fps -- found from command above or webcam spec sheet
* ``audiofs``: audio sampling frequency. Typically 44100 Hz (CD quality).
* ``preset``: ``veryfast`` or ``ultrafast`` if CPU not able to keep up.

Next are ``sys.platform`` specific parameters.
Find webcam name by:

* Windows: ``ffmpeg -list_devices true -f dshow -i dummy``
* Mac: ``ffmpeg -f avfoundation -list_devices true -i ""``
* Linux: ``v4l2-ctl --list-devices``

Seek help in FFmpeg documentation, try capturing to a file first and then update ``stream.ini`` for your ``sys.platform``.

* ``exe``: override path to desired FFmpeg executable. In case you have multiple FFmpeg versions installed (say, from Anaconda Python).

Finally are the per-site parameters.
The only thing you would possibly need to change here is the ``server`` for best performance for your geographic region.
The included ``stream.ini`` is with default servers for the Northeastern USA.

Stream Start

YouTube Live

1. `configure <>`_ YouTube Live.
2. Run Python script and chosen input will stream on YouTube Live.


python stream.ini youtube

Facebook Live

1. configure your Facebook Live stream, get stream ID from ` <>`_
2. Run Python script for Facebook with chosen input


python stream.ini facebook


1. create a new stream by EITHER:

* from phone Periscope app, go to Profile -> Settings -> Periscope Producer and see your Stream Key. The "checking source" button will go to "preview stream" once you do step #2.
* from computer web browser, go to ` <>`_ and Create New Source.
2. Run Python script for Periscope with chosen input


python stream.ini periscope

I prefer using the Phone method as then the phone is a "second screen" where I can see if the stream is lagging, and if I "leave broadcast" and come back in, I can comment from my phone etc.


1. create stream from `Twitch Dashboard <>`_
2. Run Python script for Twitch with chosen input

If you are not in the Northeast US, edit `stream.ini` to have the `closest server <>`_.


Due to the complexity of streaming and the non-specific error codes FFmpeg emits,
the default behavior is that if FFmpeg detects one stream has failed, ALL streams will stop streaming and the program ends.

* ``stream.ini`` is setup for your computer and desired parameters
* ``site`` is ``facebook``, ``periscope``, ``youtube``, etc.
* For ```` and ````, more than one ``site`` can be specified for simultaneous multi-streaming

Audio is included::

python stream.ini site(s)

Stream to multiple sites, in this example Periscope and YouTube Live simultaneously::

python stream.ini youtube periscope

Screen Share Livestream
Audio is included::

python stream.ini site(s)

Stream to multiple sites, in this example Periscope and YouTube Live simultaneously::

python stream.ini youtube periscope

File Input

Loop single video endlessly

python stream.ini site videofile

several video files
Glob list of video files to stream::

python stream.ini site path pattern

-loop optionally loop endlessly the globbed file list

stream all videos in directory
Example: all AVI videos in directory ``~/Videos``::

python stream.ini youtube ~/Videos "*.avi"

stream endlessly looping videos
Example: all AVI videos in ``~/Videos`` are endlessly looped::

python stream.ini youtube ~/Videos "*.avi" -loop

stream all audio files in directory
Glob list of video files to stream.
Must include a static image (could be your logo)::

python stream.ini site path pattern -i image

path path to where video files are
pattern e.g. ``*.avi`` pattern matching video files
-i filename of image to use as stream background

Example: stream all .mp3 audio under ``~/Library`` directory::

python stream.ini youtube ~/Library "*.mp3" -i mylogo.jpg

Screen capture to disk
This script saves your screen capture to a file on your disk::

python stream.ini myvid.avi


* ``PyLivestream.get_framerate(vidfn)`` gives the frames/sec of a video file.
* ``PyLivestream.get_resolution(vidfn)`` gives the resolution (widthxheight) of video file.


* Linux requires X11, not Wayland (choose at login)
* ``x11grab`` was deprecated in FFmpeg 3.3, was previously replaced by ``xcbgrab``
* Reference `webpage <>`_
* `Test videos <>`_ for looping/globbing

FFmpeg References

* `streaming <>`_
* `webcam <>`_
* webcam `overlay <>`_

* `DirectShow <>`_ device selection
* DirectShow `examples <>`_

Stream References

* Twitch `parameters <>`_
* Twitch `servers <>`_
* Periscope `parameters <>`_
* YouTube Live `parameters <>`_
* Facebook Live `parameters <>`_
* Mixer `parameters <>`_
* Mixer `server list <>`_
* Ustream `parameters <>`_
* Vimeo `config <>`_
* Vimeo `parameters <>`_

Logo Credits:
* Owl PC: Creative Commons no attrib. commercial
* YouTube: YouTube Brand Resources
* Facebook: Wikimedia Commons
* `Periscope <>`_

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(16.5 kB) Copy SHA256 Hash SHA256
Wheel 3.6 Feb 22, 2018
(12.2 kB) Copy SHA256 Hash SHA256
Source None Feb 22, 2018

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting