ffmpeg-normalize 1.45.3__tar.gz → 1.45.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/PKG-INFO +1 -1
  2. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/pyproject.toml +1 -1
  3. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/pyproject.toml.orig +1 -1
  4. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/src/ffmpeg_normalize/_media_file.py +65 -15
  5. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/LICENSE.md +0 -0
  6. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/README.md +0 -0
  7. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/src/ffmpeg_normalize/__init__.py +0 -0
  8. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/src/ffmpeg_normalize/__main__.py +0 -0
  9. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/src/ffmpeg_normalize/_cmd_utils.py +0 -0
  10. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/src/ffmpeg_normalize/_console.py +0 -0
  11. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/src/ffmpeg_normalize/_errors.py +0 -0
  12. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/src/ffmpeg_normalize/_ffmpeg_normalize.py +0 -0
  13. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/src/ffmpeg_normalize/_logger.py +0 -0
  14. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/src/ffmpeg_normalize/_presets.py +0 -0
  15. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/src/ffmpeg_normalize/_streams.py +0 -0
  16. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/src/ffmpeg_normalize/data/presets/music.json +0 -0
  17. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/src/ffmpeg_normalize/data/presets/podcast.json +0 -0
  18. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/src/ffmpeg_normalize/data/presets/streaming-video.json +0 -0
  19. {ffmpeg_normalize-1.45.3 → ffmpeg_normalize-1.45.5}/src/ffmpeg_normalize/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ffmpeg-normalize
3
- Version: 1.45.3
3
+ Version: 1.45.5
4
4
  Summary: Normalize audio via ffmpeg
5
5
  Keywords: ffmpeg,normalize,audio
6
6
  Author: Werner Robitza
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "ffmpeg-normalize"
7
- version = "1.45.3"
7
+ version = "1.45.5"
8
8
  description = "Normalize audio via ffmpeg"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "ffmpeg-normalize"
7
- version = "1.45.3"
7
+ version = "1.45.5"
8
8
  description = "Normalize audio via ffmpeg"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -98,6 +98,8 @@ class MediaFile:
98
98
  )
99
99
  self.output_ext = current_ext
100
100
  self.streams: StreamDict = {"audio": {}, "video": {}, "subtitle": {}}
101
+ # stream ids of attachments, e.g. fonts used by styled subtitles
102
+ self.attachment_streams: list[int] = []
101
103
  self.temp_file: Union[str, None] = None
102
104
  self.batch_reference: float | None = None
103
105
  # Second-pass filter chain per normalized audio stream, keyed by stream
@@ -227,6 +229,10 @@ class MediaFile:
227
229
  self.ffmpeg_normalize, self, stream_id
228
230
  )
229
231
 
232
+ elif "Attachment" in line and stream_id not in self.attachment_streams:
233
+ _logger.debug(f"Found attachment stream at index {stream_id}")
234
+ self.attachment_streams.append(stream_id)
235
+
230
236
  if not self.streams["audio"]:
231
237
  raise FFmpegNormalizeError(
232
238
  f"Input file {self.input_file} does not contain any audio streams"
@@ -243,6 +249,7 @@ class MediaFile:
243
249
  self.streams["audio"] = {first_stream.stream_id: first_stream}
244
250
  self.streams["video"] = {}
245
251
  self.streams["subtitle"] = {}
252
+ self.attachment_streams = []
246
253
 
247
254
  def _get_streams_to_normalize(self) -> list[AudioStream]:
248
255
  """
@@ -1067,6 +1074,21 @@ class MediaFile:
1067
1074
  # add input file and basic filter
1068
1075
  cmd.extend(["-i", self.input_file, "-filter_complex", audio_filter_cmd])
1069
1076
 
1077
+ # Determine streams to normalize and passthrough
1078
+ streams_to_normalize = self._get_streams_to_normalize()
1079
+ all_audio_streams = list(self.streams["audio"].values())
1080
+
1081
+ # Determine which streams to passthrough
1082
+ if self.ffmpeg_normalize.keep_other_audio and (
1083
+ self.ffmpeg_normalize.audio_streams is not None
1084
+ or self.ffmpeg_normalize.audio_default_only
1085
+ ):
1086
+ streams_to_passthrough = [
1087
+ s for s in all_audio_streams if s not in streams_to_normalize
1088
+ ]
1089
+ else:
1090
+ streams_to_passthrough = []
1091
+
1070
1092
  # map metadata, only if needed
1071
1093
  if self.ffmpeg_normalize.metadata_disable:
1072
1094
  cmd.extend(["-map_metadata", "-1"])
@@ -1078,6 +1100,20 @@ class MediaFile:
1078
1100
  stream_key = stream_type[0]
1079
1101
  if stream_type not in self.streams:
1080
1102
  continue
1103
+ if stream_type == "audio":
1104
+ # output audio is the normalized streams, then the
1105
+ # passthrough ones, which need not be the first input
1106
+ # streams, so take the tags from the stream itself
1107
+ for idx, audio_stream in enumerate(
1108
+ streams_to_normalize + streams_to_passthrough
1109
+ ):
1110
+ cmd.extend(
1111
+ [
1112
+ f"-map_metadata:s:a:{idx}",
1113
+ f"0:s:{audio_stream.stream_id}",
1114
+ ]
1115
+ )
1116
+ continue
1081
1117
  for idx, _ in enumerate(self.streams[stream_type].items()):
1082
1118
  cmd.extend(
1083
1119
  [
@@ -1105,21 +1141,6 @@ class MediaFile:
1105
1141
  f"The chosen output extension {self.output_ext} does not support video/cover art. It will be disabled."
1106
1142
  )
1107
1143
 
1108
- # Determine streams to normalize and passthrough
1109
- streams_to_normalize = self._get_streams_to_normalize()
1110
- all_audio_streams = list(self.streams["audio"].values())
1111
-
1112
- # Determine which streams to passthrough
1113
- if self.ffmpeg_normalize.keep_other_audio and (
1114
- self.ffmpeg_normalize.audio_streams is not None
1115
- or self.ffmpeg_normalize.audio_default_only
1116
- ):
1117
- streams_to_passthrough = [
1118
- s for s in all_audio_streams if s not in streams_to_normalize
1119
- ]
1120
- else:
1121
- streams_to_passthrough = []
1122
-
1123
1144
  # ... and map the output of the normalization filters
1124
1145
  for ol in output_labels:
1125
1146
  cmd.extend(["-map", ol])
@@ -1147,6 +1168,13 @@ class MediaFile:
1147
1168
  cmd.extend([f"-c:a:{output_audio_idx}", "copy"])
1148
1169
  output_audio_idx += 1
1149
1170
 
1171
+ # filter outputs carry no disposition, so without this the muxer would
1172
+ # mark the first audio stream as default instead of the input's default
1173
+ if any(stream.is_default for stream in all_audio_streams):
1174
+ for idx, audio_stream in enumerate(streams_to_normalize):
1175
+ disposition = "default" if audio_stream.is_default else "0"
1176
+ cmd.extend([f"-disposition:a:{idx}", disposition])
1177
+
1150
1178
  # other audio options (if any) - only apply to normalized streams
1151
1179
  if self.ffmpeg_normalize.audio_bitrate:
1152
1180
  if audio_codec == "libvorbis":
@@ -1197,11 +1225,33 @@ class MediaFile:
1197
1225
  # copy subtitles
1198
1226
  cmd.extend(["-c:s", "copy"])
1199
1227
 
1228
+ # ... and attachments, which only Matroska can hold
1229
+ if self.attachment_streams and self.output_ext.lower() in ("mkv", "mka"):
1230
+ for idx, s in enumerate(self.attachment_streams):
1231
+ # the muxer needs each attachment's filename and mimetype tags
1232
+ cmd.extend(
1233
+ ["-map", f"0:{s}", f"-map_metadata:s:t:{idx}", f"0:s:t:{idx}"]
1234
+ )
1235
+ cmd.extend(["-c:t", "copy"])
1236
+
1200
1237
  if self.ffmpeg_normalize.keep_original_audio:
1201
1238
  # Map all original audio streams after normalized and passthrough streams
1202
1239
  for index, _ in enumerate(self.streams["audio"].items()):
1203
1240
  cmd.extend(["-map", f"0:a:{index}"])
1204
1241
  cmd.extend([f"-c:a:{output_audio_idx}", "copy"])
1242
+ # the normalized stream already carries the default flag, so
1243
+ # drop it from the copy (keeping any other flags, e.g. comment)
1244
+ # to avoid players picking the un-normalized original
1245
+ cmd.extend([f"-disposition:a:{output_audio_idx}", "-default"])
1246
+ # per-stream metadata mapping above turns off ffmpeg's automatic
1247
+ # copying of stream tags, so map the copy's tags explicitly
1248
+ if not self.ffmpeg_normalize.metadata_disable:
1249
+ cmd.extend(
1250
+ [
1251
+ f"-map_metadata:s:a:{output_audio_idx}",
1252
+ f"0:s:a:{index}",
1253
+ ]
1254
+ )
1205
1255
  output_audio_idx += 1
1206
1256
 
1207
1257
  # extra options (if any)