The swiss army knife of lossless video/audio editing
implement export frame numbers csv #878
Mikael Finstad375ee5d1d4b2
diff --git a/public/menu.js b/public/menu.jsindex d0f9d26e..52b51e4d 100644--- a/public/menu.js+++ b/public/menu.js@@ -104,6 +104,12 @@ module.exports = (app, mainWindow, newVersion) => {mainWindow.webContents.send('exportEdlFile', 'csv-human');},},+ {+ label: i18n.t('Frame numbers (CSV)'),+ click() {+ mainWindow.webContents.send('exportEdlFile', 'csv-frames');+ },+ },{label: i18n.t('Timestamps (TSV/TXT)'),click() {diff --git a/src/App.jsx b/src/App.jsxindex da4a7405..8c8dba5c 100644--- a/src/App.jsx+++ b/src/App.jsx@@ -1808,7 +1808,7 @@ const App = memo(() => {async function exportEdlFile2(e, type) {if (!checkFileOpened()) return;try {- await exportEdlFile({ type, cutSegments, filePath });+ await exportEdlFile({ type, cutSegments, filePath, getFrameCount });} catch (err) {errorToast(i18n.t('Failed to export project'));console.error('Failed to export project', type, err);@@ -1963,7 +1963,7 @@ const App = memo(() => {mergeFiles, outputDir, filePath, customOutDir, startTimeOffset, userHtml5ifyCurrentFile,extractAllStreams, userOpenFiles, openSendReportDialogWithState, setWorking,loadEdlFile, cutSegments, apparentCutSegments, edlFilePath, toggleHelp, toggleSettings, ensureOutDirAccessible, html5ifyAndLoad, html5ify,- loadCutSegments, duration, checkFileOpened, loadMedia, fileFormat, reorderSegsByStartTime, closeFileWithConfirm, closeBatch, clearSegments, fixInvalidDuration, invertAllCutSegments,+ loadCutSegments, duration, checkFileOpened, loadMedia, fileFormat, reorderSegsByStartTime, closeFileWithConfirm, closeBatch, clearSegments, fixInvalidDuration, invertAllCutSegments, getFrameCount,]);const showAddStreamSourceDialog = useCallback(async () => {diff --git a/src/edlStore.js b/src/edlStore.jsindex 8dc9e072..7ff30f73 100644--- a/src/edlStore.js+++ b/src/edlStore.js@@ -42,17 +42,32 @@ export async function saveCsv(path, cutSegments) {await fs.writeFile(path, str);}-const formatDurationStr = (duration) => (duration != null ? formatDuration({ seconds: duration }) : '');--const mapSegments = (segments) => segments.map(({ start, end, name }) => [formatDurationStr(start), formatDurationStr(end), name]);+const safeFormatDuration = (duration) => (duration != null ? formatDuration({ seconds: duration }) : '');+const safeFormatFrameCount = ({ seconds, getFrameCount }) => (seconds != null ? getFrameCount(seconds) : '');++const formatSegmentsTimes = (cutSegments) => cutSegments.map(({ start, end, name }) => [+ safeFormatDuration(start),+ safeFormatDuration(end),+ name,+]);+const formatSegmentsFrameCounts = ({ cutSegments, getFrameCount }) => cutSegments.map(({ start, end, name }) => [+ safeFormatFrameCount({ seconds: start, getFrameCount }),+ safeFormatFrameCount({ seconds: end, getFrameCount }),+ name,+]);export async function saveCsvHuman(path, cutSegments) {- const str = await csvStringifyAsync(mapSegments(cutSegments));+ const str = await csvStringifyAsync(formatSegmentsTimes(cutSegments));+ await fs.writeFile(path, str);+}++export async function saveCsvFrames({ path, cutSegments, getFrameCount }) {+ const str = await csvStringifyAsync(formatSegmentsFrameCounts({ cutSegments, getFrameCount }));await fs.writeFile(path, str);}export async function saveTsv(path, cutSegments) {- const str = await csvStringifyAsync(mapSegments(cutSegments), { delimiter: '\t' });+ const str = await csvStringifyAsync(formatSegmentsTimes(cutSegments), { delimiter: '\t' });await fs.writeFile(path, str);}@@ -98,7 +113,7 @@ export async function readEdl(type) {return readEdlFile({ type, path: filePaths[0] });}-export async function exportEdlFile({ type, cutSegments, filePath }) {+export async function exportEdlFile({ type, cutSegments, filePath, getFrameCount }) {let filters;let ext;if (type === 'csv') {@@ -110,6 +125,9 @@ export async function exportEdlFile({ type, cutSegments, filePath }) {} else if (type === 'csv-human') {ext = 'csv';filters = [{ name: i18n.t('TXT files'), extensions: [ext, 'txt'] }];+ } else if (type === 'csv-frames') {+ ext = 'csv';+ filters = [{ name: i18n.t('TXT files'), extensions: [ext, 'txt'] }];} else if (type === 'llc') {ext = 'llc';filters = [{ name: i18n.t('LosslessCut project'), extensions: [ext, 'llc'] }];@@ -121,5 +139,6 @@ export async function exportEdlFile({ type, cutSegments, filePath }) {if (type === 'csv') await saveCsv(savePath, cutSegments);else if (type === 'tsv-human') await saveTsv(savePath, cutSegments);else if (type === 'csv-human') await saveCsvHuman(savePath, cutSegments);+ else if (type === 'csv-frames') await saveCsvFrames({ path: savePath, cutSegments, getFrameCount });else if (type === 'llc') await saveLlcProject({ savePath, filePath, cutSegments });}