Skip to content

The swiss army knife of lossless video/audio editing

Address review: clamp negative silence start, trim upgrade checklist

Claude88577af19d64
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 5f0429cd..be5607f1 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -164,11 +164,11 @@ Links:
Use the newest stable release branch that all platforms can get (BtbN may lag behind), and keep all platforms on the same branch.
-1. macOS: bump `FFMPEG_VERSION` (and deps) in [ffmpeg-build-script](https://github.com/mifi/ffmpeg-build-script), then tag a release there (see its README).
-2. Windows and Linux: mirror the [BtbN](https://github.com/BtbN/FFmpeg-Builds) `gpl-shared` builds for that branch in a new [ffmpeg-builds](https://github.com/mifi/ffmpeg-builds) release (see its README). BtbN only builds the newest release branches, so check that the branch you want is still built.
-3. Update the `download-ffmpeg-*` scripts in [package.json](./package.json): the release tags, file names and extracted folder names.
+1. macOS: make a new [ffmpeg-build-script](https://github.com/mifi/ffmpeg-build-script) release (see its README).
+2. Windows and Linux: make a new [ffmpeg-builds](https://github.com/mifi/ffmpeg-builds) release (see its README).
+3. Update the `download-ffmpeg-*` scripts in [package.json](./package.json).
4. Read FFmpeg's `Changelog` and `doc/APIchanges` (and the release notes) since the previous version for changes that may affect LosslessCut, e.g. removed or renamed CLI options, changed muxer/demuxer defaults, seeking behaviour (`-ss`, `-avoid_negative_ts`), `ffprobe` JSON output, and codec/format support.
-5. Test a nightly build on each platform: cutting (keyframe and normal), merging, smart cut, capture frame, waveform/thumbnails and FFmpeg-assisted playback.
+5. Test a CI build on each platform: cutting (keyframe and normal), merging, smart cut, capture frame, waveform/thumbnails and FFmpeg-assisted playback.
### Upgrade Electron
diff --git a/src/main/ffmpegUtil.test.ts b/src/main/ffmpegUtil.test.ts
index e5c95728..d5548d77 100644
--- a/src/main/ffmpegUtil.test.ts
+++ b/src/main/ffmpegUtil.test.ts
@@ -45,6 +45,9 @@ describe('parseSilenceDetectLine', () => {
test('ffmpeg >= 8.1', () => {
expect(parseSilenceDetectLine('[Parsed_silencedetect_0 @ 0x5581e0c2e540] silence_end: 10 | silence_duration: 2.5')).toEqual({ start: 7.5, end: 10 });
});
+ test('slightly negative start is clamped to 0', () => {
+ expect(parseSilenceDetectLine('[Parsed_silencedetect_1 @ 0x5581e0c2e540] silence_end: 1.522268 | silence_duration: 1.522426')).toEqual({ start: 0, end: 1.522268 });
+ });
test('silence_start line is ignored', () => {
expect(parseSilenceDetectLine('[Parsed_silencedetect_0 @ 0x5581e0c2e540] silence_start: 7.5')).toBeUndefined();
});
diff --git a/src/main/ffmpegUtil.ts b/src/main/ffmpegUtil.ts
index 37777ec8..f7479b72 100644
--- a/src/main/ffmpegUtil.ts
+++ b/src/main/ffmpegUtil.ts
@@ -17,7 +17,7 @@ function toInterval(start: number, end: number) {
return { start, end };
}
-// The log prefix is `[blackdetect @ 0x...]` before ffmpeg 8.1, and `[Parsed_blackdetect_0 @ 0x...]` since
+// The log prefix is `[blackdetect @ 0x...]` before ffmpeg 8.1, and `[Parsed_blackdetect_0 @ 0x...]` since 8.1
const filterLogPrefix = (name: string) => `^\\[(?:Parsed_)?${name}(?:_\\d+)?\\s*@\\s*0x[0-9a-f]+\\]`;
const blackDetectRegex = new RegExp(`${filterLogPrefix('blackdetect')} black_start:([\\d.]+) black_end:([\\d.]+) black_duration:[\\d.]+`);
const silenceDetectRegex = new RegExp(`${filterLogPrefix('silencedetect')} silence_end: ([\\d.]+)[|\\s]+silence_duration: ([\\d.]+)`);
@@ -32,5 +32,6 @@ export function parseSilenceDetectLine(line: string) {
const match = line.match(silenceDetectRegex);
if (!match) return undefined;
const end = parseFloat(match[1]!);
- return toInterval(end - parseFloat(match[2]!), end);
+ // start can be slightly negative if the audio timestamps start below 0
+ return toInterval(Math.max(0, end - parseFloat(match[2]!)), end);
}