The swiss army knife of lossless video/audio editing
Fix low-quality WebP frame captures and attachment file names with undefined
Claude093b9767aa57
diff --git a/src/main/ffmpeg.ts b/src/main/ffmpeg.tsindex e7b99b58..1ce003fe 100644--- a/src/main/ffmpeg.ts+++ b/src/main/ffmpeg.ts@@ -499,17 +499,17 @@ export async function captureFrames({ from, to, videoPath, outPathTemplate, qualreturn args;}-function getCaptureFrameArgs({ timestamp, videoPath, quality }: {+function getCaptureFrameArgs({ timestamp, videoPath, quality, captureFormat }: {timestamp: number,videoPath: string,quality: number,+ captureFormat: CaptureFormat,}) {- const ffmpegQuality = getFfmpegJpegQuality(quality);return ['-ss', String(timestamp),'-i', videoPath,'-frames:v', '1',- '-q:v', String(ffmpegQuality),+ ...getQualityOpts({ captureFormat, quality }),];}@@ -519,7 +519,7 @@ export async function captureFrameToClipboard({ timestamp, videoPath, quality }:quality: number,}) {const args = [- ...getCaptureFrameArgs({ timestamp, videoPath, quality }),+ ...getCaptureFrameArgs({ timestamp, videoPath, quality, captureFormat: 'jpeg' }),'-c:v', 'mjpeg','-f', 'image2','-',@@ -530,14 +530,15 @@ export async function captureFrameToClipboard({ timestamp, videoPath, quality }:await clipboard.write([new ClipboardItem({ 'image/png': new Blob([png], { type: 'image/png' }) })]);}-export async function captureFrameToFile({ timestamp, videoPath, outPath, quality }: {+export async function captureFrameToFile({ timestamp, videoPath, outPath, quality, captureFormat }: {timestamp: number,videoPath: string,outPath: string,quality: number,+ captureFormat: CaptureFormat,}) {const args = [- ...getCaptureFrameArgs({ timestamp, videoPath, quality }),+ ...getCaptureFrameArgs({ timestamp, videoPath, quality, captureFormat }),'-y', outPath,];await runFfmpegProcess(args);diff --git a/src/renderer/src/hooks/useFfmpegOperations.ts b/src/renderer/src/hooks/useFfmpegOperations.tsindex 99311470..84da452f 100644--- a/src/renderer/src/hooks/useFfmpegOperations.ts+++ b/src/renderer/src/hooks/useFfmpegOperations.ts@@ -17,7 +17,7 @@ import type { LossyMode } from '../../../main';import { UserFacingError } from '../../errors';import mainApi from '../mainApi';import { formatFfmpegNumber, getFixChannelLayoutFilter, getHwaccelArgs, hasCustomChannelLayout } from '../../../common/util';-import { join, resolve, dirname } from '../util/path';+import { join, resolve, dirname, extname } from '../util/path';const { writeFile, mkdir, access, constants: { W_OK } } = window.require('node:fs/promises');@@ -1100,9 +1100,10 @@ function useFfmpegOperations({ filePath, treatInputFileModifiedTimeAsStart, treaconsole.log('Extracting', streams.length, 'attachment streams');let streamArgs: string[] = [];- const outPaths = await pMap(streams, async ({ index, codec_name: codec, codec_type: type }) => {- const ext = codec || 'bin';- const outPath = getSuffixedOutPath({ customOutDir, filePath, nameSuffix: `stream-${index}-${type}-${codec}.${ext}` });+ const outPaths = await pMap(streams, async ({ index, codec_name: codec, codec_type: type, tags }) => {+ // Attachments like fonts often have no codec_name, so take the extension from the attachment's file name+ const ext = codec || extname(tags?.['filename'] ?? '').slice(1) || 'bin';+ const outPath = getSuffixedOutPath({ customOutDir, filePath, nameSuffix: `stream-${index}-${type}${codec ? `-${codec}` : ''}.${ext}` });invariant(outPath != null);if (!enableOverwriteOutput && await mainApi.pathExists(outPath)) throw new RefuseOverwriteError();diff --git a/src/renderer/src/hooks/useFrameCapture.ts b/src/renderer/src/hooks/useFrameCapture.tsindex 4f664931..1171574b 100644--- a/src/renderer/src/hooks/useFrameCapture.ts+++ b/src/renderer/src/hooks/useFrameCapture.ts@@ -106,7 +106,7 @@ export default ({ appendFfmpegCommandLog, formatTimecode, treatInputFileModifiedconst timecode = formatTimecode({ seconds: time, fileNameFriendly: true });const nameSuffix = `${timecode}.${captureFormat}`;const outPath = getSuffixedOutPath({ customOutDir, filePath, nameSuffix });- const args = await ffmpeg.captureFrameToFile({ timestamp: time, videoPath: filePath, outPath, quality });+ const args = await ffmpeg.captureFrameToFile({ timestamp: time, videoPath: filePath, outPath, quality, captureFormat });appendFfmpegCommandLog(args);await transferTimestamps({ inPath: filePath, outPath, cutFrom: time, cutTo: time, duration: isDurationValid(fileDuration) ? fileDuration : undefined, treatInputFileModifiedTimeAsStart, treatOutputFileModifiedTimeAsStart });