Need help writing a batch file for mencoder

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Nintynuts
Posts: 2
Joined: 25 Feb 2010 18:41

Need help writing a batch file for mencoder

#1 Post by Nintynuts » 25 Feb 2010 19:39

Hi guys,
I want to make an ambitious recursive batch file which loops through a website-style file structure until there are no child folders, then runs mencoder on the collection of video files in that final folder, saving it in the root folder (where the batch was run from) as the folder path to the file with the "\" replaced with ".". for example:

Code: Select all

Root (where the batch was run)
|- Subfolder01
|  |- SubSubfolder03
|  |  |- Video1.mpg
|  |  |- Video2.mpg
|  |  `- Video3.mpg
|  `- SubSubfolder04
|- Subfolder02
`- Subfolder01.SubSubfolder03.mpg <-- this is the resultant file of The batch process

Obviously the point of this is to generate a lot of files not just one, so when a file is created, (after possibly deleting the source files once I know this works) the pointer moves back up to the parent folder until it finds a sibling folder, then progresses down that route...etc hence the recursive nature of this batch file, exactly like a binary tree.

This is my partial pseudo code:

Code: Select all

START
for each folder in root
   if folder contains a sub-folder
      add folder name to file name string followed by "."
      add folder to root path string
      goto START
   else
      run mencoder with all files in folder
      delete source video files

The main problems I am aware of are the fact this isn't like a programming language and doesn't have methods, making the recursive bit complicated, in terms of keeping track of the current folder and although I am (maybe) obviously a programmer I don't have a clue about DOS syntax. It would be great if I could collect building blocks of knowledge and do it myself, but I can appreciate it's less hassle and quicker for you guys to just make suggestions.

Finally, here is a page about running mencoder from the command line:
http://howto.gumph.org/content/joining-movie-clips/

I'd greatly appreciate you guys' wealth of knowledge on this

Thanks
Nintynuts

aGerman
Expert
Posts: 3746
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Need help writing a batch file for mencoder

#2 Post by aGerman » 26 Feb 2010 06:45

I don't know how mencoder works (btw. have no time to figure out).

This short code shows you how to find the files and how to create the new name. I'm sure you are able to replace the ECHO-part with the mencoder line the right way.

Code: Select all

@echo off &setlocal
set "root=%~dp0"
for /f "delims=" %%a in ('dir /a-d /b /s "*.mpg"') do set "fullname=%%a" &set "filepath=%%~dpa" &call :process
echo finished
pause
goto :eof

:process
if "%root%"=="%filepath%" goto :eof
call set "newname=%%fullname:%root%=%%"
set "newname=%newname:\=.%"

:: ********* replace this part with the mencoder command line *********
echo  *in : "%fullname%"
echo  *out: "%newname%"
echo.
:: ********************************************************************

goto :eof


Regards
aGerman

Nintynuts
Posts: 2
Joined: 25 Feb 2010 18:41

Re: Need help writing a batch file for mencoder

#3 Post by Nintynuts » 26 Feb 2010 07:11

thanks for the reply,
It seems to find the files, but there are some problems;
- It only does one type of video file at a time, is there a way to make it recognize wmv avi and mpg in the same script (other than using *.*)?
- The *out string shouldn't include the individual file name (.1.mpg, .2.mpg, etc.), just the video format. As the purpose of that string is to give an output file name to mencoder for the combined video file.
- Running mencoder, is an important part I need help with because I have to pass the file names of all the video files in the deepest folder(s) in one line dynamically.

This is the format as shown in that link:

Code: Select all

mencoder -oac copy -ovc copy -noodml -o "joined.avi" "1.avi" "2.avi"

If it's simply a problem of me not understanding it, I'll need it explaining to me to finish it.

Thanks again

aGerman
Expert
Posts: 3746
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Need help writing a batch file for mencoder

#4 Post by aGerman » 28 Feb 2010 16:20

No idea. Maybe could be something like that:

Code: Select all

@echo off &setlocal
set "root=%~dp0"
for /f "delims=" %%a in ('dir /a-d /b /s "*.mpg"') do set "fullname=%%a" &set "filepath=%%~dpa" &set "ext=%%~xa" &call :process
echo finished
pause
goto :eof

:process
if "%root%"=="%filepath%" goto :eof
call set "newname=%%filepath:%root%=%%"
set "newname=%newname:\=.%%ext%"

mencoder -o "%newname%" "%fullname%"

goto :eof


Regards
aGerman

Post Reply