Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[deno]10M bps video files concation with x4 speed and x2 volume with ffmpeg command
#!/usr/bin/env -S deno run --allow-read --allow-run
// usage: deno run --allow-read --allow-run movconcat.js /Volumes/UNTITLED/Normal/F/ result.mp4
import * as path from "https://deno.land/std/path/mod.ts";
import * as flags from "https://deno.land/std/flags/mod.ts";
const parsed = flags.parse(Deno.args);
const sources = parsed._.at(-2);
const output = parsed._.at(-1);
const inputs = [];
for await (const {name} of Deno.readDir(sources)) inputs.push(name);
inputs.sort();
const list = inputs.map(f => `file ${path.toFileUrl(path.join(sources, f))}\n`).join(``);
const ffmpeg = Deno.build.os === "darwin" ? [`caffeinate`, `-imd`, `ffmpeg`] : [`ffmpeg`];
const vf = (parsed.g ? `eq=gamma=${parsed.g},` : ``) + `yadif=0:-1:1,fps=60000/1000,setpts=(PTS-STARTPTS)/4.0`;
const options = [
`-protocol_whitelist`, `file,data,pipe,crypto`, `-safe`, `0`, `-f`, `concat`, `-i`, `pipe:0`,
`-movflags`, `+faststart`,
`-c:v`, `libx264`, `-profile:v`, `high`, `-b:v`, `15M`, `-bf`, `2`, `-r`, `60`, `-g`, `30`, `-coder`, `1`, `-vf`, vf,
`-c:a`, `aac`, `-profile:a`, `aac_low`, `-b:a`, `384k`, `-ac`, `2`, `-ar`, `96000`, `-af`, `atempo=2.0,atempo=2.0,volume=2.0`,
];
const cmd = [...ffmpeg, ...options, output];
console.log(cmd.join(` `));
const proc = Deno.run({cmd, stdin: `piped`});
const tes = new TextEncoderStream();
tes.readable.pipeTo(proc.stdin.writable);
const writer = tes.writable.getWriter();
await writer.write(list);
await writer.close();
await proc.status();
#!/usr/bin/env -S deno run --allow-read --allow-run
// usage: deno run --allow-read --allow-run movconcat.js /Volumes/UNTITLED/Normal/F/ result.mp4
import * as path from "https://deno.land/std/path/mod.ts";
const sources = Deno.args.at(-2);
const output = Deno.args.at(-1);
const inputs = [];
for await (const {name} of Deno.readDir(sources)) inputs.push(name);
inputs.sort();
const list = inputs.map(f => `file ${path.toFileUrl(path.join(sources, f))}\n`).join(``);
const ffmpeg = Deno.build.os === "darwin" ? [`caffeinate`, `-imd`, `ffmpeg`] : [`ffmpeg`];
const options = [
`-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`,
];
const cmd = [...ffmpeg, ...options, output];
console.log(cmd.join(" "));
const proc = Deno.run({cmd, stdin: "piped"});
const tes = new TextEncoderStream();
tes.readable.pipeTo(proc.stdin.writable);
const writer = tes.writable.getWriter();
await writer.write(list);
await writer.close();
await proc.status();
@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