Moonbase59 / loudgain

ReplayGain 2.0 loudness normalizer based on the EBU R128/ITU BS.1770 standard (-18 LUFS, FLAC, Ogg, MP2, MP3, MP4, M4A, AAC, ALAC, Opus, ASF, WMA, WAV, AIFF, WavPack, APE)
Other
190 stars 23 forks source link

"Could not open SWResample: Invalid argument" for ALAC and WAV files #4

Closed Moonbase59 closed 5 years ago

Moonbase59 commented 5 years ago

@classicjazz reports:

$ loudgain -L -a -k -s e *.m4a
[✔] Scanning '08 Photograph.m4a' ...
[✘] Could not open SWResample: Invalid argument

on a Mac.

Moonbase59 commented 5 years ago

I downloaded 18 MacCunn The Lay of the Last Minstrel - Part 2.M4A from the Hyperion testfiles page and tried … out put in next comment because I must switch machines …

Moonbase59 commented 5 years ago
Matthiass-iMac:Documents matthias$ loudgain -L -a -k -s e *.M4A
[✔] Scanning '18 MacCunn The Lay of the Last Minstrel - Part 2 Final chorus O Caledonia! stern and wild.M4A' ...
 100% [========================================================================]

Track: 18 MacCunn The Lay of the Last Minstrel - Part 2 Final chorus O Caledonia! stern and wild.M4A
 Loudness:   -15.18 LUFS
 Range:       15.39 dB
 Peak:     0.971494 (-0.25 dBTP)
 Gain:        -2.82 dB

Album:
 Loudness:   -15.18 LUFS
 Range:       15.39 dB
 Peak:     0.971494 (-0.25 dBTP)
 Gain:        -2.82 dB
Matthiass-iMac:Documents matthias$ 

FFmpeg to verify it‘s actually ALAC:

Matthiass-iMac:Documents matthias$ ffmpeg -i 18\ MacCunn\ The\ Lay\ of\ the\ Last\ Minstrel\ -\ Part\ 2\ Final\ chorus\ O\ Caledonia\!\ stern\ and\ wild.M4A 
ffmpeg version 4.1.4 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.4_1 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fea50001400] stream 0, timescale not set
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '18 MacCunn The Lay of the Last Minstrel - Part 2 Final chorus O Caledonia! stern and wild.M4A':
  Metadata:
    major_brand     : M4A 
    minor_version   : 0
    compatible_brands: M4A mp42isom
    Source          : CD (Lossless) >> CD  (Lossless) [wav]
    UPC             : 0034571168159
    replaygain_album_gain: -2.82 dB
    replaygain_album_peak: 0.971494
    replaygain_album_range: 15.39 dB
    replaygain_reference_loudness: -18.00 LUFS
    replaygain_track_gain: -2.82 dB
    replaygain_track_peak: 0.971494
    replaygain_track_range: 15.39 dB
    album_artist    : Martyn Brabbins: BBC Scottish Symphony Orchestra
    copyright       : © Hyperion Records Ltd, London
    disc            : 1/1
    track           : 18/18
    artist          : Martyn Brabbins: BBC Scottish Symphony Orchestra
    album           : Maccunn: Land of the Mountain & the Flood
    date            : 1995
    genre           : Classical
    lyrics          : Chorus: O Caledonia! stern and wild, 
                    : Meet nurse for a poetic child! 
                    : Land of brown heath and shaggy wood, 
                    : Land of the mountain and the flood. 
                    : Land of my sires! What mortal hand 
                    : Can e’er untie the filial band, 
                    : That knits me to thy rugged strand! 
                    :  
                    : Sir Walter Scott (1771-1832) 
                    :  
                    : This concluding recitative and chorus (from MacCunn’s dramatic cantata of 1888) is the vocal expression of the same passage from Scott’s poem which inspired Land of the Mountain and the Flood. No composer was more fitted to attempt this theme than Mac 
                    : So it is that MacCunn makes no doomed attempt to resurrect a bardic manner. His is a triumphant cry of modern nationhood, cultural and political, and his setting is a thrilling monument to the memory of his genius, spent to extend the road of Scotland’s 
                    : from notes by John Purser © 1995 
                    :  
                    : Album notes: 
                    : Hamish MacCunn: the name itself is a kind of bold statement, and if ever there was a composer who emerged from the glens and firths of Scotland, fully armed, the MacCunn was that person. Yet this is the first recording devoted solely to his work and, with 
                    : John Purser © 1995
    title           : MacCunn: The Lay of the Last Minstrel - Part 2. Final chorus: O Caledonia! stern and wild
    composer        : MacCunn, Hamish (1868-1916)
  Duration: 00:02:54.80, start: 0.000000, bitrate: 696 kb/s
    Stream #0:0(eng): Audio: alac (alac / 0x63616C61), 44100 Hz, stereo, s16p, 684 kb/s (default)
    Side data:
      replaygain: track gain - -2.820000, track peak - 0.000023, album gain - -2.820000, album peak - 0.000023, 
    Stream #0:1: Video: png, pal8(pc), 700x700, 90k tbr, 90k tbn, 90k tbc
At least one output file must be specified
Matthiass-iMac:Documents matthias$ 
Moonbase59 commented 5 years ago

Could you try

ffmpeg -i '08 Photograph.m4a'

to verify your file?

Moonbase59 commented 5 years ago

Thanks for your sample. I tried it here (on MacOS 10.14.4 Mojave) and it works:

Matthiass-iMac:Downloads matthias$ loudgain -L -a -k -s e *.m4a
[✔] Scanning '08 Photograph.m4a' ...
 100% [========================================================================]

Track: 08 Photograph.m4a
 Loudness:   -10.35 LUFS
 Range:       12.19 dB
 Peak:     1.058455 (0.49 dBTP)
 Gain:        -7.65 dB

Album:
 Loudness:   -10.35 LUFS
 Range:       12.19 dB
 Peak:     1.058455 (0.49 dBTP)
 Gain:        -7.65 dB
Matthiass-iMac:Downloads matthias$ 

I think there must be some difference between our installations, I suspect the FFmpeg version maybe? I got version 4.1.4 when brew installing it.

I strongly suggest doing a

brew update
brew upgrade
brew info ffmpeg

and of course brew doctor should also not complain about things.

Please come back with your results.

classicjazz commented 5 years ago

Yes (per my email), I am running FFMPEG head due to MPV dependencies. I will uninstall all dependencies and verify with FFMPEG's current release.

classicjazz commented 5 years ago

Confirmed, loudgain works with release FFMPEG but not the latest FFMPEG (4.2).

I suspect you are already on this issue based on the new release notes:

"Had to postpone this release because FFmpeg 4.2 breaks the old API (deprecated calls no longer working). Some rework needed before release."

Moonbase59 commented 5 years ago

Yes, exactly. We’ve been using "older" calls into the FFmpeg libraries that got deprecated in the meantime, and today FFmpeg 4.2 came out that broke the API … :-( Talking about "won’t make a problem" … hee hee. I’m currently investigating and rewriting the scanner code. The last FFmpeg version where the "old" calls worked was 4.1.4.

Working on it … :-)

Moonbase59 commented 5 years ago

You might want to try new loudgain v0.6.0. Should work using either manual build or brew install, with FFmpeg 4.1.4 as well as 4.2. Took me a while to iron this out.

N.B.: This version also installs the "rgbpm" script for mass-replaygaining. (No guarantees, though, as usual. Try everything but please have a backup.)

classicjazz commented 5 years ago

Confirmed that loudgain now works well with FFMPEG HEAD (4.2 as homebrew stable is still 4.1).

Also confirmed that rgbpm works for mass tagging. But still investigating why it says "Skipping BPM calculation ..."

classicjazz commented 5 years ago

rgbpm: No 'bpm-calc' found, BPM calculation will be skipped!

Moonbase59 commented 5 years ago

Easy explanation, hee hee: I wrote that script a LONG time ago for myself and some friends, using a conglomerate of obscure vamp plugins, scripts and the sonic-annotator from the Queen Mary University of London. Since I’m lazy and just planned to support one script, I just copied mine over ;-) … which of course doesnt’t find all that stuff. But if you have a good bpm calculator script, just name it bpm-calc and it can work like a "plug-in".

So it’s actually just a notice that it’ll only do the loudgaining.

Thanks for your testing!

Teteros commented 5 years ago

Sadly I've got the issue still with ffmpeg 4.2 (and ffmpeg 4.1.3 if I rollback) on Arch Linux

loudgain some.wav
[✔] Scanning 'some.wav' ...
[✔] Stream #0: PCM signed 16-bit little-endian
[✘] Could not open SWResample: Invalid argument
loudgain -version
loudgain 0.6.0 - using:
  libebur128 1.2.4
  libavformat 58.29.100
  libswresample 3.5.100
ffmpeg -version
ffmpeg version n4.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.1.0 (GCC)
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-
libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-l
ibmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libth
eora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enabl
e-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100
libpostproc    55.  5.100 / 55.  5.100

Anything else I can provide to help debug?

Teteros commented 5 years ago

Hm, actually it could be the .wav file because I've tried an mp3 (with static build to rule out my libs) and it worked:

./loudgain.static a.mp3
[✔] Scanning 'nq-bad_apple.mp3' ...
[✔] Stream #0: MP3 (MPEG audio layer 3)
 100% [===================================================================================================================================================================================]

Track: nq-bad_apple.mp3
 Loudness:    -9.56 LUFS
 Range:        3.35 dB
 Peak:     1.120602 (0.99 dBTP)
 Gain:        -8.44 dB

./loudgain.static some.wav
[✔] Scanning 'some.wav' ...
[✔] Stream #0: PCM signed 16-bit little-endian
[✘] Could not open SWResample: Invalid argument

Sorry for the noise :S

.5 second sample of the wav some.wav.zip

Moonbase59 commented 5 years ago

Yep, loudgain doesn’t (yet?) work on .wav files, sorry.

Moonbase59 commented 5 years ago

Try out v0.6.1. This version has some bugfixes regarding multi-channel files and can read almost anything, maybe this helps.

"Could not open SWResample: Invalid argument" shouldn’t happen anymore, except maybe with multi-channel files having very exotic channel configurations.

@Teteros: Don’t be disturbed by the -nan% [] showing up instead of a progress bar on your some.wavfile—this is just a cosmetic bug that can happen on ultra-short files.

Loudgain can still not tag WAV files, since there is no accepted standard that all players would recognise. Some ReplayGain tools add ID3v2 frames, others introduce non-standard entries in the RIFF chunks, but nothing is really compatible (except with itself).

My recommendation—if anyhow possible—would be to switch to a format like FLAC (or maybe ALAC if you’re on a Mac) which are also lossless, have smaller file sizes and can be tagged easily.

Moonbase59 commented 5 years ago

If you intend to do some further processing, there’s always the option to use loudgain’s -O output for that. Here is an example that would just show columns 1 (filename) and 9 (desired ReplayGain):

$ loudgain -O -k *.wav | awk -v FS='\t' '{print $1 ";" $9}'
[✔] Scanning 'some.wav' ...
[✔] Stream #0: PCM signed 16-bit little-endian, 16 bit, 44100 Hz, 1 ch, mono
[✔] Scanning 'Spiral Skies - Awakening.wav' ...
[✔] Stream #0: PCM signed 24-bit little-endian, 24 bit, 44100 Hz, 2 ch, stereo
[✔] Scanning 'Spiral Skies - Black Hole Waltz.wav' ...
[✔] Stream #0: PCM signed 24-bit little-endian, 24 bit, 44100 Hz, 2 ch, stereo
[✔] Scanning 'Spiral Skies - Danse Macabre.wav' ...
[✔] Stream #0: PCM signed 24-bit little-endian, 24 bit, 44100 Hz, 2 ch, stereo
[✔] Scanning 'Spiral Skies - Dark Side of the Cross.wav' ...
[✔] Stream #0: PCM signed 24-bit little-endian, 24 bit, 44100 Hz, 2 ch, stereo
[✔] Scanning 'Spiral Skies - Labyrinth of the Mind.wav' ...
[✔] Stream #0: PCM signed 24-bit little-endian, 24 bit, 44100 Hz, 2 ch, stereo
[✔] Scanning 'Spiral Skies - Left Is Right and Right Is Left Behind.wav' ...
[✔] Stream #0: PCM signed 24-bit little-endian, 24 bit, 44100 Hz, 2 ch, stereo
[✔] Scanning 'Spiral Skies - Shattered Hopes.wav' ...
[✔] Stream #0: PCM signed 24-bit little-endian, 24 bit, 44100 Hz, 2 ch, stereo
[✔] Scanning 'Spiral Skies - The Prisoner.wav' ...
[✔] Stream #0: PCM signed 24-bit little-endian, 24 bit, 44100 Hz, 2 ch, stereo
[✔] Scanning 'Spiral Skies - The Wizard's Ball.wav' ...
[✔] Stream #0: PCM signed 24-bit little-endian, 24 bit, 44100 Hz, 2 ch, stereo
File;Gain
some.wav;10.51 dB
Spiral Skies - Awakening.wav;-8.25 dB
Spiral Skies - Black Hole Waltz.wav;-5.15 dB
Spiral Skies - Danse Macabre.wav;-7.19 dB
Spiral Skies - Dark Side of the Cross.wav;-8.36 dB
Spiral Skies - Labyrinth of the Mind.wav;-7.79 dB
Spiral Skies - Left Is Right and Right Is Left Behind.wav;-8.15 dB
Spiral Skies - Shattered Hopes.wav;-8.51 dB
Spiral Skies - The Prisoner.wav;-8.21 dB
Spiral Skies - The Wizard's Ball.wav;-8.12 dB
Teteros commented 5 years ago

Loudgain can still not tag WAV files, since there is no accepted standard that all players would recognise. Some ReplayGain tools add ID3v2 frames, others introduce non-standard entries in the RIFF chunks, but nothing is really compatible (except with itself).

@Moonbase59 BWF (Broadcast Wave Format) extension to WAV version 2 supports loudness tags (LoudnessValue LoudnessRange MaxTruePeakLevel MaxMomentaryLoudness MaxShortTermLoudness) and it's read/output by DAWs so it might be worth looking into https://tech.ebu.ch/docs/tech/tech3285.pdf

r128gain which is another ffmpeg based normalizer supports it

classicjazz commented 5 years ago

As Matthias suggests, converting your WAV files to FLAC or ALAC is win-win. You save disk space. There is little computational overhead. You don't lose quality because both are lossless compression methods. And you also gain standardized tag support.

Moonbase59 commented 5 years ago

You’re both right, @Teteros and @classicjazz: For the "normal" user, FLAC/ALAC would be the way to go, but in real production and broadcasting WAV is still very much (if not mostly) used. I wasn’t aware of Tech 3285 which would actually be nice to implement, I agree. Even more interesting since we have all the values (M,S,I) internally.

Unfortunately, the TagLib library I use only supports ID3 (no, no!) and at max. the RIFF 'LIST' 'INFO' chunk (and not the 'bext' chunk which we need). It won’t be possible for me in the near future to write and debug a lot of TagLib subclasses to handle all that, but you might want to file an issue at upstream TagLib to make it known this feature is needed in the professional area. (I found out that even Tascams use the BWF data!)

If you can get the colleagues at TagLib to support it, I promise to implement it. ;-)

Moonbase59 commented 5 years ago

Please also support issue #479 in libsndfile — thanks! I might end up using libsndfile for WAV (BWF) tagging.

Moonbase59 commented 5 years ago

@Teteros: You might want to experiment with v0.6.5 of loudgain, which adds rudimentary WAV support (by writing ID3v2 data into the "ID3 " chunk, for now ignoring the "bext" chunk). I don’t much like this kind of tagging, but it is compatible with foobar2000, VLC, Mp3tag and some others.

Please have a backup before testing, and read How I handle WAV (.wav) audio files.