Comments (6)
Also tried posting to the web worker on each interval:
Main JS
toggleSnapshotRecord() {
this.isRecording = !this.isRecording;
$(document.body).toggleClass("is-recording");
let interval = (this.captureSecondsDelay - 1) * 1000;
let snapCount = 0;
if (this.isRecording) {
this.snapshotInterval = setInterval(() => {
let messageData = {
size: [this.outputWidth, this.outputHeight],
frame: this.canvasContext.getImageData(0, 0, this.outputWidth, this.outputHeight)
};
if (snapCount === 0)
messageData["start"] = true;
if (snapCount === this.captureFramesNumber - 1)
messageData["finish"] = true;
this.gifWorker.postMessage(messageData);
snapCount = snapCount + 1;
if (snapCount === this.captureFramesNumber)
return this.toggleSnapshotRecord();
}, interval);
} else {
clearInterval(this.snapshotInterval);
this.gifWorker.onmessage = function(event) {
console.log(event.data);
};
};
};
Web Worker
var encoder = new GIFEncoder();
encoder.setRepeat(0);
encoder.setDelay(300);
self.addEventListener("message", function(event) {
var data = event.data;
if (data.start) {
encoder.start();
} else {
encoder.setProperties(true, true);
}
encoder.setSize(data.size[0], data.size[1]);
encoder.addFrame(data.frame, true);
if (data.finish) {
encoder.finish();
self.postMessage("data:image/gif;base64," + encode64(encoder.stream().getData()));
}
}, false);
from jsgif.
Does the black output GIF at least appear to have the correct number of frames?
from jsgif.
Negative. It looks to be just the one frame (upon inspection in Apple Preview).
from jsgif.
Got it. In passing data.frame
to encoder.addFrame()
I was passing an ImageData
object to it, when I should have been passing the ImageData's data
– all in all I just had to change it to encoder.addFrame(data.frame.data, true)
.
from jsgif.
from jsgif.
Why are you calling:
encoder.setProperties(true, true);
? It seems like those are internal parameters managed by the encoder and don't need to be changed.
Also it looks like the setSize() call can be moved into the if (data.start) { ... } area.
Clay Budin
NYC
from jsgif.
Related Issues (20)
- No license information HOT 1
- `addFrame` with `is_imageData=true` makes Chrome hang up HOT 3
- Writing canvas to GIF outputs double speed GIF HOT 1
- License HOT 1
- last frame of addFrame is not added to gif HOT 1
- Data URI generates a black gif HOT 4
- jsapng? can you make convas into animated PNG? HOT 5
- GIF almost empty HOT 4
- Pixel width black line on left edge of GIF
- Add git tag
- My webcam snapshot is being overlay by the gif ??
- No plugin.xml file
- Color Reproduction Issue HOT 2
- Fixes report HOT 1
- Global color map HOT 2
- Crashes at 300+ Frames HOT 2
- License? HOT 2
- The encoding of the Gif fails depending on the size of the canvas HOT 1
- Background image shown in canvas but not in image output HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsgif.