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

Saved video is very different from actual animation #41

Open
Liting1 opened this issue Nov 19, 2021 · 0 comments
Open

Saved video is very different from actual animation #41

Liting1 opened this issue Nov 19, 2021 · 0 comments
Labels

Comments

@Liting1
Copy link

Liting1 commented Nov 19, 2021

I tried to draw the animation using Canvas and save it by converting it to MP4.

But the saved MP4 is too different from the actual animation

node: 12.20.2
node-canvas: 2.8.0
ffmpeg-stream: 0.7.0

		const converterInput = converter.createInputStream({ f: "image2pipe", r: 20 });
		converter.createOutputToFile("out.mp4", {
			vcodec: "libx264",
  			pix_fmt: "yuv420p",
		});
		const convertingFinished = converter.run();
		let i = 0;
		let timer = null;
		const keyframes = () => {
			console.log(i);
			const canvas = this.scene.snapshot();
			const stream = canvas.createJPEGStream({quality: 1, progressive: false, chromaSubsampling: true});
			stream.on('end', () => {
				i++;
				if(i>= 150) {
					clearTimeout(timer);
					converterInput.end();
				} else {
					timer = setTimeout(keyframes, 1000 / 20);
				}
				console.log('end');
			});
			stream.pipe(converterInput, {end: false}).on('error', (err) => {
				if(err) console.log(err);
			});
		}
		keyframes();
		await convertingFinished
}```
Hope to be able to optimize repair。thank you
@phaux phaux added the question label Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants