Script for Automatic Multiple instances of cr2hdr (Windows)

Started by engardeknave, September 26, 2013, 12:36:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

engardeknave

I don't know how that works. I never use video, and I've actually since switched to Nikon. But you probably just need to make the script look for .dng files. Ie., see the line: ' if valfname(file.Name,".CR2") then ' and disable all the file organizing (organize=false).

Seanc

I've starting playing with this and really wanted to be able to use the hyperthreading cores without losing UI or foreground program responsiveness.

I don't see a way to add a priority parameter when using wshshell.run directly. The start program does though, so I've modified the script to launch start, which starts cr2hdr with low priority. My I7 is remaining responsive with 8 processes going now.

The primary change is the cr2dngcmd variable assignment. I've left the original commented out. Window minimizing is now controlled by the start command's /MIN parameter.

This is the new command passed:

QuoteExecuting: C:\WINDOWS\system32\cmd.exe /c start "Processing _UAL2744.CR2" /MIN /LOW "G:\Photo_workspace\DualISO\cr2hdr.exe" --compress "_UAL2744.CR2"

G:\Photo_workspace\DualISO\ being my test folder

'------------------------------------------------------------------
'last update: 4/06/2017

'NOTE: a copy of dcraw.exe and exiftool.exe needs to be in the folder with the dual iso images

cr2hdrpath="G:\Photo_workspace\DualISO\" 'ends with a slash \
cr2hdrexe="cr2hdr.exe"
cr2hdrargs="--compress"

exiftoolpath="G:\Photo_workspace\DualISO\" 'ends with a slash \ Used for correcttint option
inputfolder="G:\Photo_workspace\" 'dialog will start at this folder if set (ends with a slash \)

dualisocr2dir="Dual ISO CR2"
regularcr2dir="Regular CR2"
dngoutputdir="Dual ISO DNG"

organize=true 'sort files into subdirectories when done processing
correcttint=false

maxprocs=8 'Number of simultaneous processes
windowtype=7
'0 Hide the window and activate another window.
'1 Activate and display the window. (restore size and position) Specify this flag when displaying a window for the first time.
'2 Activate & minimize.
'3 Activate & maximize.
'4 Restore. The active window remains active.
'5 Activate & Restore.
'6 Minimize & activate the next top-level window in the Z order.
'7 Minimize. The active window remains active.
'3 & 7 replaced by parameters /MAX or /MIN on the start command when setting the cr2dngcmd variable
'------------------------------------------------------------------

set elog=CreateObject("System.Collections.ArrayList")
elog.add "Started: " & Now()
'starttime=Timer

'if inputfolder="" then 'not set in options
  if Wscript.Arguments.Count>0 then
    inputfolder=Wscript.Arguments(0) 'command line
  else
    inputfolder=getfolder("Select the folder containing the dual ISO .CR2 files.")
    if inputfolder="" then WScript.Quit
  end if
'end if

starttime=Timer
elog.add vbcrlf & "Input folder is " & inputfolder

set fso=CreateObject("Scripting.fileSystemObject")
set mainfolder=fso.GetFolder(inputfolder)
set files=mainfolder.Files
filecount=0
set cr2dngqueue=CreateObject("System.Collections.ArrayList")
set exiftoolqueue=CreateObject("System.Collections.ArrayList")

elog.add vbcrlf & "Searching for .CR2 files"

for Each file in files 'find applicable .cr2s
  if valfname(file.Name,".CR2") then
    cr2dngcmd="C:\WINDOWS\system32\cmd.exe /c start ""Processing " & file.name & """ /MIN /LOW " & """" & cr2hdrpath & cr2hdrexe & """ " & cr2hdrargs & " """ & file.name & """" 'no logs
'cr2dngcmd="""" & cr2hdrpath & cr2hdrexe & """ " & cr2hdrargs & " """ & file.name & """" 'no logs
    'cr2dngcmd="cmd.exe /c """"" & cr2hdrpath & cr2hdrexe & """ " & cr2hdrargs & " """ & file.name & """ > " & file.name & ".log """
    cr2dngqueue.add cr2dngcmd
    elog.add "Queued " & cr2dngcmd
    if correcttint then
      exiftoolcmd=exiftoolpath & "exiftool.exe " & replace(file.name,".CR2",".dng") & " -asshotneutral=""0.473635 1.05 0.624"" -overwrite_original"
      exiftoolqueue.add exiftoolcmd
      elog.add "Queued " & exiftoolcmd
    end if
    filecount=filecount+1
  end if
next

if filecount=0 then
  elog.add "No files found!"
  msgbox "No files found!"
  dump ""
  WScript.Quit
end if

elog.add vbcrlf & "Converting Dual ISO .CR2 files"
cr2hdrtime=runqueue(cr2dngqueue,maxprocs,cr2hdrexe)

if correcttint then
  runqueue exiftoolqueue,8,"exiftool.exe"
  elog.add vbcrlf & "Running exiftool"
end if

dngcount=0
for Each file in files
  if valfname(file.Name,".dng") then dngcount=dngcount+1
next

if dngcount=0 then
  msg="No DNG files created. Check script options and log."
  elog.add msg
  msgbox msg
  dump ""
  WScript.Quit
end if

if organize then sortfiles

finishline="Processed " & filecount & " file(s). Converted " & dngcount & " Dual ISO(s). Runtime: " & round(Timer - starttime) & " seconds."
elog.add vbcrlf & finishline & vbcrlf

if organize then
  mkdir mainfolder & "\" & "logs"
  dump("\logs")
else
  dump("")
end if

msgbox finishline

setnothing

sub sortfiles()
  elog.add vbcrlf & "Moving Dual ISO .CR2 files"
  set files=mainfolder.Files
  for Each file in files
    if valfname(file.Name,".dng") then 'find .dng but move .cr2 with same file name
      mkdir mainfolder & "\" & dualisocr2dir
      move mainfolder & "\" & fso.GetBaseName(file) & ".CR2", mainfolder & "\" & dualisocr2dir & "\" & fso.GetBaseName(file) & ".CR2"
    end if
  next

  elog.add vbcrlf & "Moving any regular .CR2 files"
  set files=mainfolder.Files
  for Each file in files
    if valfname(file.Name,".CR2") then
      mkdir mainfolder & "\" & regularcr2dir
      move mainfolder & "\" & file.Name, mainfolder & "\" & regularcr2dir & "\" & file.Name
    end if
  next   

  elog.add vbcrlf & "Moving Dual ISO .DNG files"
  set files=mainfolder.Files
  for Each file in files
    if valfname(file.Name,".dng") then
      mkdir mainfolder & "\" & dngoutputdir
      move mainfolder & "\" & file.Name, mainfolder & "\" & dngoutputdir & "\" & file.Name
    end if
  next

  elog.add vbcrlf & "Moving log files"
  set files=mainfolder.Files
  for Each file in files
    if valfname(file.Name,".log") then
      mkdir mainfolder & "\" & "logs"
      move mainfolder & "\" & file.Name, mainfolder & "\" & "logs" & "\" & file.Name
    end if
  next
end sub

function runqueue(queue,instances,exename)
  t=Timer
  Set WshShell=WScript.CreateObject("WScript.Shell")
  WshShell.currentdirectory=inputfolder 'have to set the current directory; can't pass full file path because of how cr2hdr calls adngc
  for Each line in queue
    elog.add "Executing: " & line
    wshshell.run line,windowtype,false
    waitfinish instances,exename
  next
  waitfinish 1,exename
  runqueue=Timer-t 'return elapsed time
  Set WshShell=nothing
end function

sub waitfinish(instances,exename)
  do
    Set myproc=GetObject("Winmgmts:").Execquery("Select * from Win32_Process where name='" & exename & "'")
    if(myproc.count>=instances) then wscript.sleep 100
  loop while myproc.count>=instances
end sub

function getfolder(title)
  MY_COMPUTER = &H11&
  USER_PROFILE = &H28&
  MY_PICTURES = &H27&
  WINDOW_HANDLE = 0
  OPTIONS = &H10&

  Set objShell = CreateObject("Shell.Application")
  Set objFolder = objShell.Namespace(MY_PICTURES)
  Set objFolderItem = objFolder.Self
  if inputfolder<>"" then strpath=inputfolder else strpath=objFolderItem.Path

  Set objShell = CreateObject("Shell.Application")
  Set objFolder = objShell.BrowseForFolder _
    (WINDOW_HANDLE, title, OPTIONS, strPath)
       
  If objFolder Is Nothing Then
      Wscript.Quit
  End If

  Set objFolderItem = objFolder.Self
  getfolder = objFolderItem.Path
end function

sub dump(subfolder)
  dim objfile
  set objFile=fso.CreateTextFile(mainfolder & subfolder & "\dualISOscript.log",True)
  objFile.Write Join(elog.toarray(), chr(13) & chr(10))
  objFile.Close
end sub

sub setnothing()
  set objfile=nothing
  set cr2dngqueue=nothing
  set adngcqueue=nothing
  set deldngqueue=nothing
  set elog=nothing
  set fso=nothing
end sub

function valfname(name,suffix)
  valfname=lcase(Right(name,len(suffix)))=lcase(suffix)
end function

sub mkdir(dir)
  if not fso.FolderExists(dir) then
    fso.createFolder(dir)
    elog.add "Created """ & dir & """"
  end if
end sub

sub move(src,dest)
  elog.add "Moving """ & src & """ to """ & dest & """"
  fso.MoveFile src,dest
end sub

function round(num)
  round=int((num+.005)*100)/100
end function

lureb74

Hi guys,

Is there a way to make this useful with DNGs files (as from raw dualiso video)? May be modifying the .vbs (I don't know how to do it)...