slhck / ffmpeg-normalize

Audio Normalization for Python/ffmpeg
MIT License
1.28k stars 118 forks source link

List index out of range when running normalization #257

Closed markvesterskov closed 6 months ago

markvesterskov commented 6 months ago

Checklist (please tick all boxes)

Expected behavior File normalized correctly. Tried with ffmpeg 6 and ffmpeg 7.

Actual behavior

Process failed with error
  File "/home/forge/.local/lib/python3.10/site-packages/ffmpeg_normalize/_media_file.py", line 418, in _second_pass
    audio_stream.set_second_pass_stats(all_stats[idx])
IndexError: list index out of range

Command

ffmpeg-normalize -f -lrt 50 -tp -0.2 -of /normalized/ manAwghOqAKsfXOm.mp4

Any output you get when running the command with the --debug flag:

DEBUG: Running command: /usr/bin/ffmpeg -filters
DEBUG: Parsing streams of /home/forge/offload.filmfestival.dk/storage/app/movies/manAwghOqAKsfXOm.mp4
DEBUG: Running command: /usr/bin/ffmpeg -i /home/forge/offload.filmfestival.dk/storage/app/movies/manAwghOqAKsfXOm.mp4 -c copy -t 0 -map 0 -f null /dev/null
DEBUG: Stream parsing command output:
DEBUG: ffmpeg version 6.0.1-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 8 (Debian 8.3.0-6)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/forge/offload.filmfestival.dk/storage/app/movies/manAwghOqAKsfXOm.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2021-12-02T12:14:16.000000Z
  Duration: 00:04:42.12, start: 0.000000, bitrate: 16349 kb/s
  Stream #0:0[0x1](eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 16023 kb/s, 50 fps, 50 tbr, 50k tbn (default)
    Metadata:
      creation_time   : 2021-12-02T12:14:17.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : AVC Coding
  Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2021-12-02T12:14:21.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler
      vendor_id       : [0][0][0][0]
Output #0, null, to '/dev/null':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    encoder         : Lavf60.3.100
  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 16023 kb/s, 50 fps, 50 tbr, 50k tbn (default)
    Metadata:
      creation_time   : 2021-12-02T12:14:17.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : AVC Coding
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2021-12-02T12:14:21.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=    1 fps=0.0 q=-1.0 Lsize=N/A time=-00:00:00.02 bitrate=N/A speed=N/A    /s speed=N/A
video:482kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

DEBUG: Found duration: 282.012 s
DEBUG: Found video stream at index 0
DEBUG: Found audio stream at index 1
INFO: Normalizing file manAwghOqAKsfXOm.mp4 (1 of 1)
DEBUG: Running normalization for /home/forge/offload.filmfestival.dk/storage/app/movies/manAwghOqAKsfXOm.mp4
DEBUG: Parsing normalization info for /home/forge/offload.filmfestival.dk/storage/app/movies/manAwghOqAKsfXOm.mp4
INFO: Running first pass loudnorm filter for stream 1
DEBUG: Running command: /usr/bin/ffmpeg -hide_banner -y -i /home/forge/offload.filmfestival.dk/storage/app/movies/manAwghOqAKsfXOm.mp4 -map 0:1 -filter_complex '[0:1]loudnorm=i=-23.0:lra=50.0:tp=-0.2:offset=0.0:print_format=json' -vn -sn -f null /dev/null
DEBUG: ffmpeg output: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/forge/offload.filmfestival.dk/storage/app/movies/manAwghOqAKsfXOm.mp4':
Metadata:
major_brand     : mp42
minor_version   : 0
compatible_brands: mp42mp41
creation_time   : 2021-12-02T12:14:16.000000Z
Duration: 00:04:42.12, start: 0.000000, bitrate: 16349 kb/s
Stream #0:0[0x1](eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 16023 kb/s, 50 fps, 50 tbr, 50k tbn (default)
Metadata:
creation_time   : 2021-12-02T12:14:17.000000Z
handler_name    : ?Mainconcept Video Media Handler
vendor_id       : [0][0][0][0]
encoder         : AVC Coding
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
Metadata:
creation_time   : 2021-12-02T12:14:21.000000Z
handler_name    : #Mainconcept MP4 Sound Media Handler
vendor_id       : [0][0][0][0]
Stream mapping:
Stream #0:1 (aac) -> loudnorm:default (graph 0)
loudnorm:default (graph 0) -> Stream #0:0 (pcm_s16le)
Stream #0:1 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to '/dev/null':
Metadata:
major_brand     : mp42
minor_version   : 0
compatible_brands: mp42mp41
encoder         : Lavf60.3.100
Stream #0:0: Audio: pcm_s16le, 192000 Hz, stereo, s16, 6144 kb/s
Metadata:
encoder         : Lavc60.3.100 pcm_s16le
Stream #0:1(eng): Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s (default)
Metadata:
creation_time   : 2021-12-02T12:14:21.000000Z
handler_name    : #Mainconcept MP4 Sound Media Handler
vendor_id       : [0][0][0][0]
encoder         : Lavc60.3.100 pcm_s16le
video:0kB audio:264500kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_loudnorm_0 @ 0x81de040]
{
"input_i" : "-11.29",
"input_tp" : "0.07",
"input_lra" : "7.30",
"input_thresh" : "-21.65",
"output_i" : "-21.70",
"output_tp" : "-8.40",
"output_lra" : "6.40",
"output_thresh" : "-31.93",
"normalization_type" : "dynamic",
"target_offset" : "-1.30"
}
DEBUG: Loudnorm first pass command output: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/forge/offload.filmfestival.dk/storage/app/movies/manAwghOqAKsfXOm.mp4':
Metadata:
major_brand     : mp42
minor_version   : 0
compatible_brands: mp42mp41
creation_time   : 2021-12-02T12:14:16.000000Z
Duration: 00:04:42.12, start: 0.000000, bitrate: 16349 kb/s
Stream #0:0[0x1](eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 16023 kb/s, 50 fps, 50 tbr, 50k tbn (default)
Metadata:
creation_time   : 2021-12-02T12:14:17.000000Z
handler_name    : ?Mainconcept Video Media Handler
vendor_id       : [0][0][0][0]
encoder         : AVC Coding
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
Metadata:
creation_time   : 2021-12-02T12:14:21.000000Z
handler_name    : #Mainconcept MP4 Sound Media Handler
vendor_id       : [0][0][0][0]
Stream mapping:
Stream #0:1 (aac) -> loudnorm:default (graph 0)
loudnorm:default (graph 0) -> Stream #0:0 (pcm_s16le)
Stream #0:1 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to '/dev/null':
Metadata:
major_brand     : mp42
minor_version   : 0
compatible_brands: mp42mp41
encoder         : Lavf60.3.100
Stream #0:0: Audio: pcm_s16le, 192000 Hz, stereo, s16, 6144 kb/s
Metadata:
encoder         : Lavc60.3.100 pcm_s16le
Stream #0:1(eng): Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s (default)
Metadata:
creation_time   : 2021-12-02T12:14:21.000000Z
handler_name    : #Mainconcept MP4 Sound Media Handler
vendor_id       : [0][0][0][0]
encoder         : Lavc60.3.100 pcm_s16le
video:0kB audio:264500kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[Parsed_loudnorm_0 @ 0x81de040]
{
"input_i" : "-11.29",
"input_tp" : "0.07",
"input_lra" : "7.30",
"input_thresh" : "-21.65",
"output_i" : "-21.70",
"output_tp" : "-8.40",
"output_lra" : "6.40",
"output_thresh" : "-31.93",
"normalization_type" : "dynamic",
"target_offset" : "-1.30"
}
DEBUG: Parsing loudnorm stats for stream 0
DEBUG: Loudnorm stats for stream 0 parsed: {"input_i": "-11.29", "input_tp": "0.07", "input_lra": "7.30", "input_thresh": "-21.65", "output_i": "-21.70", "output_tp": "-8.40", "output_lra": "6.40", "output_thresh": "-31.93", "normalization_type": "dynamic", "target_offset": "-1.30"}
INFO: Running second pass for /home/forge/offload.filmfestival.dk/storage/app/movies/manAwghOqAKsfXOm.mp4
DEBUG: Running command: /usr/bin/ffmpeg -hide_banner -y -i /home/forge/offload.filmfestival.dk/storage/app/movies/manAwghOqAKsfXOm.mp4 -filter_complex '[0:1]loudnorm=i=-23.0:lra=50.0:tp=-0.2:offset=-1.3:measured_i=-11.29:measured_lra=7.3:measured_tp=0.07:measured_thresh=-21.65:linear=true:print_format=json[norm1]' -map_metadata 0 -map_metadata:s:a:0 0:s:a:0 -map_metadata:s:v:0 0:s:v:0 -map_chapters 0 -map 0:0 -c:v copy -map '[norm1]' -c:a:0 pcm_s16le -c:s copy /tmp/tmpgptt5f03/out.mkv
DEBUG: ffmpeg output: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/forge/offload.filmfestival.dk/storage/app/movies/manAwghOqAKsfXOm.mp4':
Metadata:
major_brand     : mp42
minor_version   : 0
compatible_brands: mp42mp41
creation_time   : 2021-12-02T12:14:16.000000Z
Duration: 00:04:42.12, start: 0.000000, bitrate: 16349 kb/s
Stream #0:0[0x1](eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 16023 kb/s, 50 fps, 50 tbr, 50k tbn (default)
Metadata:
creation_time   : 2021-12-02T12:14:17.000000Z
handler_name    : ?Mainconcept Video Media Handler
vendor_id       : [0][0][0][0]
encoder         : AVC Coding
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
Metadata:
creation_time   : 2021-12-02T12:14:21.000000Z
handler_name    : #Mainconcept MP4 Sound Media Handler
vendor_id       : [0][0][0][0]
Stream mapping:
Stream #0:1 (aac) -> loudnorm:default
Stream #0:0 -> #0:0 (copy)
loudnorm:default -> Stream #0:1 (pcm_s16le)
Press [q] to stop, [?] for help
Output #0, matroska, to '/tmp/tmpgptt5f03/out.mkv':
Metadata:
major_brand     : mp42
minor_version   : 0
compatible_brands: mp42mp41
creation_time   : 2021-12-02T12:14:16.000000Z
encoder         : Lavf60.3.100
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 16023 kb/s, 50 fps, 50 tbr, 1k tbn (default)
Metadata:
creation_time   : 2021-12-02T12:14:17.000000Z
handler_name    : ?Mainconcept Video Media Handler
vendor_id       : [0][0][0][0]
encoder         : AVC Coding
Stream #0:1(eng): Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
Metadata:
creation_time   : 2021-12-02T12:14:21.000000Z
handler_name    : #Mainconcept MP4 Sound Media Handler
vendor_id       : [0][0][0][0]
encoder         : Lavc60.3.100 pcm_s16le
frame=8
fps=0.00
stream_0_0_q=-1.0
frame=2570
fps=0.00
stream_0_0_q=-1.0
frame=3660
fps=3658.74
stream_0_0_q=-1.0
frame=4730
fps=3152.40
stream_0_0_q=-1.0
frame=5580
fps=2789.33
stream_0_0_q=-1.0
frame=6540
fps=2615.48
stream_0_0_q=-1.0
frame=7371
fps=2449.28
stream_0_0_q=-1.0
frame=9400
fps=2678.14
stream_0_0_q=-1.0
frame=10530
fps=2625.87
stream_0_0_q=-1.0
frame=12740
fps=2824.77
stream_0_0_q=-1.0
frame=14106
fps=2877.60
stream_0_0_q=-1.0
video:551819kB audio:52900kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.033222%
[Parsed_loudnorm_0 @ 0x779d540]
{
"input_i" : "-11.26",
"input_tp" : "0.05",
"input_lra" : "7.30",
"input_thresh" : "-21.58",
"output_i" : "-22.97",
"output_tp" : "-11.66",
"output_lra" : "7.30",
"output_thresh" : "-33.25",
"normalization_type" : "linear",
"target_offset" : "-0.03"
}
DEBUG: Moving temporary file from /tmp/tmpgptt5f03/out.mkv to /home/forge/offload.filmfestival.dk/storage/app/normalized/manAwghOqAKsfXOm.mkv
DEBUG: Parsing loudnorm stats for stream 0
DEBUG: Loudnorm stats for stream 0 parsed: {"input_i": "-11.26", "input_tp": "0.05", "input_lra": "7.30", "input_thresh": "-21.58", "output_i": "-22.97", "output_tp": "-11.66", "output_lra": "7.30", "output_thresh": "-33.25", "normalization_type": "linear", "target_offset": "-0.03"}
Traceback (most recent call last):
  File "/usr/bin/ffmpeg-normalize", line 8, in <module>
    sys.exit(main())
  File "/home/forge/.local/lib/python3.10/site-packages/ffmpeg_normalize/__main__.py", line 575, in main
    ffmpeg_normalize.run_normalization()
  File "/home/forge/.local/lib/python3.10/site-packages/ffmpeg_normalize/_ffmpeg_normalize.py", line 250, in run_normalization
    raise e
  File "/home/forge/.local/lib/python3.10/site-packages/ffmpeg_normalize/_ffmpeg_normalize.py", line 240, in run_normalization
    media_file.run_normalization()
  File "/home/forge/.local/lib/python3.10/site-packages/ffmpeg_normalize/_media_file.py", line 196, in run_normalization
    for _ in self._second_pass():
  File "/home/forge/.local/lib/python3.10/site-packages/ffmpeg_normalize/_media_file.py", line 418, in _second_pass
    audio_stream.set_second_pass_stats(all_stats[idx])
IndexError: list index out of range

Environment (please complete the following information):

slhck commented 6 months ago

Thanks for the report, this is fixed now!

slhck commented 6 months ago

A new release v1.28.1 is available with the fix. Please update and report back, thanks!

markvesterskov commented 6 months ago

Wow, that was fast! Fixed the issue, thank you.