2019-03-21 18:58:00 +00:00
|
|
|
'use strict';
|
2019-07-07 04:02:01 +00:00
|
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
|
|
};
|
2019-03-21 18:58:00 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2019-07-07 04:02:01 +00:00
|
|
|
const sharp_1 = __importDefault(require("sharp"));
|
2019-08-15 19:25:33 +00:00
|
|
|
const animated_gif_detector_1 = __importDefault(require("animated-gif-detector"));
|
2019-07-07 04:02:01 +00:00
|
|
|
const path_1 = require("path");
|
|
|
|
const fs_extra_1 = require("fs-extra");
|
2019-06-15 15:06:57 +00:00
|
|
|
const delay_1 = require("delay");
|
2019-08-25 18:59:39 +00:00
|
|
|
/**
|
|
|
|
* @module FilmOut
|
|
|
|
**/
|
2019-06-18 19:42:30 +00:00
|
|
|
class FilmOut {
|
2019-03-21 22:03:53 +00:00
|
|
|
/**
|
2019-08-25 18:59:39 +00:00
|
|
|
* @constructor
|
|
|
|
* Builds FilmOut class with display, ffmpeg, ffprobe, ui and light as internal properties.
|
2019-03-21 22:03:53 +00:00
|
|
|
*
|
2019-08-25 18:59:39 +00:00
|
|
|
* @param {object} display Display object for showing frames
|
|
|
|
* @param {object} ffmpeg FFMPEG wrapper
|
|
|
|
* @param {object} ffprobe FFPROBE wrapper for file info
|
|
|
|
* @param {object} ui Electron ui object
|
|
|
|
* @param {object} light Light device object
|
2019-03-21 22:03:53 +00:00
|
|
|
**/
|
|
|
|
constructor(display, ffmpeg, ffprobe, ui, light) {
|
2019-06-18 19:42:30 +00:00
|
|
|
this.id = 'filmout';
|
2019-07-07 04:02:01 +00:00
|
|
|
this.videoExtensions = ['.mpg', '.mpeg', '.mov', '.mkv', '.avi', '.mp4'];
|
|
|
|
this.stillExtensions = ['.tif', '.tiff', '.png', '.jpg', '.jpeg', '.bmp'];
|
|
|
|
this.gifExtension = '.gif';
|
2019-03-21 22:03:53 +00:00
|
|
|
this.state = {
|
|
|
|
frame: 0,
|
|
|
|
frames: 0,
|
2019-07-07 04:02:01 +00:00
|
|
|
still: false,
|
2019-03-21 22:03:53 +00:00
|
|
|
path: null,
|
|
|
|
fileName: null,
|
|
|
|
info: {},
|
|
|
|
dir: true,
|
|
|
|
enabled: false
|
|
|
|
};
|
|
|
|
this.display = display;
|
|
|
|
this.ffmpeg = ffmpeg;
|
|
|
|
this.ffprobe = ffprobe;
|
|
|
|
this.ui = ui;
|
|
|
|
this.light = light;
|
|
|
|
this.init();
|
2019-03-21 18:58:00 +00:00
|
|
|
}
|
2019-03-21 22:03:53 +00:00
|
|
|
/**
|
2019-08-25 18:59:39 +00:00
|
|
|
* Async function for requiring log, ipcMain and bind events.
|
2019-03-21 22:03:53 +00:00
|
|
|
**/
|
|
|
|
async init() {
|
2019-06-15 15:06:57 +00:00
|
|
|
const Log = require('log');
|
2019-06-18 19:42:30 +00:00
|
|
|
this.log = await Log({ label: this.id });
|
2019-03-21 22:03:53 +00:00
|
|
|
this.ipc = require('electron').ipcMain;
|
|
|
|
this.listen();
|
2019-03-21 18:58:00 +00:00
|
|
|
}
|
2019-03-21 22:03:53 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
listen() {
|
2019-06-18 19:42:30 +00:00
|
|
|
this.ipc.on(this.id, this.onConnect.bind(this));
|
2019-06-18 17:47:55 +00:00
|
|
|
this.ipc.on('focus', this.focus.bind(this));
|
2019-06-18 19:42:30 +00:00
|
|
|
this.ipc.on('field', this.field.bind(this));
|
|
|
|
this.ipc.on('meter', this.meter.bind(this));
|
|
|
|
this.ipc.on('filmout_close', this.close.bind(this));
|
2019-06-27 00:08:49 +00:00
|
|
|
this.ipc.on('preview', this.preview.bind(this));
|
2019-06-25 16:13:15 +00:00
|
|
|
this.ipc.on('preview_frame', this.previewFrame.bind(this));
|
2019-06-27 00:08:49 +00:00
|
|
|
this.ipc.on('display', this.onDisplay.bind(this));
|
2019-03-21 18:58:00 +00:00
|
|
|
}
|
2019-03-21 22:03:53 +00:00
|
|
|
/**
|
2019-08-25 18:59:39 +00:00
|
|
|
* Sets filmout direction.
|
2019-03-21 22:03:53 +00:00
|
|
|
*
|
2019-08-25 18:59:39 +00:00
|
|
|
* @param {boolean} dir Direction of filmout
|
2019-03-21 22:03:53 +00:00
|
|
|
**/
|
|
|
|
set(dir) {
|
|
|
|
this.state.dir = dir;
|
2019-03-21 18:58:00 +00:00
|
|
|
}
|
2019-03-21 22:03:53 +00:00
|
|
|
/**
|
2019-08-25 18:59:39 +00:00
|
|
|
* Moves filmout a frame at a time.
|
2019-03-21 22:03:53 +00:00
|
|
|
**/
|
|
|
|
async move() {
|
|
|
|
let start = +new Date();
|
2019-07-07 04:02:01 +00:00
|
|
|
if (this.state.still) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-03-21 22:03:53 +00:00
|
|
|
if (this.state.dir) {
|
|
|
|
this.state.frame++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.state.frame--;
|
|
|
|
}
|
|
|
|
if (this.state.frame < 1) {
|
|
|
|
this.state.frame = 1;
|
|
|
|
}
|
|
|
|
return (+new Date()) - start;
|
2019-03-21 18:58:00 +00:00
|
|
|
}
|
2019-03-21 22:03:53 +00:00
|
|
|
/**
|
2019-08-25 18:59:39 +00:00
|
|
|
* Begin the process of exporting single frames from the video for display.
|
2019-03-21 22:03:53 +00:00
|
|
|
**/
|
|
|
|
async start() {
|
|
|
|
try {
|
|
|
|
await this.ffmpeg.clearAll();
|
|
|
|
}
|
|
|
|
catch (err) {
|
2019-06-27 00:08:49 +00:00
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
2019-03-21 22:03:53 +00:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
await this.ffmpeg.frame(this.state, this.light.state);
|
|
|
|
}
|
|
|
|
catch (err) {
|
2019-06-27 00:08:49 +00:00
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
2019-03-21 22:03:53 +00:00
|
|
|
throw err;
|
|
|
|
}
|
2019-03-22 02:33:30 +00:00
|
|
|
await this.display.show(this.state.frame);
|
2019-06-15 15:06:57 +00:00
|
|
|
await delay_1.delay(20);
|
2019-03-21 18:58:00 +00:00
|
|
|
}
|
2019-03-21 22:03:53 +00:00
|
|
|
/**
|
2019-08-25 18:59:39 +00:00
|
|
|
* Ends the filmout process and closes the display.
|
2019-07-07 04:02:01 +00:00
|
|
|
**/
|
2019-03-21 22:03:53 +00:00
|
|
|
async end() {
|
2019-06-15 15:06:57 +00:00
|
|
|
await delay_1.delay(20);
|
2019-03-22 02:33:30 +00:00
|
|
|
this.display.hide();
|
2019-03-21 18:58:00 +00:00
|
|
|
}
|
2019-03-21 22:03:53 +00:00
|
|
|
/**
|
2019-06-18 19:42:30 +00:00
|
|
|
* Use a video file as a film out source on "projector"
|
2019-03-21 22:03:53 +00:00
|
|
|
*
|
2019-08-25 18:59:39 +00:00
|
|
|
* @param {object} evt Original connect event
|
|
|
|
* @param {object} arg Arguments from ipc message
|
2019-03-21 22:03:53 +00:00
|
|
|
**/
|
2019-06-18 19:42:30 +00:00
|
|
|
async onConnect(evt, arg) {
|
2019-03-21 22:03:53 +00:00
|
|
|
let frames = 0;
|
2019-07-07 04:02:01 +00:00
|
|
|
let isAnimated = false;
|
|
|
|
let info;
|
|
|
|
let ext;
|
|
|
|
ext = path_1.extname(arg.fileName.toLowerCase());
|
2019-08-25 18:59:39 +00:00
|
|
|
//console.dir(arg)
|
|
|
|
//console.log(ext)
|
2019-07-07 04:02:01 +00:00
|
|
|
if (ext === this.gifExtension) {
|
|
|
|
try {
|
|
|
|
isAnimated = await this.isGifAnimated(arg.path);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
await this.ui.send(this.id, { valid: false });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.state.still = !isAnimated;
|
2019-03-21 22:03:53 +00:00
|
|
|
}
|
2019-07-07 04:02:01 +00:00
|
|
|
else if (this.stillExtensions.indexOf(ext) !== -1) {
|
|
|
|
this.state.still = true;
|
2019-03-21 22:03:53 +00:00
|
|
|
}
|
2019-07-07 04:02:01 +00:00
|
|
|
else if (this.videoExtensions.indexOf(ext) !== -1) {
|
|
|
|
this.state.still = false;
|
2019-03-21 22:03:53 +00:00
|
|
|
}
|
2019-07-07 04:02:01 +00:00
|
|
|
else {
|
|
|
|
this.log.error(`File is not of a valid file type`, 'FILMOUT', true, true);
|
2019-03-21 22:03:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-07-07 04:02:01 +00:00
|
|
|
if (this.state.still) {
|
|
|
|
try {
|
|
|
|
info = await this.stillInfo(arg.path);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
this.state.enabled = false;
|
|
|
|
await this.ui.send(this.id, { valid: false });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
frames = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
try {
|
|
|
|
info = await this.ffprobe.info(arg.path);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
this.state.enabled = false;
|
|
|
|
await this.ui.send(this.id, { valid: false });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
frames = await this.ffprobe.frames(arg.path);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
this.state.enabled = false;
|
|
|
|
await this.ui.send(this.id, { valid: false });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-08-25 18:59:39 +00:00
|
|
|
//console.dir(info)
|
2019-03-21 22:03:53 +00:00
|
|
|
this.state.frame = 0;
|
|
|
|
this.state.path = arg.path;
|
|
|
|
this.state.fileName = arg.fileName;
|
|
|
|
this.state.frames = frames;
|
|
|
|
this.state.info = info;
|
2019-06-18 19:42:30 +00:00
|
|
|
this.log.info(`Opened ${this.state.fileName}`, 'FILMOUT', true, true);
|
|
|
|
this.log.info(`Frames : ${frames}`, 'FILMOUT', true, true);
|
2019-03-21 22:03:53 +00:00
|
|
|
this.state.enabled = true;
|
2019-06-18 19:42:30 +00:00
|
|
|
return await this.ui.send(this.id, { valid: true, state: JSON.stringify(this.state) });
|
2019-03-21 22:03:53 +00:00
|
|
|
}
|
2019-07-07 04:02:01 +00:00
|
|
|
/**
|
|
|
|
* Return true if gif is animated, false if it is a still
|
2019-08-25 18:59:39 +00:00
|
|
|
*
|
|
|
|
* @param {string} pathStr Path to gif to check
|
|
|
|
*
|
|
|
|
* @returns {boolean} Whether or not gif is animated
|
2019-07-07 04:02:01 +00:00
|
|
|
**/
|
|
|
|
async isGifAnimated(pathStr) {
|
|
|
|
let gifBuffer;
|
|
|
|
try {
|
|
|
|
gifBuffer = await fs_extra_1.readFile(pathStr);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-15 19:25:33 +00:00
|
|
|
return animated_gif_detector_1.default(gifBuffer);
|
2019-07-07 04:02:01 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Return information on a still image using the sharp module
|
2019-08-25 18:59:39 +00:00
|
|
|
*
|
|
|
|
* @param {string} pathStr Path to gif to check
|
|
|
|
*
|
|
|
|
* @returns {object} Info about still from sharp
|
2019-07-07 04:02:01 +00:00
|
|
|
**/
|
|
|
|
async stillInfo(pathStr) {
|
|
|
|
return sharp_1.default(pathStr).metadata();
|
|
|
|
}
|
|
|
|
/**
|
2019-08-25 18:59:39 +00:00
|
|
|
* Preview a frame from the selected video.
|
2019-07-07 04:02:01 +00:00
|
|
|
*
|
2019-08-25 18:59:39 +00:00
|
|
|
* @param {object} evt Original event
|
|
|
|
* @param {object} arg Arguments from message
|
2019-07-07 04:02:01 +00:00
|
|
|
**/
|
2019-06-25 16:13:15 +00:00
|
|
|
async previewFrame(evt, arg) {
|
|
|
|
const state = JSON.parse(JSON.stringify(this.state));
|
|
|
|
let path;
|
|
|
|
state.frame = arg.frame;
|
|
|
|
try {
|
|
|
|
path = await this.ffmpeg.frame(state, { color: [255, 255, 255] });
|
|
|
|
}
|
|
|
|
catch (err) {
|
2019-06-27 00:08:49 +00:00
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
;
|
2019-06-25 16:13:15 +00:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
this.ui.send('preview_frame', { path, frame: arg.frame });
|
|
|
|
}
|
2019-07-07 04:02:01 +00:00
|
|
|
/**
|
|
|
|
*
|
2019-08-25 18:59:39 +00:00
|
|
|
*
|
|
|
|
* @param {object} evt Original event
|
|
|
|
* @param {object} arg Arguments from message
|
2019-07-07 04:02:01 +00:00
|
|
|
**/
|
2019-06-25 16:13:15 +00:00
|
|
|
async preview(evt, arg) {
|
2019-06-27 00:08:49 +00:00
|
|
|
const state = JSON.parse(JSON.stringify(this.state));
|
|
|
|
let path;
|
|
|
|
state.frame = arg.frame;
|
|
|
|
this.log.info(`Previewing frame ${state.frame} of ${state.fileName}`);
|
|
|
|
try {
|
|
|
|
path = await this.ffmpeg.frame(state, { color: [255, 255, 255] });
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
await this.display.open();
|
|
|
|
await this.display.show(arg.frame);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
}
|
2019-06-25 16:13:15 +00:00
|
|
|
}
|
2019-07-07 04:02:01 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
2019-06-18 19:42:30 +00:00
|
|
|
async focus(evt, arg) {
|
2019-06-27 00:08:49 +00:00
|
|
|
this.log.info(`Showing focus screen`);
|
2019-06-18 19:42:30 +00:00
|
|
|
try {
|
|
|
|
await this.display.open();
|
|
|
|
await this.display.focus();
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
}
|
|
|
|
}
|
2019-07-07 04:02:01 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
2019-06-18 19:42:30 +00:00
|
|
|
async field(evt, arg) {
|
2019-08-25 19:26:43 +00:00
|
|
|
const ratio = arg.ratio;
|
2019-06-27 00:08:49 +00:00
|
|
|
this.log.info(`Showing field guide screen`);
|
2019-06-18 19:42:30 +00:00
|
|
|
try {
|
|
|
|
await this.display.open();
|
2019-08-25 19:26:43 +00:00
|
|
|
await this.display.field(ratio);
|
2019-06-18 19:42:30 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
}
|
|
|
|
}
|
2019-07-07 04:02:01 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
2019-06-18 19:42:30 +00:00
|
|
|
async meter(evt, arg) {
|
2019-06-27 00:08:49 +00:00
|
|
|
this.log.info(`Showing meter screen`);
|
2019-06-18 19:42:30 +00:00
|
|
|
try {
|
|
|
|
await this.display.open();
|
|
|
|
await this.display.meter();
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
}
|
|
|
|
}
|
2019-07-07 04:02:01 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
2019-06-18 19:42:30 +00:00
|
|
|
async close(evt, arg) {
|
|
|
|
try {
|
|
|
|
await this.display.hide();
|
|
|
|
await this.display.close();
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
this.log.error(err, 'FILMOUT', true, true);
|
|
|
|
}
|
2019-06-18 17:47:55 +00:00
|
|
|
}
|
2019-07-07 04:02:01 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
**/
|
2019-06-27 00:08:49 +00:00
|
|
|
onDisplay(evt, arg) {
|
|
|
|
this.display.change(arg.display);
|
|
|
|
this.log.info(`Changing the display to ${arg.display}`);
|
|
|
|
}
|
2019-03-21 22:03:53 +00:00
|
|
|
}
|
|
|
|
module.exports = (display, ffmpeg, ffprobe, ui, light) => {
|
2019-06-18 19:42:30 +00:00
|
|
|
return new FilmOut(display, ffmpeg, ffprobe, ui, light);
|
2019-03-21 18:58:00 +00:00
|
|
|
};
|
|
|
|
//# sourceMappingURL=index.js.map
|