0

I know you can use FFmpeg to extract the album art of an mp3 file. I also know you can combine an image and audio file to create a video. But, to my surprise, I cannot figure out nor find a way to do this in one step. Has anyone ever figured this out or is it really impossible?

What might be useful is FFmpeg does demux the album art, but it does not show up as video frames. E.g.

ffmpeg -i 1.mp3 out.mp4

results in

Input #0, mp3, from '1.mp3':
  Metadata:
    artist          : Dazzled Sticks
    TST             : Dazzled Sticks - Let's Dans (Martijn Groeneveld Mashup)
    genre           : Hiphop/Rap
    title           : Dazzled Sticks - Let's Dans (Martijn Groeneveld Mashup)
    date            : 2016
  Duration: 00:02:46.84, start: 0.025056, bitrate: 154 kb/s
    Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
    Metadata:
      encoder         : Lavc56.26
    Stream #0:1: Video: png, rgb24(pc), 1800x1800 [SAR 11811:11811 DAR 1:1], 90k
 tbr, 90k tbn, 90k tbc
    Metadata:
      comment         : Other
    Stream #0:2: Video: png, rgb24(pc), 1800x1800 [SAR 11811:11811 DAR 1:1], 90k
 tbr, 90k tbn, 90k tbc
    Metadata:
      comment         : Other
4
  • What's your album art extraction command? Is it a regular stream or a binary tag packet?
    – Gyan
    Dec 11, 2017 at 13:23
  • I don't understand your question. As we are discussing mp3 files, the art would need to come from its ID3 tag. Is there any other form of embedding album art these days? Dec 11, 2017 at 14:03
  • Sorry, been a long time since I dealt with MP3 metadata. With some formats, ffmpeg demuxes the cover images as a distinct stream and with others, as a tag blob i.e. -map won't apply.
    – Gyan
    Dec 11, 2017 at 14:05
  • I added some more details related to this in the original Q. Dec 11, 2017 at 14:15

2 Answers 2

1

Basic command syntax would be

ffmpeg -i in.mp3 -filter_complex "color[c];[c][0]scale2ref[c][art];[c][art]overlay" -shortest out.mp4
6
  • This does not work, the error I get is "image: No such file or directory". Frankly I don't understand this command at all although I think I understand what you are trying to do. But why first.png and second.png? Dec 11, 2017 at 14:50
  • It's a template command. You have to replace image and audio with the names/paths of the image and audio you want to process. first and second.png are the names I've put for the extracted album art. I see two in the input properties you have added in your command. This command generates three outputs. The first is the video, and the next two, the extracted images.
    – Gyan
    Dec 11, 2017 at 15:20
  • I don't want to add images, I want to use the embedded image (the album art, see my Q). Dec 11, 2017 at 15:28
  • Ah, now I see. I think your Q should be reworded, maybe "How to create a regular video from a MP3 using its cover art as the video input?" - I didn't see your new title - only reread the body.
    – Gyan
    Dec 11, 2017 at 16:09
  • 1
    edited command.
    – Gyan
    Dec 11, 2017 at 17:28
2

I know that you were trying to find a way to do this in a single step. However, for those who stumble across this question, it's much easier to chain two ffmpeg commands like so:

ffmpeg -i in.mp3 -an out.png && ffmpeg -loop 1 -i out.png -i in.mp3 -c:a aac -ab 256k -c:v libx264 -pix_fmt yuv420p -shortest -strict -2 out.mp4

Note that this reencodes the mp3, as it's not a supported codec in mp4 containers.

1
  • MP3 is supported in MP4 by the file format standard but not by many players.
    – Gyan
    Oct 4, 2019 at 4:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.