updated image conversion part
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,6 +3,8 @@
|
|||||||
*.mp3
|
*.mp3
|
||||||
*.gif
|
*.gif
|
||||||
*.webm
|
*.webm
|
||||||
|
*.heic
|
||||||
|
*.heif
|
||||||
converted-ss/
|
converted-ss/
|
||||||
tmp-ss/
|
tmp-ss/
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|||||||
@@ -1,63 +1,98 @@
|
|||||||
module.exports = convertToAscii = async (file = __dirname + 'input.png', output = __dirname + '/output.png', dotSize = 24, verticalSpacinModifier = 4, callback) => {
|
const { createCanvas } = require("canvas");
|
||||||
console.log('converting image to ascii');
|
const ImageDataURI = require("image-data-uri");
|
||||||
const hobbitImageFile = file;
|
var sizeOf = require("image-size");
|
||||||
const density = 'Ñ@#W$9876543210?!abc;:+=-,._ ';
|
const { exec, execSync } = require("child_process");
|
||||||
|
const heicToPng = require("./heicToPng");
|
||||||
|
|
||||||
const { createCanvas } = require('canvas')
|
module.exports = convertToAscii = async (
|
||||||
const ImageDataURI = require('image-data-uri');
|
file = __dirname + "input.png",
|
||||||
var sizeOf = require('image-size');
|
output = __dirname + "/output.png",
|
||||||
var dimensions = sizeOf(hobbitImageFile);
|
dotSize = 24,
|
||||||
|
verticalSpacingModifier = 4,
|
||||||
|
scaledSize = 120,
|
||||||
|
callback
|
||||||
|
) => {
|
||||||
|
const filePNG = file + (file.toLowerCase().endsWith(".png") ? "" : ".png");
|
||||||
|
let fileToConvert = file;
|
||||||
|
if (
|
||||||
|
file.toLowerCase().endsWith(".heic") ||
|
||||||
|
file.toLowerCase().endsWith(".heif")
|
||||||
|
) {
|
||||||
|
console.log("heic file got");
|
||||||
|
await heicToPng(file, filePNG);
|
||||||
|
fileToConvert = filePNG;
|
||||||
|
}
|
||||||
|
console.log("pre image resize");
|
||||||
|
const scaledFile = "scaled-" + filePNG;
|
||||||
|
execSync(
|
||||||
|
`ffmpeg -i ${fileToConvert} -vf scale=${scaledSize}:-2 ${scaledFile} -y`
|
||||||
|
);
|
||||||
|
console.log("post image scale");
|
||||||
|
|
||||||
const hobbit = {
|
await convert(scaledFile, output, dotSize, verticalSpacingModifier);
|
||||||
width: dimensions.width,
|
callback(output);
|
||||||
height: dimensions.height,
|
};
|
||||||
pixels: [],
|
|
||||||
}
|
|
||||||
|
|
||||||
function clamp(input, min, max) {
|
const convert = async (file, output, dotSize, verticalSpacingModifier) => {
|
||||||
return input < min ? min : input > max ? max : input;
|
const density = "Ñ@#W$9876543210?!abc;:+=-,._ ";
|
||||||
}
|
var dimensions = sizeOf(file);
|
||||||
|
|
||||||
function map(current, in_min, in_max, out_min, out_max) {
|
const image = {
|
||||||
const mapped = ((current - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min;
|
width: dimensions.width,
|
||||||
return clamp(mapped, out_min, out_max);
|
height: dimensions.height,
|
||||||
}
|
pixels: [],
|
||||||
|
};
|
||||||
|
|
||||||
await new Promise((res, rej) => {
|
function clamp(input, min, max) {
|
||||||
var PNG = require('png-js');
|
return input < min ? min : input > max ? max : input;
|
||||||
PNG.decode(hobbitImageFile, function(pixels) {
|
}
|
||||||
|
|
||||||
const canvas = createCanvas(hobbit.width * dotSize, hobbit.height * dotSize);
|
function map(current, in_min, in_max, out_min, out_max) {
|
||||||
const ctx = canvas.getContext('2d')
|
const mapped =
|
||||||
|
((current - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min;
|
||||||
|
return clamp(mapped, out_min, out_max);
|
||||||
|
}
|
||||||
|
|
||||||
hobbit.pixels = pixels;
|
await new Promise((res, rej) => {
|
||||||
|
var PNG = require("png-js");
|
||||||
|
PNG.decode(file, function (pixels) {
|
||||||
|
const canvas = createCanvas(
|
||||||
|
image.width * dotSize,
|
||||||
|
image.height * dotSize
|
||||||
|
);
|
||||||
|
const ctx = canvas.getContext("2d");
|
||||||
|
|
||||||
ctx.fillStyle = 'black';
|
image.pixels = pixels;
|
||||||
ctx.fillRect(0, 0, hobbit.width * dotSize, hobbit.height * dotSize);
|
|
||||||
|
|
||||||
ctx.font = (dotSize + verticalSpacinModifier) + "px Courier";
|
|
||||||
ctx.textAlign = 'center';
|
|
||||||
ctx.textBaseline = 'middle';
|
|
||||||
ctx.fillStyle = `white`;
|
|
||||||
|
|
||||||
for(let x = 0; x < hobbit.width; x++) {
|
ctx.fillStyle = "black";
|
||||||
for(let y = 0; y < hobbit.height; y++) {
|
ctx.fillRect(0, 0, image.width * dotSize, image.height * dotSize);
|
||||||
const pixelPosition = (x + y*hobbit.width)*4;
|
|
||||||
const r = hobbit.pixels[pixelPosition + 0];
|
|
||||||
const g = hobbit.pixels[pixelPosition + 1];
|
|
||||||
const b = hobbit.pixels[pixelPosition + 2];
|
|
||||||
const a = hobbit.pixels[pixelPosition + 3];
|
|
||||||
|
|
||||||
const avg = Math.floor((r+g+b)/ 3) * (a/255);
|
|
||||||
|
|
||||||
const gray = map(255 - avg, 0, 255, 0, density.length);
|
ctx.font = dotSize + verticalSpacingModifier + "px Courier";
|
||||||
ctx.fillText(density.charAt(gray), x*dotSize + dotSize/2, y*dotSize + dotSize/2);
|
ctx.textAlign = "center";
|
||||||
}
|
ctx.textBaseline = "middle";
|
||||||
}
|
ctx.fillStyle = `white`;
|
||||||
|
|
||||||
ImageDataURI.outputFile(canvas.toDataURL(), output);
|
for (let x = 0; x < image.width; x++) {
|
||||||
res(1);
|
for (let y = 0; y < image.height; y++) {
|
||||||
});
|
const pixelPosition = (x + y * image.width) * 4;
|
||||||
|
const r = image.pixels[pixelPosition + 0];
|
||||||
|
const g = image.pixels[pixelPosition + 1];
|
||||||
|
const b = image.pixels[pixelPosition + 2];
|
||||||
|
const a = image.pixels[pixelPosition + 3];
|
||||||
|
|
||||||
|
const avg = Math.floor((r + g + b) / 3) * (a / 255);
|
||||||
|
|
||||||
|
const gray = map(255 - avg, 0, 255, 0, density.length);
|
||||||
|
ctx.fillText(
|
||||||
|
density.charAt(gray),
|
||||||
|
x * dotSize + dotSize / 2,
|
||||||
|
y * dotSize + dotSize / 2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageDataURI.outputFile(canvas.toDataURL(), output);
|
||||||
|
res(1);
|
||||||
});
|
});
|
||||||
callback(output);
|
});
|
||||||
}
|
};
|
||||||
|
|||||||
12
heicToPng.js
Normal file
12
heicToPng.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
const { promisify } = require("util");
|
||||||
|
const fs = require("fs");
|
||||||
|
const convert = require("heic-convert");
|
||||||
|
|
||||||
|
module.exports = async function heicToPng(input, output) {
|
||||||
|
const inputBuffer = await promisify(fs.readFile)(input);
|
||||||
|
const outputBuffer = await convert({
|
||||||
|
buffer: inputBuffer,
|
||||||
|
format: "PNG",
|
||||||
|
});
|
||||||
|
await promisify(fs.writeFile)(output, outputBuffer);
|
||||||
|
};
|
||||||
517
index.js
517
index.js
@@ -21,10 +21,10 @@ const convertToAscii = require("./convertToAscii");
|
|||||||
const extractFrames = require("./extractFrames");
|
const extractFrames = require("./extractFrames");
|
||||||
const gifToMp4 = require("./gifToMp4");
|
const gifToMp4 = require("./gifToMp4");
|
||||||
const scaleVideo = require("./scaleVideo");
|
const scaleVideo = require("./scaleVideo");
|
||||||
const fs = require('fs');
|
const fs = require("fs");
|
||||||
const makeVideoFromImages = require("./makeVideoFromImages");
|
const makeVideoFromImages = require("./makeVideoFromImages");
|
||||||
const mp4ToGif = require("./mp4ToGif");
|
const mp4ToGif = require("./mp4ToGif");
|
||||||
const fsExtra = require('fs-extra');
|
const fsExtra = require("fs-extra");
|
||||||
|
|
||||||
args = process.argv;
|
args = process.argv;
|
||||||
|
|
||||||
@@ -37,277 +37,350 @@ const randomName = (Math.random() + 1).toString(36).substring(2);
|
|||||||
|
|
||||||
const action = args.shift();
|
const action = args.shift();
|
||||||
|
|
||||||
let usage = '';
|
let usage = "";
|
||||||
let example = '';
|
let example = "";
|
||||||
|
|
||||||
|
|
||||||
let input;
|
let input;
|
||||||
let output;
|
let output;
|
||||||
let pixelSize;
|
let pixelSize;
|
||||||
let pixelModifyer;
|
let pixelModifier;
|
||||||
let scaledSize;
|
let scaledSize;
|
||||||
let fps;
|
let fps;
|
||||||
|
|
||||||
|
const _scaleVideo = (
|
||||||
|
inputFile,
|
||||||
const _scaleVideo = (inputFile, pixelSize, pixelModifyer, scaledSize, fps, output, convertToGif = false, deleteInputFile = false) => {
|
pixelSize,
|
||||||
scaleVideo(inputFile, 'mp4-scaled-' + randomName + '.mp4', scaledSize, fps, (scaledFile) => {
|
pixelModifier,
|
||||||
if (deleteInputFile) {
|
scaledSize,
|
||||||
fs.rmSync(inputFile);
|
fps,
|
||||||
}
|
output,
|
||||||
const outputFolder = __dirname + '/extracted-frames-'+randomName;
|
convertToGif = false,
|
||||||
extractFrames(scaledFile, outputFolder, async () => {
|
deleteInputFile = false
|
||||||
fs.rmSync(scaledFile);
|
) => {
|
||||||
let files = fs.readdirSync(outputFolder);
|
scaleVideo(
|
||||||
const convertedFolder = __dirname + '/converted-frames-'+randomName;
|
inputFile,
|
||||||
let index = 0;
|
"mp4-scaled-" + randomName + ".mp4",
|
||||||
for (let file of files) {
|
scaledSize,
|
||||||
index++;
|
fps,
|
||||||
await convertToAscii(outputFolder + '/' + file, convertedFolder + '/' + file, pixelSize, pixelModifyer, () => {
|
(scaledFile) => {
|
||||||
console.log(index, '/', files.length);
|
if (deleteInputFile) {
|
||||||
fs.rmSync(outputFolder + '/' + file);
|
fs.rmSync(inputFile);
|
||||||
});
|
}
|
||||||
|
const outputFolder = __dirname + "/extracted-frames-" + randomName;
|
||||||
|
extractFrames(scaledFile, outputFolder, async () => {
|
||||||
|
fs.rmSync(scaledFile);
|
||||||
|
let files = fs.readdirSync(outputFolder);
|
||||||
|
const convertedFolder = __dirname + "/converted-frames-" + randomName;
|
||||||
|
let index = 0;
|
||||||
|
for (let file of files) {
|
||||||
|
index++;
|
||||||
|
await convertToAscii(
|
||||||
|
outputFolder + "/" + file,
|
||||||
|
convertedFolder + "/" + file,
|
||||||
|
pixelSize,
|
||||||
|
pixelModifier,
|
||||||
|
scaledSize,
|
||||||
|
() => {
|
||||||
|
console.log(index, "/", files.length);
|
||||||
|
fs.rmSync(outputFolder + "/" + file);
|
||||||
}
|
}
|
||||||
fsExtra.emptyDirSync(outputFolder);
|
);
|
||||||
fs.rmdirSync(outputFolder);
|
}
|
||||||
makeVideoFromImages(convertedFolder + '/%d.png', __dirname + 'generated-video-' + randomName + '.mp4', fps, fps, (generatedVideoFIle) => {
|
fsExtra.emptyDirSync(outputFolder);
|
||||||
fsExtra.emptyDirSync(convertedFolder);
|
fs.rmdirSync(outputFolder);
|
||||||
fs.rmdirSync(convertedFolder);
|
makeVideoFromImages(
|
||||||
if (convertToGif) {
|
convertedFolder + "/%d.png",
|
||||||
mp4ToGif(generatedVideoFIle, output, (gif) => {
|
__dirname + "generated-video-" + randomName + ".mp4",
|
||||||
console.log('gif generated in: ' + gif);
|
fps,
|
||||||
});
|
fps,
|
||||||
} else {
|
(generatedVideoFIle) => {
|
||||||
fs.renameSync(generatedVideoFIle, output);
|
fsExtra.emptyDirSync(convertedFolder);
|
||||||
console.log('video generated in: ' + output);
|
fs.rmdirSync(convertedFolder);
|
||||||
}
|
if (convertToGif) {
|
||||||
});
|
mp4ToGif(generatedVideoFIle, output, (gif) => {
|
||||||
})
|
console.log("gif generated in: " + gif);
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
|
fs.renameSync(generatedVideoFIle, output);
|
||||||
|
console.log("video generated in: " + output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'img':
|
case "img":
|
||||||
|
usage = `Usage: npm run convert:img input-image-path.png[optional, default:./input.png] output-image-path.png[optional, default:./output.png] pixel-size[optional, default:24] font-size-modifier[optional, degault:4]`;
|
||||||
|
example = `Example: npm run convert:img input.png output.png 24 0`;
|
||||||
|
|
||||||
usage = `Usage: npm run convert:img input-image-path.png[optional, default:./input.png] output-image-path.png[optional, default:./output.png] pixel-size[optional, default:24] font-size-modifier[optional, degault:4]`;
|
if (args[0] === "help") {
|
||||||
example = `Example: npm run convert:img input.png output.png 24 0`;
|
console.log(`${usage}\n${example}`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (args[0] === 'help') {
|
if (args.length > 5) {
|
||||||
console.log(`${usage}\n${example}`);
|
console.error(`Invalid parameter count!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 4) {
|
if (args[2] && isNaN(parseInt(args[2], base))) {
|
||||||
console.error(`Invalid parameter count!\n${usage}\n${example}`);
|
console.error(`Pixel size must be a number!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[2] && isNaN(parseInt(args[2], base))) {
|
if (args[3] && isNaN(parseInt(args[3], base))) {
|
||||||
console.error(`Pixel size must be a number!\n${usage}\n${example}`);
|
console.error(
|
||||||
process.exit(0);
|
`Font size modifier must be a number!\n${usage}\n${example}`
|
||||||
}
|
);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (args[3] && isNaN(parseInt(args[3], base))) {
|
if (args[4] && isNaN(parseInt(args[4], base))) {
|
||||||
console.error(`Font size modifier must be a number!\n${usage}\n${example}`);
|
console.error(`Scaled size must be a number!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
convertToAscii(args[0], args[1], args[2], args[3], () => {
|
input = args[0];
|
||||||
console.log(`Image converted and saved in ${args[1]}`);
|
output = args[1];
|
||||||
});
|
pixelSize = parseInt(args[2], base);
|
||||||
|
pixelModifier = parseInt(args[3], base);
|
||||||
|
scaledSize = parseInt(args[4], base);
|
||||||
|
|
||||||
|
convertToAscii(input, output, pixelSize, pixelModifier, scaledSize, () => {
|
||||||
|
console.log(`Image converted and saved in ${args[1]}`);
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'gif:gif':
|
case "gif:gif":
|
||||||
|
usage = `Usage: npm run convert:gif:gif input-image-path.png[optional, default:./input.gif] output-image-path.png[optional, default:./output.gif] pixel-size[optional, default:24] font-size-modifier[optional, degault:4] scaled-size[optional, default=120] fps[optional, default=10]`;
|
||||||
|
example = `Example: npm run convert:gif:gif input.gif output.gif 24 4 120 10`;
|
||||||
|
|
||||||
usage = `Usage: npm run convert:gif:gif input-image-path.png[optional, default:./input.gif] output-image-path.png[optional, default:./output.gif] pixel-size[optional, default:24] font-size-modifier[optional, degault:4] scaled-size[optional, default=120] fps[optional, default=10]`;
|
if (args[0] === "help") {
|
||||||
example = `Example: npm run convert:gif:gif input.gif output.gif 24 4 120 10`;
|
console.log(`${usage}\n${example}`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (args[0] === 'help') {
|
if (args.length > 7) {
|
||||||
console.log(`${usage}\n${example}`);
|
console.error(`Invalid parameter count!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 7) {
|
if (args[2] && isNaN(parseInt(args[2], base))) {
|
||||||
console.error(`Invalid parameter count!\n${usage}\n${example}`);
|
console.error(`Pixel size must be a number!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[2] && isNaN(parseInt(args[2], base))) {
|
if (args[3] && isNaN(parseInt(args[3], base))) {
|
||||||
console.error(`Pixel size must be a number!\n${usage}\n${example}`);
|
console.error(
|
||||||
process.exit(0);
|
`Font size modifier must be a number!\n${usage}\n${example}`
|
||||||
}
|
);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (args[3] && isNaN(parseInt(args[3], base))) {
|
if (args[4] && isNaN(parseInt(args[4], base))) {
|
||||||
console.error(`Font size modifier must be a number!\n${usage}\n${example}`);
|
console.error(`Scaled size must be a number!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[4] && isNaN(parseInt(args[4], base))) {
|
if (args[5] && isNaN(parseInt(args[5], base))) {
|
||||||
console.error(`Scaled size must be a number!\n${usage}\n${example}`);
|
console.error(`Original FPS must be a number!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[5] && isNaN(parseInt(args[5], base))) {
|
input = args[0];
|
||||||
console.error(`Original FPS must be a number!\n${usage}\n${example}`);
|
output = args[1];
|
||||||
process.exit(0);
|
pixelSize = parseInt(args[2], base);
|
||||||
}
|
pixelModifier = parseInt(args[3], base);
|
||||||
|
scaledSize = parseInt(args[4], base);
|
||||||
|
fps = parseInt(args[5], base);
|
||||||
|
|
||||||
input = args[0];
|
gifToMp4(input, "gif-to-mp4-" + randomName + ".mp4", (convertedFile) => {
|
||||||
output = args[1];
|
_scaleVideo(
|
||||||
pixelSize = parseInt(args[2], base);
|
convertedFile,
|
||||||
pixelModifyer = parseInt(args[3], base);
|
pixelSize,
|
||||||
scaledSize = parseInt(args[4], base);
|
pixelModifier,
|
||||||
fps = parseInt(args[5], base);
|
scaledSize,
|
||||||
|
fps,
|
||||||
|
output,
|
||||||
gifToMp4(input, 'gif-to-mp4-'+randomName+'.mp4', (convertedFile) => {
|
true,
|
||||||
_scaleVideo(convertedFile, pixelSize, pixelModifyer, scaledSize, fps, output, true, true);
|
true
|
||||||
});
|
);
|
||||||
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'gif:mp4':
|
case "gif:mp4":
|
||||||
|
usage = `Usage: npm run convert:gif:mp4 input-image-path.gif[optional, default:./input.gif] output-image-path.mp4[optional, default:./output.mp4] pixel-size[optional, default:24] font-size-modifier[optional, degault:4] scaled-size[optional, default=120] fps[optional, default=10]`;
|
||||||
|
example = `Example: npm run convert:gif:mp4 input.gif output.mp4 24 4 120 10`;
|
||||||
|
|
||||||
usage = `Usage: npm run convert:gif:mp4 input-image-path.gif[optional, default:./input.gif] output-image-path.mp4[optional, default:./output.mp4] pixel-size[optional, default:24] font-size-modifier[optional, degault:4] scaled-size[optional, default=120] fps[optional, default=10]`;
|
if (args[0] === "help") {
|
||||||
example = `Example: npm run convert:gif:mp4 input.gif output.mp4 24 4 120 10`;
|
console.log(`${usage}\n${example}`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (args[0] === 'help') {
|
if (args.length > 7) {
|
||||||
console.log(`${usage}\n${example}`);
|
console.error(`Invalid parameter count!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 7) {
|
if (args[2] && isNaN(parseInt(args[2], base))) {
|
||||||
console.error(`Invalid parameter count!\n${usage}\n${example}`);
|
console.error(`Pixel size must be a number!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[2] && isNaN(parseInt(args[2], base))) {
|
if (args[3] && isNaN(parseInt(args[3], base))) {
|
||||||
console.error(`Pixel size must be a number!\n${usage}\n${example}`);
|
console.error(
|
||||||
process.exit(0);
|
`Font size modifier must be a number!\n${usage}\n${example}`
|
||||||
}
|
);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (args[3] && isNaN(parseInt(args[3], base))) {
|
if (args[4] && isNaN(parseInt(args[4], base))) {
|
||||||
console.error(`Font size modifier must be a number!\n${usage}\n${example}`);
|
console.error(`Scaled size must be a number!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[4] && isNaN(parseInt(args[4], base))) {
|
if (args[5] && isNaN(parseInt(args[5], base))) {
|
||||||
console.error(`Scaled size must be a number!\n${usage}\n${example}`);
|
console.error(`Original FPS must be a number!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[5] && isNaN(parseInt(args[5], base))) {
|
input = args[0];
|
||||||
console.error(`Original FPS must be a number!\n${usage}\n${example}`);
|
output = args[1];
|
||||||
process.exit(0);
|
pixelSize = parseInt(args[2], base);
|
||||||
}
|
pixelModifier = parseInt(args[3], base);
|
||||||
|
scaledSize = parseInt(args[4], base);
|
||||||
|
fps = parseInt(args[5], base);
|
||||||
|
|
||||||
input = args[0];
|
gifToMp4(input, "gif-to-mp4-" + randomName + ".mp4", (convertedFile) => {
|
||||||
output = args[1];
|
_scaleVideo(
|
||||||
pixelSize = parseInt(args[2], base);
|
convertedFile,
|
||||||
pixelModifyer = parseInt(args[3], base);
|
pixelSize,
|
||||||
scaledSize = parseInt(args[4], base);
|
pixelModifier,
|
||||||
fps = parseInt(args[5], base);
|
scaledSize,
|
||||||
|
fps,
|
||||||
|
output,
|
||||||
gifToMp4(input, 'gif-to-mp4-'+randomName+'.mp4', (convertedFile) => {
|
false,
|
||||||
_scaleVideo(convertedFile, pixelSize, pixelModifyer, scaledSize, fps, output, false, true);
|
true
|
||||||
});
|
);
|
||||||
|
});
|
||||||
break;
|
|
||||||
case 'mp4:gif':
|
|
||||||
|
|
||||||
usage = `Usage: npm run convert:mp4:gif input-image-path.mp4[optional, default:./input.mp4] output-image-path.gif[optional, default:./output.gif] pixel-size[optional, default:24] font-size-modifier[optional, degault:4] scaled-size[optional, default=120] fps[optional, default=10]`;
|
|
||||||
example = `Example: npm run convert:mp4:gif input.mp4 output.gif 24 4 120 10`;
|
|
||||||
|
|
||||||
if (args[0] === 'help') {
|
|
||||||
console.log(`${usage}\n${example}`);
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length > 7) {
|
|
||||||
console.error(`Invalid parameter count!\n${usage}\n${example}`);
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[2] && isNaN(parseInt(args[2], base))) {
|
|
||||||
console.error(`Pixel size must be a number!\n${usage}\n${example}`);
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[3] && isNaN(parseInt(args[3], base))) {
|
|
||||||
console.error(`Font size modifier must be a number!\n${usage}\n${example}`);
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[4] && isNaN(parseInt(args[4], base))) {
|
|
||||||
console.error(`Scaled size must be a number!\n${usage}\n${example}`);
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[5] && isNaN(parseInt(args[5], base))) {
|
|
||||||
console.error(`Original FPS must be a number!\n${usage}\n${example}`);
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
input = args[0];
|
|
||||||
output = args[1];
|
|
||||||
pixelSize = parseInt(args[2], base);
|
|
||||||
pixelModifyer = parseInt(args[3], base);
|
|
||||||
scaledSize = parseInt(args[4], base);
|
|
||||||
fps = parseInt(args[5], base);
|
|
||||||
|
|
||||||
|
|
||||||
_scaleVideo(input, pixelSize, pixelModifyer, scaledSize, fps, output, true, false);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'mp4:mp4':
|
case "mp4:gif":
|
||||||
|
usage = `Usage: npm run convert:mp4:gif input-image-path.mp4[optional, default:./input.mp4] output-image-path.gif[optional, default:./output.gif] pixel-size[optional, default:24] font-size-modifier[optional, degault:4] scaled-size[optional, default=120] fps[optional, default=10]`;
|
||||||
|
example = `Example: npm run convert:mp4:gif input.mp4 output.gif 24 4 120 10`;
|
||||||
|
|
||||||
usage = `Usage: npm run convert:mp4:mp4 input-image-path.mp4[optional, default:./input.mp4] output-image-path.mp4[optional, default:./output.mp4] pixel-size[optional, default:24] font-size-modifier[optional, degault:4] scaled-size[optional, default=120] fps[optional, default=10]`;
|
if (args[0] === "help") {
|
||||||
example = `Example: npm run convert:mp4:mp4 input.mp4 output.mp4 24 4 120 10`;
|
console.log(`${usage}\n${example}`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (args[0] === 'help') {
|
if (args.length > 7) {
|
||||||
console.log(`${usage}\n${example}`);
|
console.error(`Invalid parameter count!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 7) {
|
if (args[2] && isNaN(parseInt(args[2], base))) {
|
||||||
console.error(`Invalid parameter count!\n${usage}\n${example}`);
|
console.error(`Pixel size must be a number!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[2] && isNaN(parseInt(args[2], base))) {
|
if (args[3] && isNaN(parseInt(args[3], base))) {
|
||||||
console.error(`Pixel size must be a number!\n${usage}\n${example}`);
|
console.error(
|
||||||
process.exit(0);
|
`Font size modifier must be a number!\n${usage}\n${example}`
|
||||||
}
|
);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (args[3] && isNaN(parseInt(args[3], base))) {
|
if (args[4] && isNaN(parseInt(args[4], base))) {
|
||||||
console.error(`Font size modifier must be a number!\n${usage}\n${example}`);
|
console.error(`Scaled size must be a number!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[4] && isNaN(parseInt(args[4], base))) {
|
if (args[5] && isNaN(parseInt(args[5], base))) {
|
||||||
console.error(`Scaled size must be a number!\n${usage}\n${example}`);
|
console.error(`Original FPS must be a number!\n${usage}\n${example}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args[5] && isNaN(parseInt(args[5], base))) {
|
input = args[0];
|
||||||
console.error(`Original FPS must be a number!\n${usage}\n${example}`);
|
output = args[1];
|
||||||
process.exit(0);
|
pixelSize = parseInt(args[2], base);
|
||||||
}
|
pixelModifier = parseInt(args[3], base);
|
||||||
|
scaledSize = parseInt(args[4], base);
|
||||||
|
fps = parseInt(args[5], base);
|
||||||
|
|
||||||
input = args[0];
|
_scaleVideo(
|
||||||
output = args[1];
|
input,
|
||||||
pixelSize = parseInt(args[2], base);
|
pixelSize,
|
||||||
pixelModifyer = parseInt(args[3], base);
|
pixelModifier,
|
||||||
scaledSize = parseInt(args[4], base);
|
scaledSize,
|
||||||
fps = parseInt(args[5], base);
|
fps,
|
||||||
|
output,
|
||||||
|
true,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "mp4:mp4":
|
||||||
|
usage = `Usage: npm run convert:mp4:mp4 input-image-path.mp4[optional, default:./input.mp4] output-image-path.mp4[optional, default:./output.mp4] pixel-size[optional, default:24] font-size-modifier[optional, degault:4] scaled-size[optional, default=120] fps[optional, default=10]`;
|
||||||
|
example = `Example: npm run convert:mp4:mp4 input.mp4 output.mp4 24 4 120 10`;
|
||||||
|
|
||||||
_scaleVideo(input, pixelSize, pixelModifyer, scaledSize, fps, output, false, false);
|
if (args[0] === "help") {
|
||||||
|
console.log(`${usage}\n${example}`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length > 7) {
|
||||||
|
console.error(`Invalid parameter count!\n${usage}\n${example}`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[2] && isNaN(parseInt(args[2], base))) {
|
||||||
|
console.error(`Pixel size must be a number!\n${usage}\n${example}`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[3] && isNaN(parseInt(args[3], base))) {
|
||||||
|
console.error(
|
||||||
|
`Font size modifier must be a number!\n${usage}\n${example}`
|
||||||
|
);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[4] && isNaN(parseInt(args[4], base))) {
|
||||||
|
console.error(`Scaled size must be a number!\n${usage}\n${example}`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[5] && isNaN(parseInt(args[5], base))) {
|
||||||
|
console.error(`Original FPS must be a number!\n${usage}\n${example}`);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
input = args[0];
|
||||||
|
output = args[1];
|
||||||
|
pixelSize = parseInt(args[2], base);
|
||||||
|
pixelModifier = parseInt(args[3], base);
|
||||||
|
scaledSize = parseInt(args[4], base);
|
||||||
|
fps = parseInt(args[5], base);
|
||||||
|
|
||||||
|
_scaleVideo(
|
||||||
|
input,
|
||||||
|
pixelSize,
|
||||||
|
pixelModifier,
|
||||||
|
scaledSize,
|
||||||
|
fps,
|
||||||
|
output,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log(`Available commands:
|
console.log(`Available commands:
|
||||||
convert:gif:gif - converts regular gif to ascii gif
|
convert:gif:gif - converts regular gif to ascii gif
|
||||||
convert:gif:mp4 - converts regular gif to ascii mp4
|
convert:gif:mp4 - converts regular gif to ascii mp4
|
||||||
convert:mp4:mp4 - converts regular mp4 to ascii mp4
|
convert:mp4:mp4 - converts regular mp4 to ascii mp4
|
||||||
|
|||||||
@@ -15,10 +15,13 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"canvas": "^2.9.0",
|
"canvas": "^2.9.0",
|
||||||
|
"ffmpeg": "0.0.4",
|
||||||
"ffmpeg-extract-frames": "^2.0.2",
|
"ffmpeg-extract-frames": "^2.0.2",
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
|
"heic-convert": "^1.2.4",
|
||||||
"image-data-uri": "^2.0.1",
|
"image-data-uri": "^2.0.1",
|
||||||
"image-size": "^1.0.1",
|
"image-size": "^1.0.1",
|
||||||
"png-js": "^1.0.0"
|
"png-js": "^1.0.0",
|
||||||
|
"util": "^0.12.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
- input-file
|
- input-file
|
||||||
- file to be converted (original is kept)
|
- file to be converted (original is kept)
|
||||||
- default: input.mp4/input.gif/input.png depending on command used
|
- default: input.mp4/input.gif/input.png depending on command used
|
||||||
@@ -52,4 +53,4 @@
|
|||||||
|
|
||||||
### Convert PNG to ASCII PNG
|
### Convert PNG to ASCII PNG
|
||||||
|
|
||||||
`npm run convert:img [input-file] [output-file] [pixel-size] [font-size-modifier]`
|
`npm run convert:img [input-file] [output-file] [pixel-size] [font-size-modifier] [scaled-size]`
|
||||||
|
|||||||
Reference in New Issue
Block a user