FFmpeg: Convert FLAC to mp3 and add album art in one step
Asked Answered
S

2

1

I convert FLAC to MP3 using

ffmpeg -i x.flac -f mp3 -vn -b:a 64K x.mp3

and I add album art using

ffmpeg -i x.mp3 -i x.jpg -map 0:0 -map 1:0 -c copy -id3v2_version 3 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (Front)" xx.mp3

Is it possible to do it in one step? Because I want to do it during "live" transcoding.

Scathe answered 19/7, 2014 at 13:5 Comment(1)
Thanks to konsolebox for his answer. See this post.Musing
F
1

You can use a pipe instead of using a temporary file. You just have to explicitly specify the format of input/output. Example:

ffmpeg -i input.mp3 -f mp3 - | ffmpeg -f mp3 -i - -y output.mp3

Probably your version would be:

ffmpeg -i x.flac -f mp3 -vn -b:a 64K x.mp3 - | ffmpeg -f mp3 -i - -i x.jpg -map 0:0 -map 1:0 -c copy -id3v2_version 3 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (Front)" xx.mp3

That is if you really can't do:

ffmpeg -i x.flac -i x.jpg -map 0:0 -map 1:0 -c copy -id3v2_version 3 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (Front)" -f mp3 -vn -b:a 64K xx.mp3
  • -y makes ffmpeg overwrite output file by default.
Fawcett answered 19/7, 2014 at 13:17 Comment(3)
I want to avoid piping because currently I use a tcp socket to get the transcoded file.Scathe
So I tried your 3rd proposal (without pipe). But I get 2 errors :[mp3 @ 029adc40] Invalid audio stream. Exactly one MP3 audio stream is required. Could not write header for output file #0 (incorrect codec parameters ?): Error number -22 occurred –Scathe
This is the way it works : ffmpeg -i x.flac -i x.jpg -map 0:0 -map 1:0 -id3v2_version 3 -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (Front)" -f mp3 -b:a 64K xx.mp3Scathe
G
1

As of ffmpeg 4.1.4 (I list the compilation flags below)

ffmpeg -i file.flac b:a 320k file.mp3

results in a high bitrate mp3 that keeps the original cover art and tags.

Some commenter argued VBR are transparent enough and save bitrate. Yes they are but I experienced seeking problems with them in some smartphone/hardware players.

built with gcc 8 (Debian 8.3.0-6) configuration: --prefix=/usr --extra-version=1mx19+1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared

Griggs answered 30/12, 2019 at 20:23 Comment(1)
I needed to use -b:a instead of just b:a. Other than that this worked great for me to convert all flac files within a folder to mp3, when combined with the recursive conversion method described at the Arch Wiki. Final command: fd -t f -e flac -x ffmpeg -i "{}" -b:a 320k "{.}.mp3". Album art was preserved along with metadata.Lor

© 2022 - 2024 — McMap. All rights reserved.