canvas-recorder
Advanced tools
Comparing version 1.4.1 to 1.5.0
@@ -12,5 +12,42 @@ #! /usr/bin/env node | ||
.option( "-r, --fps <num>", "The framerate at which the sequence should play. Default is 30." ) | ||
.option( "-k, --format <format>", "The file format generated: mp4 or gif. Default is mp4" ) | ||
.parse( process.argv ); | ||
function valueOrDefault( name, defaultValue, restrictions ) { | ||
const value = program[ name ]; | ||
if ( !value ) { | ||
return defaultValue; | ||
} | ||
if ( restrictions && restrictions.indexOf( value ) < 0 ) { | ||
throw new Error( name + ' has to be one of: ' + restrictions.join ( ', ' ) ); | ||
} | ||
return value; | ||
} | ||
function getCommand( options ) { | ||
switch ( options.format ) { | ||
case "mp4": | ||
return [ | ||
`-framerate ${ options.fps }`, | ||
"-i %06d.png", | ||
"-c:v libx264", | ||
"-pix_fmt yuv420p", | ||
options.output, | ||
]; | ||
case "gif": | ||
return [ | ||
"-f image2", | ||
`-framerate ${ options.fps }`, | ||
"-i %06d.png", | ||
`-r ${ options.fps }`, | ||
options.output, | ||
]; | ||
default: | ||
return []; | ||
} | ||
} | ||
exec( "ffmpeg -version", function( error, stdout, stderr ) { | ||
@@ -26,18 +63,29 @@ if ( error || stderr ) { | ||
const fps = program.fps || 30; | ||
const output = program.output || "out.mp4"; | ||
const input = program.input || "."; | ||
const options = {}; | ||
spawn( "ffmpeg", [ | ||
"-i %06d.png", | ||
`-framerate ${ fps }`, | ||
`-r ${ fps }`, | ||
"-c:v libx264", | ||
`-vf "fps=${ fps },format=yuv420p"`, | ||
output, | ||
], { | ||
try { | ||
options.format = valueOrDefault( "format", "mp4", [ "mp4", "gif" ] ); | ||
options.fps = valueOrDefault( "fps", 30 ); | ||
options.output = valueOrDefault( "output", "out." + options.format ); | ||
options.input = valueOrDefault( "input", "." ); | ||
} catch( error ) { | ||
console.error( error.message ); | ||
return; | ||
} | ||
const spawnOptions = { | ||
stdio: "inherit", | ||
shell: true, | ||
cwd: input, | ||
} ); | ||
cwd: options.input, | ||
} | ||
const spawnFlags = getCommand( options ); | ||
if ( !spawnFlags ) { | ||
console.error( "Something went wrong. canvas-recorder didn't understand the command." ); | ||
return; | ||
} | ||
spawn( "ffmpeg", spawnFlags, spawnOptions ); | ||
} ); |
@@ -0,0 +0,0 @@ import { BaseRecorder, Settings } from "./shared"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /// <reference types="jszip" /> |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "canvas-recorder", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "Browserside tool to record canvas animations frame by frame.", | ||
@@ -5,0 +5,0 @@ "types": "./", |
# Canvas Recorder | ||
> A blatant ripoff of [Looper](https://github.com/spite/looper) | ||
> A blatant ripoff of [Looper](https://github.com/spite/looper) 😎 | ||
@@ -220,2 +220,2 @@ This is a small utility to record a canvas based animation of any sort. The tool can be used to | ||
} | ||
``` | ||
``` |
@@ -0,0 +0,0 @@ /// <reference types="jszip" /> |
@@ -0,0 +0,0 @@ "use strict"; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32263
586
221