Switching machines, ffmpeg + readable byte stream
This commit is contained in:
parent
243fb46fc3
commit
b268768c36
8 changed files with 86 additions and 1 deletions
BIN
.dataset/Dont-Panic.webp
Normal file
BIN
.dataset/Dont-Panic.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
5
.run/Test.run.xml
Normal file
5
.run/Test.run.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Test" type="DenoConfigurationType" inputPath="$PROJECT_DIR$" programParameters="test">
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
|
|
@ -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`
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"lib": [
|
||||
"deno.ns"
|
||||
"deno.ns",
|
||||
"dom"
|
||||
]
|
||||
},
|
||||
"lint": {
|
||||
|
|
|
|||
14
lib/log.ts
Normal file
14
lib/log.ts
Normal file
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
21
lib/media/video/fmpeg.ts
Normal file
21
lib/media/video/fmpeg.ts
Normal file
|
|
@ -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!");
|
||||
9
lib/parse/file.test.ts
Normal file
9
lib/parse/file.test.ts
Normal file
|
|
@ -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");
|
||||
});
|
||||
|
||||
33
lib/parse/file.ts
Normal file
33
lib/parse/file.ts
Normal file
|
|
@ -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
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue