VideoHelp Forum




+ Reply to Thread
Results 1 to 6 of 6
  1. Member
    Join Date
    Feb 2018
    Location
    UK
    Search Comp PM
    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.
    Quote Quote  
  2. 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"
    Quote Quote  
  3. 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
    I guess the last should read: the batch file adds jpg_1.jpg to mp3_1.mp3 and jpg_2.jpg to mp3_2.mp3

    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
    But why not make life easier on yourself and change the file names to eg file1.mp3 file1.jpg ... and use what sneaker wrote
    Last edited by videobruger; 7th Feb 2018 at 11:03. Reason: Corrected script to PUSHD %sourcedir%
    Quote Quote  
  4. Member
    Join Date
    Feb 2018
    Location
    UK
    Search Comp PM
    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.
    Quote Quote  
  5. 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.
    https://technet.microsoft.com/library/bb490909.aspx
    Quote Quote  
  6. Member
    Join Date
    Feb 2018
    Location
    UK
    Search Comp PM
    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!
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!