nathom / streamrip

A scriptable music downloader for Qobuz, Tidal, SoundCloud, and Deezer
GNU General Public License v3.0
2.35k stars 209 forks source link

[BUG] Bit depth issues when converting to FLAC/ALAC #615

Open disconnect78 opened 5 months ago

disconnect78 commented 5 months ago

Describe the bug

Converting a file to ALAC and FLAC can fail depending on the bit_depth setting (this may happen for other codecs too but these are the only two I checked).

If bit_depth is set to 24 then converting to FLAC will fail as streamrip passes -sample_fmt s32p to ffmpeg, but the version I'm using (6.1.1) doesn't support s32p for FLAC files. Amending convert.py to pass s32 instead will result in successful conversion.

Similarly, if bit_depth is set to 16 then converting to ALAC will fail as streamrip passes -sample_fmt s16 to ffmpeg, but it doesn't support s16 for ALAC files. Amending convert.py to pass s16p instead will again result in successful conversion.

In other words, I need to pass s16 or s32 to ffmpeg for FLAC files; and s16p or s32p to ffmpeg for ALAC files. (I don't know if this is an issue with the version of ffmpeg I'm using or if it's down to the codecs.)

Command Used

rip url https://www.qobuz.com/gb-en/album/crypt-of-ancestral-knowledge-ep-wolves-in-the-throne-room/rcm3qga8o1eab

Debug Traceback

...
│ /Users/xxxxxxxxxxx/.pyenv/versions/3.11.6/lib/python3.11/site-packages/streamrip/conve │
│ rter.py:100 in convert                                                                 │
│                                                                                        │
│    97 │   │   │   shutil.move(self.tempfile, self.final_fn)                            │
│    98 │   │   │   logger.debug("Moved: %s -> %s", self.tempfile, self.final_fn)        │
│    99 │   │   else:                                                                    │
│ ❱ 100 │   │   │   raise ConversionError(f"FFmpeg output:\n{out, err}")                 │
│   101 │                                                                                │
│   102 │   def _gen_command(self):                                                      │
│   103 │   │   command = [                                                              │
│                                                                                        │
│ ╭────────────────────────────────────── locals ──────────────────────────────────────╮ │
│ │ custom_fn = None                                                                   │ │
│ │       err = b'ffmpeg version 6.1.1 Copyright (c) 2000-2023 the FFmpeg developers\n │ │
│ │             built with '+3127                                                      │ │
│ │       out = None                                                                   │ │
│ │   process = <Process 34935>                                                        │ │
│ │      self = <streamrip.converter.FLAC object at 0x105924090>                       │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────╯ │
╰────────────────────────────────────────────────────────────────────────────────────────╯
ConversionError: FFmpeg output:
(None, b"ffmpeg version 6.1.1 Copyright (c) 2000-2023 the FFmpeg developers\n  built with 
Apple clang version 15.0.0 (clang-1500.1.0.2.5)\n  configuration: 
--prefix=/opt/homebrew/Cellar/ffmpeg/6.1.1_2 --enable-shared --enable-pthreads 
--enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' 
--enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 
--enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl 
--enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist 
--enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh 
--enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab 
--enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 
--enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig 
--enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb 
--enable-libopencore-amrwb --enable-libopenjpeg --enable-libopenvino --enable-libspeex 
--enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack 
--enable-videotoolbox --enable-audiotoolbox --enable-neon\n  libavutil      58. 29.100 / 
58. 29.100\n  libavcodec     60. 31.102 / 60. 31.102\n  libavformat    60. 16.100 / 60. 
16.100\n  libavdevice    60.  3.100 / 60.  3.100\n  libavfilter     9. 12.100 /  9. 
12.100\n  libswscale      7.  5.100 /  7.  5.100\n  libswresample   4. 12.100 /  4. 
12.100\n  libpostproc    57.  3.100 / 57.  3.100\nInput #0, flac, from './Wolves In The 
Throne Room - Crypt of Ancestral Knowledge - EP (2023) [FLAC] [24B-96kHz] [221270337]/4. 
Wolves In The Throne Room - Crown of Stone.flac':\n  Metadata:\n    TITLE           : 
Crown of Stone\n    ARTIST          : Wolves In The Throne Room\n    ALBUM           : 
Crypt of Ancestral Knowledge - EP\n    album_artist    : Wolves In The Throne Room\n    
COMPOSER        : Aaron Weaver\n    YEAR            : 2023\n    GENRE           : Rock, 
Metal, Pop\n    COPYRIGHT       : \xe2\x84\x97 2023 Century Media Records Ltd.\n    track 
: 04\n    disc            : 01\n    TRACKTOTAL      : 04\n    DISCTOTAL       : 01\n    
DATE            : 2023-09-29\n    ISRC            : US2642355004\n  Duration: 00:03:17.76,
start: 0.000000, bitrate: 3033 kb/s\n  Stream #0:0: Audio: flac, 96000 Hz, stereo, s32 (24
bit)\n  Stream #0:1: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 
600x600 [SAR 300:300 DAR 1:1], 90k tbr, 90k tbn (attached pic)\n    Metadata:\n      
comment         : Cover (front)\nStream mapping:\n  Stream #0:1 -> #0:0 (copy)\n  Stream 
#0:0 -> #0:1 (flac (native) -> flac (native))\nPress [q] to stop, [?] for help\n[flac @ 
0x15562b740] Specified sample format s32p is not supported by the flac encoder\n[flac @ 
0x15562b740] Supported sample formats:\n[flac @ 0x15562b740]   s16\n[flac @ 0x15562b740]  
s32\n[aost#0:1/flac @ 0x155713110] Error while opening encoder - maybe incorrect 
parameters such as bit_rate, rate, width or height.\nError while filtering: Invalid 
argument\n[out#0/flac @ 0x15570fbe0] Nothing was written into output file, because at 
least one of its streams received no packets.\nsize=       0kB time=00:00:00.00 
bitrate=N/A speed=   0x    \nConversion failed!\n")

Config File

...
# Convert tracks to a codec after downloading them.
[conversion]
enabled = true
# FLAC, ALAC, OPUS, MP3, VORBIS, or AAC
codec = "FLAC"
# In Hz. Tracks are downsampled if their sampling rate is greater than this. 
# Value of 48000 is recommended to maximize quality and minimize space
sampling_rate = 48000
# Only 16 and 24 are available. It is only applied when the bit depth is higher
# than this value.
bit_depth = 24
# Only applicable for lossy codecs
lossy_bitrate = 320
...

Operating System

macOS

streamrip version

2.0.5

Screenshots and recordings

No response

Additional context

No response