The swiss army knife of lossless video/audio editing
zero pad SEG_NUM #1446
Mikael Finstadf5ea3daecb19
diff --git a/src/App.jsx b/src/App.jsxindex e521d420..4c99bcc3 100644--- a/src/App.jsx+++ b/src/App.jsx@@ -65,7 +65,7 @@ import {checkDirWriteAccess, dirExists, isMasBuild, isStoreBuild, dragPreventer,filenamify, getOutFileExtension, generateSegFileName, defaultOutSegTemplate,havePermissionToReadFile, resolvePathIfNeeded, getPathReadAccessError, html5ifiedPrefix, html5dummySuffix, findExistingHtml5FriendlyFile,- deleteFiles, isOutOfSpaceError, shuffleArray,+ deleteFiles, isOutOfSpaceError, shuffleArray, getNumDigits,} from './util';import { formatDuration } from './util/duration';import { adjustRate } from './util/rate-calculator';@@ -1235,13 +1235,14 @@ const App = memo(() => {const { start, end, name = '' } = segment;const cutFromStr = formatTimecode({ seconds: start, fileNameFriendly: true });const cutToStr = formatTimecode({ seconds: end, fileNameFriendly: true });- const segNum = i + 1;+ const numDigits = getNumDigits(segments.length);+ const segNum = `${i + 1}`.padStart(numDigits, '0');const filenamifyOrNot = (fileName) => (safeOutputFileName || forceSafeOutputFileName ? filenamify(fileName) : fileName).substr(0, maxLabelLength);- // https://github.com/mifi/lossless-cut/issues/583let segSuffix = '';if (name) segSuffix = `-${filenamifyOrNot(name)}`;+ // https://github.com/mifi/lossless-cut/issues/583else if (segments.length > 1) segSuffix = `-seg${segNum}`;const ext = getOutFileExtension({ isCustomFormatSelected, outFormat: fileFormat, filePath });diff --git a/src/hooks/useFrameCapture.js b/src/hooks/useFrameCapture.jsindex c06bbaba..16921f9a 100644--- a/src/hooks/useFrameCapture.js+++ b/src/hooks/useFrameCapture.js@@ -1,7 +1,7 @@import dataUriToBuffer from 'data-uri-to-buffer';import pMap from 'p-map';-import { getSuffixedOutPath, getOutDir, transferTimestamps, getSuffixedFileName, getOutPath, escapeRegExp } from '../util';+import { getSuffixedOutPath, getOutDir, transferTimestamps, getSuffixedFileName, getOutPath, escapeRegExp, getNumDigits } from '../util';import { captureFrame as ffmpegCaptureFrame, captureFrames as ffmpegCaptureFrames } from '../ffmpeg';@@ -27,7 +27,7 @@ export default ({ formatTimecode }) => {const getSuffix = (prefix) => `${prefix}.${captureFormat}`;if (!outputTimestamps) {- const numDigits = Math.floor(Math.log10(estimatedMaxNumFiles)) + 1;+ const numDigits = getNumDigits(estimatedMaxNumFiles);const nameTemplateSuffix = getSuffix(`%0${numDigits}d`);const nameSuffix = getSuffix(`${'1'.padStart(numDigits, '0')}`); // mimic ffmpeg outputconst outPathTemplate = getSuffixedOutPath({ customOutDir, filePath, nameSuffix: nameTemplateSuffix });diff --git a/src/util.js b/src/util.jsindex 871d3e6b..dd78e0c0 100644--- a/src/util.js+++ b/src/util.js@@ -352,6 +352,8 @@ export function shuffleArray(arrayIn) {return array;}+export const getNumDigits = (value) => Math.floor(value > 0 ? Math.log10(value) : 0) + 1;+// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escapingexport function escapeRegExp(string) {return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string