fix(downloads): improve ffmpeg logging
This commit is contained in:
parent
286a123e02
commit
88ec8feb6b
4 changed files with 22 additions and 5 deletions
|
|
@ -238,6 +238,10 @@ export function updateDownloadProgress(trackId, progress) {
|
||||||
progressFill.style.background = '#3b82f6'; // Blue for encoding
|
progressFill.style.background = '#3b82f6'; // Blue for encoding
|
||||||
statusEl.textContent = `Converting: ${percent}%`;
|
statusEl.textContent = `Converting: ${percent}%`;
|
||||||
} else if (progress instanceof ProgressMessage || progress.message) {
|
} else if (progress instanceof ProgressMessage || progress.message) {
|
||||||
|
if (progress instanceof FfmpegProgress && (progress.stage == 'parsing' || progress.stage == 'stdout')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
progressFill.style.width = '100%';
|
progressFill.style.width = '100%';
|
||||||
progressFill.style.background = '#3b82f6';
|
progressFill.style.background = '#3b82f6';
|
||||||
statusEl.textContent = progress.message;
|
statusEl.textContent = progress.message;
|
||||||
|
|
@ -961,7 +965,7 @@ function updateBulkDownloadProgress(notifEl, current, total, currentItem, progre
|
||||||
}
|
}
|
||||||
|
|
||||||
if (progress instanceof FfmpegProgress) {
|
if (progress instanceof FfmpegProgress) {
|
||||||
if (progress.stage == 'stdout') {
|
if (progress.stage == 'stdout' || progress.stage == 'parsing') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
15
js/ffmpeg.js
15
js/ffmpeg.js
|
|
@ -55,11 +55,13 @@ async function ffmpegWorker(
|
||||||
const assets = loadFfmpeg();
|
const assets = loadFfmpeg();
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
let endCategory = null;
|
||||||
const worker = new FfmpegWorker();
|
const worker = new FfmpegWorker();
|
||||||
|
|
||||||
// Handle abort signal
|
// Handle abort signal
|
||||||
const abortHandler = () => {
|
const abortHandler = () => {
|
||||||
worker.terminate();
|
worker.terminate();
|
||||||
|
endCategory?.();
|
||||||
reject(new FfmpegError('FFMPEG aborted'));
|
reject(new FfmpegError('FFMPEG aborted'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -72,20 +74,30 @@ async function ffmpegWorker(
|
||||||
}
|
}
|
||||||
|
|
||||||
worker.onmessage = (e) => {
|
worker.onmessage = (e) => {
|
||||||
const { type, blob, message, stage, progress } = e.data;
|
const { type, blob, message, stage, progress, command } = e.data;
|
||||||
|
|
||||||
if (type === 'complete') {
|
if (type === 'complete') {
|
||||||
if (signal) signal.removeEventListener('abort', abortHandler);
|
if (signal) signal.removeEventListener('abort', abortHandler);
|
||||||
worker.terminate();
|
worker.terminate();
|
||||||
|
endCategory?.();
|
||||||
resolve(blob);
|
resolve(blob);
|
||||||
} else if (type === 'error') {
|
} else if (type === 'error') {
|
||||||
if (signal) signal.removeEventListener('abort', abortHandler);
|
if (signal) signal.removeEventListener('abort', abortHandler);
|
||||||
worker.terminate();
|
worker.terminate();
|
||||||
|
endCategory?.();
|
||||||
reject(new FfmpegError(message));
|
reject(new FfmpegError(message));
|
||||||
} else if (type === 'progress' && message) {
|
} else if (type === 'progress' && message) {
|
||||||
onProgress?.(new FfmpegProgress(stage, progress || 0, message));
|
onProgress?.(new FfmpegProgress(stage, progress || 0, message));
|
||||||
} else if (type === 'progress' && stage != 'loading' && progress !== null) {
|
} else if (type === 'progress' && stage != 'loading' && progress !== null) {
|
||||||
onProgress?.(new FfmpegProgress(stage, progress || 0, message));
|
onProgress?.(new FfmpegProgress(stage, progress || 0, message));
|
||||||
|
} else if (type === 'command') {
|
||||||
|
if (logConsole) {
|
||||||
|
const consoleCategory = `ffmpeg ${command?.join(' ')}`;
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.groupCollapsed(consoleCategory);
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
endCategory = () => console.groupEnd();
|
||||||
|
}
|
||||||
} else if (type === 'log') {
|
} else if (type === 'log') {
|
||||||
onProgress?.(new FfmpegProgress('stdout', 0, message));
|
onProgress?.(new FfmpegProgress('stdout', 0, message));
|
||||||
if (logConsole) {
|
if (logConsole) {
|
||||||
|
|
@ -97,6 +109,7 @@ async function ffmpegWorker(
|
||||||
worker.onerror = (error) => {
|
worker.onerror = (error) => {
|
||||||
if (signal) signal.removeEventListener('abort', abortHandler);
|
if (signal) signal.removeEventListener('abort', abortHandler);
|
||||||
worker.terminate();
|
worker.terminate();
|
||||||
|
endCategory?.();
|
||||||
reject(new FfmpegError('Worker failed: ' + error.message));
|
reject(new FfmpegError('Worker failed: ' + error.message));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
export class FfmpegProgress implements MonochromeProgress {
|
export class FfmpegProgress implements MonochromeProgress {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly stage: 'loading' | 'encoding' | 'finalizing' | 'stdout',
|
public readonly stage: 'loading' | 'parsing' | 'encoding' | 'finalizing' | 'stdout',
|
||||||
public readonly progress: number,
|
public readonly progress: number,
|
||||||
public readonly message?: string
|
public readonly message?: string
|
||||||
) {}
|
) {}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ async function loadFFmpeg(loadOptions = {}) {
|
||||||
ffmpeg = new FFmpeg();
|
ffmpeg = new FFmpeg();
|
||||||
|
|
||||||
ffmpeg.on('log', ({ message }) => {
|
ffmpeg.on('log', ({ message }) => {
|
||||||
self.postMessage({ type: 'log', message });
|
self.postMessage({ type: 'log', stage: 'stdout', message });
|
||||||
|
|
||||||
// Try to extract total duration from input log
|
// Try to extract total duration from input log
|
||||||
if (totalDurationSeconds === null) {
|
if (totalDurationSeconds === null) {
|
||||||
|
|
@ -124,7 +124,7 @@ self.onmessage = async (e) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const ffmpegArgs = ['-i', 'input', ...args, ...(output.name ? [output.name] : [])];
|
const ffmpegArgs = ['-i', 'input', ...args, ...(output.name ? [output.name] : [])];
|
||||||
self.postMessage({ type: 'log', message: `FFmpeg command: ffmpeg ${ffmpegArgs.join(' ')}` });
|
self.postMessage({ type: 'command', command: ffmpegArgs });
|
||||||
|
|
||||||
const exitCode = await ffmpeg.exec(ffmpegArgs);
|
const exitCode = await ffmpeg.exec(ffmpegArgs);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue