Skip to content

The swiss army knife of lossless video/audio editing

Use one helper for decoding ffmpeg output in the renderer

Claudeffd164acc678
diff --git a/src/renderer/src/ffmpeg.ts b/src/renderer/src/ffmpeg.ts
index 01e4255a..d116a1c8 100644
--- a/src/renderer/src/ffmpeg.ts
+++ b/src/renderer/src/ffmpeg.ts
@@ -8,7 +8,7 @@ import invariant from 'tiny-invariant';
import z from 'zod';
import { pcmAudioCodecs, isMov } from './util/streams';
-import { isExecaError } from './util';
+import { decodeText, isExecaError, safeCreateBlob } from './util';
import { isDurationValid } from './segments';
import type { FFprobeChapter, FFprobeFormat, FFprobeProbeResult, FFprobeStream } from '../../common/ffprobe';
import { parseSrt, parseSrtToSegments } from './edlFormats';
@@ -31,17 +31,6 @@ export class RefuseOverwriteError extends Error {
}
}
-// execa's stdout/stderr (from main, via @electron/remote) are backed by a resizable ArrayBuffer,
-// which Web APIs don't accept, e.g. "Failed to construct 'Blob': The provided ArrayBufferView value must not be resizable."
-// (and since Electron 43 also TextDecoder), so we copy them first.
-// maybe when moving away from @electron/remote, it's not needed anymore?
-// https://stackoverflow.com/a/25255750/6519037
-const copyResizable = (array: Uint8Array) => new Uint8Array(array);
-
-export const safeCreateBlob = (array: Uint8Array, options?: BlobPropertyBag) => new Blob([copyResizable(array)], options);
-
-export const decodeText = (array: Uint8Array) => new TextDecoder().decode(copyResizable(array));
-
export function logStdoutStderr({ stdout, stderr }: { stdout: Uint8Array, stderr: Uint8Array }) {
if (stdout.length > 0) {
console.log('%cSTDOUT:', 'color: green; font-weight: bold');
diff --git a/src/renderer/src/hooks/useFfmpegOperations.ts b/src/renderer/src/hooks/useFfmpegOperations.ts
index a318efc5..df8f9d8d 100644
--- a/src/renderer/src/hooks/useFfmpegOperations.ts
+++ b/src/renderer/src/hooks/useFfmpegOperations.ts
@@ -4,8 +4,8 @@ import pMap from 'p-map';
import invariant from 'tiny-invariant';
import i18n from 'i18next';
-import { getSuffixedOutPath, transferTimestamps, getOutFileExtension, getOutDir, getHtml5ifiedPath, unlinkWithRetry, getFrameDuration, isMac, html5ifiedPrefix, html5dummySuffix, assertFileExists } from '../util';
-import { isCuttingStart, isCuttingEnd, runFfmpegWithProgress, getFfCommandLine, getDuration, createChaptersFromSegments, readFileFfprobeMeta, getExperimentalArgs, getVideoTimescaleArgs, logStdoutStderr, runFfmpegConcat, RefuseOverwriteError, runFfmpeg, decodeText } from '../ffmpeg';
+import { getSuffixedOutPath, transferTimestamps, getOutFileExtension, getOutDir, getHtml5ifiedPath, unlinkWithRetry, getFrameDuration, isMac, html5ifiedPrefix, html5dummySuffix, assertFileExists, decodeText } from '../util';
+import { isCuttingStart, isCuttingEnd, runFfmpegWithProgress, getFfCommandLine, getDuration, createChaptersFromSegments, readFileFfprobeMeta, getExperimentalArgs, getVideoTimescaleArgs, logStdoutStderr, runFfmpegConcat, RefuseOverwriteError, runFfmpeg } from '../ffmpeg';
import { getEffectiveAvoidNegativeTs, getKeyframeCutSeekCompensation, getMapStreamsArgs, getStreamIdsToCopy, isCopyingOnlyAudioStreams, isCropActive, isAspectRatioActive } from '../util/streams';
import { needsSmartCut, getCodecParams } from '../smartcut';
import { getGuaranteedSegments, isDurationValid } from '../segments';
diff --git a/src/renderer/src/hooks/useWaveform.ts b/src/renderer/src/hooks/useWaveform.ts
index aa60cec5..2e32f348 100644
--- a/src/renderer/src/hooks/useWaveform.ts
+++ b/src/renderer/src/hooks/useWaveform.ts
@@ -2,7 +2,8 @@ import { useState, useRef, useEffect, useCallback } from 'react';
import sortBy from 'lodash/sortBy';
import invariant from 'tiny-invariant';
-import { renderWaveformPng, safeCreateBlob } from '../ffmpeg';
+import { renderWaveformPng } from '../ffmpeg';
+import { safeCreateBlob } from '../util';
import type { OverviewWaveform, WaveformSlice } from '../types';
import type { FFprobeStream } from '../../../common/ffprobe';
diff --git a/src/renderer/src/util.ts b/src/renderer/src/util.ts
index 49fb8196..4ac663e7 100644
--- a/src/renderer/src/util.ts
+++ b/src/renderer/src/util.ts
@@ -293,7 +293,18 @@ export const isAbortedError = (err: unknown) => (
|| (err instanceof Error && err.name === 'AbortError')
);
-export const getStdioString = (stdio: string | Uint8Array) => (stdio instanceof Uint8Array ? Buffer.from(stdio).toString('utf8') : stdio);
+// execa's stdout/stderr (from main, via @electron/remote) are backed by a resizable ArrayBuffer,
+// which Web APIs don't accept, e.g. "Failed to construct 'Blob': The provided ArrayBufferView value must not be resizable."
+// (and since Electron 43 also TextDecoder), so we copy them first.
+// maybe when moving away from @electron/remote, it's not needed anymore?
+// https://stackoverflow.com/a/25255750/6519037
+const copyResizable = (array: Uint8Array) => new Uint8Array(array);
+
+export const safeCreateBlob = (array: Uint8Array, options?: BlobPropertyBag) => new Blob([copyResizable(array)], options);
+
+export const decodeText = (array: Uint8Array) => new TextDecoder().decode(copyResizable(array));
+
+export const getStdioString = (stdio: string | Uint8Array) => (stdio instanceof Uint8Array ? decodeText(stdio) : stdio);
// A bit hacky but it works, unless someone has a file called "No space left on device" ( ͡° ͜ʖ ͡°)
export const isOutOfSpaceError = (err: InvariantExecaError) => (