0

I'm not an expert in batch programming, my only skill is in C\C++. I'm not even sure how to go about this really.

I've got a bunch of videos like Video1.mp4, Video2.mp4 (that's not their actual names, but they do have numbers indicating beginning and end)

Basically I have this FFMPEG command that I can use to convert all of these to an aspect ratio of 16:10 that looks something like this:

"ffmpeg -i "Section 1 Video 1.mp4" -aspect 16:10 OutSection 1 Video 1.mp4"
"ffmpeg -i "Section 1 Video 2.mp4" -aspect 16:10 OutSection 1 Video 2.mp4"
"ffmpeg -i "Section 2 Video 1.mp4" -aspect 16:10 OutSection 2 Video 1.mp4"

Now instead of writing this command over and over again, is there anyway for me to substitute the numbers for actual variables? I know that Section 1 ends at Video 27 and Section 2 ends at Video 26 and so on. Basically I need the loop to run 165 times so I don't need to write the command 165 times.

Or is this beyond the scope of capability of a mere batch program?

NetStarter
  • 3,189
  • 7
  • 37
  • 48
Michael Barth
  • 45
  • 1
  • 5

1 Answers1

0

Well, of course batch can do it, the real question is can you handle framing the question correctly?

Here's three ways - the FFMPEG command is simply echoed. Remove the ECHO to activate.

@ECHO OFF
SETLOCAL enabledelayedexpansion
:: way the first
for /l %%a IN (1,1,27) DO FOR /l %%b IN (1,1,27) DO (
 IF EXIST "section %%a video %%b.mp4" ECHO FFMPEG -i "Section %%a Video %%b.mp4" -aspect 16:10 "OutSection %%a Video %%b.mp4"
)
ECHO ==============================
:: Way the second
for /l %%a IN (1,1,27) DO FOR /l %%b IN (1,1,27) DO (
 SET /a total=%%a+%%b
 IF !total! leq 28 ECHO FFMPEG -i "Section %%a Video %%b.mp4" -aspect 16:10 "OutSection %%a Video %%b.mp4"
)
ECHO ==============================
:: Way the third
FOR %%i IN ("Section * Video *.mp4") DO (
ECHO FFMPEG -i "%%i" -aspect 16:10 "Out%%i"
)
ECHO ==============================

Now - the question here is - are you sure about your FFMPEG line? Seems to me that you've omitted the quotes around the output filename.

And the other question is can you count? If you have as you say, 27 videos in section 1, 26 in 2 and so on, then you would probably have 27+26+25...3+2+1 videos to convert - and that would be 378 according to my calculation - and more importantly, batch - not 165.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Haha, yeah I realized I messed up the command, but that was intended as a mockup command, it looks like that, but it's not the real command that I used with real names. But the second way seems like the way that I'd be looking for. Thank you! – Michael Barth May 13 '13 at 15:59
  • Oh and there's 165 videos, and in your example you make it go through 27 sections where I only have 6 sections, and the number of videos per section is varied. – Michael Barth May 13 '13 at 16:31