benbusby / piro

A Raspberry Pi security camera rover
MIT License
100 stars 17 forks source link

Only works with HTTPS connections #15

Closed acidtech closed 4 years ago

acidtech commented 4 years ago

All working browsers now require SSL encryption for WebRTC. This basically means iOS will not work with this unless you go through a very convoluted process of creating a CA cerificate, then a self signed cert using that CA and then installing that CA in iOS. Android is less an issue since you can just bypass the warning, but you can't go full screen if the SSL cert has an error so if you want full screen video on a phone/tablet you are stuck with the same workaround needed for iOS to work at all.

Note I've built effectively this same app and am looking for an alternative workaround. Eg low latency streaming to a browser. WebRTC is just not going to do it.

benbusby commented 4 years ago

That's why the README and setup script both involve steps for easily setting up a https connection through Dataplicity, which I've been using on iOS for a while (safari only though). The SSL certs from LetsEncrypt also work for setting up your own https web server to live stream with WebRTC as well, and isn't convoluted at all (takes under a minute to set up, provided you have a domain to generate the cert for). I went the Dataplicity route since that's the most hands off, was easily integrated with the setup script for the project, fulfills the https requirement for streaming and provides a unique and persistent domain, and allows one Raspberry Pi connection for free.

acidtech commented 4 years ago

Maybe I misunderstood. How would you use this on a non-internet connected RPi? Eg when an RPi is setup as an access point or is just another IP address on your local internet? In those cases you either dont have an internet connection or you dont want to stream your video out to the internet just to get it back to your local network.

Nathan Scherdin

On Sun, Dec 1, 2019 at 12:07 PM Ben Busby notifications@github.com wrote:

That's why the README and setup script both involve steps for easily setting up a https connection through Dataplicity, which I've been using on iOS for a while (safari only though). The SSL certs from LetsEncrypt also work for setting up your own https web server to live stream with WebRTC as well, and isn't convoluted at all (takes under a minute to set up, provided you have a domain to generate the cert for). I went the Dataplicity route since that's the most hands off, was easily integrated with the setup script for the project, fulfills the https requirement for streaming and provides a unique and persistent domain, and allows one Raspberry Pi connection for free.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/benbusby/raztot/issues/15?email_source=notifications&email_token=AE3QXKLJPH3UJVNNSGYPB4LQWQKRLA5CNFSM4JTI25NKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFRUCTQ#issuecomment-560152910, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE3QXKIKBNHXHAZIIZLLRH3QWQKRLANCNFSM4JTI25NA .

benbusby commented 4 years ago

The only intended use case is on an internet connected raspberry pi. I assumed I had made that clear in the readme, but I’ll update it to be more explicit.

acidtech commented 4 years ago

That was basically why I posted. To prevent people wasting several hours building the project just to find it wont work for a local network setup. The example, a rover with camera, is basically a FPV system which was what Im trying to implements.

I've made some progress on streaming h264 live video from RPi to html5 video using gstreamer. 100 to 200ms latency. I found the original code online but a few key settings were required to get the low latency. Still a few bugs to work out, like forcing the HTML5 video to always play from the live(latest) packets. I've attached the test code if you are interested.

Use firefox with the current test.html. Chrome blocks autoplay video by default. I used the autoplay because it starts playing immediately(within 100ms) of the stream. If you dont use autoplay and click play manually you have to seek to the newest section of video manually. Note, this is just a proof of concept but it is functional and doesnt require https. I've found no other method that can use a regular browser with a RPi stream on a local connection.

You will need gstreamer1.0 installed along with the good and bad pluggins(h264parse is in the bad plugins). I think everything else is already on the latest Raspbian Buster. I tested with a Zero but it should also work on other RPi models.

Nathan Scherdin

On Sun, Dec 1, 2019 at 12:59 PM Ben Busby notifications@github.com wrote:

The only intended use case is on an internet connected raspberry pi. I assumed I had made that clear in the readme, but I’ll update it to be more explicit.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/benbusby/raztot/issues/15?email_source=notifications&email_token=AE3QXKKUQQLHE2IYZPUZLUDQWQQTXA5CNFSM4JTI25NKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFRVNEY#issuecomment-560158355, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE3QXKMM3L6VFZGJPYHA5TTQWQQTXANCNFSM4JTI25NA .

import gi import time import subprocess # for piping from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler

class RequestHandler(BaseHTTPRequestHandler): def _writeheaders(self): self.send_response(200) # 200 OK http response self.send_header('Content-type', 'video/mp4') self.end_headers()

def do_HEAD(self):
    self._writeheaders()

def do_GET(self):
    self._writeheaders()

    DataChunkSize = 25000

command = 'gst-launch-1.0 -e -q v4l2src ! video/x-h264,width=640,height=480,framerate=30/1,stream-format=byte-stream ! h264parse config-interval=$

    command = 'gst-launch-1.0 -e -q v4l2src ! video/x-h264,width=640,height=480,framerate=60/1 ! h264parse !  mp4mux fragment-duration=1 ! filesink lo$
    print("running command: %s" % (command, ))
    p = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=-1, shell=True)

    print("starting polling loop.")
    while(p.poll() is None):

print "looping... "

print time.time()

        stdoutdata = p.stdout.read(DataChunkSize)
        self.wfile.write(stdoutdata)

    print("Done Looping")

    print("dumping last data, if any")
    stdoutdata = p.stdout.read(DataChunkSize)
    self.wfile.write(stdoutdata)

if name == 'main': serveraddr = ('', 8765) # connect to port 8765 srvr = HTTPServer(serveraddr, RequestHandler) srvr.serve_forever()

acidtech commented 4 years ago

There was one other thing you need to do. Use v4l2-ctl to change the h264_i_frame_period=1 or some other low number. It defaults to 60 which causes a most of the 1 second default latency.

Nathan Scherdin

On Sun, Dec 1, 2019 at 12:59 PM Ben Busby notifications@github.com wrote:

The only intended use case is on an internet connected raspberry pi. I assumed I had made that clear in the readme, but I’ll update it to be more explicit.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/benbusby/raztot/issues/15?email_source=notifications&email_token=AE3QXKKUQQLHE2IYZPUZLUDQWQQTXA5CNFSM4JTI25NKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFRVNEY#issuecomment-560158355, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE3QXKMM3L6VFZGJPYHA5TTQWQQTXANCNFSM4JTI25NA .

benbusby commented 4 years ago

Closing this issue now that I've added clarification to the readme, but I'll keep responding here. I'll get back to you once I have a sec to check out your code!

acidtech commented 4 years ago

No problem. Just thought you would be interested. I'm also looking at setting up a Janus server on the RPi which may also allow me to use WebRTC without the normal media access which is the part that forces https.

Nathan Scherdin

On Mon, Dec 2, 2019 at 10:41 AM Ben Busby notifications@github.com wrote:

Closed #15 https://github.com/benbusby/raztot/issues/15.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/benbusby/raztot/issues/15?email_source=notifications&email_token=AE3QXKJLQ3BXFGZMCTJV5HDQWVJEXA5CNFSM4JTI25NKYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOVGXO3CQ#event-2846813578, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE3QXKLEUWRXLBLKKEDWPQ3QWVJEXANCNFSM4JTI25NA .