Skip to content
m4bwav edited this page Oct 1, 2026 · 1 revision

Tasks people do with TrailerClipper, each run as shown against the published 2.0.0 on .NET 10, .NET 8 and .NET Framework 4.8 (the same results on all three).

Several folders in one call

One options entry per folder, each with its own lengths, and the settings saved for next time:

var clipper = new TrailerClipper();
clipper.RemoveTrailers(new[]
{
    new TrailerClipperOptions("Season1", 2000m) { OutputToConsole = false },
    new TrailerClipperOptions("Season2", 1000m) { RemoveIntro = true, IntroLengthInMilliseconds = 1500m, OutputToConsole = false },
}, "seasons.json");
Season1/clipped/s1e1.wav: 8.000 s; audio pcm_s16le
Season1/s1e1.wav: 10.000 s; audio pcm_s16le
Season2/clipped/s2e1.mp3: 7.500 s; audio mp3
Season2/s2e1.mp3: 10.000 s; audio mp3

The entries run in order, one after the other. seasons.json holds both entries (Configuration).

Several folders from one settings file

The tool does the same from a hand-written file. With this seasons.json:

[
  { "InputPath": "Season1", "TrailerLengthInMilliSeconds": 2000, "OutputToConsole": false },
  { "InputPath": "Season2", "TrailerLengthInMilliSeconds": 1000, "RemoveIntro": true, "IntroLengthInMilliseconds": 1500, "OutputToConsole": false }
]
$ tclipper -c seasons.json
$ echo $?
0

It left the same two copies (8 s and 7.5 s). Properties you leave out take their defaults.

Check for ffmpeg before a long job

FFmpegLocator.Find() returns null when nothing is found, and InstallHint says what to do; see Getting started for the call and API reference for the hint's text. Without the check, the first media file throws ToolNotFoundException with the same text.

Report each failure and carry on

A batch with files ffprobe cannot read clips the rest and then throws once. With two or more failures, the InnerException is an AggregateException with one exception per file:

try
{
    new TrailerClipper().RemoveTrailers(new TrailerClipperOptions("Broken2", 2000m) { OutputToConsole = false });
}
catch (InvalidOperationException e) when (e.InnerException is AggregateException all)
{
    foreach (var failure in all.InnerExceptions)
        Console.WriteLine(failure.Message);
}
ffprobe could not read 'Broken2\bad.mp3': ffprobe exited with non-zero exit-code (1 - [mp3 @ <address>] Failed to find two consecutive MPEG audio frames. | Broken2\bad.mp3: Invalid data found when processing input)
ffprobe could not read 'Broken2\bad.wav': ffprobe exited with non-zero exit-code (1 - Broken2\bad.wav: Invalid data found when processing input)

With a single failure, that file's exception is thrown as it is, with no AggregateException; catch InvalidOperationException without the filter to handle both. ToolNotFoundException is also an InvalidOperationException, so test for it first if you treat it differently.

Capture the progress lines

The progress lines go to Console.Out. To send them elsewhere, swap it for the call:

var original = Console.Out;
var lines = new StringWriter();
Console.SetOut(lines);
new TrailerClipper().RemoveTrailers("Episodes", 2000m);
Console.SetOut(original);
Console.WriteLine(lines.ToString().Split('\n').Count(l => l.StartsWith("Finished")) + " files clipped");
4 files clipped

Console.SetOut is process-wide, so do not do this while other threads write to the console. To silence the lines instead, set OutputToConsole = false.

Through the interface, for dependency injection

ITrailerClipperService has every clipping method, so code can depend on it and tests can fake it:

ITrailerClipperService service = new TrailerClipper();
service.RemoveIntros("Episodes/ep3.wav", 1500m);
Starting on file: Episodes/ep3.wav
Finished on trimming file, output: <cwd>\Episodes\clipped\ep3.wav

The copy, Episodes/clipped/ep3.wav, is 8.5 seconds long. The interface has no CreateDefaultSampleConfig, and FFmpegLocator is static, so a fake cannot replace the ffmpeg search.

Clip from a script

tclipper returns 0 or 1 and never asks a question when standard input is not a terminal, so it fits in scripts and CI. Use -cf to keep logs short, check the exit code, and point TRAILERCLIPPER_FFMPEG at ffmpeg when it is not on PATH (Configuration). Do not use -o with a value you have not checked (Commands).

Clone this wiki locally