1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
\# SPDX-FileCopyrightText: 2025 Dennis Fink <me+coding@dennisfink.me>
\# SPDX-License-Identifier: BSD-3-Clause
.TH TRANSCODE.SH 1 "2026-02-02" "1.0.0" "User Commands"
.SH NAME
transcode.sh \- batch transcode helper for media files using ffmpeg
.SH SYNOPSIS
.B transcode.sh
[\fIOPTION\fR]... [\fB\-\-\fR] \fIFILE\fR...
.SH DESCRIPTION
.B transcode.sh
is a batch transcoding wrapper around
.BR ffmpeg (1)
that processes one or more media files in place, replacing each with a
re-encoded version.
.PP
Encoding parameters are not hard-coded; instead they are supplied by
.IR presets ,
which are small shell snippets stored under the preset directory (see
.B FILES
below). Each preset must define a Bash array named
.B ffargs
containing the extra arguments passed to
.BR ffmpeg (1).
.PP
The script probes every input file with
.BR ffprobe (1)
to detect the input video codec and pixel format. Files whose codec
appears in the skip list are silently skipped. The output pixel format
is derived automatically so that chroma subsampling (4:2:0, 4:2:2,
4:4:4) and bit depth (8, 10, 12, 16\-bit) are preserved.
.PP
All streams, metadata and chapter markers from the input are retained by
default (\fB\-map 0 \-map_metadata 0 \-map_chapters 0 \-c copy\fR); the
preset only needs to override the streams it cares about (typically
video).
.PP
Encoding is performed into a temporary file in the same directory as the
input, which ensures an atomic rename on completion.
.SH OPTIONS
.TP
.BR \-c ", " \-\-continue
Continue processing the next file even if
.BR ffmpeg (1)
fails on the current one. Without this flag the script exits immediately
on the first failure.
.TP
.BR \-\-no\-continue
Do not continue processing next file even if
.BR ffmpeg (1)
fails on the current one.
.TP
.BR \-\-config\-file " \fIPATH\fR, " \-\-config\-file= \fIPATH\fR
Load configuration from \fIPATH\fR instead of the default location
.RI ( ${XDG_CONFIG_HOME:-$HOME/.config}/transcode.sh/config.toml ).
If the specified file does not exist the script exits with a configuration
error. CLI flags always take precedence over values in the config file.
Requires
.BR tomlq (1)
when the file is present.
.TP
.BR \-f " \fIPATH\fR, " \-\-encode-file " \fIPATH\fR, " \-\-encode-file= \fIPATH\fR
Read the list of files to encode from \fIPATH\fR (one file per line)
instead of taking files from the command line.
.TP
.BR \-n ", " \-\-dry\-run
Print what would be done without actually invoking
.BR ffmpeg (1).
Combine with
.B \-v
to see the detected codec and pixel format information.
.TP
.BR \-N " \fIVALUE\fR, " \-\-nice " \fIVALUE\fR, " \-\-nice= \fIVALUE\fR
Run
.BR ffmpeg (1)
under
.BR nice (1)
with the given niceness value. Defaults to
.BR 19
(lowest priority).
.TP
.BR \-s ", " \-\-saving
After each successful encode, append a line to the savings log file
recording the filename, original size in bytes, new size in bytes and the
percentage saved. Requires
.BR bc (1).
.TP
.BR \-\-saving\-file " \fIPATH\fR, " \-\-saving\-file= \fIPATH\fR
Path to the savings log file written by
.BR \-\-saving .
Defaults to
.B transcode_savings
in the current working directory.
.TP
.BR \-S " \fILIST\fR, " \-\-skip\-codec " \fILIST\fR, " \-\-skip\-codec= \fILIST\fR
Comma-, space- or colon-separated list of video codec names to skip.
Files whose detected input codec appears in this list are left untouched.
Codecs specified here are merged with any codecs listed under
.B [skip] codecs
in
.B config.toml
\(em both sources contribute to the skip list.
.TP
.BR \-l ", " \-\-only\-if\-smaller
After encoding, replace the original only when the new file is strictly
smaller. If the transcoded file is larger the temporary file is removed
and the original is kept unchanged.
.TP
.BR \-\-no\-only\-if\-smaller
After encoding, replace the original also if the new file is bigger.
.TP
.BR \-p " \fINAME\fR, " \-\-preset " \fINAME\fR, " \-\-preset= \fINAME\fR
Load the preset named \fINAME\fR from the preset directory. Defaults to
.BR default .
.TP
.BR \-h ", " \-\-help ", " \-?
Print a short help message and exit.
.TP
.BR \-q ", " \-\-quiet
Suppress all normal output. Takes precedence over
.BR \-v / \-\-verbose .
.TP
.BR \-v ", " \-\-verbose
Emit additional informational messages (detected codec, pixel format,
etc.).
.TP
.B \-\-version
Print version, author and license information and exit.
.TP
.B \-\-color
Force colored output even when stdout is not a terminal or
.B NO_COLOR
is set.
.TP
.B \-\-no\-color
Disable colored output unconditionally.
.TP
.B \-\-
End of options. All subsequent arguments are treated as file names even
if they begin with
.BR \- .
.SH ENVIRONMENT
.TP
.B NO_COLOR
When set (to any value), colored output is disabled. See
.IR https://no-color.org/ .
.TP
.B FORCE_COLOR
When set, colored output is enabled regardless of
.B NO_COLOR
or terminal detection.
.TP
.B DEBUG
Set to
.B 1
to enable structured debug messages (high-level state reporting).
After configuration loading, a summary of all effective option values
is printed.
.TP
.B TRACE
Set to
.B 1
to enable Bash execution tracing
.RB ( set\ \-x ),
which prints every command as it is executed.
.TP
.B XDG_CONFIG_HOME
Base directory for user configuration. Defaults to
.BR $HOME/.config .
.SH FILES
.TP
.IR "${XDG_CONFIG_HOME:-$HOME/.config}/transcode.sh/presets/<name>.sh"
Preset files. Each preset is sourced as Bash code and must define an
array variable named
.B ffargs
containing additional arguments for
.BR ffmpeg (1).
The following variables are available to presets at source time:
.RS
.TP
.B input_codec
The video codec of the input file as reported by
.BR ffprobe (1)
(e.g.\&
.IR h264 ,
.IR hevc ).
.TP
.B input_pixel_format
The pixel format of the input file after
.I yuvj*
normalisation (e.g.\&
.IR yuv420p ,
.IR yuv444p10le ).
.TP
.B output_pixel_format
The recommended output pixel format, automatically derived from the
input to preserve chroma subsampling (4:2:0, 4:2:2, 4:4:4) and bit
depth (8, 10, 12, 16\-bit).
.TP
.B input_frame_rate
The raw frame rate of the input video stream as reported by
.BR ffprobe (1),
expressed as a fraction (e.g.\&
.IR 30000/1001 ,
.IR 25/1 ,
.IR 60/1 ).
.TP
.B input_fps
The input frame rate rounded to the nearest integer (e.g.\&
.IR 30 ,
.IR 25 ,
.IR 60 ).
Derived from
.B input_frame_rate
and provided as a convenience for encoder heuristics that require a whole
number.
.TP
.B output_gop_size
The recommended GOP (Group of Pictures) size for the output, derived from
.B input_fps
as approximately five seconds of video (capped at 300 frames).
Use this in presets to set
.B \-g
for encoders that accept an explicit GOP size.
.RE
.IP
Before the preset's
.B ffargs
are appended, the script always passes the following base arguments to
.BR ffmpeg (1):
.RS
.nf
\-map 0 # include all streams from the input
\-map_metadata 0 # copy all container\-level metadata
\-map_chapters 0 # copy all chapter markers
\-c copy # default to stream copy for every stream
.fi
.RE
.IP
A preset therefore only needs to specify the streams it wishes to
re-encode (typically
.BR \-c:v:0 )
and any associated encoder options. All other streams — audio,
subtitles, attachments — are passed through unchanged unless the preset
explicitly overrides them.
.IP
Example preset:
.RS
.nf
ffargs=( \-c:v:0 libsvtav1 \-crf 30 \-preset 6 \-pix_fmt "$output_pixel_format" )
.fi
.RE
.IP
.B Warning:
presets are executed as shell code. Only use presets from trusted
sources.
.TP
.IR "${XDG_CONFIG_HOME:-$HOME/.config}/transcode.sh/config.toml"
Optional TOML configuration file. Provides defaults for all options.
CLI flags always take precedence. The file must be valid TOML; an
unparseable file is a hard error. Requires
.BR tomlq (1).
Supported sections and keys:
.RS
.TP
.B [encoding] preset
String. Default preset name. Equivalent to
.BR \-p .
.TP
.B [encoding] nice
Integer. Default niceness value. Equivalent to
.BR \-N .
.TP
.B [skip] codecs
Array of strings. Merged with any codecs from
.BR \-S .
.TP
.B [saving] enabled
Boolean. Equivalent to
.BR \-s .
.TP
.B [saving] file
String. Equivalent to
.BR \-\-saving\-file .
.TP
.B [output] verbose
Boolean. Equivalent to
.BR \-v .
.TP
.B [output] quiet
Boolean. Equivalent to
.BR \-q .
.RE
.TP
.IR "${XDG_CONFIG_HOME:-$HOME/.config}/transcode.sh/skip.conf"
.B Deprecated.
This file is no longer read. If it exists, a warning is printed.
Migrate its contents to
.B [skip] codecs
in
.B config.toml
and delete the file.
.SH EXIT STATUS
.TP
.B 0
Success (or all skipped files were intentionally skipped).
.TP
.B 1
Runtime failure (e.g.
.BR ffmpeg (1)
error on one or more files).
.TP
.B 2
Usage error (invalid option or missing argument).
.TP
.B 3
Configuration error (missing or invalid preset).
.TP
.B 127
A required dependency
.RB ( ffmpeg ,
.BR ffprobe ,
.BR nice ,
.B bc
when
.B \-\-saving
is active, or
.B tomlq
when
.B config.toml
is present) was not found.
.SH EXAMPLES
Transcode a single file using the default preset:
.PP
.RS
.nf
transcode.sh video.mp4
.fi
.RE
.PP
Transcode a batch of files listed in a file and log size savings:
.PP
.RS
.nf
transcode.sh \-s \-f list.txt
.fi
.RE
.PP
Dry-run with verbosity to inspect detected formats:
.PP
.RS
.nf
transcode.sh \-n \-v my_movie.mkv
.fi
.RE
.PP
Use a custom preset and only keep the result if it is smaller:
.PP
.RS
.nf
transcode.sh \-p av1_fast \-l /media/films/*.mkv
.fi
.RE
.PP
Run at a less aggressive niceness and skip already-AV1 files:
.PP
.RS
.nf
transcode.sh \-N 10 \-S av1 input.mkv
.fi
.RE
.PP
Load an alternative configuration file:
.PP
.RS
.nf
transcode.sh \-\-config\-file ~/profiles/fast.toml input.mp4
.fi
.RE
.PP
Use
.BR ffmpeg (1)
installed via Homebrew (macOS):
.PP
.RS
.nf
PATH="/opt/homebrew/bin:$PATH" transcode.sh input.mp4
.fi
.RE
.SH NOTES
The script resets
.B PATH
to
.I /bin:/usr/bin:/usr/local/bin
for security. If
.BR ffmpeg (1)
is installed outside these directories (e.g. via Homebrew or Nix),
prepend the correct directory to
.B PATH
before invoking
.BR transcode.sh .
.SH SEE ALSO
.BR ffmpeg (1),
.BR ffprobe (1),
.BR nice (1),
.BR bc (1),
.BR tomlq (1)
.SH AUTHOR
Dennis Fink <me+coding@dennisfink.me>
.SH LICENSE
BSD\-3\-Clause
|