
Live Streaming Setup for Raspberry Pi: Complete Guide
"Learn how to set up live streaming on your Raspberry Pi with detailed instructions on installing necessary packages, creating a server, and starting the stream. Follow this comprehensive guide for an effective Raspberry Pi camera setup."
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
IoT() 2016 2 4.
4. 2
4 $ sudo apt-get update $ sudo apt-get upgrade enable $ sudo raspi-config $ $ raspistill -o image.jpg $ raspistill --help $ raspivid -o video.h264 $ raspivid --help
5 http://thejackalofjavascript.com/rpi-live-streaming/ $ mkdir liveStreaming $ cd liveStreaming $ npm init $ npm install express socket.io --save $ nano index.js $ nano index.html
6 <!DOCTYPE html> <html lang="en"> var express = require('express'); var app = express(); var http = require('http').Server(app); var io = require('socket.io')(http); var fs = require('fs'); var path = require('path'); <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Stream My Lab </title> var spawn = require('child_process').spawn; var proc; app.use('/', express.static(path.join(__dirname, 'stream'))); <!-- Bootstrap CSS --> <link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> app.get('/', function(req, res) { res.sendFile(__dirname + '/index.html'); }); <style type="text/css"> #stream { height: 99%; margin: 0px auto; display: block; margin-top: 20px; } </style> var sockets = {}; io.on('connection', function(socket) { sockets[socket.id] = socket; console.log("Total clients connected : ", Object.keys(sockets).length); socket.on('disconnect', function() { delete sockets[socket.id]; <!-- jQuery --> <script src="http://code.jquery.com/jquery.js"></script> <!-- Bootstrap JavaScript --> <script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> <script src="/socket.io/socket.io.js"></script> <script> var socket = io(); socket.on('liveStream', function(url) { $('#stream').attr('src', url); $('.start').hide(); }); // no more sockets, kill the stream if (Object.keys(sockets).length == 0) { app.set('watchingFile', false); if (proc) proc.kill(); fs.unwatchFile('./stream/image_stream.jpg'); } }); socket.on('start-stream', function() { startStreaming(io); }); }); http.listen(3000, function() { console.log('listening on *:3000'); }); function startStream() { socket.emit('start-stream'); $('.start').hide(); } </script> </head> function stopStreaming() { if (Object.keys(sockets).length == 0) { app.set('watchingFile', false); if (proc) proc.kill(); fs.unwatchFile('./stream/image_stream.jpg'); } } <body class="container"> <h1 class="text-center">My Lab <small>Powered by PI</small> </h1> function startStreaming(io) { if (app.get('watchingFile')) { io.sockets.emit('liveStream', 'image_stream.jpg?_t=' + (Math.random() * 100000)); return; } <hr> <button type="button" id="" class="btn btn-info start" onclick="startStream()">Start Camera</button> var args = ["-w", "640", "-h", "480", "-o", "./stream/image_stream.jpg", "-t", "999999999", "-tl", "100"]; proc = spawn('raspistill', args); <div class="row"> <img src="" id="stream"> </div> console.log('Watching for changes...'); app.set('watchingFile', true); </body> fs.watchFile('./stream/image_stream.jpg', function(current, previous) { io.sockets.emit('liveStream', 'image_stream.jpg?_t=' + (Math.random() * 100000)); }) </html> } Index.js Index.html <script src="/socket.io/socket.io.js"></script> https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js
7 $ mkdir stream ( ) $ sudo node index.js http://localhost:3000 http://IP :3000
8 raspberry-pi-mjpeg-server https://github.com/john-doherty/raspberry-pi-mjpeg-server $ git clone https://github.com/john-doherty/raspberry-pi- mjpeg-server $ cd raspberry-pi-mjpeg-server $ npm install $ sudo node raspberry-pi-mjpeg-server.js -w 1280 -l 1024 Localhost:8080
9 http://irisschaffer.com/taking-photos-with-raspberry-pi-socket- io/ $ git clone https://github.com/irisSchaffer/rpi-socket- streaming.git $ cd rpi-socket-streaming $ npm install