diff --git a/.dataset/Dont-Panic.webp b/.dataset/Dont-Panic.webp new file mode 100644 index 0000000..250243e Binary files /dev/null and b/.dataset/Dont-Panic.webp differ diff --git a/.run/Test.run.xml b/.run/Test.run.xml new file mode 100644 index 0000000..26b72b7 --- /dev/null +++ b/.run/Test.run.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 27ceb35..ba906fd 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,5 @@ Do not edit, EXTEND or otherwise play with ANY variable, unless you UNDERSTAND t [Read Before Use](DISCLAIMER.md) you've been warned. +- ffmpeg + `deno run --unstable --allow-read --allow-run https://github.com/Snider/Enchatrix/lib/media/video/fmpeg.ts` diff --git a/deno.json b/deno.json index 00f78ac..5a3e9fc 100644 --- a/deno.json +++ b/deno.json @@ -2,7 +2,8 @@ "compilerOptions": { "target": "esnext", "lib": [ - "deno.ns" + "deno.ns", + "dom" ] }, "lint": { diff --git a/lib/log.ts b/lib/log.ts new file mode 100644 index 0000000..80444bb --- /dev/null +++ b/lib/log.ts @@ -0,0 +1,14 @@ +export class EnchantrixLog { + + constructor(entry: string, level: number = 1) { + switch (level) { + case 0: + break; + case 1: + console.log(entry) + break + case 2: + console.warn(entry) + } + } +} diff --git a/lib/media/video/fmpeg.ts b/lib/media/video/fmpeg.ts new file mode 100644 index 0000000..8f232cc --- /dev/null +++ b/lib/media/video/fmpeg.ts @@ -0,0 +1,21 @@ +#!deno run --unstable --allow-read --allow-run + +import { ffmpeg } from "https://deno.land/x/fast_forward@0.1.6/ffmpeg.ts"; + +await ffmpeg("https://www.w3schools.com/html/mov_bbb.mp4") + // Global encoding options (applied to all outputs). + .audioBitrate("192k") + .videoBitrate("1M") + .width(480) + .height(640) + // Ouput 1. + .output("output.mp4") + .audioCodec("aac") + .videoCodec("libx264") + // Ouput 2. + .output("output.webm") + .audioCodec("libvorbis") + .videoCodec("libvpx-vp9") + .encode(); + +console.log("All encodings done!"); diff --git a/lib/parse/file.test.ts b/lib/parse/file.test.ts new file mode 100644 index 0000000..fe583ac --- /dev/null +++ b/lib/parse/file.test.ts @@ -0,0 +1,9 @@ +import { assertEquals } from "https://deno.land/std@0.122.0/testing/asserts.ts"; +import { EnchantrixParseFile } from "./file.ts"; + +// Compact form: name and function +Deno.test("IN: Snider OUT: r3dinS", () => { + const x = new EnchantrixParseFile(".dataset/Dont-Panic.webp").load(); + assertEquals(x, "r3dinS"); +}); + diff --git a/lib/parse/file.ts b/lib/parse/file.ts new file mode 100644 index 0000000..7d8f531 --- /dev/null +++ b/lib/parse/file.ts @@ -0,0 +1,33 @@ +#!deno run --allow-read --allow-net + +import * as path from "https://deno.land/std@0.122.0/path/mod.ts"; +import { readableStreamFromReader } from "https://deno.land/std@0.122.0/streams/mod.ts"; +import {EnchantrixLog} from '../log.ts'; + +export class EnchantrixParseFile { + + protected _input: string; + protected _data: any; + + constructor(file: string) { + this._input = file; + } + + load() { + + try { + this._data = Deno.openSync(this._input, { read: true }); + const stat = this._data.statSync(); + + } catch { + throw new EnchantrixLog('Failed to load file') + } + +// Build a readable stream so the file doesn't have to be fully loaded into +// memory while we send it + const readableStream = readableStreamFromReader(this._data); + + return readableStream + + } +}