How to sequence two file conversion commands?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
linchpinza
Posts: 2
Joined: 05 Jun 2012 14:56

How to sequence two file conversion commands?

#1 Post by linchpinza » 05 Jun 2012 15:32

Hello everyone :)

I'm wanting to make a batch file that can do two conversions on an input file, one after the other.

I need to convert image files to a special image format called 'tiled & mipmapped EXR'. The problem is I dont have a program
that can do both the EXR conversion and the tiling/mipmapping EXR optimization in one go.
But I do have a seperate program for each, one that can convert to EXR, and then a second that can optimize EXR files so they are tiled & mipmapped.

I'm wanting to create a bat file that can run both these seperate programs in sequence on a single input file.
So it would essentially do something like this in the end:

1) Run 'image to EXR' conversion on the input file
add '_tmp' to the name of the conversion output (so it would end up being $inputFileName_tmp.exr)

2) run the mipmap conversion on all files that end in '_tmp.exr'
make the mipmap conversion output its file as just $inputFileName.exr
delete all _tmp.exr files in the folder.


I just cant for the life of me figure out how to link these two seperate operations together in a single bat file.
I wouldn't mind having to delete the '_tmp.exr' files manually afterward but it would be great if I could get the bat to delete all '_tmp.exr' files automatically
as a bonus extra step. :P
All I have at the moment is just two seperate bat files for each operation.

This is the bat file for the initial .exr conversion

Code: Select all

for %%i in (%*) do \\TXSERVER\Textures\img2tiledexr %%i %%i_tmp.exr -32bit -compression zip -tileSize 32x32 -linear auto

And this is the bat file I have for the optimization which creates the final mipmap/tiled EXR output I require.

Code: Select all

@for %%i in (%*) do \\TXSERVER\Textures\exrmaketiled -m -u -v %%i %%i


So I basically need to join those two operations together to give me a single output EXR file.
Is this possible ? :o
Sorry for my noob-ness :oops: , I would really really appreciate some help on this.

Thanks,
Christopher.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: How to sequence two file conversion commands?

#2 Post by Fawers » 05 Jun 2012 16:03

I'm neither acquainted to this program nor to this image format, so I'll try to help following your parameters.

Are these pieces of code written in different batch files? You can easily call a second batch from the first one with the CALL command. CALL /? for help.

Convert.bat:

Code: Select all

@echo off
for %%i in (%*) do (
 \\TXSERVER\Textures\img2tiledexr %%i "%%~i_tmp.exr" -32bit -compression zip -tileSize 32x32 -linear auto
 call optimize.bat "%%~i_tmp.exr"
)


Optimize.bat:

Code: Select all

@echo off
for %%i in (%*) do \\TXSERVER\Textures\exrmaketiled -m -u -v %%i "%%~i.tmp" &&(
  del /q %%i
  ren "%%~i.tmp" %%i
  echo %%~NXi was converted successfully.
  )

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

Re: How to sequence two file conversion commands?

#3 Post by aGerman » 05 Jun 2012 16:10

You could try that one

Code: Select all

@echo off
for %%i in (%*) do (
  \\TXSERVER\Textures\img2tiledexr "%%~i" "%%~ni.exr" -32bit -compression zip -tileSize 32x32 -linear auto
  \\TXSERVER\Textures\exrmaketiled -m -u -v "%%~ni.exr" "%%~ni.exr"
)

I guess there is no need in that case to create the *_temp.exr files because each pre-converted file will be directly converted to the final file type. -- But I'm not familiar with that image business :)

Regards
aGerman

linchpinza
Posts: 2
Joined: 05 Jun 2012 14:56

Re: How to sequence two file conversion commands?

#4 Post by linchpinza » 05 Jun 2012 19:47

Wow you guys are awesome! :D
@Fawers, thanks for the help!! really appreciate it. Your bat worked perfectly but I've chosen to use aGermans one
because it skips the whole _tmp stage, sorry I thought that _tmp stage would be neccessary :P

@aGerman
Thanks so much man, Your script works perfectly.
The next thing I added to it was to create a sub directory called Published and move any *.exr files into the subdirectory published
So I added this

Code: Select all

md Published
move *.*exr Published


So the current bat file looks like this..

Code: Select all

@echo off
for %%i in (%*) do (
  \\TXSERVER\Textures\img2tiledexr "%%~i" "%%~ni.exr" -32bit -compression zip -tileSize 32x32 -linear auto
  \\TXSERVER\Textures\exrmaketiled -m -u -v "%%~ni.exr" "%%~ni.exr"
)
md Published
move *.*exr Published
PAUSE


The only problem now is, all of this works 100% for local directories/files but as soon as I try run the bat using files on the network
it outputs the files to C:\Windows\ as if it cant write to the network path.
I have full permissions on the server, I can create and delete files/folders manually with no problem which got me thinking
that there must be different commands you have to use or something when working with files on a network path?

So say Im running a file through the bat, that has the path "\\server\project\textures\texture.jpg"
It runs through the whole process of converting the file no problem but doesnt create the EXR in the network directory"\\server\project\textures\"
and instead reverts to saving the file in "C:\Windows"

Any Ideas on how to get this working ? :oops:
Thanks, really appreciate the help :mrgreen:

PS. Just for a little background info for if you guys are wondering exactly what Im using this stuff for..
Im a CGI visual effects artist, currently trying to optimize the pipeline at a new studio I joined.
I had the luxury of in-house developers at my previous studio, who handled all the streamlining of the production pipeline but now in this much smaller
studio there's almost no pipeline. So I'm trying to optimize the pipeline where I can.
Textures render a lot quicker when sourced as tiled EXR's, so this bat file is the start of a texture publishing workflow which
will help us render our jobs a lot quicker :) My eventual plan is to have a tool,thinking of creating it with python.. that can
recreate all the EXR's in a specified directory and its subdirectories if the EXR's are older than the current date. I also want it
to have a function that can check for any image files that dont have a corresponding EXR, and create them if they're missing.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: How to sequence two file conversion commands?

#5 Post by Fawers » 05 Jun 2012 21:26

linchpinza wrote:@Fawers, thanks for the help!! really appreciate it. Your bat worked perfectly but I've chosen to use aGermans one
because it skips the whole _tmp stage, sorry I thought that _tmp stage would be neccessary

No problem at all. Feel free to choose the codes that work better for you, always.

linchpinza wrote:So say Im running a file through the bat, that has the path "\\server\project\textures\texture.jpg"
It runs through the whole process of converting the file no problem but doesnt create the EXR in the network directory"\\server\project\textures\"
and instead reverts to saving the file in "C:\Windows"

Any Ideas on how to get this working ?
Thanks, really appreciate the help

I think batch files can't "recognize" directories on a server, but it might work if you map this network path to a network drive; have "\\server\project\textures" as a new drive letter, e.g., "S:\". So instead of running your batch from "\\server\project\textures", you run it directly from "S:\".
As I said before, it "just" might work, I'm not sure if it will.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How to sequence two file conversion commands?

#6 Post by foxidrive » 05 Jun 2012 23:55

Use this for a network drive:

Code: Select all

@echo off
pushd "\\server\share\"

:: your batch file here

popd

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How to sequence two file conversion commands?

#7 Post by foxidrive » 06 Jun 2012 00:33

Test these, based upon your code:

#1 should process *.jpg *.gif *.tga if the "same named file.exr" doesn't exist
#2 should recreate .exr files and will detect files older than for example -30 days and recreate the files - assuming they can be overwritten. Change fs in batch file #3 from *.* to *.exr if you only want to process .EXR files. It will process all subdirectories and files are placed in a folder called "Published" in each subdirectory

#3 is used by #2 and should be in the same folder.

Code: Select all

::Create exr from lone images.bat
:: launch as 'batch.bat "c:\folder\root\to process"
@echo off
pushd "%~1" && (
for /f "delims=" %%i in ('dir *.jpg *.gif *.tga /b /s /a-d') do (
pushd "%%~dpi" 
if not exist "%%~ni.exr" (
\\TXSERVER\Textures\img2tiledexr "%%~i" "%%~ni.exr" -32bit -compression zip -tileSize 32x32 -linear auto
  \\TXSERVER\Textures\exrmaketiled -m -u -v "%%~ni.exr" "%%~ni.exr"
md Published 2>nul
move *.exr Published
)
popd
)
)



Code: Select all

:: Process exr older than xx.bat
:: launch as Batch.bat "c:\folder root\to\process" -30
@echo off
call "echo older than xx days.bat" "%~1" %2 >$temp.tmp
for /f "delims=" %%i in ($temp.tmp) do (
pushd "%%~dpi"
  \\TXSERVER\Textures\img2tiledexr "%%~i" "%%~ni.exr" -32bit -compression zip -tileSize 32x32 -linear auto
  \\TXSERVER\Textures\exrmaketiled -m -u -v "%%~ni.exr" "%%~ni.exr"
md Published 2>nul
move *.exr Published
popd
)
del $temp.tmp


Code: Select all

:: "echo older than xx days.bat"
@echo off
:: Syntax: Batch.bat "c:\folder root\to\process" -30
::
:: Echos files older than -30 days
:: %1 is the "drv:\Source Folder"
:: %2 is the number of days
:: fs is the filespec (*.*)
::
:: set s=-s to recursively process folders
:: and remove -s to make it process only the current folder
::
:: If you don't have it then download forfiles from
:: ftp://ftp.microsoft.com/reskit/y2kfix/x86/forfiles.exe
setlocal
set p1=%comspec% /C if not @ISDIR
set p2=ECHO 0x22@PATH\@FILE0x22
set days=%2
set from="%~1"
set fs=*.*
set s=-s
if "%~2"=="" (
echo PLEASE ENTER batch.bat "d:\source\folder" -30
echo for 30 days ago
pause
goto: EOF
)
FORFILES -p%from% -m%fs% -d%days% %s% -c"%p1%==TRUE %p2%"

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: How to sequence two file conversion commands?

#8 Post by Squashman » 06 Jun 2012 05:46

Fawers wrote:I think batch files can't "recognize" directories on a server, but it might work if you map this network path to a network drive; have "\\server\project\textures" as a new drive letter, e.g., "S:\". So instead of running your batch from "\\server\project\textures", you run it directly from "S:\".
As I said before, it "just" might work, I'm not sure if it will.


MS KB article
http://support.microsoft.com/KB/112744

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: How to sequence two file conversion commands?

#9 Post by Fawers » 06 Jun 2012 09:36

Squashman wrote:
Fawers wrote:I think batch files can't "recognize" directories on a server, but it might work if you map this network path to a network drive; have "\\server\project\textures" as a new drive letter, e.g., "S:\". So instead of running your batch from "\\server\project\textures", you run it directly from "S:\".
As I said before, it "just" might work, I'm not sure if it will.


MS KB article
http://support.microsoft.com/KB/112744

I didn't know it was possible to do that with NET USE. This is going to save me a lot of time. Thanks!

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

Re: How to sequence two file conversion commands?

#10 Post by aGerman » 06 Jun 2012 10:05

Perhaps you could do all in one step.

Code: Select all

@echo off
md Published
for %%i in (%*) do (
  \\TXSERVER\Textures\img2tiledexr "%%~i" "Published\%%~ni.exr" -32bit -compression zip -tileSize 32x32 -linear auto
  \\TXSERVER\Textures\exrmaketiled -m -u -v "Published\%%~ni.exr" "Published\%%~ni.exr"
)

Regards
aGerman

Post Reply