HWZ Forums

Login Register FAQ Mark Forums Read

Batch mp3 to mp4 recursive

Like Tree2Likes
  • 1 Post By davidktw
  • 1 Post By davidktw
Reply
 
LinkBack Thread Tools
Old 02-01-2021, 03:31 PM   #1
Arch-Supremacy Member
 
yusoffb01's Avatar
 
Join Date: Jun 2008
Posts: 12,840
Batch mp3 to mp4 recursive

Currently I use this script to convert mp3 inside mp3 folder into mp4 with album art
echo off for %%a in ("*.mp3") do ( "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -an -y -vcodec copy "E:\songs\mp3\%%~na.jpg" "C:\ffmpeg\bin\ffmpeg.exe" -loop 1 -i "E:\songs\mp3\%%~na.jpg" -i "%%a" -y -c:v libx264 -preset veryfast -tune stillimage -crf 50 -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 128k -shortest "E:\songs\mp3\%%~na.mp4" ) pause
How do I change it so it can recursively process subfolders too?
__________________
There will be a time when gold can be found on Euphrates(river in iraq) and people will kill for it
yusoffb01 is offline   Reply With Quote
Old 03-01-2021, 12:45 AM   #2
Arch-Supremacy Member
 
davidktw's Avatar
 
Join Date: Apr 2010
Posts: 10,990
Currently I use this script to convert mp3 inside mp3 folder into mp4 with album art
echo off for %%a in ("*.mp3") do ( "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -an -y -vcodec copy "E:\songs\mp3\%%~na.jpg" "C:\ffmpeg\bin\ffmpeg.exe" -loop 1 -i "E:\songs\mp3\%%~na.jpg" -i "%%a" -y -c:v libx264 -preset veryfast -tune stillimage -crf 50 -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 128k -shortest "E:\songs\mp3\%%~na.mp4" ) pause
How do I change it so it can recursively process subfolders too?
There are a couple of different methods.
You can use powershell commands, you can also simply use the "FOR /R ..." command if you want to stay at a most outer level directory structure and perform your commands.

The following is a recursive approach using just windows batch command that will recursively go into each directory and process within that directory where your ffmpeg command will run in

That will allow keeping your input and output in the same directory

@echo off setlocal enabledelayedexpansion CALL :PROCESS_DIR "C:\Your Starting Directory" pause REM SUBROUTINE TO PROCESS THE DIRECTORY GIVEN AS FIRST PARAMETER :PROCESS_DIR pushd %1 echo INSIDE DIRECTORY !CD! for %%F in ("*.mp3") do ( REM THIS IS WHERE YOU DO YOUR PER FILE PROCESSING echo PROCESS FILE %%F TO %%~nF.mp4 ) REM FIND ALL DIRECTORIES IN THE CURRENT DIRECTORY AND RECURSIVELY CALL THE PROCESS_DIR SUBROUTINE for /D %%D in ("*") do ( CALL :PROCESS_DIR %%D ) popd EXIT /B
Here is a simpler one
@echo off setlocal enabledelayedexpansion pushd "C:\Your Starting Directory" FOR /R %%F IN ("*.mp3") do ( pushd %%~pF echo INSIDE DIRECTORY !CD! echo PROCESS FILE %%F TO %%~pF%%~nF.mp4 popd ) popd pause
I will let others show you the powershell commands
yusoffb01 likes this.

Last edited by davidktw; 03-01-2021 at 01:04 AM..
davidktw is offline   Reply With Quote
Old 03-01-2021, 11:05 AM   #3
Arch-Supremacy Member
 
yusoffb01's Avatar
 
Join Date: Jun 2008
Posts: 12,840
Thanks for the help!

I managed to change my initial command to work in any folder, but not recursively.
echo off for %%a in ("*.flac") do ( "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -an -y -vcodec copy "%~dp0\%%~na.jpg" "C:\ffmpeg\bin\ffmpeg.exe" -loop 1 -i "%~dp0\%%~na.jpg" -i "%%a" -y -c:v libx264 -preset veryfast -tune stillimage -crf 20 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 128k -shortest "%~dp0\%%~na.mp4" ) pause
So for files in the folder, it creates an image and combines with the audio into mp4.

when I tried to edit your command it did say file not found. How should I edit your command to fit in the 2 things.
__________________
There will be a time when gold can be found on Euphrates(river in iraq) and people will kill for it
yusoffb01 is offline   Reply With Quote
Old 03-01-2021, 10:56 PM   #4
Arch-Supremacy Member
 
davidktw's Avatar
 
Join Date: Apr 2010
Posts: 10,990
Thanks for the help!

I managed to change my initial command to work in any folder, but not recursively.
echo off for %%a in ("*.flac") do ( "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -an -y -vcodec copy "%~dp0\%%~na.jpg" "C:\ffmpeg\bin\ffmpeg.exe" -loop 1 -i "%~dp0\%%~na.jpg" -i "%%a" -y -c:v libx264 -preset veryfast -tune stillimage -crf 20 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 128k -shortest "%~dp0\%%~na.mp4" ) pause
So for files in the folder, it creates an image and combines with the audio into mp4.

when I tried to edit your command it did say file not found. How should I edit your command to fit in the 2 things.
Maybe this will do it
@echo off setlocal enabledelayedexpansion pushd "C:\Your Starting Directory" set FFMPEG="C:\ffmpeg\bin\ffmpeg.exe" FOR /R %%F IN ("*.mp3") do ( pushd %%~pF echo CUR DIR = !CD! echo PROCESS FILE %%~nxF TO %%~nF.mp4 %FFMPEG% -i "%%~nxF" -an -y -vcodec copy "%%~nF.jpg" %FFMPEG% -loop 1 -i "%%~nF.jpg" -i "%%~nxF" -y -c:v libx264 -preset veryfast -tune stillimage -crf 20 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 128k -shortest "%%~nF.mp4" ) popd ) popd pause
yusoffb01 likes this.
davidktw is offline   Reply With Quote
Old 04-01-2021, 09:40 AM   #5
High Supremacy Member
 
YouHeypiCanLiao's Avatar
 
Join Date: May 2017
Posts: 33,053
Currently I use this script to convert mp3 inside mp3 folder into mp4 with album art
echo off for %%a in ("*.mp3") do ( "C:\ffmpeg\bin\ffmpeg.exe" -i "%%a" -an -y -vcodec copy "E:\songs\mp3\%%~na.jpg" "C:\ffmpeg\bin\ffmpeg.exe" -loop 1 -i "E:\songs\mp3\%%~na.jpg" -i "%%a" -y -c:v libx264 -preset veryfast -tune stillimage -crf 50 -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 128k -shortest "E:\songs\mp3\%%~na.mp4" ) pause
How do I change it so it can recursively process subfolders too?
how come never use spotify?
__________________
https://www.privacytools.io
https://fastgood.cheap
Beh tehhan liao!
YouHeypiCanLiao is online now   Reply With Quote
Old 04-01-2021, 01:37 PM   #6
Arch-Supremacy Member
 
yusoffb01's Avatar
 
Join Date: Jun 2008
Posts: 12,840
Maybe this will do it
@echo off setlocal enabledelayedexpansion pushd "C:\Your Starting Directory" set FFMPEG="C:\ffmpeg\bin\ffmpeg.exe" FOR /R %%F IN ("*.mp3") do ( pushd %%~pF echo CUR DIR = !CD! echo PROCESS FILE %%~nxF TO %%~nF.mp4 %FFMPEG% -i "%%~nxF" -an -y -vcodec copy "%%~nF.jpg" %FFMPEG% -loop 1 -i "%%~nF.jpg" -i "%%~nxF" -y -c:v libx264 -preset veryfast -tune stillimage -crf 20 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -pix_fmt yuv420p -c:a aac -shortest -strict experimental -b:a 128k -shortest "%%~nF.mp4" ) popd ) popd pause
THANKS! This works perfectly!
__________________
There will be a time when gold can be found on Euphrates(river in iraq) and people will kill for it
yusoffb01 is offline   Reply With Quote
Old 04-01-2021, 01:38 PM   #7
Arch-Supremacy Member
 
yusoffb01's Avatar
 
Join Date: Jun 2008
Posts: 12,840
how come never use spotify?
Free google photos is going away. But if you upload before the deadline the files you have remains there. And you can download the original files.

__________________
There will be a time when gold can be found on Euphrates(river in iraq) and people will kill for it

Last edited by yusoffb01; 04-01-2021 at 01:42 PM..
yusoffb01 is offline   Reply With Quote
Reply
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ. Forum members and moderators are responsible for their own posts.

Please refer to our Terms of Service for more information.


Thread Tools

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On