diff --git a/dist/fd/index.d.ts b/dist/fd/index.d.ts index 9f8abc4..f3719c1 100644 --- a/dist/fd/index.d.ts +++ b/dist/fd/index.d.ts @@ -12,14 +12,17 @@ declare enum Mode { RGB_CHANNELS = 4, INVERT_CHANNELS = 5 } +export interface fdOutgoingPosition { + x: number; + y: number; + w: number; + h: number; +} export interface fdOutgoingMessage { action: Action; image: string; mode?: Mode; - x?: number; - y?: number; - w?: number; - h?: number; + position?: fdOutgoingPosition; exposure?: number[]; } export interface fdIncomingMessage { @@ -52,8 +55,9 @@ export declare class FD { private send; private receive; load(image: string, x: number, y: number, w: number, h: number): Promise; - display(image: string, exposure: number[]): Promise; + display(image: string, exposure?: number[]): Promise; stop(image: string): Promise; isConnected(): boolean; + private test; } export {}; diff --git a/dist/fd/index.js b/dist/fd/index.js index 0325af3..9833b61 100644 --- a/dist/fd/index.js +++ b/dist/fd/index.js @@ -38,6 +38,7 @@ class FD { this.shell = new shell_1.Shell([this.bin, `${this.width}`, `${this.height}`, `${this.port}`], this.logstd.bind(this), this.logsterr.bind(this), null, true); this.startDisplay(); this.startClient(); + this.test(); } async startDisplay() { this.log.info(`Launching fd binary ${this.bin}`); @@ -59,15 +60,28 @@ class FD { }.bind(this)); this.client.on('close', () => { this.log.info('Closing connection'); + this.socketConnected = false; }); this.client.on('error', (err) => { - this.log.error('Error:', err); + this.log.error('Error in socket client', err); + this.socketConnected = false; + this.shell.kill(); }); } logstd(data) { - this.log.info(`[shell] ${data}`); - if (data.indexOf('TCP server listening on port') !== -1 && data.indexOf(`${this.port}`) !== -1) { - this.socketAvailable = true; + let parsed = null; + try { + parsed = JSON.parse(data); + } + catch (err) { + this.log.error(`Error parsing line ${data}`, err); + } + if (parsed !== null) { + this.log.info(`[shell] ${data}`); + if (typeof parsed['listening'] !== 'undefined' && parsed['listening'] === true + && typeof parsed['port'] !== 'undefined' && parsed['port'] === this.port) { + this.socketAvailable = true; + } } } logsterr(data) { @@ -90,10 +104,12 @@ class FD { const msg = { action: Action.LOAD, image, - x, - y, - w, - h + position: { + x, + y, + w, + h + } }; const startTime = +new Date(); const promise = new Promise(function (resolve, reject) { @@ -112,9 +128,9 @@ class FD { }; }.bind(this)); this.send(msg); - return promise; + return await promise; } - async display(image, exposure) { + async display(image, exposure = []) { const msg = { action: Action.DISPLAY, image, @@ -137,7 +153,7 @@ class FD { }; }.bind(this)); this.send(msg); - return promise; + return await promise; } async stop(image) { const msg = { @@ -161,11 +177,25 @@ class FD { }; }.bind(this)); this.send(msg); - return promise; + return await promise; } isConnected() { return this.socketConnected; } + async test() { + const img = '/Users/matthewmcwilliams9/src/filmout_display/img/4kSnake.png'; + await (0, delay_1.delay)(2000); + await this.load(img, 100, 200, 640, 640); + await (0, delay_1.delay)(2000); + await this.display(img, [4000]); + await (0, delay_1.delay)(8000); + await this.load(img, 100, 200, 640, 640); + await (0, delay_1.delay)(1000); + await this.display(img); + await (0, delay_1.delay)(2000); + await this.stop(img); + process.exit(); + } } exports.FD = FD; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/fd/index.js.map b/dist/fd/index.js.map index debd924..a251943 100644 --- a/dist/fd/index.js.map +++ b/dist/fd/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fd/index.ts"],"names":[],"mappings":";;;;;;AACA,8CAAsB;AAEtB,gCAAkC;AAClC,oCAAiC;AACjC,oCAAiC;AAEjC,IAAK,MAKJ;AALD,WAAK,MAAM;IACV,mCAAI,CAAA;IACJ,mCAAI,CAAA;IACJ,yCAAO,CAAA;IACP,mCAAI,CAAA;AACL,CAAC,EALI,MAAM,KAAN,MAAM,QAKV;AAED,IAAK,IAOJ;AAPD,WAAK,IAAI;IACR,6BAAG,CAAA;IACH,2BAAE,CAAA;IACF,mCAAM,CAAA;IACN,yCAAS,CAAA;IACT,+CAAY,CAAA;IACZ,qDAAe,CAAA;AAChB,CAAC,EAPI,IAAI,KAAJ,IAAI,QAOR;AAyBD,MAAa,EAAE;IAcd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CAAC;IAEM,WAAW;QACjB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC7B,CAAC;IAEO,KAAK,CAAC,IAAI;QACjB,MAAM,GAAG,GAAG,+DAA+D,CAAC;QAE5E,MAAM,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC;QAElB,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACzC,MAAM,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC;QAElB,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAE,IAAI,CAAE,CAAE,CAAC;QACnC,MAAM,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC;QAElB,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACzC,MAAM,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC;QAElB,MAAM,IAAI,CAAC,OAAO,CAAE,GAAG,CAAC,CAAC;QACzB,MAAM,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC;QAClB,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAErB,OAAO,CAAC,IAAI,EAAE,CAAC;IAChB,CAAC;CACD;AAtMD,gBAsMC"} \ No newline at end of file diff --git a/dist/ffmpeg/index.d.ts b/dist/ffmpeg/index.d.ts new file mode 100644 index 0000000..ff9972f --- /dev/null +++ b/dist/ffmpeg/index.d.ts @@ -0,0 +1,11 @@ +export declare class FFMPEG { + private bin; + private log; + private shell; + private formats; + private formatsInfo; + constructor(bin?: string); + private rawList; + private demuxerInfo; + listFormats(): Promise; +} diff --git a/dist/ffmpeg/index.js b/dist/ffmpeg/index.js new file mode 100644 index 0000000..2946094 --- /dev/null +++ b/dist/ffmpeg/index.js @@ -0,0 +1,81 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.FFMPEG = void 0; +const log_1 = require("../log"); +const shell_1 = require("../shell"); +const os_1 = require("os"); +class FFMPEG { + constructor(bin = 'ffmpeg') { + this.formats = []; + this.formatsInfo = {}; + this.bin = bin; + this.log = (0, log_1.createLog)('ffmpeg'); + } + async rawList() { + const cmd = [this.bin, '-formats']; + return new Promise(async (resolve, reject) => { + this.shell = new shell_1.Shell(cmd, null, null, resolve, true); + await this.shell.execute(); + }); + } + async demuxerInfo(demuxer) { + const cmd = [this.bin, `ffmpeg -h demuxer=${demuxer}`]; + return new Promise(async (resolve, reject) => { + this.shell = new shell_1.Shell(cmd, null, null, resolve, true); + await this.shell.execute(); + }); + } + async listFormats() { + let list = null; + let rows; + let key; + let description; + let info; + this.formats = []; + this.formatsInfo = {}; + try { + list = await this.rawList(); + } + catch (err) { + this.log.error('Error listing formats', err); + } + if (list !== null) { + rows = list.split(os_1.EOL); + for (let row of rows) { + //this.log.info(`"${row}"`); + if (row.startsWith(' DE ')) { + key = row.substring(4, row.length - 1).split(' ')[0]; + description = row.replace(key, '').trim(); + this.log.info(key); + /*try { + this.log.info(await this.demuxerInfo(key)); + } catch (err) { + this.log.error(err); + }*/ + this.formats.push(key); + this.formatsInfo[key] = { + description + }; + } + else if (row.startsWith(' D ')) { + key = row.substring(4, row.length - 1).split(' ')[0]; + description = row.replace(key, '').trim(); + this.log.info(key); + /*try { + this.log.info(await this.demuxerInfo(key)); + } catch (err) { + this.log.error(err); + }*/ + this.formats.push(key); + this.formatsInfo[key] = { + description + }; + } + } + } + return this.formats; + } +} +exports.FFMPEG = FFMPEG; +module.exports = { FFMPEG }; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/ffmpeg/index.js.map b/dist/ffmpeg/index.js.map new file mode 100644 index 0000000..7e77799 --- /dev/null +++ b/dist/ffmpeg/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ffmpeg/index.ts"],"names":[],"mappings":";;;AACA,gCAAkC;AAClC,oCAAiC;AAEjC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C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBACnB;;;;uBAIG;oBACH,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBACvB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG;wBACvB,WAAW;qBACX,CAAC;gBACH,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;CACD;AAjFD,wBAiFC;AAED,MAAM,CAAC,OAAO,GAAG,EAAE,MAAM,EAAE,CAAC"} \ No newline at end of file diff --git a/dist/files/index.d.ts b/dist/files/index.d.ts index b05eb23..56ea7f1 100644 --- a/dist/files/index.d.ts +++ b/dist/files/index.d.ts @@ -3,8 +3,14 @@ interface SequenceObject { hash: string; name: string; } +interface VideoObject { + path: string; + hash: string; + name: string; +} export declare class Files { static exists(path: string): Promise; static enumerateSequences(path: string): Promise; + static enumerateVideos(path: string): Promise; } -export type { SequenceObject }; +export type { SequenceObject, VideoObject }; diff --git a/dist/files/index.js b/dist/files/index.js index 591b668..616790e 100644 --- a/dist/files/index.js +++ b/dist/files/index.js @@ -7,6 +7,11 @@ exports.Files = void 0; const promises_1 = __importDefault(require("fs/promises")); const hash_1 = require("../hash"); const path_1 = require("path"); +const fileExtension = [ + '.mp4', + '.mkv', + '.mov' +]; class Files { static async exists(path) { try { @@ -44,6 +49,12 @@ class Files { } return dirs; } + static async enumerateVideos(path) { + const videos = []; + let all; + let stats; + return videos; + } } exports.Files = Files; module.exports = { Files }; diff --git a/dist/files/index.js.map b/dist/files/index.js.map index 4272383..b8ae143 100644 --- a/dist/files/index.js.map +++ b/dist/files/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/files/index.ts"],"names":[],"mappings":";;;;;;AAAA,2DAA6B;AAE7B,kCAAiC;AACjC,+BAAgC;AAQhC,MAAa,KAAK;IACV,MAAM,CAAC,KAAK,CAAC,MAAM,CAAE,IAAa;QACxC,IAAI,CAAC;YACJ,MAAM,kBAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACtB,OAAO,IAAI,CAAC;QACb,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAE,IAAa;QACpD,MAAM,IAAI,GAAsB,EAAE,CAAC;QACnC,IAAI,GAAc,CAAC;QACnB,IAAI,KAAa,CAAC;QAClB,IAAI,CAAC;YACJ,GAAG,GAAG,MAAM,kBAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC7B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,MAAM,GAAG,CAAC;QACX,CAAC;QAED,KAAK,IAAI,IAAI,IAAI,GAAG,EAAE,CAAC;YACtB,IAAI,CAAC;gBACJ,KAAK,GAAG,MAAM,kBAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC1B,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;oBACzB,IAAI,CAAC,IAAI,CAAC;wBACT,IAAI,EAAG,IAAI;wBACX,IAAI,EAAG,aAAM,CAAC,UAAU,CAAC,IAAI,CAAC;wBAC9B,IAAI,EAAG,IAAA,eAAQ,EAAC,IAAI,CAAC;qBACrB,CAAC,CAAC;gBACJ,CAAC;YACL,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACd,EAAE;YACH,CAAC;QACF,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AArCD,sBAqCC;AAGD,MAAM,CAAC,OAAO,GAAG,EAAE,KAAK,EAAE,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/files/index.ts"],"names":[],"mappings":";;;;;;AAAA,2DAA6B;AAE7B,kCAAiC;AACjC,+BAAyC;AAczC,MAAM,aAAa,GAAc;IAChC,MAAM;IACN,MAAM;IACN,MAAM;CACN,CAA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AO,GAAG,EAAE,KAAK,EAAE,CAAC"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index c502e37..38761b4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -33,9 +33,11 @@ const body_parser_1 = __importDefault(require("body-parser")); const Handlebars = __importStar(require("handlebars")); const log_1 = require("./log"); const files_1 = require("./files"); +const ffmpeg_1 = require("./ffmpeg"); const log = (0, log_1.createLog)('fm'); const app = (0, express_1.default)(); let fd; +let ffmpeg; let index; let port; let sequences; @@ -139,10 +141,12 @@ app.get('/', async (req, res, next) => { async function main() { await settings(); index = await createTemplate('./views/index.hbs'); + ffmpeg = new ffmpeg_1.FFMPEG(); //fd = new FD(process.env['FD'], width, height, process.env['FD_HOST'], parseInt(process.env['FD_PORT'])); app.listen(port, async () => { log.info(`filmout_manager HTTP server running on port ${port}`); }); + log.info(await ffmpeg.listFormats()); } main(); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map index 6f4bb2f..78a375b 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yBAAsB;AACtB,sDAA8B;AAE9B,2DAA6B;AAI7B,8DAAqC;AAKrC,uDAAyC;AAGzC,+BAAiC;AAEjC,mCAAgC;AAMhC,MAAM,GAAG,GAAY,IAAA,eAAS,EAAC,IAAI,CAAC,CAAC;AACrC,MAAM,GAAG,GAAa,IAAA,iBAAO,GAAE,CAAC;AAChC,IAAI,EAAO,CAAC;AACZ,IAAI,KAAuC,CAAC;AAE5C,IAAI,IAAa,CAAC;AAClB,IAAI,SAAkB,CAAC;AACvB,IAAI,MAAe,CAAC;AACpB,IAAI,KAAc,CAAC;AACnB,IAAI,MAAe,CAAC;AAEpB,GAAG,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;AAExC,GAAG,CAAC,GAAG,CAAC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CAAC;AACF,CAAC;AAED,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAa,EAAE,GAAc,EAAE,IAAmB,EAAE,EAAE;IACzE,MAAM,IAAI,GAAsB,MAAM,aAAK,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC1E,MAAM,IAAI,GAAY,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IACrD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC,CAAC,CAAC;AAEH,KAAK,UAAU,IAAI;IAClB,MAAM,QAAQ,EAAE,CAAC;IACjB,KAAK,GAAG,MAAM,cAAc,CAAC,mBAAmB,CAAC,CAAC;IAClD,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;IACtB,6GAA6G;IAC7G,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;QAC3B,GAAG,CAAC,IAAI,CAAC,+CAA+C,IAAI,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,IAAI,CAAC,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;AACtC,CAAC;AAGD,IAAI,EAAE,CAAC"} \ No newline at end of file diff --git a/src/fd/index.ts b/src/fd/index.ts index 2706e28..2c53b9a 100644 --- a/src/fd/index.ts +++ b/src/fd/index.ts @@ -21,14 +21,18 @@ enum Mode { INVERT_CHANNELS } +export interface fdOutgoingPosition { + x : number, + y : number, + w : number, + h : number +} + export interface fdOutgoingMessage { action : Action, image : string, mode? : Mode, - x? : number, - y? : number, - w? : number, - h? : number, + position? : fdOutgoingPosition, exposure? : number[] } @@ -68,6 +72,7 @@ export class FD { this.shell = new Shell([ this.bin, `${this.width}`, `${this.height}`, `${this.port}` ], this.logstd.bind(this), this.logsterr.bind(this), null, true); this.startDisplay(); this.startClient(); + this.test(); } private async startDisplay () { @@ -93,17 +98,29 @@ export class FD { this.client.on('close', () => { this.log.info('Closing connection'); + this.socketConnected = false; }); this.client.on('error', (err : Error) => { - this.log.error('Error:', err); + this.log.error('Error in socket client', err); + this.socketConnected = false; + this.shell.kill(); }); } private logstd (data : string ) { - this.log.info(`[shell] ${data}`); - if (data.indexOf('TCP server listening on port') !== -1 && data.indexOf(`${this.port}`) !== -1) { - this.socketAvailable = true; + let parsed : any = null; + try { + parsed = JSON.parse(data); + } catch (err) { + this.log.error(`Error parsing line ${data}`, err); + } + if (parsed !== null) { + this.log.info(`[shell] ${data}`); + if (typeof parsed['listening'] !== 'undefined' && parsed['listening'] === true + && typeof parsed['port'] !== 'undefined' && parsed['port'] === this.port) { + this.socketAvailable = true; + } } } @@ -130,10 +147,12 @@ export class FD { const msg : fdOutgoingMessage = { action : Action.LOAD, image, - x, - y, - w, - h + position : { + x, + y, + w, + h + } }; const startTime : number = +new Date(); const promise : Promise = new Promise(function (resolve : Function, reject : Function) { @@ -151,10 +170,10 @@ export class FD { } }.bind(this)); this.send(msg); - return promise; + return await promise; } - public async display (image : string, exposure : number[]) : Promise { + public async display (image : string, exposure : number[] = []) : Promise { const msg : fdOutgoingMessage = { action : Action.DISPLAY, image, @@ -176,7 +195,7 @@ export class FD { } }.bind(this)); this.send(msg); - return promise; + return await promise; } public async stop (image : string) : Promise { @@ -200,11 +219,32 @@ export class FD { } }.bind(this)); this.send(msg); - return promise; + return await promise; } public isConnected () : boolean { return this.socketConnected; } + + private async test () { + const img = '/Users/matthewmcwilliams9/src/filmout_display/img/4kSnake.png'; + + await delay(2000); + + await this.load(img, 100, 200, 640, 640); + await delay(2000); + + await this.display(img, [ 4000 ] ); + await delay(8000); + + await this.load(img, 100, 200, 640, 640); + await delay(1000); + + await this.display (img); + await delay(2000); + await this.stop(img); + + process.exit(); + } } diff --git a/src/ffmpeg/index.ts b/src/ffmpeg/index.ts new file mode 100644 index 0000000..37c4578 --- /dev/null +++ b/src/ffmpeg/index.ts @@ -0,0 +1,90 @@ +import type { Logger } from 'winston'; +import { createLog } from '../log' +import { Shell } from '../shell'; +import { delay } from '../delay'; +import { EOL } from 'os'; + +export class FFMPEG { + private bin : string; + private log : Logger; + private shell : Shell; + private formats : string[] = []; + private formatsInfo : any = {}; + + constructor (bin: string = 'ffmpeg') { + this.bin = bin; + this.log = createLog('ffmpeg'); + } + + private async rawList () : Promise { + const cmd : string[] = [ this.bin, '-formats' ]; + return new Promise(async (resolve : Function, reject : Function) => { + this.shell = new Shell(cmd, null, null, resolve, true); + await this.shell.execute(); + }); + } + + private async demuxerInfo (demuxer : string) : Promise { + const cmd : string[] = [ this.bin, `ffmpeg -h demuxer=${demuxer}` ]; + return new Promise(async (resolve : Function, reject : Function) => { + this.shell = new Shell(cmd, null, null, resolve, true); + await this.shell.execute(); + }); + } + + async listFormats () : Promise { + + let list : string = null; + let rows : string[]; + let key : string; + let description : string; + let info : string; + + this.formats = []; + this.formatsInfo = {}; + + try { + list = await this.rawList(); + } catch (err) { + this.log.error('Error listing formats', err); + } + + if (list !== null) { + rows = list.split(EOL); + for (let row of rows) { + //this.log.info(`"${row}"`); + if (row.startsWith(' DE ')) { + key = row.substring(4, row.length - 1).split(' ')[0]; + description = row.replace(key, '').trim(); + this.log.info(key); + /*try { + this.log.info(await this.demuxerInfo(key)); + } catch (err) { + this.log.error(err); + }*/ + this.formats.push(key); + this.formatsInfo[key] = { + description + }; + } else if (row.startsWith(' D ')) { + key = row.substring(4, row.length - 1).split(' ')[0]; + description = row.replace(key, '').trim(); + this.log.info(key); + /*try { + this.log.info(await this.demuxerInfo(key)); + } catch (err) { + this.log.error(err); + }*/ + this.formats.push(key); + this.formatsInfo[key] = { + description + }; + } + } + } + + return this.formats; + } +} + +module.exports = { FFMPEG }; \ No newline at end of file diff --git a/src/files/index.ts b/src/files/index.ts index d82c0fa..3f7fa07 100644 --- a/src/files/index.ts +++ b/src/files/index.ts @@ -1,7 +1,7 @@ import fs from 'fs/promises'; import type { Stats } from 'fs'; import { Hashes } from '../hash'; -import { basename } from 'path'; +import { basename, extname } from 'path'; interface SequenceObject { path : string, @@ -9,6 +9,18 @@ interface SequenceObject { name : string } +interface VideoObject { + path : string, + hash : string, + name : string +} + +const fileExtension : string[] = [ + '.mp4', + '.mkv', + '.mov' +]; + export class Files { public static async exists (path : string) : Promise { try { @@ -46,7 +58,15 @@ export class Files { return dirs; } + + public static async enumerateVideos (path : string) : Promise { + const videos : VideoObject[] = []; + let all : string[]; + let stats : Stats; + + return videos; + } } -export type { SequenceObject }; +export type { SequenceObject, VideoObject }; module.exports = { Files }; diff --git a/src/index.ts b/src/index.ts index c81c343..40f8e23 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,14 +16,16 @@ import { Server } from 'ws'; import { createLog } from './log' import { sendMail } from './mail'; import { Files } from './files'; -import type { SequenceObject } from './files'; +import type { SequenceObject, VideoObject } from './files'; import { Shell } from './shell'; import { delay } from './delay'; import { FD } from './fd'; +import { FFMPEG } from './ffmpeg'; const log : Logger = createLog('fm'); const app : Express = express(); let fd : FD; +let ffmpeg : FFMPEG; let index : HandlebarsTemplateDelegate; let port : number; @@ -125,10 +127,12 @@ app.get('/', async (req : Request, res : Response, next : NextFunction) => { async function main () { await settings(); index = await createTemplate('./views/index.hbs'); + ffmpeg = new FFMPEG(); //fd = new FD(process.env['FD'], width, height, process.env['FD_HOST'], parseInt(process.env['FD_PORT'])); app.listen(port, async () => { log.info(`filmout_manager HTTP server running on port ${port}`); }); + log.info(await ffmpeg.listFormats()); }