quodlibet / mutagen

Python module for handling audio metadata
https://mutagen.readthedocs.io
GNU General Public License v2.0
1.53k stars 158 forks source link

`beet convert` failing to export tags for AAC #535

Closed purew closed 3 years ago

purew commented 3 years ago

I'm trying to export aac files from my source flac music. Problem is that I seem to lose the metadata tags in the process:

I'm seeing a crypticerror reading song.aac: b'song.aac': of mutagen type AAC error message:

beet convert output

$ beet convert letar
Maxida Märak - Utopi - Letar lite ljus här
Convert? (Y/n) 
convert: Encoding /home/anders/Music/flac/Maxida Märak/2019 Utopi/01 Letar lite ljus här.flac
convert: Finished encoding /home/anders/Music/flac/Maxida Märak/2019 Utopi/01 Letar lite ljus här.flac
error reading /home/anders/Music/aac/Maxida Märak/2019 Utopi/01 Letar lite ljus här.aac: b'/home/anders/Music/aac/Maxida M\xc3\xa4rak/2019 Utopi/01 Letar lite ljus h\xc3\xa4r.aac': of mutagen type AAC

# AAC file is exported, but there are no tags
$ ls -hl
total 3.1M
-rw-r--r-- 1 anders anders 3.1M Aug 17 19:53 '01 Letar lite ljus här.aac'

beet-config

convert:
    format: aac
    formats:
      aac:
        #command: ffmpeg -i $source -y -vn -acodec aac -aq 1 $dest
        command: ffmpeg -i $source -c:v copy -c:a libfdk_aac -vbr 5 $dest
    dest: ~/Music/aac/
    copy_album_art: yes

plugins: embedart fetchart lastgenre convert

Version

beet version
beets version 1.5.0
Python version 3.9.6
plugins: convert, embedart, fetchart, lastgenre
purew commented 3 years ago

Some additional information: Using the beet convert --pretend I got the underlying ffmpeg command and ran it manually like so:

$ ffmpeg -i /home/anders/Music/flac/Maxida\ Märak/2019\ Utopi/01\ Letar\ lite\ ljus\ här.flac -c:v copy -c:a libfdk_aac -vbr 5 /tmp/01\ Letar\ lite\ ljus\ här.aac            
ffmpeg version n4.4 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11.1.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --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-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librav1e --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-openssl --enable-shared --enable-version3 --enable-libfdk_aac --enable-nonfree
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, flac, from '/home/anders/Music/flac/Maxida Märak/2019 Utopi/01 Letar lite ljus här.flac':
  Metadata:
    ALBUM           : Utopi
    TITLE           : Letar lite ljus här
    track           : 1
    TRACKTOTAL      : 10
    disc            : 1
    DISCTOTAL       : 1
    DATE            : 2019
    COPYRIGHT       : 2019 Playground Music Scandinavia AB
    GENRE           : Rap - Hip Hop
    album_artist    : Maxida Märak
    ARTIST          : Maxida Märak
    comment         : Interprètes : Copyright Control, MusicPublisher
                    : Anton Axélo, Composer, Producer, Arranger, Programming
                    : Maxida Märak, Lyricist, Arranger, Backing Vocals, Lead Vocals, Artist, MainArtist
                    : Jonathan Ojeda, Mixer, Mastering Engineer, Sound Engineer 
                    : Label : ...
  Duration: 00:03:58.88, start: 0.000000, bitrate: 968 kb/s
  Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
  Stream #0:1: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 600x600 [SAR 1:1 DAR 1:1], 90k tbr, 90k tbn, 90k tbc (attached pic)
    Metadata:
      comment         : Cover (front)
      title           : Utopi
Stream mapping:
  Stream #0:0 -> #0:0 (flac (native) -> aac (libfdk_aac))
Press [q] to stop, [?] for help
[libfdk_aac @ 0x55d8601d3980] Note, the VBR setting is unsupported and only works with some parameter combinations
Output #0, adts, to '/tmp/01 Letar lite ljus här.aac':
  Metadata:
    ALBUM           : Utopi
    TITLE           : Letar lite ljus här
    track           : 1
    TRACKTOTAL      : 10
    disc            : 1
    DISCTOTAL       : 1
    DATE            : 2019
    COPYRIGHT       : 2019 Playground Music Scandinavia AB
    GENRE           : Rap - Hip Hop
    album_artist    : Maxida Märak
    ARTIST          : Maxida Märak
    comment         : Interprètes : Copyright Control, MusicPublisher
                    : Anton Axélo, Composer, Producer, Arranger, Programming
                    : Maxida Märak, Lyricist, Arranger, Backing Vocals, Lead Vocals, Artist, MainArtist
                    : Jonathan Ojeda, Mixer, Mastering Engineer, Sound Engineer 
                    : Label : ...
    encoder         : Lavf58.76.100
  Stream #0:0: Audio: aac, 44100 Hz, stereo, s16
    Metadata:
      encoder         : Lavc58.134.100 libfdk_aac
size=    6548kB time=00:03:58.86 bitrate= 224.6kbits/s speed=43.2x    
video:0kB audio:6548kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%

The metadata is visible in the output above, but the generated .aac file is empty of metadata.

purew commented 3 years ago

Ok, I believe I solved it. I think the .aac file cannot store metadata? I instead changed to the container format .m4a with the following config:

convert:
    format: m4a
    formats:
      m4a:
        command: ffmpeg -i $source -c:v copy -c:a libfdk_aac -vbr 5 $dest

which seems to result in AAC data + metadata inside.

phw commented 3 years ago

Your solution is what I'd have recommended. An .aac file is basically really just the ASC encoded audio with some very minimal header. There is no metadata support. Some software supports reading and/or writing APE tags (e.g. foobar2000, Picard) or ID3 tags, but that's not widely supported and causes some issues in software not supporting it. The metadata is then usually interpreted as part of the audio, which leads to issues like wrongly reported playback duration and playback errors.

purew commented 3 years ago

Do you think it would be meaningful to throw an error on invalid configurations?

In my case I had set copy_album_art: yes which realistically should not work on the aac output?

I'm trying to think of a more userfriendly error than error reading song.aac: b'song.aac': of mutagen type AAC which led me down the rabbithole :)

sampsyo commented 3 years ago

Hi, @PureW—that would be a question for the beets project, not Mutagen! If you'd like to discuss a better error message, may I suggest opening a Discussions thread to brainstorm what that might look like?

purew commented 3 years ago

Woops, I'm so sorry. I thought I was in the beets project. I blame being jetlagged :facepalm: