Giter Club home page Giter Club logo

pistreaming's Introduction

Pi Video Streaming Demo

This is a demonstration for low latency streaming of the Pi's camera module to any reasonably modern web browser, utilizing Dominic Szablewski's excellent JSMPEG project. Other dependencies are the Python ws4py library, my picamera library (specifically version 1.7 or above), and FFmpeg.

Installation

Firstly make sure you've got a functioning Pi camera module (test it with raspistill to be certain). Then make sure you've got the following packages installed:

$ sudo apt-get install ffmpeg git python3-picamera python3-ws4py

Next, clone this repository:

$ git clone https://github.com/waveform80/pistreaming.git

Usage

Run the Python server script which should print out a load of stuff to the console as it starts up:

$ cd pistreaming
$ python3 server.py
Initializing websockets server on port 8084
Initializing HTTP server on port 8082
Initializing camera
Initializing broadcast thread
Spawning background conversion process
Starting websockets thread
Starting HTTP server thread
Starting broadcast thread

Now fire up your favourite web-browser and visit the address http://pi-address:8082/ - it should fairly quickly start displaying the feed from the camera. You should be able to visit the URL from multiple browsers simultaneously (although obviously you'll saturate the Pi's bandwidth sooner or later).

If you find the video stutters or the latency is particularly bad (more than a second), please check you have a decent network connection between the Pi and the clients. I've found ethernet works perfectly (even with things like powerline boxes in between) but a poor wifi connection doesn't provide enough bandwidth, and dropped packets are not handled terribly well.

To shut down the server press Ctrl+C - you may find it'll take a while to shut down unless you close the client web browsers (Chrome in particular tends to keep connections open which will prevent the server from shutting down until the socket closes).

Inside the server script

The server script is fairly simple but may look a bit daunting to Python newbies. There are several major components which are detailed in the following sections.

HTTP server

This is implemented in the StreamingHttpServer and StreamingHttpHandler classes, and is quite simple:

  • In response to an HTTP GET request for "/" it will redirect the client to "/index.html".
  • In response to an HTTP GET request for "/index.html" it will serve up the contents of index.html, replacing @ADDRESS@ with the Pi's IP address and the websocket port.
  • In response to an HTTP GET request for "/jsmpg.js" it will serve up the contents of jsmpg.js verbatim.
  • In response to an HTTP GET request for anything else, it will return 404.
  • In response to an HTTP HEAD request for any of the above, it will simply do the same as for GET but will omit the content.
  • In response to any other HTTP method it will return an error.

Websockets server

This is implemented in the StreamingWebSocket class and is ridiculously simple. In response to a new connection it will immediately send a header consisting of the four characters "jsmp" and the width and height of the video stream encoded as 16-bit unsigned integers in big-endian format. This header is expected by the jsmpg implementation. Other than that, the websocket server doesn't do much. The actual broadcasting of video data is handled by the broadcast thread object below.

Broadcast output

The BroadcastOutput class is an implementation of a picamera custom output. On initialization it starts a background FFmpeg process (avconv) which is configured to expect raw video data in YUV420 format, and will encode it as MPEG1. As unencoded video data is fed to the output via the write method, the class feeds the data to the background FFmpeg process.

Broadcast thread

The BroadcastThread class implements a background thread which continually reads encoded MPEG1 data from the background FFmpeg process started by the BroadcastOutput class and broadcasts it to all connected websockets. In the event that no websockets are currently connected the broadcast method simply discards the data. In the event that no more data is available from the FFmpeg process, the thread checks that the FFmpeg process hasn't finished (with poll) and terminates if it has.

Main

Finally, the main method may look long and complicated but it's mostly boiler-plate code which constructs all the necessary objects, wraps several of them in background threads (the HTTP server gets one, the main websockets server gets another, etc.), configures the camera and starts it recording to the BroadcastOutput object. After that it simply sits around calling wait_recording until someone presses Ctrl+C, at which point it shuts everything down in an orderly fashion and exits.

Background

Since authoring the picamera library, a frequent (almost constant!) request has been "how can I stream video to a web page with little/no latency?" I finally had cause to look into this while implementing a security camera system using the Pi.

My initial findings were that streaming video over a network is pretty easy: open a network socket, shove video over it, done! Low latency isn't much of an issue either; you just need a player that's happy to use a small buffer (e.g. mplayer). Better still there's plenty of applications which will happily decode and play the H.264 encoded video streams which the Pi's camera produces ... unfortunately none of them are web browsers.

When it comes to streaming video to web browsers, the situation at the time of writing is pretty dire. There's a fair minority of browsers that don't support H.264 at all. Even those that do have rather variable support for streaming including weird not-really-standards like Apple's HLS (which usually involves lots of latency). Then there's the issue that the Pi's camera outputs raw H.264, and what most browsers want is a nice MPEG transport stream (TS). FFmpeg seemed like the answer to that, but the version that ships with Raspbian doesn't seem to like outputting valid PTS (Presentation Time Stamps) with the Pi's output. Perhaps later versions work better, but I was looking for a solution that wouldn't involve users having to jump through hoops to create a custom FFmpeg build (mostly because I could just imagine the amount of extra support questions I'd get from going that route)!

So, what about other formats? Transcoding to almost anything else (WebM, Ogg, etc.) is basically out of the question because the Pi's CPU just isn't fast enough, not to mention none of those really solve the "universal client" problem as there's plenty of browsers that don't support these formats either. MJPEG looked an intruiging (if thoroughly backward) possibility but I found it rather astonishing that we'd have to resort to something as primitive as that. Surely in this day and age we could at least manage a proper video format?!

Then, out of the blue, and by sheer coincidence a group in Canada got in contact to ask whether the Pi could produce raw (i.e. unencoded) video output. This wasn't something I'd ever been asked before but it turned out to be fairly simple, so I added it to the list of tickets for 1.7 and finished the code for it about a week later. I confess I pretty much skimmed the rest of their e-mail the first time I read it, but with the implementation done I went back and read it properly. They wanted to know whether they could use the picamera library with Dominic Szablewski's Javascript-based MPEG1 decoder.

This was an interesting idea! Javascript implementations are near universal in browsers these days, and Dominic's decoder was fast enough that it would run happily even on relatively small platforms (for example it runs on iPhones and reasonably modern Androids like a Nexus). Furthermore, the Pi is just about fast enough to handle MPEG1 transcoding with FFmpeg (at least at low resolutions).

Okay, it's not a modern codec like the excellent H.264. It's not using "proper" HTML5 video tags. All round, it's still basically a hack, and yes it's pretty appalling that we have to resort to hacks like this just to come up with a universally accessible video streaming solution. But hey ... it works, and it's not (quite) as primitive as MJPEG so I'm happy to declare victory. I spent an evening bashing together a Python version of the server side. It turned out a bit too complex to include as a recipe in the docs, hence why it's here, but I think it provides a reasonable basis for others to work from and extend.

Enjoy!

Dave.

pistreaming's People

Contributors

dblicken avatar petschki avatar waveform80 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  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

pistreaming's Issues

(Question) high CPU usage with pistreaming

I noticed that the pistreaming uses quite a bit CPU(around 70%) on Raspberry PI 3, the majority of the CPU usage is on avconv, any suggestion on how to reduce the CPU usage with pistreaming? I am trying to preserve CPU for further video analysis effort. Thanks.

PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
13718 root      20   0  217464  35556  21256 S  70.8  4.0   1:04.35 avconv
13707 root      20   0  118320  17132   8104 S  11.8  1.9   0:12.03 python3

Change of resolution produces script failure

I have been attempting to run server.py with a resolution of 1920x1080 and a low resolution of 5 fps on a Pi Zero. No problem is encountered with the script unmodified. On each occasion the script produces an error of the following kind. 👍

/usr/local/lib/python3.7/dist-packages/picamera/encoders.py:544: PiCameraResolutionRounded: frame size rounded up from 1920x1080 to 1920x1088
width, height, fwidth, fheight)))
Initializing camera
Initializing websockets server on port 8084
Initializing HTTP server on port 8082
Initializing broadcast thread
Spawning background conversion process
Starting recording
Starting websockets thread
Starting HTTP server thread
Starting broadcast thread
Waiting for background conversion process to exit
Stopping recording
Traceback (most recent call last):
File "server.py", line 184, in
main()
File "server.py", line 170, in main
camera.stop_recording()
File "/usr/local/lib/python3.7/dist-packages/picamera/camera.py", line 1196, in stop_recording
self.wait_recording(0, splitter_port)
File "/usr/local/lib/python3.7/dist-packages/picamera/camera.py", line 1167, in wait_recording
encoder.wait(timeout)
File "/usr/local/lib/python3.7/dist-packages/picamera/encoders.py", line 398, in wait
raise self.exception
File "server.py", line 165, in main
camera.wait_recording(1)
File "/usr/local/lib/python3.7/dist-packages/picamera/camera.py", line 1167, in wait_recording
encoder.wait(timeout)
File "/usr/local/lib/python3.7/dist-packages/picamera/encoders.py", line 398, in wait
raise self.exception
File "/usr/local/lib/python3.7/dist-packages/picamera/encoders.py", line 267, in _callback
stop = self._callback_write(buf)
File "/usr/local/lib/python3.7/dist-packages/picamera/encoders.py", line 580, in _callback_write
return super(PiRawMixin, self)._callback_write(buf, key)
File "/usr/local/lib/python3.7/dist-packages/picamera/encoders.py", line 921, in _callback_write
return super(PiVideoEncoder, self)._callback_write(buf, key)
File "/usr/local/lib/python3.7/dist-packages/picamera/encoders.py", line 298, in _callback_write
written = output.write(buf.data)
File "server.py", line 106, in write
self.converter.stdin.write(b)
BrokenPipeError: [Errno 32] Broken pipe

I would be grateful for any advice on how this might be resolved. Thanks.

Autostart at reboot

Hey guys,

is there an easy way to autostart the script at reboot? already tried the crontab.

@reboot python3 /home/pi/pistreaming/server.py
but this is not working.

No output display

Hello
I tried to implement your code with different browsers. But am not able to get any output. Error: No Connection..

Help me out..

Script does not fully close on CTRL-C

The script as it is now does not fully close. A thread named WebSocketManager is still running. I found that adding the command websocket_server.server_close() before websocket_server.shutdown() solves this issue.

after Exit via Ctrl+C, Start fail again.

pi@HXF-Raspberrypi:~/MyFiles/Camera/pistreaming $ python3 server.py
Initializing camera
Initializing websockets server on port 8084
Initializing HTTP server on port 8082
Initializing broadcast thread
Spawning background conversion process
Starting recording
Starting websockets thread
Starting HTTP server thread
Starting broadcast thread
10.10.10.198 - - [10/Jan/2020 10:08:44] "GET / HTTP/1.1" 301 -
10.10.10.198 - - [10/Jan/2020 10:08:44] "GET /index.html HTTP/1.1" 200 -
10.10.10.198 - - [10/Jan/2020 10:08:44] "GET /jsmpg.js HTTP/1.1" 200 -
10.10.10.198 - - [10/Jan/2020 10:08:44] code 404, message File not found
10.10.10.198 - - [10/Jan/2020 10:08:44] "GET /favicon.ico HTTP/1.1" 404 -
10.10.0.1 - - [10/Jan/2020 10:10:02] "GET / HTTP/1.1" 301 -
10.10.0.1 - - [10/Jan/2020 10:10:02] "GET /index.html HTTP/1.1" 200 -
10.10.0.1 - - [10/Jan/2020 10:10:02] "GET /jsmpg.js HTTP/1.1" 200 -
10.10.0.1 - - [10/Jan/2020 10:10:03] code 404, message File not found
10.10.0.1 - - [10/Jan/2020 10:10:03] "GET /favicon.ico HTTP/1.1" 404 -
^Z
[1]+ 已停止 python3 server.py

=====
it works fine, exit via ctrl + c .
So start it again, but fail.

pi@HXF-Raspberrypi:~/MyFiles/Camera/pistreaming $ python3 server.py
Initializing camera
mmal: mmal_vc_port_enable: failed to enable port vc.null_sink:in:0(OPQV): ENOSPC
mmal: mmal_port_enable: failed to enable connected port (vc.null_sink:in:0(OPQV))0x12456b0 (ENOSPC)
mmal: mmal_connection_enable: output port couldn't be enabled
Traceback (most recent call last):
File "server.py", line 184, in
main()
File "server.py", line 134, in main
with picamera.PiCamera() as camera:
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 433, in init
self._init_preview()
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 513, in _init_preview
self, self._camera.outputs[self.CAMERA_PREVIEW_PORT])
File "/usr/lib/python3/dist-packages/picamera/renderers.py", line 558, in init
self.renderer.inputs[0].connect(source).enable()
File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 2212, in enable
prefix="Failed to enable connection")
File "/usr/lib/python3/dist-packages/picamera/exc.py", line 184, in mmal_check
raise PiCameraMMALError(status, prefix)
picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources

==================

How to exit? I hope works fine when start it again.

BrokenPipeError After Refreshing Web Page

I'm running with the default configuration (640x480 at 24fps) and if I refresh the web page a couple times, I get this BrokenPipeError and the video feed stops. Issue #13 seemed related, but it sounds like that was taken care of already. Is there anything else that could prevent this? Of course, I'd rather not turn down the resolution... Thanks for your help and thanks for the library!

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3/dist-packages/ws4py/manager.py", line 310, in run
    if not ws.once():
  File "/usr/lib/python3/dist-packages/ws4py/websocket.py", line 305, in once
    if not self.process(b):
  File "/usr/lib/python3/dist-packages/ws4py/websocket.py", line 362, in process
    self.close(s.closing.code, s.closing.reason)
  File "/usr/lib/python3/dist-packages/ws4py/websocket.py", line 176, in close
    self._write(self.stream.close(code=code, reason=reason).single(mask=self.stream.always_mask))
  File "/usr/lib/python3/dist-packages/ws4py/websocket.py", line 243, in _write
    self.sock.sendall(b)
BrokenPipeError: [Errno 32] Broken pipe

Broken Pipe Error

I frequently encounter "BrokenPipeError: [Errno 32] Broken pipe". Initially, I didn't know if the problem was with stdin or stdout but have sometimes seen an exception raised with the thread running the websocket server which indicates I have a problem with stdout. I considered changing the read bytes from 512 to 1024 but I don't know the implications of it. I read that doing so lead to problems in other cases. My understanding is that pipes are limited to 65K and image frames are significantly larger. Running at 320x240 @ 24fps can survive a long time but I can quickly get a broken pipe if running at 30fps. I'm using code adapted from server.py which is called from another class so I have other threads and timer events that complicate the issue and I likely have a timing problem. I’m also not using camera.start_recording() but instead am using camera.capture_continuous() so that I can modify images before sending but I don’t suspect this as contributing to the problem. I’m guessing that the stdout pipe and the broadcast rate aren’t playing well together. Any idea of what might be going on here?

New jsmpeg

I'm not familiar with the history of jsmpeg, but the latest code looks like it's changed quite a bit from the copy in this repository. I assume it's improved by various measures.

I couldn't get it to work though. :(

Has anyone tried more recent versions?

No Stream on my browser window

Hi,
after installing pistreamer on my raspi 2 I started the server $python server.py .
After the information at the console I opened the firefox browser and start the address of my raspi: http://ip-address:8082/

But I see no stream. Only a grey background. The two GET lines show ... index.html... 200
and .../jsmpg.js .... 200 .
What goes wrong? Can you help me? Thanks
[email protected]

No module name http.server?

Hi,

Followed instructions, but upon running server.py:

~/pistreaming $ ./server.py
Traceback (most recent call last):
  File "./server.py", line 12, in <module>
    from http.server import HTTPServer, BaseHTTPRequestHandler
ImportError: No module named http.server

I'm sure it's something obvious, but I'm a beginner. . . .could you help me out?

python3-ws4py The following packages have unmet dependencies: python3-ws4py : Depends: python3:any (>= 3.3.2-2~)

I see that there have not been updates for a while.
I am new to using raspberry pi's but I can't get past this error:

sudo apt-get install python3-ws4py
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
python3-ws4py : Depends: python3:any (>= 3.3.2-2~)
E: Unable to correct problems, you have held broken packages.

I have also tried:
sudo pip install ws4py
cd pistreaming/
python3 server.py

Traceback (most recent call last):
File "server.py", line 16, in
from ws4py.websocket import WebSocket
ModuleNotFoundError: No module named 'ws4py'

Initializing server.py

Hello, when i want to run the script this appears, do you know what can it be?
Thanks :)

pi@qwerty:~/pistreaming $ python3 server.py
Initializing camera
Initializing websockets server on port 8084
Initializing HTTP server on port 8082
Initializing broadcast thread
Spawning background conversion process
Traceback (most recent call last):
  File "server.py", line 184, in <module>
    main()
  File "server.py", line 153, in main
    output = BroadcastOutput(camera)
  File "server.py", line 103, in __init__
    shell=False, close_fds=True)
  File "/usr/lib/python3.4/subprocess.py", line 859, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.4/subprocess.py", line 1457, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg'

Code of Capture image in browser using Web Socket

Hello Sir,
AM working on this project. But, in additional I have one requirement regarding capture image from browser. Can you help me out how it can be possible to capture image from browser with PiCamera and using web Socket.
Its Urgent..

Waiting for positive response..

Thankyou

Adafruit Neopixel Sticks not coloring correctly.

I have 2 different types of the Adafruit Neopixel Sticks:
Adafruit 2868 NeoPixel Stick RGBW.
Adafruit 1426 NeoPixel Stick RGB.
Neither of which work exactly as expected. the color and pixel assignments are messed up.
I've found a partial fix if I add ether of these two lines at around line 21 in server.py file.

For RGBW array I added:

hat.light_mode(hat.WS2812)
hat.light_type(hat.GRBW)

Or for the RGB array I added:

hat.light_mode(hat.WS2812)
hat.light_type(hat.GRB)

This fixes most of the problems I've been getting, but for some reason the second and third pixels (1, 2) on the RGBW, or the second, third and forth pixels (1, 2, 3) on the RGB are still not being assigned their correct colors, and seem to be a little mixed up with each other.
Unfortunately I don't know enough about code to find the reason for this and correct it.

Rasbian Buster

Hi,

The new Buster release breaks some dependencies of the streaming server.

python3-ws4py does not play nice with Python3.7, however you can work around this, install everything apart from python3-ws4py using the instructions, then-

sudo apt install python3-pip
sudo pip3 install ws4py

Now you should be back in the game.

No longer works in iOS

Hi,

This no longer seems to work in iOS (I think since I upgraded to 10.)

Any thoughts? I don't see any error messages client or server side so at a bit of a loss.

Thanks.

Error Running on Raspberry

Dear author:
I am a Chinese college students. My English is very basic so please reply to me in simple English, if any.
I have been using Raspberry to make something. I want to play the video that is captured by cameras on Raspberry in my web browser. I use your pistreaming, but I get the following error:

Initializing camera
Initializing websockets server on port 8084
Initializing HTTP server on port 8082
Initializing broadcast thread
Spawning background conversion process
Traceback (most recent call last):
File "server.py", line 184, in
main()
File "server.py", line 153, in main
output = BroadcastOutput(camera)
File "server.py", line 103, in init
shell=False, close_fds=True)
File "/usr/lib/python3.4/subprocess.py", line 859, in init
restore_signals, start_new_session)
File "/usr/lib/python3.4/subprocess.py", line 1457, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg'

I have been working on my project for a long time and it is the deadline ten days later. I have write all the other codes, but I just cannot get the video. Could you please help me?
If possible, I can send you a handmade gift in my hometown as a gift.
Thanks!

Frame Rate Issue

If the frame rate is lowered below 24, a Broken pipe error happens.

Getting error in Raspberry pi zero w

When i run the command i get this error:
$ python3 server.py
Initializing camera
Initializing websockets server on port 8084
Initializing HTTP server on port 8000
Initializing broadcast thread
Spawning background conversion process
Starting recording
Starting websockets thread
Starting HTTP server thread
Starting broadcast thread
Waiting for background conversion process to exit
Stopping recording
Traceback (most recent call last):
File "server.py", line 184, in
main()
File "server.py", line 170, in main
camera.stop_recording()
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1196, in stop_recording
self.wait_recording(0, splitter_port)
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1167, in wait_recording
encoder.wait(timeout)
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 398, in wait
raise self.exception
File "server.py", line 165, in main
camera.wait_recording(1)
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1167, in wait_recording
encoder.wait(timeout)
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 398, in wait
raise self.exception
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 267, in _callback
stop = self._callback_write(buf)
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 580, in _callback_write
return super(PiRawMixin, self)._callback_write(buf, key)
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 921, in _callback_write
return super(PiVideoEncoder, self)._callback_write(buf, key)
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 298, in _callback_write
written = output.write(buf.data)
File "server.py", line 106, in write
self.converter.stdin.write(b)
BrokenPipeError: [Errno 32] Broken pipe

I used this code in Raspberry Pi 3B+, and it worked well. But in pi zero w, i'm getting error.

How do I save a video to my hard drive

dear author,i want to save a video to my hard drive,What should I do?
i saw this code:
buf = self.converter.stdout.read1(32768)
and i think i should write the buf to my file,but i can't use ffmpeg convert. i want to save mp4

Trying to get working on a public website

ello,

I am doing a college project security system.

I am trying to get this working on a public website the Pan and tilt buttons work fine but the stream shows “loading…” i have the ports 8082 and 8084 forwarded. I read that i have to add a externa ip address in the code but whenever i look for the area i have to change it does not exist?

Taking stills

Hello Dave,
Your PiStreaming is working superbly :-) thank you.

I would like to be able to take a still image/photo, would that be possible?
Using Raspistill doesn't want to work, presumably because other services have snaffled the resource.
I don't mind if the video stream flickers/pauses while the configuration modes are changed in order to get a higher resolution than 640x480 - in fact for a still image it is preferable.

Many thanks,
Brian.

http.server in Python 3.6 syntax errors

I'm following instructions in an O'Reily book on data viz to set up a local host 8888 server. Code typed exactly like book results in syntax error. Tried many searches and can't find an answer - - anyone see what's wrong? I have python 3.6.4 on a windows 10 machine.

-m http.server 8888 &
File "", line 1
-m http.server 8888 &
^
SyntaxError: invalid syntax

[Question] How "low latency"

The README.md references that it is low latency multiple times. Was this ever tested for an exact value or was it just your best prediction?

USB camera

I really like the idea of your cross-platform streaming solution, but haven't been able to get it to work yet. When I run server.py I get the error that says "Camera is not enabled", but I think that's because I'm not using the Pi camera (I'm using a Microsoft USB webcam) which is incompatible with the picamera python module.

Is there any way to get this to work with a USB webcam?

Syntax Error

This two bug was found on Python3.2 for RaspberryPi.

  1. COLOR = u'#444'
    ^
    SyntaxError: invalid syntax
    Fix: remove the "u" before '#444'

  2. File "server.py", line 123, in run
    buf = self.converter.stdout.read1(32768)
    AttributeError: '_io.FileIO' object has no attribute 'read1'
    Fix: use "stdout.read()" instead of "stdout.read1()"

Segmentation fault

pi@raspberrypi:~/pistreaming $ python3 server.py
Initializing camera
Initializing websockets server on port 8084
Initializing HTTP server on port 8082
Initializing broadcast thread
Spawning background conversion process
Starting recording
Starting websockets thread
Starting HTTP server thread
Starting broadcast thread
Segmentation fault.

raspberry pi 4b.
std camera.

Cannot open video stream on the web

Hi all,

Made the setup and everything is working fine in my local wireless connection.

I have opened the port 8082 on port forwarding in my router, I can reach the server remotely and see its response. However, I dont get the video streaming, I dont know what should I do to get working on web. Its maybe related to router port forwarding or something like that? Could someone give any clue?

Its even strange because I can see the request on my Pi log, and it shows any error.

Thanks in advance.

IPv6 support missing?

I would like to connect to the server using IPv6 address.

Unfortunately get ERR_CONNECTION_REFUSED

python websocket code to grab stream

I need to grab the video stream from the url to process the video. What should be the accompanying code to retrieve the image from the websocket? I am trying something like this. But it is not workigng

from PIL import Image
import websocket
import cStringIO
import base64
import cv2

class WSClient():
    def __init__(self):
        websocket.enableTrace(False)
        self.ws = websocket.WebSocketApp("ws://192.168.0.105:8084",
                                         on_message=self.on_message,
                                         on_error=self.on_error,
                                         on_close=self.on_close)
        self.ws.on_open = self.on_open
        self.ws.run_forever()

    def on_message(self, ws, message):
        print "here"
        # image_string = cStringIO.StringIO(base64.b64decode(message))
        image = Image.open(message)
        image.show()
        cv2.imshow("asd",image)
        # print 'a'+image_string

    def on_error(self, ws, error):
        print error

    def on_close(self, ws):
        print "connection closed"

    def on_open(self, ws):
        print "connected"


if __name__ == "__main__":
    client = WSClient()

Flask....

Dear author! Very much I ask you to give a hint how to implement your server code on a python on Flask. Most newbies on a python like me, master the server code exactly by means Flask. Please help). 'm sorry I'm from Russia and I do not speak English well. If he expressed his request as something bad. Excuse me)...

Error on OpenCV

Dear author:
After successfully installing Pistreaming on my RaspiberryPi, I can now watch the video by 192.168.137.2:8082 in my browser.
But when I try to use it in the opencv, I failed to open the camera by
VideoCapture video; video.open(192.168.137.2:8082);
So how can I get the video in OpenCV?

How to change the resolution of video?

I simply changed the resolution in server.py but I met the "Broken pipe [Error 32]" error, So I wonder if I can change the resolution higher, like 720p, and how?

Low throughput from encoder causes lots of lag / skipped frames

Hi Dave,

thanks a ton for getting this project started, really useful. I'm running into some troubles - happy to do the legwork, but would love some pointers.

Here's what I have:

Pi: B+ running latest raspbian
Desktop: up to date Ubuntu 14.04
Browser: tried latest chrome and FF
Connection: ethernet to the same switch (hp managed, good switch)
Ping flood test: packets transmitted, 6165 received, 0% packet loss, time 3693ms
rtt min/avg/max/mdev = 0.396/0.555/0.970/0.072 ms, ipg/ewma 0.599/0.510 ms
Other tests: Raspimjpeg and mplayer streaming work just fine with no lag

I'm seeing about 10s lag and some sections of the video are entirely skipped and oveall video plays like in slow motion. Load on the pi is 0.7 while running pistreaming.

Anything I can check or do to further debug the issue?

thanks,

Spike

hello! ctr+C Stopping recording .Is there another way to stop recording?thank you!

import os
import RPi.GPIO as GPIO
from picamera import PiCamera
from time import sleep

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.IN, pull_up_down = GPIO.PUD_UP )#接上轻触开关,一个脚接地
GPIO.setup(18,GPIO.OUT) #接LED灯

GPIO.add_event_detect(17, GPIO.RISING) # 在通道上添加上管脚触发方式

flag = 1
while True:
if GPIO.event_detected(17): #判断按键按下事件
if flag:
#os.system("sudo systemctl start create_ap.service")
GPIO.output(18,True)
os.system("python3 /home/pi/pistreaming/server.py")
else:
### (Is there another way to stop recording)
flag = not flag

GPIO.cleanup()

TLS Implementation

It would be quite useful to be able to use HTTPS and WSS. I'm pretty new to python and the LAMP stack in general, so I wasn't able to convert your server script myself.

Thank you!!

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.