I'm trying to use FFmpeg to convert all of the .flac's in my music library to .mp3's while maintaining the metadata and directory structure of the original files. I've got everything working so far except for maintaining the directory structure.
So far I have:
@echo off
rem Copies the original directory structure from F:\Music to D:\Music
xcopy /T %1 %2
rem Recursively converts files with .flac extension from F:\Music to .mp3 in D:\Music
for /R %1 %%i in (*.flac) do (
echo Currently converting "%%~nxi"
ffmpeg -v quiet -i "%%i" -q:a 0 -map_metadata 0 -id3v2_version 3 -write_id3v1 1 "%2\%%~ni.mp3"
)
echo Completed.
pause
I feel like my issue is coming from having my FFmpeg output as "%2\%%~ni.mp3"
, however I can't get it to maintain the original directory structure. I have played around with dpni as options for the output, but then it does not convert correctly.
The .bat is being executed from the command line as convert F:\Music D:\Music
All music in the original directory has the structure F:\Music\Artist Name\Album Name\Song.flac and I want it to end up as D:\Music\Artist Name\Album Name\Song.mp3.
Alternatively, is there a way to convert the .flac to an .mp3 within the same directory as the source file and then delete the flac?
When the for /R recurses into subflders the original %2 doesn't include these subfolder names, so try:
ffmpeg -v quiet -i "%%~fi" -q:a 0 -map_metadata 0 -id3v2_version 3 -write_id3v1 1 "%~d2%%~pni.mp3"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With