Skip to content

How Files Are Clipped

m4bwav edited this page Oct 1, 2026 · 1 revision

What a call does to a file or a folder, rule by rule. The library and tclipper follow the same rules; the tool's options map to the properties named here (Commands).

The rules in short

  1. A path that is a folder means every file directly in it, in name order (ordinal), not its subfolders.
  2. Only files whose extension is m4b, wav, mp3, mp4, flv, avi, mpg or mov (any case) are clipped, unless ProcessEveryFile is set (-a).
  3. The new length is the file's duration minus the trailer, minus the intro when RemoveIntro is set. A file left with nothing (zero or less) is skipped with a console line.
  4. The copy keeps the file's name and goes to a clipped folder beside the original, or to OutputDirectoryPath. An existing copy is overwritten.
  5. ffmpeg re-encodes the copy, choosing codecs by the extension. Nothing else about the copy is chosen by TrailerClipper.
  6. The original stays unless DeleteOriginalFiles is set (-d), and is deleted only after its copy was written.
  7. A file ffmpeg cannot read or write does not stop the others; the failures are thrown together at the end (Errors and edge cases).

The examples use a folder Episodes with 10-second files made by ffmpeg's test sources: ep1.mp4 (H.264 and AAC), ep2.mp3, ep3.wav, ep4.m4b (AAC), extra.mkv (H.264 and Vorbis) and notes.txt.

Which files

The folder call on Home clipped the four files with listed extensions and left extra.mkv and notes.txt alone. With ProcessEveryFile, every file in the folder is tried:

var clipper = new TrailerClipper();
clipper.RemoveTrailers(new TrailerClipperOptions("Mixed", 2000m) { ProcessEveryFile = true });
Starting on file: Mixed\ep3.wav
Finished on trimming file, output: <cwd>\Mixed\clipped\ep3.wav
Starting on file: Mixed\extra.mkv
Finished on trimming file, output: <cwd>\Mixed\clipped\extra.mkv
Mixed/clipped/ep3.wav: 8.000 s; audio pcm_s16le
Mixed/clipped/extra.mkv: 8.003 s; video h264, audio vorbis
Mixed/ep3.wav: 10.000 s; audio pcm_s16le
Mixed/extra.mkv: 10.003 s; video h264, audio vorbis

The extension check applies to a single file too. Naming a .mkv file on its own clips nothing and prints nothing:

new TrailerClipper().RemoveTrailers("Episodes/extra.mkv", 2000m);

Episodes afterwards has no clipped folder. Set ProcessEveryFile to clip it.

How long the copy is

The duration comes from ffprobe and is rounded to hundredths of a second, as 1.1.0 read ffmpeg's Duration: line. ffmpeg is then asked to start at the intro length and write duration - trailer - intro. What ffmpeg writes can be a few milliseconds off for formats with fixed-size audio frames. From the runs on these pages (ffmpeg 9.0.1 on Windows; ffmpeg n9.0.2 on Linux gave the same numbers):

Input (10 s) Trailer 2000 Intro 1500, trailer 2000 Intro 1500 only
ep1.mp4 (H.264, AAC) 8.000 s 6.500 s 8.500 s
ep2.mp3 8.000 s 6.500 s 8.500 s
ep3.wav 8.000 s 6.500 s 8.500 s
ep4.m4b (AAC) 8.011 s 6.509 s 8.500 s
extra.mkv with -a (10.003 s) 8.003 s

MP3 copies are the requested length. 1.1.0's bundled 2015 ffmpeg left the encoder's padding in them (8.033 s for an 8 s cut), see Versions and upgrading.

A file whose intro and trailer add up to its length or more is skipped, and nothing is written for it:

var clipper = new TrailerClipper();
clipper.RemoveIntrosAndTrailers("Short", 1500m, 2000m);
Starting on file: Short\ep3.wav
Finished on trimming file, output: <cwd>\Short\clipped\ep3.wav
Starting on file: Short\short.wav
Skipped file, nothing is left after the cut: Short\short.wav
Short/clipped/ep3.wav: 6.500 s; audio pcm_s16le
Short/ep3.wav: 10.000 s; audio pcm_s16le
Short/short.wav: 3.000 s; audio pcm_s16le

A trailer of 0 copies the whole file (re-encoded). Negative lengths throw before any file is touched (Errors and edge cases).

What ffmpeg does to the copy

TrailerClipper passes ffmpeg only the start time, the length, the input and the output path. ffmpeg picks the container from the output's extension and its default codecs for that container, so the copy is re-encoded, not cut in place. In the runs above the codecs came out as they went in (H.264 and AAC for MP4 and M4B, MP3, 16-bit PCM for WAV, H.264 and Vorbis for MKV), because ffmpeg's defaults matched the inputs. Bit rates and quality are ffmpeg's defaults, not the input's. The ffmpeg you install decides all of this.

A file with no extension cannot be written back, because ffmpeg cannot tell which container to use (Errors and edge cases).

Where the copies go

For a folder, the copies go to <folder>/clipped; for a single file, to a clipped folder beside it:

var clipper = new TrailerClipper();
clipper.RemoveTrailers("Episodes/ep2.mp3", 2000m);
Starting on file: Episodes/ep2.mp3
Finished on trimming file, output: <cwd>\Episodes\clipped\ep2.mp3

The "Starting" line repeats the path as you passed it; the "Finished" line gives the full path of the copy. With OutputDirectoryPath, every copy goes to that one folder, created when missing. A relative OutputDirectoryPath is relative to the current folder, not to the input. Here with DeleteOriginalFiles too:

var clipper = new TrailerClipper();
clipper.RemoveTrailers(new TrailerClipperOptions("Episodes", 2000m)
{
    OutputDirectoryPath = "Clipped",
    DeleteOriginalFiles = true,
    OutputToConsole = false
});
Clipped/ep1.mp4: 8.000 s; video h264, audio aac
Clipped/ep2.mp3: 8.000 s; audio mp3
Clipped/ep3.wav: 8.000 s; audio pcm_s16le
Clipped/ep4.m4b: 8.011 s; audio aac
Episodes/extra.mkv: 10.003 s; video h264, audio vorbis
Episodes/notes.txt: 10 bytes, not media

Clipped was made in the current folder, beside Episodes, and the four originals are gone. The two files that were not clipped stay.

Progress lines

With OutputToConsole (the default), each clipped file prints Starting on file: <path> after ffprobe has read it, then Finished on trimming file, output: <copy> or Skipped file, nothing is left after the cut: <path>. They go to Console.Out, so they reach whatever the program set it to (Recipes). A file ffmpeg cannot read prints nothing; the failure is in the exception.

In parallel

MultiTaskFiles (-m) clips the files of a folder with Parallel.ForEach:

var clipper = new TrailerClipper();
clipper.RemoveTrailers(new TrailerClipperOptions("Episodes", 2000m) { MultiTaskFiles = true, OutputToConsole = false });

It left the same four 8-second copies as a plain run. Each ffmpeg is a process of its own, so this can run several at once; with progress lines on, their order is whatever order the files finish in. The property's own documentation still calls it experimental. Missing ffmpeg surfaces as ToolNotFoundException here too, not wrapped in an AggregateException.

What it never does

  • Read subfolders of a folder.
  • Change the original file, unless asked to delete it.
  • Touch the network: it runs only the ffmpeg and ffprobe it finds (Configuration). The tool's --install-ffmpeg runs your package manager, which does download.
  • Accept a file name that contains a double quote (Errors and edge cases).

Clone this wiki locally