Last active
May 21, 2022 09:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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]}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
deno version of concat.mjs : https://gist.github.com/bellbind/17d112a7a83cd5d4ea4acd354654230b