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.


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).


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 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 \

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

maxprocs=8 'Number of simultaneous processes
'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()

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

elog.add vbcrlf & "Input folder is " & inputfolder

set fso=CreateObject("Scripting.fileSystemObject")
set mainfolder=fso.GetFolder(inputfolder)
set files=mainfolder.Files
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 " & & """ /MIN /LOW " & """" & cr2hdrpath & cr2hdrexe & """ " & cr2hdrargs & " """ & & """" 'no logs
'cr2dngcmd="""" & cr2hdrpath & cr2hdrexe & """ " & cr2hdrargs & " """ & & """" 'no logs
    'cr2dngcmd="cmd.exe /c """"" & cr2hdrpath & cr2hdrexe & """ " & cr2hdrargs & " """ & & """ > " & & ".log """
    cr2dngqueue.add cr2dngcmd
    elog.add "Queued " & cr2dngcmd
    if correcttint then
      exiftoolcmd=exiftoolpath & "exiftool.exe " & replace(,".CR2",".dng") & " -asshotneutral=""0.473635 1.05 0.624"" -overwrite_original"
      exiftoolqueue.add exiftoolcmd
      elog.add "Queued " & exiftoolcmd
    end if
  end if

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

elog.add vbcrlf & "Converting Dual ISO .CR2 files"

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

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

if dngcount=0 then
  msg="No DNG files created. Check script options and log."
  elog.add msg
  msgbox msg
  dump ""
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"
end if

msgbox finishline


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

  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

  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

  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
end sub

function runqueue(queue,instances,exename)
  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 line,windowtype,false
    waitfinish instances,exename
  waitfinish 1,exename
  runqueue=Timer-t 'return elapsed time
  Set WshShell=nothing
end function

sub waitfinish(instances,exename)
    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)
  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
  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))
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)
end function

sub mkdir(dir)
  if not fso.FolderExists(dir) then
    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)
end function


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)...