Having drawn a blank after an internet search and also of the forum I am hoping some one here can point me in the right direction. I am a newbie with not much knowledge of batch files but I can use ffMPEG in one to add the same jpg to each mp3 in a folder. I use the following batch file to do so:
@echo off
set "sourcedir=C:\Utilities\ffMPEG - MP4 Generator\Bin\SourceFolder"
set "outputdir=C:\Utilities\ffMPEG - MP4 Generator\Bin\GeneratedFolder"
PUSHD "%sourcedir%"
for %%F in (*.mp3) DO ffmpeg -r 1 -loop 1 -i abc.jpg -i "%%F" -acodec copy -r 1 -shortest -vf scale=1280:720 "%outputdir%\%%F.mp4"
POPD
However, what I am trying to do is add not abc.jpg to the mp3s but a different jpg on each occasion that the folder mp3 file is called in the loop. I have two folders one with JPGs the other with MP3s. Simply put, what I am trying to achieve is that the batch file adds jpg_1 to mp3_1 and jpg_2 to mp3_2 and jpg_3 to mp3_3 and so on. In other words instead of having "abc.jpg" have the batch file loop through each of the different jpgs. Obviously I will have to be careful with the numbering of these files so they are called in the correct sequence.
Any help with this will be gratefully received.
+ Reply to Thread
Results 1 to 6 of 6
-
-
for %%F in (*.mp3) DO ffmpeg -r 1 -loop 1 -i "%%~nF.jpg" -i "%%F" -acodec copy -r 1 -shortest -vf scale=1280:720 "%outputdir%\%%F.mp4"
or if in a subfolder:
for %%F in (*.mp3) DO ffmpeg -r 1 -loop 1 -i "jpg_subfolder\%%~nF.jpg" -i "%%F" -acodec copy -r 1 -shortest -vf scale=1280:720 "%outputdir%\%%F.mp4" -
I have two folders one with JPGs the other with MP3s.the batch file adds jpg_1 to mp3_1 and jpg_2 to mp3_2
Then
Code:@echo off SETLOCAL EnableDelayedExpansion set "sourcedir=C:\Utilities\ffMPEG - MP4 Generator\Bin\SourceFolder" set "jpgdir=C:\Utilities\ffMPEG - MP4 Generator\Bin\SourceFolder" set "outputdir=C:\Utilities\ffMPEG - MP4 Generator\Bin\GeneratedFolder" PUSHD %sourcedir% for %%g in (*.mp3) do ( set mp3file=%%g set jpgfile=!mp3file! set jpgfile=!jpgfile:mp3_=jpg_! set jpgfile=!jpgdir!\!jpgfile:.mp3=.jpg! ffmpeg -loop 1 -i "!jpgfile!" -i "!mp3file!" -c:a copy -c:v libx264 -shortest -vf scale=1280:720 "!outputdir!\%%~ng.mp4" ) POPD ENDLOCAL
Last edited by videobruger; 7th Feb 2018 at 11:03. Reason: Corrected script to PUSHD %sourcedir%
-
To sneaker and videobruger my grateful thanks for your solutions. Videobruger I have decided to take your advice and keep the naming simple. It's easier that way.
However, I have a problem with the output naming. This is created in the original script I was using where the output name is Song1.mp3.mp4 etc. I want the output name to be Song1.mp4 etc. This not a problem since I can achieve this by using:
POPD
PUSHD "%outputdir%"
for %%F in (*.mp4) do @ren "%%F" "????????????????????????????????????????????????? ?%%~xF"
POPD
Obviously this is a longwinded way of getting there and stems from my inexperience with batch files but I would like to know what the correct coding ought to have been. If you can put me right here it would be great. Thank you. -
From what I can see Videobruger's script already handles this. He is using variable name "g" and sets output name as "%%~ng.mp4". The "n" means file "name without extension". (You can also cat multiple such modifiers.)
Code:Variable with modifier Description %~I Expands %I which removes any surrounding quotation marks (""). %~fI Expands %I to a fully qualified path name. %~dI Expands %I to a drive letter only. %~pI Expands %I to a path only. %~nI Expands %I to a file name only. %~xI Expands %I to a file extension only. %~sI Expands path to contain short names only. %~aI Expands %I to the file attributes of file. %~tI Expands %I to the date and time of file. %~zI Expands %I to the size of file. %~$PATH:I Searches the directories listed in the PATH environment variable and expands %I to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, this modifier expands to the empty string.
-
Thanks Sneaker, the list of variable modifiers along with the link was very welcome. You were right about the output from Videbruger's coding. However, when I first copied it and ran it I got an error message. I ran it again after your post and it still didn't work. After a lot of unfruitful checking while obviously wearing a blindfold I realized that "%outputdir%" had been omitted after PUSHD. Once added the outcome was what I wanted.
Many thanks to you both again!
Similar Threads
-
Problem with audio using x264 .bat encoding
By Verdq in forum Newbie / General discussionsReplies: 7Last Post: 18th Aug 2014, 20:17 -
Help: ffmpeg .bat .ogm -> .mp4
By doomtomb in forum Video ConversionReplies: 10Last Post: 29th Dec 2013, 16:53 -
problem mkvmerge/bat file
By whereswally007 in forum Video ConversionReplies: 0Last Post: 9th Oct 2013, 18:56 -
Creating a video file with FFMPEG using a single image (Mask)
By GoldenMeanie in forum Video ConversionReplies: 7Last Post: 8th Jun 2013, 15:18 -
Could someone change this .sh Linux script into a usable .bat? (ffmpeg)
By RabblerouserGT in forum Video Streaming DownloadingReplies: 11Last Post: 8th Feb 2013, 14:43