Embed Cover Art in M4A and FLAC with FFmpeg
Adding album artwork to your digital music library helps organize and visually identify your tracks in media players. This guide provides a straightforward tutorial on how to use FFmpeg, a powerful command-line tool, to embed cover art images (such as JPEG or PNG) directly into M4A and FLAC audio files without re-encoding the audio.
How to Embed Cover Art in M4A Files
M4A files (which use the MP4 container) store cover art as a video stream marked as an attached picture.
To merge your M4A audio file and cover image, use the following command:
ffmpeg -i input.m4a -i cover.jpg -map 0:a -map 1:v -c copy -disposition:v attached_pic output.m4aCommand Breakdown:
-i input.m4a: Specifies the input audio file.-i cover.jpg: Specifies the input image file (JPEG or PNG).-map 0:a: Selects the audio stream from the first input (the M4A file).-map 1:v: Selects the video/image stream from the second input (the image file).-c copy: Copies both the audio and image data directly without re-encoding, ensuring zero quality loss and near-instant processing.-disposition:v attached_pic: Defines the video stream (the image) as an attached picture, which media players recognize as album artwork.
How to Embed Cover Art in FLAC Files
FLAC files handle metadata differently than MP4 containers, but FFmpeg uses a very similar command structure to embed artwork as a FLAC picture block.
To add artwork to a FLAC file, run this command:
ffmpeg -i input.flac -i cover.jpg -map 0:a -map 1:v -c copy -disposition:v attached_pic output.flacCommand Breakdown:
-i input.flac: Specifies your lossless FLAC input.-i cover.jpg: Specifies your cover image.-map 0:a -map 1:v: Maps the FLAC audio and the cover image stream.-c copy: Copies the streams stream-for-stream to prevent generation loss.-disposition:v attached_pic: Tells FFmpeg to write the image into the FLAC metadata block as the front cover.
Batch Processing Multiple Files (Optional)
If you have a folder of files and want to apply the same cover art
(cover.jpg) to all of them, you can use a simple
command-line loop.
For Windows (Command Prompt):
for %i in (*.mp3 *.m4a *.flac) do ffmpeg -i "%i" -i cover.jpg -map 0:a -map 1:v -c copy -disposition:v attached_pic "tagged_%i"For Linux / macOS (Terminal):
for f in *.flac; do ffmpeg -i "$f" -i cover.jpg -map 0:a -map 1:v -c copy -disposition:v attached_pic "tagged_$f"; done