Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compression feature (imagemagick) #3

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,17 @@ pi_livestreaming
================

[Raspberry Pi, Camera and Node.js – Live Streaming with Websockets #IoT](http://thejackalofjavascript.com/rpi-live-streaming)

Adding compression feature

Before doing anything :
apt-get install imagemagick

### from 200~ Ko per picture to 70~ Ko

using shell command : convert ...

## Change the convert quality (string)
```
var convertQuality = "65";
```
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<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 Aquarium</title>
<title>Stream My Rabbit</title>

<!-- Bootstrap CSS -->
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
Expand Down Expand Up @@ -39,7 +39,7 @@
</head>

<body class="container">
<h1 class="text-center">My Aquarium
<h1 class="text-center">My Rabbit
<small>Powered by PI</small>
</h1>

Expand All @@ -48,7 +48,7 @@ <h1 class="text-center">My Aquarium
<button type="button" id="" class="btn btn-info start" onclick="startStream()">Start Camera</button>

<div class="row">
<img src="" id="stream">
<img src="" id="stream" style="transform: rotate(180deg)">
</div>

</body>
Expand Down
18 changes: 13 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ var http = require('http').Server(app);
var io = require('socket.io')(http);
var fs = require('fs');
var path = require('path');
var port = 27020;
var convertQuality = "85";

var spawn = require('child_process').spawn;
var proc;
var _compressing = false;

app.use('/', express.static(path.join(__dirname, 'stream')));

Expand All @@ -30,6 +33,7 @@ io.on('connection', function(socket) {
app.set('watchingFile', false);
if (proc) proc.kill();
fs.unwatchFile('./stream/image_stream.jpg');
fs.unwatchFile('./stream/compressed.jpg');
}
});

Expand All @@ -39,8 +43,8 @@ io.on('connection', function(socket) {

});

http.listen(3000, function() {
console.log('listening on *:3000');
http.listen(port, function() {
console.log('listening on *: '+port);
});

function stopStreaming() {
Expand All @@ -54,19 +58,23 @@ function stopStreaming() {
function startStreaming(io) {

if (app.get('watchingFile')) {
io.sockets.emit('liveStream', 'image_stream.jpg?_t=' + (Math.random() * 100000));
io.sockets.emit('liveStream', 'compressed.jpg?_t=' + (Math.random() * 100000));
return;
}

var args = ["-w", "640", "-h", "480", "-o", "./stream/image_stream.jpg", "-t", "999999999", "-tl", "100"];
proc = spawn('raspistill', args);

if(!_compressing){
proc = spawn('raspistill', args);
}

console.log('Watching for changes...');

app.set('watchingFile', true);

fs.watchFile('./stream/image_stream.jpg', function(current, previous) {
console.log('updating...');
io.sockets.emit('liveStream', 'image_stream.jpg?_t=' + (Math.random() * 100000));
})
});

}
1 change: 1 addition & 0 deletions node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

212 changes: 212 additions & 0 deletions node_modules/accepts/HISTORY.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions node_modules/accepts/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading