GithubHelp home page GithubHelp logo

dynamicdevices / makespacelive Goto Github PK

View Code? Open in Web Editor NEW
13.0 9.0 3.0 416 KB

Connecting people with a platform to enable straightforward live streaming and recording of events and makespaces

License: Other

Python 6.69% Shell 39.37% Rust 47.04% HTML 3.39% JavaScript 3.52%
makerspace raspberrypi gstreamer livestream opensource openhardware raspberrypizerow youtube twitch facebook resin-io

makespacelive's Introduction

Overview

We host a variety of events at the DoES Liverpool MakerSpace/Tech. Hub in Liverpool and have been thinking for some time of how we might live stream these.

Being a community of makers it seemed appropriate that we should look at what can be achieved with OpenSource / OpenHardware platforms for live streaming

This would then give us the options of

  • streaming events at DoES Liverpool to the wider world (via Twitch, Facebook, Youtube Live, other)
  • working with other groups to live stream their events to DoES Liverpool and elsewhere
  • other use cases such as video conferencing, monitoring 3D print builds, building security etc.

Such a project may also help to foster links with other Makerspaces to create a "Federation of Makerspaces" where we interact with each other, are aware of each others' capabilities and events

The needs for such an infrastructure are

  • very easy to live stream an event
  • low cost hardware for live streaming
  • easy to remotely access and update firmware on the hardware device
  • has to look reasonably professional to viewers (minimal "buffering", options for cuts between multiple video sources.
  • accessible to all on the internet
  • potential for monetisation of events

News

For a discussion of what we've been up to in the initial stages of the project please see the demonstration we did for the Liverpool Linux User Group (LivLUG) - https://youtu.be/lT5uTzIM5s8

Device - Hardware

On the device side we are testing with the Raspberry Pi v3 which has Wifi and a GPU core for video encoding acceleration. We are also testing out whether a Raspberry Pi Zero W is capable enough for livestreaming.

With this platform we can use either a PiCam or a webcam. We've been testing with a Logitech C270, Logitech C920, and PiCams. Audio is supported from the Logitech webcams and we've successfully tested USB audio adaptors for use with PiCam-based systems

Device - Firmware

We are using the Resin.io cloud firmware management infrastructure to manage firmware updates and remote access to devices

The live streaming support on the client is based on GStreamer1.0 pipelines.

The Gstreamer pipeline is configured to stream audio/video as H.264/FLV encoded RTMP streams to a configurable internet server

Device - Enclosures

We're currently looking at a couple of Raspberry Pi Zero enclosure designs.

  • PiZero design for PiCam here
  • Remixed design for 2xPiZero and PiCam for 360 video experiements here

There are lots of others under various Creative Commons licenses which we are interested in hearing feedback on.

Cloud RTMP - servers

We have been testing with the Restream.io cloud platform which takes an RTMP stream and will then restream to other cloud endpoints such as Twitch, Youtube, and Facebook

The RTMP Stream URL and Stream Key are configurable and can be pointed to other endpoints easily

Real time editing

We are currently working on VM images for

  • Local Nginx based RTMP restreaming and transcoding servers
  • OBS Studio VM image for real time a/v editing for live streams

Maintainers & Contributers

Architecture

Architecture is currently very simple and consists of:

  • Dockerfile.template which scripts creation of the Resin.io OS image (this can be recreated manually if you don't want to use Resin - see below)
  • Support files from Resin.io resin-io-connect project to support local Wifi AP configuration
  • stream.py Python script which performs all streaming setup and runs the GStreamer1.0 pipeline

Supported Hardware

Please feel free to test and feed back your successes so we can grow this list

  • Raspberry Pi v3 (beta)
  • Raspberry Pi Zero W (alpha)
Camera Support Status Notes Needed Settings
Logitech Fusion audio/video alpha Device drops off USB bus, AV_VIDEO_WIDTH=640, AV_VIDEO_HEIGHT=480
Audio clicks
Logitech C920 audio/video alpha Audio drops out
Logitech C270 audio/video beta AV_AUDIO_SAMPLING_RATE=32000
PiCam video beta
PiCam Zero video alpha

Installation

Standalone

Live Streaming support should work on any platform capable of running GStreamer1.0 pipelines. We also require support for Python3 and Python3 GStreamer1.0 bindings for script.py

This project is currently focussed on Linux platforms on Raspberry Pi hardware (v3 / Zero W) but there should be no real hurdle in running on other Linux/Embedded Linux platforms or indeed under Windows as GStreamer1.0 and Python are available for Win32.

Different platform builds of GStreamer1.0 can have slightly different plugin naming conventions and/or sometimes plugins can be missing. This may involve a certain amount of hand-rolling. Feel free to raise an issue if you run into trouble.

The [Dockerfile.template)(./Dockerfile.template) contains Docker format scripting to build a Linux image for Raspberry Pi with all needed components, and some optional extras.

At the time of writing you should be able to

  • Grab the current Raspbian image from here
  • Write this to a uSD card using dd or your flash writing tool of choice e.g. Etcher
  • Boot up the image and allow it to configure
  • Ensure you've set up wired or wireless internet connectivity
  • You will need to set gpu_mem in the config.txt file in the uSD FAT boot partition to e.g. 128
  • You will need to set start_x=1 in the config.txt file in the uSD FAT boot partition if you will be using PiCams.

Then run the following APT command to install needed dependencies. NB. Check the current commit of Dockerfile.template for the current command

apt-get update \
    && apt-get install -y dnsmasq wireless-tools dbus xterm \
               v4l-utils nano bc wget unzip netcat alsa-utils build-essential git usbutils openssh-server \
               python3 python3-gi \
               gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad \
               gstreamer1.0-plugins-ugly gstreamer1.0-omx gstreamer1.0-alsa \
               autoconf automake libtool pkg-config \
               libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libraspberrypi-dev \
    && apt-get clean

Git clone this repository to have the needed stream.py file

cd ~
git clone https://github.com/DynamicDevices/makespacelive.git

If using a Picam you will need to build and install the rpicamsrc GStreamer1.0 plugin

cd ~
git clone https://github.com/thaytan/gst-rpicamsrc.git
cd gst-rpicamsrc && ./autogen.sh && make && sudo make install

An example setup script would be something like:

cd ~/makespacelive
export AV_STREAM_URL=my_stream_url
export AV_STREAM_KEY=my_stream_key
./stream.py

Resin.io Based

Follow the Resin.io getting started tutorial here

There are a range of example projects. We suggest working through the link above.

Then you can clone this repository and push it to your Resin.io repo endpoint which will build the Docker container(s) and deploy to your device(s)

git clone https://github.com/DynamicDevices/makespacelive.git

When the container runs up it will be unable to connect to Wifi and so will start a local Wifi Access Point called "Wifi Connect"

You should connect to this AP with your phone and a page will pop up allowing you to select the Wifi SSSID and enter the correct password.

The device will then connect to the internet and to the Resin.io dashboard.

You should end up with a dashboard that looks something like this

example

The last step is to set environment variables for your stream URL and Key as in the Operation section below

You should do this in your Resin.io dashboard under the 'Service Variables' tab e.g.

example

Operation

  • Configure environment variables AV_STREAM_URL and AV_STREAM_KEY for your RTMP server endpoint

You may choose to create a free Restream.io account for testing. You will first need to add a channel to your Restream.io dashboard (e.g. Twitch or YouTube) and then will be able to see your unique URL and key. Click on the key to make it visible.

  • Optionally set other configuration environment variables as needed but defaults should work ok with Restream.io

  • Run the stream.py script. This will do some detection of connected webcams/Picams and start livestreaming to your configured endpoint

  • If using Restream.io you will see the image come up something like this

example

Configuration

Configuration is achieved by setting environment variables prior to running stream.py

Currently supported variables are:

Key Description Default Value
AV_STREAM_URL Target for RTMP live stream rtmp://10.0.31.212/live
AV_STREAM_KEY Stream key if applcable
AV_DISABLE_AUDIO Do not transmit audio 0
AV_AUDIO_SAMPLING_RATE Audio sample rate in Hz 16000
AV_AUDIO_DEVICE ALSA audio hardware device 1
AV_AUDIO_BITRATE Encoded audio bitrate in kbps 128
AV_VIDEO_SOURCE Override the detected video source [TBD]
AV_VIDEO_WIDTH Width of captured/encoded video 1280
AV_VIDEO_HEIGHT Height of captured/encoded video 720
AV_VIDEO_FRAMERATE Video frame rate in fps 30
AV_H264_ENCODER_PARAMS Extra params for H.264 encoder plugin

An example setup script would be something like:

cd ~/makespacelive
export AV_STREAM_URL=my_stream_url
export AV_STREAM_KEY=my_stream_key
./stream.py

A message from our sponsors: Be excellent to each other!

makespacelive's People

Contributors

ajlennon avatar james2710 avatar jeanminet avatar methoddan avatar nchronas avatar page- avatar shaunmulligan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

makespacelive's Issues

Key frame interval is incorrect

Need a way to set the key frame interval to 2 (2s or 60 frames at 30fps say) in the gstreamer pipeline. Currently it seems to default to something like 10s

We can stream successfully to Restream.io without this but we get warnings and there may be knock on effects

Make the setup fool proof for *actual fools* like me

@ajlennon Its alive! Went for the standalone method having not realised that resin could do it all for me, ah well. Always scroll down. So yep it works well enough for me to follow. I could help with a bit more handholding as in "What is Resin"

Had to do all the apt-get install -y stuff line by line to get it all to install. Imagine the Resin method would get rid of all that.

But after an hour faffing, It's restream.io'ing with Twitch. Yay I now have wireless house security cam with adverts!

Really well done Alex its awesome and be handy for documenting workshops for me aswell as DoES. Im going to try that 360 DIY cam soon and see if it works on google cardboard with youtube nice one dream-stream-team

Rpi Zero W 'RpiCamSrc' is flakey

It seems to seg fault very quickly on the Pi0w. Seems OK on the Piv3 though.

May need to look at an alternative source such as piping out of raspivid

GSTREAM ERROR when running microscope stream

Sorry to bug @ajlennon but keep getting this error after about a second after initialising Pi Cam on my microscope streamer. Worked fine a few weeks back. Ive made new restream keys etc but cants seem to resolve error... hope u well :)

heres a still to prove pi cam works and some images of the scope prototype ;) (the red ring is because I used red PLA as a material for the microscope which the strong light source penetrates and you can see )

Defaulting to PiCam
No audio capture available
Pipeline stream:
rpicamsrc keyframe-interval=2 hflip=true vflip=true ! omxh264enc  !  video/x-h264,width=1280,height=720,framerate=30/1 ! h264parse ! flvmux streamable=true name=mux ! queue ! rtmpsink location='rtmp://10.0.31.212/live/ live=1 flashver=FME/3.0%20(compatible;%20FMSc%201.0)'
GST ERROR (gerror=GLib.Error('Could not open resource for writing.', 'gst-resource-error-quark', 6), debug='gstrtmpsink.c(245): gst_rtmp_sink_render (): /GstPipeline:pipeline0/GstRTMPSink:rtmpsink0:\nCould not connect to RTMP stream "\'rtmp://10.0.31.212/live/ live=1 flashver=FME/3.0%20(compatible;%20FMSc%201.0)\'" for writing'

test_image2
cab1

Current Balena Pi0 image doesn't support gstreamer head

There's an issue with the RPi firmware used in the current Balena base image which causes GStreamer to fail to initialise the h264enc plugin

gst-launch-1.0 -v videotestsrc ! omxh264enc ! fakesink

gives

/GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0.GstPad:src: caps = video/x-raw, width=(int)320, height=(int)240, framerate=(fraction)30/1, format=(string)I420, multiview-mode=(string)mono, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive
0:00:00.381993085   595  0x13de750 ERROR                    omx gstomx.c:1399:gst_omx_component_set_parameter:<omxh264enc-omxh264enc0> Set video_encode parameter at index 0x02000001: Bad parameter (0x80001005)
0:00:00.388058054   595  0x13de750 ERROR                    omx gstomx.c:1578:gst_omx_port_update_port_definition:<omxh264enc-omxh264enc0> Updated video_encode port 200 definition: Bad parameter (0x80001005)
0:00:00.406862960   595  0x13de750 ERROR                    omx gstomx.c:1399:gst_omx_component_set_parameter:<omxh264enc-omxh264enc0> Set video_encode parameter at index 0x02000001: Bad parameter (0x80001005)
0:00:00.413642926   595  0x13de750 ERROR                    omx gstomx.c:1578:gst_omx_port_update_port_definition:<omxh264enc-omxh264enc0> Updated video_encode port 200 definition: Bad parameter (0x80001005)
0:00:00.452508731   595  0x13de750 ERROR                    omx gstomx.c:1399:gst_omx_component_set_parameter:<omxh264enc-omxh264enc0> Set video_encode parameter at index 0x02000001: Bad parameter (0x80001005)
0:00:00.457898704   595  0x13de750 ERROR                    omx gstomx.c:1578:gst_omx_port_update_port_definition:<omxh264enc-omxh264enc0> Updated video_encode port 200 definition: Bad parameter (0x80001005)
0:00:00.475185618   595  0x13de750 ERROR                    omx gstomx.c:1399:gst_omx_component_set_parameter:<omxh264enc-omxh264enc0> Set video_encode parameter at index 0x02000001: Bad parameter (0x80001005)
0:00:00.478108603   595  0x13de750 ERROR                    omx gstomx.c:1578:gst_omx_port_update_port_definition:<omxh264enc-omxh264enc0> Updated video_encode port 200 definition: Bad parameter (0x80001005)
ERROR: from element /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0: Internal data stream error.
Additional debug info:
gstbasesrc.c(3064): gst_base_src_loop (): /GstPipeline:pipeline0/GstVideoTestSrc:videotestsrc0:
streaming stopped, reason not-negotiated (-4)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
Freeing pipeline ...

This is noted as a bug here and should be fixable with an rpi-update to the base image

raspberrypi/firmware#1051

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.