1

The script is to process images named Image1.png thru Image10.png. The images are resized then the resized image is converted to video with same file name with extension mp4.

Please consider the following script:

FOR %%G IN (Image*.png) DO (


ffmpeg -i %%G -vf scale=4096:-1 -y out.png

Set "FF=%~n1"
ffmpeg -loop 1 -i out.png -c:v libx264 -t 1 -crf 25 -pix_fmt yuv420p -y %FF%.mp4


del out.png
)

The result from this script is:

  1. Each Image file is resized and written to file out.png in turn.
  2. File out.png is deleted at the end of session.
  3. The video created is MP4.mp4 which is from the last .png file being Image9.png

Why is variable %FF% which is %~n1 not being passed through FFMPEG?

2 Answers 2

0

The syntax for extracting the file-name part without extension or path for the loop variable of the FOR command is as follows:

Set FF=%%~nG

You need two percent characters inside the loop, rather than one, and the variable is G and not 1 (which is the notation for the first argument of a script).

Another problem is that you need EnableDelayedExpansion for variables to be expanded at execution time rather than at parse time.

This is my test script that demonstrates these points that you can use as a model :

%echo off
setlocal EnableDelayedExpansion
FOR %%G IN (*.png) DO (
  rem echo %%G : %%~nG
  Set FF=%%~nG
  echo !FF!
)
5
  • Changing the script as you recommend result is is similar to before only one MP4 file created and it is for 'Goggle9.png". For diagnostics I added the line "Echo %FF% > hh.txt" and the file contain ECHO is on.
    – James
    Mar 17 at 21:39
  • Will look at it tomorrow.
    – harrymc
    Mar 17 at 21:51
  • I see that the problem is with my ffmpeg script to create the MP4. It appears that %FF% is returning nothing within the ffmpeg script. Here is what was display within the CMD Window:
    – James
    Mar 18 at 0:18
  • C:\Users\xxxxx\Pictures\Saved Pictures>FOR %G IN (Goggles*.png) DO ( ffmpeg -i %G -vf scale=4096:-1 -y out.png Set "FF=%~nG" ffmpeg -loop 1 -i out.png -c:v libx264 -t 1 -crf 25 -pix_fmt yuv420p -y .mp4 del out.png ) C:\Users\xxxxx\Pictures\Saved Pictures>( ffmpeg -i Goggles1.png -vf scale=4096:-1 -y out.png Set "FF=Goggles1" ffmpeg -loop 1 -i out.png -c:v libx264 -t 1 -crf 25 -pix_fmt yuv420p -y .mp4 del out.png )
    – James
    Mar 18 at 0:19
  • If my answer was helpful, please consider marking it as accepted (click the ✔ sign).
    – harrymc
    Mar 18 at 9:34
0

The syntax issue about Set FF=%%~nG is resolved.

But the second problem is not resolve and will be resubmitted to the group.

The script %FF%.mp4 fails to pass which is in:

ffmpeg -loop 1 -i out.png -c:v libx264 -t 1 -crf 25 -pix_fmt yuv420p -y %FF%.mp4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.