Skip to content

Instantly share code, notes, and snippets.

@bellbind
Last active May 21, 2022 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bellbind/a5cc2a5bba0508eb4a02e184f2ffc707 to your computer and use it in GitHub Desktop.
Save bellbind/a5cc2a5bba0508eb4a02e184f2ffc707 to your computer and use it in GitHub Desktop.
[nodejs][macos] 10M bps video files concation with x4 speed and x2 volume with ffmpeg command
#!/usr/bin/env node
// usage: node concat.mjs /Volumes/UNTITLED/Normal/F/ result.mp4
import * as cp from "node:child_process";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import * as process from "node:process";
import * as stream from "node:stream";
import * as url from "node:url";
//console.log(process.argv);
const sources = process.argv.at(-2);
const output = process.argv.at(-1);
const inputs = (await fs.readdir(sources)).sort();
//console.log(inputs.length);
const list = inputs.map(f => `file ${url.pathToFileURL(path.join(sources, f))}\n`).join("");
const ffmpeg = process.platform === "darwin" ? `caffeinate -i -m -d ffmpeg` : "ffmpeg";
const command = `${ffmpeg} -protocol_whitelist "file,data,pipe,crypto" -safe 0 -f concat -i pipe:0 -movflags +faststart \
-c:v libx264 -profile:v high -b:v 10M -bf 2 -r 30 -g 15 -coder 1 -vf "yadif=0:-1:1,setpts=PTS/4.0" \
-c:a aac -profile:a aac_low -b:a 384k -ac 2 -ar 96000 -af "atempo=2.0,atempo=2.0,volume=2.0" \
${output}`;
console.log(command);
cp.execSync(command, {input: list, stdio: [null, 1, 2]});
#!/usr/bin/env node
// $ node mov2mp4.mjs SRC_MOV_DIR DEST_MP4_DIR
import * as cp from "node:child_process";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import * as process from "node:process";
//console.log(process.argv);
const sources = process.argv.at(-2);
const dests = process.argv.at(-1);
const movs = await fs.readdir(sources);
for (const mov of movs) {
const input = path.join(sources, mov);
const mp4 = mov.replace(path.extname(mov), ".mp4");
const output = path.join(dests, mp4);
const command = `ffmpeg -i ${input} -c:v copy -c:a copy ${output}`;
console.log(command);
cp.execSync(command);
}
@bellbind
Copy link
Author

bellbind commented May 21, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment