GithubHelp home page GithubHelp logo

jaredpetersen / raspilive Goto Github PK

View Code? Open in Web Editor NEW
144.0 11.0 33.0 87 KB

๐Ÿ“ท Stream video from the Raspberry Pi Camera Module to the web

License: MIT License

Go 100.00%
raspberry-pi raspberry-pi-camera hls dash video livestream

raspilive's Introduction

raspilive

๐Ÿ“ท raspilive is a command-line application that streams video from the Raspberry Pi Camera module to the web

Usage

raspilive streams video from the Raspberry Pi Camera Module to the web

For more information visit https://github.com/jaredpetersen/raspilive

Usage:
  raspilive [command]

Available Commands:
  hls         Stream video using HLS
  dash        Stream video using DASH
  help        Help about any command

Flags:
      --debug             enable debug logging
      --fps int           video framerate (default 30)
      --height int        video height (default 720)
  -h, --help              help for raspilive
      --horizontal-flip   horizontally flip video
  -v, --version           version for raspilive
      --vertical-flip     vertically flip video
      --width int         video width (default 1280)

Use "raspilive [command] --help" for more information about a command.

Commands

HLS

The hls command muxes the video stream into the HLS video streaming format and serves the produced content by starting a static file server.

If you're not familiar with HLS, the technology works by splitting the video stream into small, consumable segments. These segments are arranged into a constantly updating playlist of files. Clients periodically read these playlists, download the listed videos, and queue up the segments to produce a seamless playback experience. Twitch uses it to distribute streaming video to all of its viewers.

Stream video using HLS

Usage:
  raspilive hls [flags]

Flags:
      --port int              static file server port
      --directory string      static file server directory
      --tls-cert string       static file server TLS certificate
      --tls-key string        static file server TLS key
      --segment-type string   format of the video segments (valid ["mpegts", "fmp4"], default "mpegts")
      --segment-time int      target segment duration in seconds (default 2)
      --playlist-size int     maximum number of playlist entries (default 10)
      --storage-size int      maximum number of unreferenced segments to keep on disk before removal (default 1)
  -h, --help                  help for hls

Global Flags:
      --debug             enable debug logging
      --fps int           video framerate (default 30)
      --height int        video height (default 720)
      --horizontal-flip   horizontally flip video
      --vertical-flip     vertically flip video
      --width int         video width (default 1280)

DASH

The dash command muxes the video stream into the DASH video streaming format and serves the produced content by starting a static file server.

DASH effectively utilizes the same mechanism for streaming video as HLS. The video is split into small segments and listed in a changing playlist file. Clients download the playlist and the videos listed in it to piece the video together seamlessly.

Stream video using DASH

Usage:
  raspilive dash [flags]

Flags:
      --port int            static file server port
      --directory string    static file server directory
      --tls-cert string     static file server TLS certificate
      --tls-key string      static file server TLS key
      --segment-time int    target segment duration in seconds (default 2)
      --playlist-size int   maximum number of playlist entries (default 10)
      --storage-size int    maximum number of unreferenced segments to keep on disk before removal (default 1)
  -h, --help                help for dash

Global Flags:
      --debug             enable debug logging
      --fps int           video framerate (default 30)
      --height int        video height (default 720)
      --horizontal-flip   horizontally flip video
      --vertical-flip     vertically flip video
      --width int         video width (default 1280)

Performance Tips

HLS & DASH

HLS and DASH are inherently latent streaming technologies. However, you can still produce some lower latency video streams.

The general recommendations seem to be:

  • Reduce the segment size
  • Increase the number of segments in the playlist to build up a buffer

Experiment with the flags and see what seems to work best for your Pi. We try to provide "sane" defaults but Raspberry Pis are computationally diverse so you may find better performance with some tweaking.

Additionally, you may find that the SD card on the Raspberry Pi is a limitation. Fast disk read/writes are important and SD cards can only perform so many in their lifetime. For better performance and longevity, you may consider setting up a RAM drive so that the files are stored in memory instead.

Installation

raspilive uses raspivid to operate the Raspberry Pi Camera Module. This is already available on the Raspbian operating system and can be enabled via raspi-config.

raspilive also uses Ffmpeg, a prominent video conversion command line utility, to process the streaming video that the Raspberry Pi Camera Module outputs. Version 4.0 or higher is required.

sudo apt-get install ffmpeg

Download the latest version of raspilive from the Releases page. All of the release binaries are compiled for ARM 6 and are compatible with Raspberry Pi.

raspilive's People

Contributors

jaredpetersen avatar johnwcassidy avatar nicklasfrahm avatar zanel avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raspilive's Issues

GO Rewrite

I've decided to rewrite the application in GO and rebrand to raspilive.

This was motivated by a couple of limitations:

  • Configuration with CLI arguments is tedious and we ran out of one-character arguments
  • We're currently very locked in to the idea of transforming a video stream into static files and serving them. Ideally, we should support other streaming formats like RTMP which does not use the disk.
  • Node.js is a requirement for using the application. We could probably generate binaries but at the end of the day it's still going to be bloated. JavaScript just isn't the right tool for the job and was only originally chosen because that's what I was most familiar.
  • We don't have any tests and the application is not testable

This rewrite seeks to address these issues.

I've made pretty good progress so far on the golang-rewrite branch.

This issue is mainly to track progress on that effort.

Stuff that needs to be done:

  • Basic existing functionality working
  • Take another look at file management (should we delete things and create directories?)
  • Set up a logging library (probably with zerolog)
  • Finalize configuration strategy (probably using environment variables instead of arguments)

Stretch goals:

  • Log Ffmpeg stats (involves parsing)
  • Access log for apps that use the static server
  • RTMP support

Support ability to choose between fmp4 or mpegts with HLS

using m4s causes issues with chrome when using video.js for playback. Switching to mpegts fixes the issue.

if (format === 'hls') {
    const outputOptions = [
      '-hls_time',
      time,
      '-hls_list_size',
      listSize,
      '-hls_delete_threshold',
      storageSize,
      '-hls_flags',
      'split_by_time+delete_segments+second_level_segment_index',
      '-strftime',
      1,
      '-hls_segment_filename',
      path.join(directory, '%s-%%d.ts'),
      '-hls_segment_type',
      'mpegts'
    ];

not sure if this should be configurable or not as I wasn't able to get it working with m4s.

Returns 404

I installed raspi-live on a Raspberry Pi 2B+ with a version 1 camera.
I ran raspi-live as a normal user raspi-live start
I entered the URL http://webcam.local:8080 into Chrome browser.

I expected a video to start playing.
The raspi-live server instead gave me a 404: GET http://webcam.local:8080/ 404 (Not Found)

The raspi-live executable printed:

configuration: /home/pi/camera hls 1280 720 25 false false 9 2 10 10 8080 false  
camera stream server started

and it continuously printed the FFMPEG log.

The .m4s files, an init.mp4 file and the .m3u8 file are all in the expected location of /home/pi/camera, where pi is the user.

I do not know how to debug it further.

Update command for ffmpeg configuration

Quick fix to the README.md. We should probably update it to use a different configuration command as the Raspberry Pi 3B+ has an armhf CPU architecture, not armel.

The fix could simply be: sudo ./configure --arch=$(dpkg --print-architecture) --target-os=linux --enable-gpl --enabl e-omx --enable-omx-rpi --enable-nonfree

Will submit a PR.

CORS configuration

First off, thanks for creating raspilive, it saved me a lot of time setting similar solution.
I have a bit of a problem with connecting served file with web app I've created because of a CORS error. I guess I need to set Access-Control-Allow-Origin to my website address. Can you point me to the direction where should I change the server configuration to edit its CORS headers?
I have zero GOlang experience but I'm willing to learn anything

Thanks a lot.

took over my desktop

after i installed the software and ran the rasp-live start command
a video stream from my camera took over the screen and i could not get back to a terminal window to stop it.

not sure if this is a known issue or a bug or some thinbg else.

had to pull the power on the pi to reboot it,

checking for l,ogs and info now.

Configuration Refactor

We've pretty much reached the limits of the current CLI argument structure.

Instead of having one start command, we should have a stream-hls and a stream-dash command with separate options (but obviously there would be overlap). Options should stop using single character shorthands because we're running out of characters to use that make any kind of sense for the option they configure.

Alternatively, we might want to just get rid of the CLI entirely. Running raspi-live would start the server and it would look at the environment variables or a particular config file for its configuration. I'm not sure how popular this would be though and definitely welcome feedback.

ffmpeg error processing with USB camera

Error: ffmpeg exited with code 1: pipe:0: Invalid data found when processing input

I believe I'm getting this error because I'm trying to use a standard USB webcam, not the raspberry pi camera module.

How do I configure it to work with USB camera?

start -h, --height overlaps with start -h, --help

Running raspi-live start -h tries to start livestreaming with a height option rather than outputting start help.

The short name for the height option needs to change. Not sure what it should be though, since it's only allowed to be one character.

Stream (m3u8 format) cannot be played on iOS devices

Hi, I created a HLS video on my Raspberry Pi Zero W by this command:

# http://<raspi-address>:8000/camera/livestream.m3u8
raspi-live start -w 640 -h 360 -p 8000

And I wrote a simple static web page and served it by python3 -m http.server 80:

<!DOCTYPE html>
<!-- index.html -->
<html lang="en">
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <video src="http://localhost:8000/camera/livestream.m3u8" width="400" height="300"></video>
  </body>
</html>

I found that the video cannot be played in Safari on iPhone and iPad. I confirmed that the iOS version Safari supports HLS (m3u8) indeed and I tested the following sample video:

<!-- this sample video is ok on iOS-->
<video src="http://delta-media.mediasocial.tv.s3.amazonaws.com/Videos/348/ios.m3u8" ...

So there must be something wrong. Maybe incorrect ffmpeg command?

Run at boot

Is it possible to start the service at boot?

Less Delay

Hi, I want to use raspi-live as a live video camera with doorbell function. But the delay is to much. Is there a way to lessen the delay?

Enforce code style through prettier

Enforce code style through the usage of prettier and a pre-commit git hook. This will ensure things like trailing whitespace never make it into pull requests.

EDIT: Fixed broken link

support lhls option

First, thanks for providing this. It has been very useful to help me bootstrap my prototype.

I quickly implemented something, and got it working this morning, but the latency is 10-15 seconds. I tried the tuning you suggested (t=.5, l=24, s=100), but it is still lagging at about this rate.

I came across the -lhls option, which seems to be available as an experimental feature in ffmpeg 4.1, and I am wondering if you have looked at this option.

I am a little confused by the option as I tried to explain here:

https://stackoverflow.com/questions/65459568/confused-about-lhls-in-ffmpeg

I have looked at your server.js code, and I would like to take a stab at implementing this, but only after I clear up the confusion about it. There is also a comment about the 'dash' output not working with a file in this thread:

https://stackoverflow.com/questions/56700705/how-to-enable-lhls-in-ffmpeg-4-1

Which may mean this won't work in any case, or at least not yet.

I was just wondering if you had looked at this experimental option and if it is something you think is worth exploring.

I am available to contribute as well.

Thanks.

SSL streaming

Hi Team,

Thank you so much for your awesome documentation.
I am currently using a raspberry zero 2W for this project and I need some help with the SSL configuration so that I can access the stream through secured HTTPS protocol instead of HTTP.
I found some documentation related to --secure, --key, and --certificate but could not figure out how to use these commands for the integration. Please help me with your suggestions.

Thanks,
Pritish Dwibedi

[Question] How do I see the stream on the browser

Hello,
I'm fairly new at Raspberry Pi world and I've been trying to set up a Security Camera in my home. I manage to download the project and compile it for my Raspberry Pi Zero but I'm not being able to see the output stream in my network.
I think I'm missing something like a complete URL: {IP}:{PORT}/livestream.mpd or {IP}:{PORT}/livestream.m3u8

Screen Shot 2022-04-04 at 01 32 20

How can I see the output stream on my browser? Thank you in advance!

Installation Instructions

I'd like to use raspi-live, either the newest version or the old one. The old one worked great and I'm having to rebuild my rpi so I'd like to use this again.

However, the old one appears to no longer work and the "Download the latest version of raspilive from the Releases page" doesn't give enough info. Tried it using wget with the release asset and running but it's a no-go.

I'd assuming Go must be installed first? If so what version?
And if it requires 'go install raspilive" what is required for that to work? Tried that a few ways and it didn't work either.

Since I no nothing about Go, detailed steps to get this working are appreciated. Thanks.

Image Rotation

Hi,

is it possible to implement a Image Rotation for 90, 180 an 270 degree?

Old segment files are not removed when service is stopped and started again

Steps to reproduce:

  1. Start service
  2. Stream for a few moments so some file segments are added to wherever they are configured to go
  3. stop service
  4. start service
  5. stream for a few moments again

Expected result:
orphaned segments are cleaned up

Actual result:
orphaned segments remain

This is a concern for the configuration I currently have, where i setup a system service to execute raspi-live, and control when it starts and stops with cron. With each stop and start, I'm accumulating orphaned segment files that I will need to clean up manually.

Screen Shot 2020-05-14 at 11 39 24 PM

ffmpeg fails to compile on newest version of raspbian

In the readme this line:
sudo ./configure --arch=arm --target-os=linux --enable-gpl --enable-omx --enable-omx-rpi --enable-nonfree

Needs an extra flag at the end:
sudo ./configure --arch=arm --target-os=linux --enable-gpl --enable-omx --enable-omx-rpi --enable-nonfree --extra-ldflags="-latomic"

or else the compilation throws this error: undefined reference to__atomic_store_8

Shows that it is running, but no m3u8 file is generated

show๏ผš

configuration: /home/pi/camera hls 1280 720 25 false false 9 2 10 10 8080
camera stream server started
Usage: raspi-live [options] [command]

self-contained raspberry pi video streaming server

Options:
  -v, --version    output the version number
  -h, --help       output usage information

Commands:
  start [options]  start streaming video from the raspberry pi camera module

but,in /home/pi/camera,no m3u8 file is generated

Debian packaging

It would be AMAZING if we could get this packaged for Debian so that users could just install it with a single command:

sudo apt-get install raspilive

I've been looking into it but it appears to be a complicated process. I have a rudimentary control file created that I was able to use to build a .deb and install with apt-get. However, I suspect that this is missing a lot of stuff.

If anyone is familiar with this process please let me know!

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.