The swiss army knife of lossless video/audio editing
use logger
Mikael Finstad1d03b38eb278
diff --git a/.eslintrc.cjs b/.eslintrc.cjsindex 4e50762b..539feb52 100644--- a/.eslintrc.cjs+++ b/.eslintrc.cjs@@ -1,7 +1,6 @@module.exports = {extends: ['mifi'],rules: {- 'no-console': 0,'jsx-a11y/click-events-have-key-events': 0,'jsx-a11y/interactive-supports-focus': 0,'jsx-a11y/control-has-associated-label': 0,@@ -15,6 +14,7 @@ module.exports = {browser: true,},rules: {+ 'no-console': 0,'import/no-extraneous-dependencies': 0,},},@@ -23,6 +23,9 @@ module.exports = {env: {browser: true,},+ rules: {+ 'no-console': 0,+ },},{files: ['./script/**/*.{js,cjs,mjs,jsx,ts,tsx,mts}', 'electron.vite.config.ts'],diff --git a/script/xcrun-wrapper.mts b/script/xcrun-wrapper.mtsindex 924cdef1..9c341d16 100644--- a/script/xcrun-wrapper.mts+++ b/script/xcrun-wrapper.mts@@ -1,4 +1,5 @@// eslint-disable-line unicorn/filename-case+/* eslint-disable no-console */import { execa } from 'execa';import { readFile } from 'node:fs/promises';diff --git a/src/main/compatPlayer.ts b/src/main/compatPlayer.tsindex 5f34e3fa..0ee7fbd5 100644--- a/src/main/compatPlayer.ts+++ b/src/main/compatPlayer.ts@@ -71,8 +71,8 @@ export function createMediaSourceStream({ path, videoStreamIndex, audioStreamInd// @ts-expect-error todoif (!(err.killed)) {// @ts-expect-error todo- console.warn(err.message);- console.warn(stderr.toString('utf8'));+ logger.warn(err.message);+ logger.warn(stderr.toString('utf8'));}}})();diff --git a/src/main/ffmpeg.ts b/src/main/ffmpeg.tsindex f62503d8..e234aed7 100644--- a/src/main/ffmpeg.ts+++ b/src/main/ffmpeg.ts@@ -10,6 +10,7 @@ import { app } from 'electron';import { platform, arch, isWindows, isMac, isLinux } from './util.js';import { CaptureFormat, Html5ifyMode, Waveform } from '../../types.js';import isDev from './isDev.js';+import logger from './logger.js';const runningFfmpegs = new Set<ExecaChildProcess<Buffer>>();@@ -46,7 +47,7 @@ const getFfprobePath = () => getFfPath('ffprobe');export const getFfmpegPath = () => getFfPath('ffmpeg');export function abortFfmpegs() {- console.log('Aborting', runningFfmpegs.size, 'ffmpeg process(es)');+ logger.info('Aborting', runningFfmpegs.size, 'ffmpeg process(es)');runningFfmpegs.forEach((process) => {process.kill('SIGTERM', { forceKillAfterTimeout: 10000 });});@@ -102,7 +103,7 @@ function handleProgress(process: { stderr: Readable | null }, durationIn: numberonProgress(progress);} catch (err) {// @ts-expect-error todo- console.log('Failed to parse ffmpeg progress line:', err.message);+ logger.error('Failed to parse ffmpeg progress line:', err.message);}});}@@ -122,7 +123,7 @@ function getExecaOptions({ env, ...customExecaOptions }: Omit<ExecaOptions<Buffe// todo collect warnings from ffmpeg output and show them after export? example: https://github.com/mifi/lossless-cut/issues/1469function runFfmpegProcess(args: readonly string[], customExecaOptions?: Omit<ExecaOptions<BufferEncodingOption>, 'encoding'>, additionalOptions?: { logCli?: boolean }) {const ffmpegPath = getFfmpegPath();- if (additionalOptions?.logCli) console.log(getFfCommandLine('ffmpeg', args));+ if (additionalOptions?.logCli) logger.info(getFfCommandLine('ffmpeg', args));const process = execa(ffmpegPath, args, getExecaOptions(customExecaOptions));@@ -163,10 +164,10 @@ export async function runFfmpegWithProgress({ ffmpegArgs, duration, onProgress }export async function runFfprobe(args: readonly string[], { timeout = isDev ? 10000 : 30000 } = {}) {const ffprobePath = getFfprobePath();- console.log(getFfCommandLine('ffprobe', args));+ logger.info(getFfCommandLine('ffprobe', args));const ps = execa(ffprobePath, args, getExecaOptions());const timer = setTimeout(() => {- console.warn('killing timed out ffprobe');+ logger.warn('killing timed out ffprobe');ps.kill();}, timeout);try {@@ -201,8 +202,8 @@ export async function renderWaveformPng({ filePath, start, duration, color, stre'-',];- console.log(getFfCommandLine('ffmpeg1', args1));- console.log('|', getFfCommandLine('ffmpeg2', args2));+ logger.info(getFfCommandLine('ffmpeg1', args1));+ logger.info('|', getFfCommandLine('ffmpeg2', args2));let ps1: ExecaChildProcess<Buffer> | undefined;let ps2: ExecaChildProcess<Buffer> | undefined;@@ -216,7 +217,7 @@ export async function renderWaveformPng({ filePath, start, duration, color, streconst timer = setTimeout(() => {ps1?.kill();ps2?.kill();- console.warn('ffmpeg timed out');+ logger.warn('ffmpeg timed out');}, 10000);let stdout;@@ -453,7 +454,7 @@ export async function captureFrame({ timestamp, videoPath, outPath, quality }: {async function readFormatData(filePath: string) {- console.log('readFormatData', filePath);+ logger.info('readFormatData', filePath);const { stdout } = await runFfprobe(['-of', 'json', '-show_format', '-i', filePath, '-hide_banner',@@ -482,7 +483,7 @@ export async function html5ify({ outPath, filePath: filePathArg, speed, hasAudioelse video = 'copy';}- console.log('Making HTML5 friendly version', { filePathArg, outPath, speed, video, audio });+ logger.info('Making HTML5 friendly version', { filePathArg, outPath, speed, video, audio });let videoArgs;let audioArgs;@@ -571,7 +572,7 @@ export async function html5ify({ outPath, filePath: filePathArg, speed, hasAudioif (duration) handleProgress(process, duration, onProgress);const { stdout } = await process;- console.log(stdout.toString('utf8'));+ logger.info(stdout.toString('utf8'));}export function readOneJpegFrame({ path, seekTo, videoStreamIndex }: { path: string, seekTo: number, videoStreamIndex: number }) {@@ -658,7 +659,7 @@ export function createMediaSourceProcess({ path, videoStreamIndex, audioStreamIn'-f', 'mp4', '-movflags', '+frag_keyframe+empty_moov+default_base_moof', '-',];- if (enableLog) console.log(getFfCommandLine('ffmpeg', args));+ if (enableLog) logger.info(getFfCommandLine('ffmpeg', args));return execa(getFfmpegPath(), args, { encoding: null, buffer: false, stderr: enableLog ? 'inherit' : 'pipe' });}