You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: implement automatic audio codec selection based on output container
This is based on ffmpeg's default choice (a shell call to ffmpeg parses it), and still picks PCM for containers that support it to prevent quality loss.
Copy file name to clipboardExpand all lines: README.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,8 @@ This program normalizes media files to a certain loudness level using the EBU R1
34
34
35
35
## 🆕 What's New
36
36
37
+
- Version 1.41.0 automatically picks the correct output audio codec for the output container, so you no longer need to specify `-c:a`/`--audio-codec` unless you want to override the default. PCM is chosen for containers that support it; others will use teh default that ffmpeg picks. See [the usage guide](https://slhck.info/ffmpeg-normalize/usage/file-input-output/#how-the-output-audio-codec-is-chosen) for details.
38
+
37
39
- Version 1.40.0 can optionally **skip files that are already at the target level** via `--threshold` (e.g. `--threshold 0.5`, disabled by default). Such files are copied through unchanged instead of being re-encoded. The `--print-stats` output now includes a per-file `status` (`normalized`, `skipped`, or `error`, plus an `error` message on failure), and the exit code is non-zero if any file failed to process, so a script can tell what happened to each file.
Copy file name to clipboardExpand all lines: docs/advanced/faq.md
+7-1Lines changed: 7 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,6 +36,12 @@ If you decide to run `ffmpeg-normalize` with the default options, it will encode
36
36
37
37
I chose MKV as a default output container since it handles almost every possible combination of audio, video, and subtitle codecs. If you know which audio/video codec you want, and which container is supported, use the output options to specify the encoder and output file name manually.
38
38
39
+
## Which audio codec is used for my output?
40
+
41
+
If you do not set `-c:a`/`--audio-codec`, the codec is chosen for you based on the output container: PCM (lossless) for containers that support it (such as WAV or MKV), or — for containers that cannot store PCM, like MP3, MP4, FLAC, or Opus — the same default codec your ffmpeg would use for that container (e.g. `.mp3` → MP3, `.m4a` → AAC, `.flac` → FLAC, `.opus` → Opus).
42
+
43
+
See also: [How the output audio codec is chosen](../usage/file-input-output.md#how-the-output-audio-codec-is-chosen).
44
+
39
45
## I get a "Could not write header for output file" error
40
46
41
47
See the [next section](#the-conversion-does-not-work-and-i-get-a-cryptic-ffmpeg-error).
@@ -54,7 +60,7 @@ One possible reason is that the input file contains some streams that cannot be
54
60
55
61
- You are trying to normalize a movie file, writing to a `.wav` or `.mp3` file. WAV/MP3 files only support audio, not video. Disable video and subtitles with `-vn` and `-sn`, or choose a container that supports video (e.g. `.mkv`).
56
62
57
-
- You are trying to normalize a file, writing to an `.mp4` container. This program defaults to PCM audio, but MP4 does not support PCM audio. Make sure that your audiocodec is set to something MP4 containers support (e.g. `-c:a aac`).
63
+
- You explicitly requested PCM audio (e.g. `-c:a pcm_s16le`) while writing to a container that cannot store PCM, such as `.mp4`, `.flac`, or `.opus`. Either drop the `-c:a` option, in which case a suitable codec is [chosen automatically](../usage/file-input-output.md#how-the-output-audio-codec-is-chosen), or pick a codec the container supports (e.g. `-c:a aac` for MP4).
58
64
59
65
The default output container is `.mkv` as it will support most input stream types. If you want a different output container, [make sure that it supports](https://en.wikipedia.org/wiki/Comparison_of_container_file_formats) your input file's video, audio, and subtitle streams (if any).
Copy file name to clipboardExpand all lines: docs/index.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,8 @@ Batch processing of several input files is possible, including video files.
33
33
34
34
## 🆕 What's New
35
35
36
+
- Version 1.41.0 automatically picks the correct output audio codec for the output container, so you no longer need to specify `-c:a`/`--audio-codec` unless you want to override the default. PCM is chosen for containers that support it; others will use teh default that ffmpeg picks. See [the usage guide](https://slhck.info/ffmpeg-normalize/usage/file-input-output/#how-the-output-audio-codec-is-chosen) for details.
37
+
36
38
- Version 1.40.0 can optionally **skip files that are already at the target level** via `--threshold` (e.g. `--threshold 0.5`, disabled by default). Such files are copied through unchanged instead of being re-encoded. The `--print-stats` output now includes a per-file `status` (`normalized`, `skipped`, or `error`, plus an `error` message on failure), and the exit code is non-zero if any file failed to process, so a script can tell what happened to each file.
Copy file name to clipboardExpand all lines: docs/usage/cli-options.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -218,7 +218,7 @@ Audio codec to use for output files.
218
218
219
219
See `ffmpeg -encoders` for a list.
220
220
221
-
Will use PCM audio with input stream bit depth by default.
221
+
Will use PCM audio with input stream bit depth by default. For output containers that cannot store PCM (e.g. MP3, FLAC, Opus), the codec that ffmpeg uses by default for that container is chosen automatically, so you usually do not need to set this.
Copy file name to clipboardExpand all lines: docs/usage/file-input-output.md
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,9 +73,25 @@ for %i in (*.mkv) do ffmpeg-normalize "%i" -c:a aac -b:a 192k
73
73
74
74
CMD loops run `ffmpeg-normalize` once per file. This means `--batch` mode will **not** work, because each invocation only sees a single file. Use one of the methods above if you need batch normalization.
75
75
76
+
## How the output audio codec is chosen
77
+
78
+
When you do not pass `-c:a`/`--audio-codec`, `ffmpeg-normalize` picks the audio codec for you, based on the output container:
79
+
80
+
- For containers that can store uncompressed audio (such as WAV, MKV, or MOV), it uses **PCM** audio, matching the input bit depth. This is lossless, but produces large files.
81
+
- For containers that cannot store PCM (MP3, MP4/M4A, FLAC, Ogg, Opus, WebM), it uses the **same default codec that ffmpeg itself would pick for that container**, so you do not have to specify one. For example:
82
+
83
+
-`.mp3` → MP3 (`libmp3lame`)
84
+
-`.m4a` / `.mp4` → AAC
85
+
-`.flac` → FLAC
86
+
-`.opus` → Opus (`libopus`)
87
+
88
+
The exact codec is read from your ffmpeg build at runtime rather than hardcoded, so it always matches what plain ffmpeg would do. This means it can differ between builds: for example, on some builds `.ogg` defaults to FLAC rather than Vorbis. To see what your ffmpeg would choose for a given container, run e.g. `ffmpeg -h muxer=flac` and look at the "Default audio codec" line.
89
+
90
+
You can always override this by setting `-c:a` explicitly, for example `-c:a libvorbis` to force an Ogg Vorbis file. Note that re-encoding to a lossy codec (MP3, AAC, Opus, …) introduces [generation loss](https://en.wikipedia.org/wiki/Generation_loss); to keep your audio lossless, use a PCM-capable container (WAV, MKV) or a lossless codec such as FLAC.
91
+
76
92
## Create an MP3 file as output
77
93
78
-
Normalize an MP3 file and write an MP3 file (you have to explicitly specify the encoder):
94
+
Normalize an MP3 file and write an MP3 file. The codec is chosen automatically (MP3 via `libmp3lame`), but you can specify the encoder and bitrate explicitly to control quality:
0 commit comments