Magic Lantern Forum

Using Magic Lantern => Raw Video => Raw Video Postprocessing => Topic started by: dubzeebass on September 14, 2013, 09:50:57 PM

Title: Applescript - Postprocessing MLV files on Mac - Script by Nick.P
Post by: dubzeebass on September 14, 2013, 09:50:57 PM
Create a new Applescript, paste this, and save it as an APP.

on run
set these_items to {} as list
set outputfolder to ""
set mlv2dng to (choose file with prompt "Choose the mlv2dng app") as string
set outputfolder to chooseoutputfolder(outputfolder)
set these_items to choosefilesbutton(these_items)
processfileselection(these_items, mlv2dng, outputfolder)
end run
on chooseoutputfolder(outputfolder)
set outputfolder to (choose folder with prompt "Select an output folder:") as list
repeat with i from 1 to (the count of (outputfolder as list))
  set this_item to item i of (outputfolder as list)
  set the item_info to info for (this_item)
  if folder of the item_info is true then
   set outputfolder to POSIX path of outputfolder
  else
   set outputfolder to POSIX path of (container of outputfolder)
  end if
end repeat
return outputfolder
end chooseoutputfolder

on choosefilesbutton(these_items)
set these_items to (choose file with prompt "Choose a file or folder to process. Note: you can select any or all files; only the MVL files will be processed." with multiple selections allowed) as list
return these_items
end choosefilesbutton

on processfileselection(these_items, mlv2dng, outputfolder)
repeat with i from 1 to (the count of (these_items as list))
  set this_item to item i of (these_items as list)
  set the item_info to info for (this_item)
  if folder of the item_info is true then
   processfolder(this_item, mlv2dng, outputfolder)
  else
   processfile(this_item, mlv2dng, outputfolder)
  end if
end repeat

end processfileselection

on processfolder(this_folder, mlv2dng, outputfolder)
set these_items to list folder (this_folder) without invisibles
repeat with i from 1 to (the count of (these_items as list))
  set this_item to (((this_folder as Unicode text) & ((item i of these_items) as Unicode text)) as alias)
  set the item_info to info for this_item
  if folder of the item_info is true then
   processfolder(this_item, mlv2dng, outputfolder)
  else
   processfile(this_item, mlv2dng, outputfolder)
  end if
end repeat
end processfolder

on processfile(this_individual_item, mlv2dnglocation, outputfolder)
set validExtensions to {"MLV"}
set this_extension to "" as string
set AppleScript's text item delimiters to "."
tell application "Finder"
  set n to name of file (this_individual_item)
  if n contains "." then set this_extension to (text item -1 of n) as text
  if n contains "." then set this_name to (text item -2 of n) as text
end tell
tell application "Finder"
end tell
if this_extension is in validExtensions then
  tell application "System Events"
   set thePath to POSIX path of (container of this_individual_item)
  end tell
  set myFile to POSIX path of mlv2dnglocation
  log "got to here"
  set shellscript to "mkdir -p '" & outputfolder & this_name & "'"
  log shellscript
  do shell script shellscript
  log "here"
  set thefirstscript to "cp " & quoted form of myFile & " '" & outputfolder & this_name & "'"
  log thefirstscript
  do shell script thefirstscript
  log "copying"
  set thescript to "cd '" & outputfolder & this_name & "' && '" & outputfolder & this_name & "/mlv2dng' " & quoted form of (POSIX path of this_individual_item)
  log thescript
  do shell script thescript
  do shell script "rm '" & outputfolder & this_name & "/mlv2dng'"
end if
end processfile
Title: Re: Applescript - Postprocessing MLV files on Mac
Post by: nick.p on September 14, 2013, 10:26:50 PM
Is this your code?
Edit: The problem I've discovered with getting the filename using Finder is that it often fails. I've got a script obj-c applescript that I can easily convert to a proper applescript if you want it.
Title: Re: Applescript - Postprocessing MLV files on Mac
Post by: nick.p on September 14, 2013, 11:02:00 PM
Save you the hard work :D
I've got it setting everything via folder prompts but you could change it to hardcoded strings if you wanted to speed things up.

on run
set these_items to {} as list
set outputfolder to ""
set mlv2dng to (choose file with prompt "Choose the mlv2dng app") as string
set outputfolder to chooseoutputfolder(outputfolder)
set these_items to choosefilesbutton(these_items)
processfileselection(these_items, mlv2dng, outputfolder)
end run
on chooseoutputfolder(outputfolder)
set outputfolder to (choose folder with prompt "Select an output folder:") as list
repeat with i from 1 to (the count of (outputfolder as list))
set this_item to item i of (outputfolder as list)
set the item_info to info for (this_item)
if folder of the item_info is true then
set outputfolder to POSIX path of outputfolder
else
set outputfolder to POSIX path of (container of outputfolder)
end if
end repeat
return outputfolder
end chooseoutputfolder

on choosefilesbutton(these_items)
set these_items to (choose file with prompt "Choose a file or folder to process. Note: you can select any or all files; only the MVL files will be processed." with multiple selections allowed) as list
return these_items
end choosefilesbutton

on processfileselection(these_items, mlv2dng, outputfolder)
repeat with i from 1 to (the count of (these_items as list))
set this_item to item i of (these_items as list)
set the item_info to info for (this_item)
if folder of the item_info is true then
processfolder(this_item, mlv2dng, outputfolder)
else
processfile(this_item, mlv2dng, outputfolder)
end if
end repeat

end processfileselection

on processfolder(this_folder, mlv2dng, outputfolder)
set these_items to list folder (this_folder) without invisibles
repeat with i from 1 to (the count of (these_items as list))
set this_item to (((this_folder as Unicode text) & ((item i of these_items) as Unicode text)) as alias)
set the item_info to info for this_item
if folder of the item_info is true then
processfolder(this_item, mlv2dng, outputfolder)
else
processfile(this_item, mlv2dng, outputfolder)
end if
end repeat
end processfolder

on processfile(this_individual_item, mlv2dnglocation, outputfolder)
set validExtensions to {"MLV"}
set this_extension to "" as string
set AppleScript's text item delimiters to "."
tell application "Finder"
set n to name of file (this_individual_item)
if n contains "." then set this_extension to (text item -1 of n) as text
if n contains "." then set this_name to (text item -2 of n) as text
end tell
tell application "Finder"
end tell
if this_extension is in validExtensions then
tell application "System Events"
set thePath to POSIX path of (container of this_individual_item)
end tell
set myFile to POSIX path of mlv2dnglocation
log "got to here"
set shellscript to "mkdir -p '" & outputfolder & this_name & "'"
log shellscript
do shell script shellscript
log "here"
set thefirstscript to "cp " & quoted form of myFile & " '" & outputfolder & this_name & "'"
log thefirstscript
do shell script thefirstscript
log "copying"
set thescript to "cd '" & outputfolder & this_name & "' && '" & outputfolder & this_name & "/mlv2dng' " & quoted form of (POSIX path of this_individual_item)
log thescript
do shell script thescript
do shell script "rm '" & outputfolder & this_name & "/mlv2dng'"
end if
end processfile
Title: Re: Applescript - Postprocessing MLV files on Mac
Post by: dubzeebass on September 15, 2013, 01:40:03 AM
Quote from: nick.p on September 14, 2013, 11:02:00 PM
Save you the hard work :D
I've got it setting everything via folder prompts but you could change it to hardcoded strings if you wanted to speed things up.

on run
set these_items to {} as list
set outputfolder to ""
set mlv2dng to (choose file with prompt "Choose the mlv2dng app") as string
set outputfolder to chooseoutputfolder(outputfolder)
set these_items to choosefilesbutton(these_items)
processfileselection(these_items, mlv2dng, outputfolder)
end run
on chooseoutputfolder(outputfolder)
set outputfolder to (choose folder with prompt "Select an output folder:") as list
repeat with i from 1 to (the count of (outputfolder as list))
set this_item to item i of (outputfolder as list)
set the item_info to info for (this_item)
if folder of the item_info is true then
set outputfolder to POSIX path of outputfolder
else
set outputfolder to POSIX path of (container of outputfolder)
end if
end repeat
return outputfolder
end chooseoutputfolder

on choosefilesbutton(these_items)
set these_items to (choose file with prompt "Choose a file or folder to process. Note: you can select any or all files; only the MVL files will be processed." with multiple selections allowed) as list
return these_items
end choosefilesbutton

on processfileselection(these_items, mlv2dng, outputfolder)
repeat with i from 1 to (the count of (these_items as list))
set this_item to item i of (these_items as list)
set the item_info to info for (this_item)
if folder of the item_info is true then
processfolder(this_item, mlv2dng, outputfolder)
else
processfile(this_item, mlv2dng, outputfolder)
end if
end repeat

end processfileselection

on processfolder(this_folder, mlv2dng, outputfolder)
set these_items to list folder (this_folder) without invisibles
repeat with i from 1 to (the count of (these_items as list))
set this_item to (((this_folder as Unicode text) & ((item i of these_items) as Unicode text)) as alias)
set the item_info to info for this_item
if folder of the item_info is true then
processfolder(this_item, mlv2dng, outputfolder)
else
processfile(this_item, mlv2dng, outputfolder)
end if
end repeat
end processfolder

on processfile(this_individual_item, mlv2dnglocation, outputfolder)
set validExtensions to {"MLV"}
set this_extension to "" as string
set AppleScript's text item delimiters to "."
tell application "Finder"
set n to name of file (this_individual_item)
if n contains "." then set this_extension to (text item -1 of n) as text
if n contains "." then set this_name to (text item -2 of n) as text
end tell
tell application "Finder"
end tell
if this_extension is in validExtensions then
tell application "System Events"
set thePath to POSIX path of (container of this_individual_item)
end tell
set myFile to POSIX path of mlv2dnglocation
log "got to here"
set shellscript to "mkdir -p '" & outputfolder & this_name & "'"
log shellscript
do shell script shellscript
log "here"
set thefirstscript to "cp " & quoted form of myFile & " '" & outputfolder & this_name & "'"
log thefirstscript
do shell script thefirstscript
log "copying"
set thescript to "cd '" & outputfolder & this_name & "' && '" & outputfolder & this_name & "/mlv2dng' " & quoted form of (POSIX path of this_individual_item)
log thescript
do shell script thescript
do shell script "rm '" & outputfolder & this_name & "/mlv2dng'"
end if
end processfile



DUDE YOU ARE THEMAN !!  Linked from the MLV2DNG thread.
Title: Re: Applescript - Postprocessing MLV files on Mac
Post by: Cellulo on September 15, 2013, 12:05:28 PM
@ nick.p,

thanks for the script,
i try it but i get this:

error "sh: line 1:   386 Segmentation fault      '/Users/xxx/Pictures/[ Raw Test ]/MLV Test/M05-1436/mlv2dng' '/Users/xxx/Pictures/[ Raw Test ]/M05-1436.MLV'" number 139

I'm on OSX 10.6.8, i tried several time with different files but always the same results, any clue ?
Also i tried the Mac Gui version  from 8-beeeaaat but it's only for 10.8 and it doesn't run on my mac.

@ dubzeebass
Which is your OS ?
Does work for you ?

Thanks for your efforts
Cellulo
Title: Re: Applescript - Postprocessing MLV files on Mac
Post by: dubzeebass on September 15, 2013, 12:14:22 PM
ML. Do you have a link to the GUI version?
Title: Re: Applescript - Postprocessing MLV files on Mac
Post by: Cellulo on September 15, 2013, 03:39:13 PM
Thx dubzeebass,

Another thing i noticed, the script is creating a copy of mlv2dng in the folder i've made for the dng files.

Here the AppleScript GUI
(http://img534.imageshack.us/img534/2355/mkx3.jpg)

I try to run the script on a MacBookPro 2,4Ghz C2D, 10.6.8
I run the laste TragicLatern build from Andy600 (Tragic_Lantern_50D109-Andy600.Build.2013Sep08.zip)

Title: Re: Applescript - Postprocessing MLV files on Mac
Post by: dubzeebass on September 15, 2013, 07:46:18 PM
All I can think is that maybe it's the [ ] brackets?  Try without.
Title: Re: Applescript - Postprocessing MLV files on Mac
Post by: Cellulo on September 16, 2013, 09:54:33 AM
I tried to remove brackets (no other brackets in the path) but same problem happens,
see below

(http://img21.imageshack.us/img21/1514/0fio.jpg)

I tried the script on a MacPro 2,1 (10.6.8) and got the same problem

Thx
eric
Title: Re: Applescript - Postprocessing MLV files on Mac
Post by: a1ex on September 16, 2013, 09:59:37 AM
The segmentation fault is likely caused by mlv2dng. An easy way to diagnose this kind of errors is to run the program under valgrind. If you compile it without optimization and with -ggdb, it will be a lot easier for valgrind to show the exact source of the problem.
Title: Re: Applescript - Postprocessing MLV files on Mac
Post by: Cellulo on September 16, 2013, 10:54:23 AM
Thanks a1ex,
i'm not a dev, i downloaded valgrind and i tried it,
this app sounds like a UFO for me... i didn't understand nothing (i read FAQ and Quick Start Guide)
I am sorry and i would love to give the best info to solve the problem but it's to far from me.
How can i help in antoher way ?
Is there another way to convert MLV in OSX 10.6.8 ?
thx
eric
Title: Re: Applescript - Postprocessing MLV files on Mac
Post by: a1ex on September 16, 2013, 10:59:26 AM
You can upload a sample video that crashes (1-2 seconds).

I don't use a mac, so I can't help you here. But anyone who can compile mlv2dng should be able to look into it.
Title: Re: Applescript - Postprocessing MLV files on Mac
Post by: Cellulo on September 16, 2013, 02:24:51 PM
Thx a1ex,
here is a link where you can download short MLV footage from my 50D:
http://we.tl/IAvDaSTiWk (http://we.tl/IAvDaSTiWk)
Title: Re: Applescript - Postprocessing MLV files on Mac - Script by Nick.P
Post by: Cellulo on September 18, 2013, 06:45:15 PM
@dubzeebass+nick.p
I need a little help, could you try to convert the MLV file i've uploaded (link in my last post) in your mac cause a1ex told that he haven't a mac ?
Got lot of project working on 10.6.8 for the moment but i will migrate to 10.7 soon (last OS available for a MacPro 2,1), but for the moment i would love to test the MLV format.
Many thx