audiovideoffmpegbatch-processingalbumart

FFmpeg: Batch convert all audio (mp3) in folder to video (mp4) with album artwork


I'm looking to batch convert all audio (mp3) in folder to video (mp4) with album artwork. This for uploading audios to youtube. I have pretty much a working code but I want to automate the whole thing.

Here's the code from .bat file I'm using.

(source:FFMpeg Batch Image + Multiple Audio to video)

echo off
for %%a in ("*.mp3") do "C:\ffmpeg\bin\ffmpeg" -loop 1 -i  "C:\ffmpeg\bin\input.jpg.jpg" -i "%%a" -c:v libx264 -preset veryslow -tune stillimage -crf 18 -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 192k -shortest "C:\mp4\%%~na.mp4"
pause

This works great except I have to manually put the album art each time. I want ffmpeg to automatically extract the album art from each audio file and then convert it to video in batch.

This is the code for extracting album art from .mp3 files

ffmpeg -i input.mp3 -an -vcodec copy cover.jpg

Thanks.


Solution

  • I've figured it out. Thanks to @L. Scott Johnson for the help.

    Here's the code

    echo off
    for %%a in ("*.mp3") do (
      "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -an -y -vcodec copy "E:\songgs\%%~na.jpg"
      "C:\ffmpeg\bin\ffmpeg.exe" -loop 1 -i  "E:\songs\%%~na.jpg" -i "%%a" -y -c:v libx264 -preset veryslow -tune stillimage -crf 18 -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 192k -shortest "E:\songs\%%~na.mp4" )
    pause
    

    This is the basic version of the code.

    You can edit many things from the code.

    For example you can add subtitles for synchronized lyrics with this code

    -vf "subtitles=%%~na.srt"

    Resize the cover with this code

    -vf "scale=1500:1500"

    And if you want to both of them together just add them with comma (,) Like this:

    -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2,subtitles=%%~na.srt"

    you can also change the encoder to Nvidia NVENC for faster encoding...

    And many more.. you get the idea.

    Again, thanks to @L. Scott Johnson for helping me with this code. Feel free to ask any question and I'll try to help. I'm just learning this, as my user name says, I'm a noob :)