3

Everytime I encode my songs to lossy formats, the output file keeps the tags (title, artist, album, etc...), but drops the album art.

I tried to encode to any lossy format, including AAC, OGG and OPUS. They all drop the album art... except MP3.

I've figured out that I can't encode my songs to M4A and OGG formats, unless I add -vn flag, which removes the album art. So instead of M4A and OGG, i tried any other container, including .aac, .oga, .mka. But they all drop the album art too.

What I've tried:

ffmpeg -y -i "/storage/sdcard1/Music/01 Adam Foroush.m4a" -c:a libopus -b:a 128k -af aresample=48000:resampler=soxr:precision=33:cheby=1:dither_method=shibata -vbr on -compression_level 10 -frame_duration 60 -application audio "/storage/emulated/0/FFMPEG/01 Adam Foroush.opus"

Things gets more weird when I use opus-tools (to encode to OPUS) and used vorbis-tools (to encode to OGG). Unlike FFmpeg, they both gave me output files that retained the album art. But I don't like to use them since they both have poor input decoding support.

And about FFmpeg, I know I can encode my songs to OPUS, OGG or AAC, and then in the next step, embed the album art in them, but that's not a good solution.

Anyone? Any help?

slhck
  • 223,558
  • 70
  • 607
  • 592
  • Are you specifying `attached_pic`? – harrymc Jun 19 '19 at 10:08
  • Share your full command. – Gyan Jun 19 '19 at 10:15
  • 1
    @harrymc does it embed the pic that i use as the second input? nah, that's not the solution that i'm looking for... see, i can use any TagEditor app and embed a picture into my songs. But it's an "extra step". I don't like it. I wan't FFmpeg to keep the album art when i encode my songs to m4a (aac), ogg, and opus. That's all i want! – آرنولد پفکی Jun 19 '19 at 10:16
  • ffmpeg -y -i "/storage/sdcard1/Music/01 Adam Foroush.m4a" -c:a libopus -b:a 128k -af aresample=48000:resampler=soxr:precision=33:cheby=1:dither_method=shibata -vbr on -compression_level 10 -frame_duration 60 -application audio "/storage/emulated/0/FFMPEG/01 Adam Foroush.opus" – آرنولد پفکی Jun 19 '19 at 10:20
  • forgot to say that i'm using FFmpeg v4.1.3, which is the latest version. – آرنولد پفکی Jun 19 '19 at 10:53
  • Ideally, please share the whole command's log output by [edit]ing your question. – slhck Jun 19 '19 at 11:59
  • same issue here. no solution yet. but converting from mp3 to opus 16k makes music awesomely small!! – cregox May 11 '21 at 16:34
  • similar issue https://superuser.com/a/706808/28411 – cregox May 13 '21 at 10:42

2 Answers2

1

I faced this problem too, the answer is very easy, just pass -c:v copy and that's all. FFMpeg tries to encode any video to h264 format by default, but audio containers not supporting this, so we should copy .jpg cover without encoding. And please, do not covert lossy format to other lossy, use lossless as source

megapro17
  • 113
  • 5
0

FFmpeg version 4.4 automatically supports embedding album art into Ogg containers with the Theora video codec (see "Ogg codecs" on Wikipedia for a list of supported codecs, although they may not all be supported by FFmpeg).

Here's an example converting an MP3 file with a video track containing album art to an Ogg file with Opus encoded audio and Theora encoded video:

$ ffprobe -hide_banner '01 - State of Grace.mp3' 
[mp3 @ 0x5594cbafe320] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from '01 - State of Grace.mp3':
  Metadata:
    lyrics-eng      :  
    copyright       : š 2012 Big Machine Records, LLC.
    title           : State of Grace
    album_artist    : Taylor Swift
    album           : Red (Deluxe Version)
    date            : 2012
    track           : 01/22
    genre           : Country
    composer        : Taylor Swift
    disc            : 1/1
    comment         : Taylor Swift
  Duration: 00:04:55.81, start: 0.000000, bitrate: 321 kb/s
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 320 kb/s
  Stream #0:1: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 600x600 [SAR 72:72 DAR 1:1], 90k tbr, 90k tbn, 90k tbc (attached pic)
    Metadata:
      title           : Cover
      comment         : Cover (front)
$ ffmpeg -hide_banner -i '01 - State of Grace.mp3' -c:a libopus -b:a 128000 -c:v libtheora -q:v 10 '01 - State of Grace.ogg'
[mp3 @ 0x55ebe6d3cc40] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from '01 - State of Grace.mp3':
  Metadata:
    lyrics-eng      :  
    copyright       : š 2012 Big Machine Records, LLC.
    title           : State of Grace
    album_artist    : Taylor Swift
    album           : Red (Deluxe Version)
    date            : 2012
    track           : 01/22
    genre           : Country
    composer        : Taylor Swift
    disc            : 1/1
    comment         : Taylor Swift
  Duration: 00:04:55.81, start: 0.000000, bitrate: 321 kb/s
  Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 320 kb/s
  Stream #0:1: Video: mjpeg (Baseline), yuvj444p(pc, bt470bg/unknown/unknown), 600x600 [SAR 72:72 DAR 1:1], 90k tbr, 90k tbn, 90k tbc (attached pic)
    Metadata:
      title           : Cover
      comment         : Cover (front)
Stream mapping:
  Stream #0:1 -> #0:0 (mjpeg (native) -> theora (libtheora))
  Stream #0:0 -> #0:1 (mp3 (mp3float) -> opus (libopus))
Press [q] to stop, [?] for help
[swscaler @ 0x55ebe6db69e0] deprecated pixel format used, make sure you did set range correctly
[ogg @ 0x55ebe6d44c80] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2
Output #0, ogg, to '01 - State of Grace.ogg':
  Metadata:
    lyrics-eng      :  
    copyright       : š 2012 Big Machine Records, LLC.
    title           : State of Grace
    album_artist    : Taylor Swift
    album           : Red (Deluxe Version)
    date            : 2012
    track           : 01/22
    genre           : Country
    composer        : Taylor Swift
    disc            : 1/1
    comment         : Taylor Swift
    encoder         : Lavf58.76.100
  Stream #0:0: Video: theora, yuv444p(tv, bt470bg/unknown/unknown, progressive), 600x600 [SAR 1:1 DAR 1:1], q=2-31, 200 kb/s, 90k fps, 90k tbn (attached pic)
    Metadata:
      title           : Cover
      DESCRIPTION     : Cover (front)
      encoder         : Lavc58.134.100 libtheora
      lyrics-eng      :  
      copyright       : š 2012 Big Machine Records, LLC.
      ALBUMARTIST     : Taylor Swift
      album           : Red (Deluxe Version)
      date            : 2012
      TRACKNUMBER     : 01/22
      genre           : Country
      composer        : Taylor Swift
      DISCNUMBER      : 1/1
  Stream #0:1: Audio: opus, 48000 Hz, stereo, flt, 128 kb/s
    Metadata:
      encoder         : Lavc58.134.100 libopus
      lyrics-eng      :  
      copyright       : š 2012 Big Machine Records, LLC.
      title           : State of Grace
      ALBUMARTIST     : Taylor Swift
      album           : Red (Deluxe Version)
      date            : 2012
      TRACKNUMBER     : 01/22
      genre           : Country
      composer        : Taylor Swift
      DISCNUMBER      : 1/1
      DESCRIPTION     : Taylor Swift
[mp3float @ 0x55ebe6d96360] Header missing time=00:04:31.63 bitrate=   0.1kbits/s speed=59.8x    64x    
Error while decoding stream #0:0: Invalid data found when processing input
frame=    1 fps=0.2 q=-0.0 Lsize=    4929kB time=00:04:55.79 bitrate= 136.5kbits/s speed=59.8x    
video:58kB audio:4830kB subtitle:0kB other streams:0kB global headers:3kB muxing overhead: 0.845459%
$ mpv '01 - State of Grace.ogg'
 (+) Video --vid=1 'Cover' (theora 600x600)
 (+) Audio --aid=1 'State of Grace' (opus 2ch 48000Hz)
AO: [alsa] 48000Hz stereo 2ch float
VO: [gpu] 600x600 yuv444p
(Paused) AV: -00:00:00 / 00:04:55 (0%)

Exiting... (Quit)
$ 

I wrote a more detailed answer about how to do this here: https://stackoverflow.com/a/70166081/17549713

  • Welcome to Super User! Please do not post the same answer to multiple questions. If the same information really answers both questions, then one question (usually the newer one) should be closed as a duplicate of the other. You can indicate this by [voting to close it as a duplicate](https://superuser.com/help/privileges/close-questions) or, if you don't have enough reputation for that, [raise a flag](https://superuser.com/help/privileges/flag-posts) to indicate that it's a duplicate. Otherwise tailor your answer to this question and don't just paste the same answer in multiple places. – DavidPostill Nov 30 '21 at 12:48
  • I cannot flag any answer other than my own. The "Flag" button does not appear. In any case, they're not strictly duplicates and it's hard to say which should be closed. My answer is relevant to both and may be considered a sufficient workaround, but one deals with embedding album art images as tags and another with using FFmpeg directly. These answers were intended to be comments, but I didn't have enough reputation at the time and my answer-as-a-comment stating this was deleted for being a link only answer. But the rules are beside the point, I'm just trying to inform people of the options. – user17549713 Nov 30 '21 at 23:29