1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-21 18:02:35 +01:00

use logger

This commit is contained in:
Mikael Finstad 2024-08-06 22:30:30 +02:00
parent f2f98d40a7
commit 1d03b38eb2
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26
4 changed files with 20 additions and 15 deletions

View File

@ -1,7 +1,6 @@
module.exports = { module.exports = {
extends: ['mifi'], extends: ['mifi'],
rules: { rules: {
'no-console': 0,
'jsx-a11y/click-events-have-key-events': 0, 'jsx-a11y/click-events-have-key-events': 0,
'jsx-a11y/interactive-supports-focus': 0, 'jsx-a11y/interactive-supports-focus': 0,
'jsx-a11y/control-has-associated-label': 0, 'jsx-a11y/control-has-associated-label': 0,
@ -15,6 +14,7 @@ module.exports = {
browser: true, browser: true,
}, },
rules: { rules: {
'no-console': 0,
'import/no-extraneous-dependencies': 0, 'import/no-extraneous-dependencies': 0,
}, },
}, },
@ -23,6 +23,9 @@ module.exports = {
env: { env: {
browser: true, browser: true,
}, },
rules: {
'no-console': 0,
},
}, },
{ {
files: ['./script/**/*.{js,cjs,mjs,jsx,ts,tsx,mts}', 'electron.vite.config.ts'], files: ['./script/**/*.{js,cjs,mjs,jsx,ts,tsx,mts}', 'electron.vite.config.ts'],

View File

@ -1,4 +1,5 @@
// eslint-disable-line unicorn/filename-case // eslint-disable-line unicorn/filename-case
/* eslint-disable no-console */
import { execa } from 'execa'; import { execa } from 'execa';
import { readFile } from 'node:fs/promises'; import { readFile } from 'node:fs/promises';

View File

@ -71,8 +71,8 @@ export function createMediaSourceStream({ path, videoStreamIndex, audioStreamInd
// @ts-expect-error todo // @ts-expect-error todo
if (!(err.killed)) { if (!(err.killed)) {
// @ts-expect-error todo // @ts-expect-error todo
console.warn(err.message); logger.warn(err.message);
console.warn(stderr.toString('utf8')); logger.warn(stderr.toString('utf8'));
} }
} }
})(); })();

View File

@ -10,6 +10,7 @@ import { app } from 'electron';
import { platform, arch, isWindows, isMac, isLinux } from './util.js'; import { platform, arch, isWindows, isMac, isLinux } from './util.js';
import { CaptureFormat, Html5ifyMode, Waveform } from '../../types.js'; import { CaptureFormat, Html5ifyMode, Waveform } from '../../types.js';
import isDev from './isDev.js'; import isDev from './isDev.js';
import logger from './logger.js';
const runningFfmpegs = new Set<ExecaChildProcess<Buffer>>(); const runningFfmpegs = new Set<ExecaChildProcess<Buffer>>();
@ -46,7 +47,7 @@ const getFfprobePath = () => getFfPath('ffprobe');
export const getFfmpegPath = () => getFfPath('ffmpeg'); export const getFfmpegPath = () => getFfPath('ffmpeg');
export function abortFfmpegs() { export function abortFfmpegs() {
console.log('Aborting', runningFfmpegs.size, 'ffmpeg process(es)'); logger.info('Aborting', runningFfmpegs.size, 'ffmpeg process(es)');
runningFfmpegs.forEach((process) => { runningFfmpegs.forEach((process) => {
process.kill('SIGTERM', { forceKillAfterTimeout: 10000 }); process.kill('SIGTERM', { forceKillAfterTimeout: 10000 });
}); });
@ -102,7 +103,7 @@ function handleProgress(process: { stderr: Readable | null }, durationIn: number
onProgress(progress); onProgress(progress);
} catch (err) { } catch (err) {
// @ts-expect-error todo // @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/1469 // todo collect warnings from ffmpeg output and show them after export? example: https://github.com/mifi/lossless-cut/issues/1469
function runFfmpegProcess(args: readonly string[], customExecaOptions?: Omit<ExecaOptions<BufferEncodingOption>, 'encoding'>, additionalOptions?: { logCli?: boolean }) { function runFfmpegProcess(args: readonly string[], customExecaOptions?: Omit<ExecaOptions<BufferEncodingOption>, 'encoding'>, additionalOptions?: { logCli?: boolean }) {
const ffmpegPath = getFfmpegPath(); 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)); 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 } = {}) { export async function runFfprobe(args: readonly string[], { timeout = isDev ? 10000 : 30000 } = {}) {
const ffprobePath = getFfprobePath(); const ffprobePath = getFfprobePath();
console.log(getFfCommandLine('ffprobe', args)); logger.info(getFfCommandLine('ffprobe', args));
const ps = execa(ffprobePath, args, getExecaOptions()); const ps = execa(ffprobePath, args, getExecaOptions());
const timer = setTimeout(() => { const timer = setTimeout(() => {
console.warn('killing timed out ffprobe'); logger.warn('killing timed out ffprobe');
ps.kill(); ps.kill();
}, timeout); }, timeout);
try { try {
@ -201,8 +202,8 @@ export async function renderWaveformPng({ filePath, start, duration, color, stre
'-', '-',
]; ];
console.log(getFfCommandLine('ffmpeg1', args1)); logger.info(getFfCommandLine('ffmpeg1', args1));
console.log('|', getFfCommandLine('ffmpeg2', args2)); logger.info('|', getFfCommandLine('ffmpeg2', args2));
let ps1: ExecaChildProcess<Buffer> | undefined; let ps1: ExecaChildProcess<Buffer> | undefined;
let ps2: ExecaChildProcess<Buffer> | undefined; let ps2: ExecaChildProcess<Buffer> | undefined;
@ -216,7 +217,7 @@ export async function renderWaveformPng({ filePath, start, duration, color, stre
const timer = setTimeout(() => { const timer = setTimeout(() => {
ps1?.kill(); ps1?.kill();
ps2?.kill(); ps2?.kill();
console.warn('ffmpeg timed out'); logger.warn('ffmpeg timed out');
}, 10000); }, 10000);
let stdout; let stdout;
@ -453,7 +454,7 @@ export async function captureFrame({ timestamp, videoPath, outPath, quality }: {
async function readFormatData(filePath: string) { async function readFormatData(filePath: string) {
console.log('readFormatData', filePath); logger.info('readFormatData', filePath);
const { stdout } = await runFfprobe([ const { stdout } = await runFfprobe([
'-of', 'json', '-show_format', '-i', filePath, '-hide_banner', '-of', 'json', '-show_format', '-i', filePath, '-hide_banner',
@ -482,7 +483,7 @@ export async function html5ify({ outPath, filePath: filePathArg, speed, hasAudio
else video = 'copy'; else 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 videoArgs;
let audioArgs; let audioArgs;
@ -571,7 +572,7 @@ export async function html5ify({ outPath, filePath: filePathArg, speed, hasAudio
if (duration) handleProgress(process, duration, onProgress); if (duration) handleProgress(process, duration, onProgress);
const { stdout } = await process; 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 }) { 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', '-', '-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' }); return execa(getFfmpegPath(), args, { encoding: null, buffer: false, stderr: enableLog ? 'inherit' : 'pipe' });
} }