Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

QuickTime Pro Scripting - Audio Channel Mapping

Does anyone know if there is a way to script audio channel mapping and renaming in QuickTime Pro 7? I deal with a lot of 5.1 audio that needs to be channel mapped and renamed to its specific channel for iTunes uploading. I'm currently doing this task manually in QuickTime Pro, but I'd love to know if there is a possibility to automate this task. I'm new to scripting, and its been very helpful with a lot of my day to day tasks, but I can't seem to figure this one out. Any suggestions would be awesome! Thanks!

Mac Pro, OS X Mountain Lion (10.8.5)

Posted on Mar 5, 2014 8:33 PM

Reply
14 replies

Mar 19, 2014 10:21 AM in response to Millerpmiller

QuickTime scripting is on the outer fringe, not a lot of people do it. On top of that the work you are doing is a bit specialized, not even sure how you would do that from the App (or what you are exactly doing 😀) .


However if you were to explain in a bit of detail your workflow and how you do it in the app and what you have done with Applescript that doesn't work or comes close some help might be offered.


Same to the second poster, however you might want to start your own thread for this to keep things from getting cluttered.


regards

Mar 19, 2014 11:03 AM in response to Frank Caggiano

Workflow:

1. Open a ProRes file in Quicktime Pro 7. (This file is usually a 444 with 8 channels of audio - 5.1 + Stereo)

2. Command J opens the Properties window of the source and displays the settings for the video track as well as all 8 audio tracks.

User uploaded file

3. Manually remap audio channels to match the specific configuration of the mix. Ch.1-Left, Ch.2-Right, Ch.3-Center, Ch.4-LFE Screen, etc.

4. Rename each specific channel in the track naming column.

User uploaded file

5. Save the file as is.


Its strange to me that this is considered "specialized." I post to both itunes and netflix and both will kick back if these configurations aren't being remapped and renamed exactly to spec. If I were only doing one offs it wouldn't be a concern, but I'm having to remap sometimes 30 or 40 versions and if there is any spelling errors or inconsistency I get kick back.


Please help!


Thanks!

Mar 19, 2014 11:30 AM in response to Millerpmiller

I must be missing something but I don;t see how you are getting the information for the renaming. How do you know Sound Track 1 is Right or Left or whatever?


Also when I said this is 'specialized' I wasn't referring to the work you are doing here (I''m sure it is common) I was referring to the scripting of QT especially for something like this.


Would it be possible to put one of these files in dropouts or somewhere I could get at it (or it they are large a stripped down version) for testing?


Also have you tried to write any scripts yet? Anything come close?


regards


Message was edited by: Frank Caggiano - Also could you include the column headers in a screen shot. The info window I get for movies seems somewhat different the the ones you show for audio.

Mar 20, 2014 12:48 AM in response to Millerpmiller

Hello


If I understand it correctly, you may try something like the script below. You may run it in AppleScript Editor.app and choose source file(s) when asked or save it as an applet and drag-and-drop source file(s) onto it.


The script will overwrite the original file and so please make sure you have backup of the original file in advance.


Hope this may help,

H


on run
    open (choose file with prompt "Choose source file(s)" with multiple selections allowed)
end run

on open ff
    repeat with f in ff
        remap_sound_tracks_name(f's POSIX path)
    end repeat
end open

on remap_sound_tracks_name(f)
    (*
        string f : POSIX path of source movie file
    *)
    script o
        on map(n)
            set mm to {¬
                {"Sound Track 1", "Left"}, ¬
                {"Sound Track 2", "Right"}, ¬
                {"Sound Track 3", "Center"}, ¬
                {"Sound Track 4", "LFE Screen"}, ¬
                {"Sound Track 5", "Left Surround"}, ¬
                {"Sound Track 6", "Right Surround"}, ¬
                {"Sound Track 7", "Left Total"}, ¬
                {"Sound Track 8", "Right Total"} ¬
                    }
            repeat with m in mm
                if m's item 1 = n then return m's item 2
            end repeat
            return n
        end map
        
        set f to f as POSIX file
        tell application id "com.apple.quicktimeplayer" -- QuickTime Player 7
            set dc to count documents
            open f
            repeat until (count documents) > dc
                delay 0.2
            end repeat
            tell document 1
                repeat with t in (get tracks whose audio channel count > 0)
                    set t to t's contents
                    set n to t's name
                    set n1 to my map(n)
                    if n1 ≠ n then set t's name to n1
                end repeat
                if modified then save
                close
            end tell
        end tell
    end script
    tell o to run
end remap_sound_tracks_name

Apr 2, 2014 1:04 PM in response to Hiroto

Hi, this nearly does what I want, but instead of changing the 'name' column of each audio track, I'm looking at changing the 'Channel' column of each audio track, so instead of each of the 8 mono audios being all caled 'mono' I need applescript to change them from Mono to Left, Right, Center, LFE, Left Surround, Right Surround, Left Total, Right Total. Sometimes the last two track, left total right total are two seperate mono's and sometimes they are a stereo pair. If someone could help I would be veryb gratefull.


Kind regards.

Apr 9, 2015 8:15 AM in response to Hiroto

Hello Hiroto !


I've been reading through your work on this forum and I'm encountering a situation similar to speedyrazor's.

You seem to write relly good scripting, so I was wondering if you could help me :


I'm receiving Quicktime files with 4 audio channels.

Each channel is currently set to "Mono".

I'd like channel 1 and 2 to be set to "Unused" while channel 3 and 4 remain on "Mono".


I'm new to scripting and tried to work from some scripts you wrote on this forum but without success.

If you could help me, I would be very gratefull.


Best regards.

Apr 10, 2015 10:29 PM in response to Chris_Evrard

Hello


A QT file contains sound tracks and a sound track contains audio channels.


If you mean your QT file has 4 sound tracks each of which contains one audio channel marked as "Mono", you may try the following script. Please make sure you have complete backup of files in advance, for this script will overwrite the files.


Script is basically the same as the one posted in the following thread except for the channel_layouts_map definition.


Quicktime Pro Applescript - Assign audio channels

https://discussions.apple.com/thread/6055790



Notes.


* You need to have QuickTime Player 7 Pro. QuickTime X Player is useless for this.


* You need to enable GUI scripting.


cf.

OS X: Using AppleScript with Accessibility and Security features in Mavericks

http://support.apple.com/kb/HT5914



Briefly tested with QuickTime Player Pro 7.6.6 (1710) (QuickTime version 7.6.6 (1800)) under OS X 10.6.8.


Good luck,

H




on run open (choose file with prompt ("Choose movie file(s)") ¬ of type {"com.apple.quicktime-movie", "public.mpeg-4"} ¬ with multiple selections allowed) end run on open aa (* set channel_layouts_map1 to {¬ {1, 1, {"Unused"}}, ¬ {2, 2, {"Unused"}}, ¬ {3, 3, {"Mono"}}, ¬ {4, 4, {"Mono"}} ¬ } *) set channel_layouts_map1 to {¬ {1, 1, {"Unused"}}, ¬ {2, 2, {"Unused"}} ¬ } repeat with a in aa set f to a's POSIX path set k to count_sound_tracks(f, {_close:false}) if k = 4 then remap_audio_channels(f, channel_layouts_map1) else -- ignore it (just close it) close_document(f, {_save:false}) end if end repeat end open on count_sound_tracks(f, {_close:_close}) (* string f : POSIX path of QT movie boolean _close: true to close document, false othewise *) tell application id "com.apple.quicktimeplayer" -- QuickTime Player 7 Pro open (f as POSIX file) tell (document 1 whose path = f) repeat until exists delay 0.2 end repeat set k to count (tracks whose audio channel count > 0) if _close then close end tell end tell return k end count_sound_tracks on close_document(f, {_save:_save}) (* string f : POSIX path of QT movie boolean _save: true to save document (if modified), false othewise *) tell application id "com.apple.quicktimeplayer" -- QuickTime Player 7 Pro tell (document 1 whose path = f) if exists then if _save and modified then save close end if end tell end tell end close_document on remap_audio_channels(f, channel_layouts_map) (* string f : POSIX path of source movie list channel_layouts_map : list of {trk, trk_new, layouts} trk = (string or integer) name or index of source sound track trk_new = (string or integer) new name for source track (integer i denotes original name of sound track i) layouts = list of audio layout for channel(s) in source sound track Mono Left Right Center LFE Screen Left Surround Right Surround Left Center Right Center Center Surround Rear Surround Left Rear Surround Right Left Total Right Total Discrete-0 Discrete-1 Unused e.g. 1 {{"Sound Track 1", "Left", {"Left"}}, ¬ {"Sound Track 2", "Right", {"Right"}}, ¬ {"Sound Track 3", "Center", {"Center"}}, ¬ {"Sound Track 4", "LFE Screen", {"LFE Screen"}}, ¬ {"Sound Track 5", "Left Surround", {"Left Surround"}}, ¬ {"Sound Track 6", "Right Surround", {"Right Surround"}}, ¬ {"Sound Track 7", "Left Total", {"Left Total"}}, ¬ {"Sound Track 8", "Right Total", {"Right Total"}}} e.g. 2 {{1, 1, {"Left", "Right"}}, ¬ {2, 2, {"Center", "LFE, Screen"}}, ¬ {3, 3, {"Left Surround", "Right Surround"}}, ¬ {4, 4, {"Left Total", "Right Total"}}} * this handler behaves as follows: 1) open f 2) scan sound tracks of document 1 for each trk and remap the track's audio channel layouts as specified 3) scan sound tracks of document 1 for each trk and rename the track as specified 4) save and close document 1 * if specified trk is not found, it is ignored and no remapping is performed on the track. * if specified layout is not found, it is ignored and no remapping is performed on the layout. * if specified layout count is greater than channel count of the target track, excessive layouts are ignored. * if specified layout count is smaller than channel count of target track, excessive channels are ignored. * if trk and trk_new denotes the same track, renaming is not performed on the track. *) script o property map : channel_layouts_map property pp : {} property qq : {} -- get name and id of sound tracks tell application id "com.apple.quicktimeplayer" -- QuickTime Player 7 Pro activate open (f as POSIX file) tell (document 1 whose path = f) repeat until exists delay 0.2 end repeat tell (tracks whose audio channel count > 0) set {pp, qq} to {name, id} -- name and id of sound tracks end tell end tell end tell -- remap audio channel layouts as specified tell application "System Events" tell (process 1 whose bundle identifier = "com.apple.quicktimeplayer") -- open movie properties window keystroke "j" using {command down} tell (window 1 whose subrole = "AXDialog") -- properties for movie repeat until exists delay 0.2 end repeat repeat with m in my map set {trk, undef, layouts} to m -- [TRK: repeat 1 times if trk's class = integer then if trk < 1 or trk > (count my pp) then exit repeat -- TRK: set trk to my pp's item trk end if tell scroll area 1 tell table 1 tell (row 1 whose text field 1's value = trk) -- target sound track whose name = trk if not (exists) then exit repeat -- TRK: select end tell end tell end tell tell tab group 1 click radio button 3 -- audio settings tell scroll area 1 tell table 1 -- channel assignment table set ix to count layouts repeat with i from 1 to count rows if i > ix then exit repeat tell row i -- channel i tell pop up button 1 click tell menu 1 -- channel assignment menu tell (menu item 1 whose title = layouts's item i) if exists then click end tell end tell end tell end tell end repeat end tell end tell end tell end repeat -- /TRK:] end repeat -- close movie properties window click (button 1 whose subrole = "AXCloseButton") end tell end tell end tell -- rename sound tracks as specified tell application id "com.apple.quicktimeplayer" tell document 1 repeat with m in my map -- [RENAME: repeat 1 times set {x, y} to m's items 1 thru 2 -- {old name or index, new name or index} if x's class = integer then if x < 1 or x > (count my pp) then exit repeat -- RENAME: else set x to my _index_of(pp, x) if x = 0 then exit repeat -- RENAME: end if if y's class = integer then if y < 1 or y > (count my pp) then exit repeat -- RENAME: set y to my pp's item y end if set p to my pp's item x set q to my qq's item x if p ≠ y then set track id q's name to y end repeat -- /RENAME:] end repeat if modified then save close end tell end tell end script --tell o to run run script o end remap_audio_channels on _index_of(xx, x) (* list xx : source list anything x : item to be searched in xx return integer : the first index of x in xx if {x} is in xx, or 0 if not. *) script o property aa : xx local i, j, k if {x} is not in my aa then return 0 set i to 1 set j to count my aa repeat while j > i set k to (i + j) div 2 if {x} is in my aa's items i thru k then set j to k else set i to k + 1 end if end repeat return i end script tell o to run end _index_of

Apr 11, 2015 11:54 AM in response to Hiroto

Hi !


Thank you very much for your quick response !


I'm sorry I wasn't clear about the audio tracks on my first message, those are indeed QT files with 1 audio track containing 4 channels.

Is it complicated to alter your script in that purpose ?

So audio track 1 would have : channel 1 and 2 set to "Unused", channel 3 and 4 set to "Mono".


In advance, a big thank you for your time.


Best regards,

Apr 11, 2015 8:31 PM in response to Chris_Evrard

Hello


Then you may replace the open handler with the following one. Currently it will only change the first two audio channels to "Unused" and leave the rest alone. If you want to make sure the rest two to be "Mono", use the first channel_layouts_map1 definition currently commented out.



on open aa (* set channel_layouts_map1 to {¬ {1, 1, {"Unused", "Unused", "Mono", "Mono"}} ¬ } *) set channel_layouts_map1 to {¬ {1, 1, {"Unused", "Unused"}} ¬ } repeat with a in aa set f to a's POSIX path set k to count_sound_tracks(f, {_close:false}) if k = 1 then remap_audio_channels(f, channel_layouts_map1) else -- ignore it (just close it) close_document(f, {_save:false}) end if end repeat end open



Regards,

H

Apr 13, 2015 12:34 PM in response to Hiroto

Hello dear,


I tested the script this evening and it works like a charm !

I replaced the open handler as you advised and the script allows Quicktime to automatically change channel layout.

Great job !

It is going to save me a lot of time treating those files.


I was wondering about one thing : when the files are opened, I still have to press "command + J" myself to open the Properties window.

Is it due to the fact that I'm using an european keyboard ?

The keystroke command is : keystroke "j" using {command down}

Is there a way to make it automatic ?


Anyway, the scripts is already extremely handy !


A big thank you for your help !


Best regards,

Apr 15, 2015 9:52 AM in response to Chris_Evrard

Sorry for late reply.


Well, that's strange. The keystroke command successfully opens movie properties window here under 10.6.8.


Since you can open the movie properties window by manually pressing command + j and resume the script when it stalls, it means script is just waiting for movie properties window to come into existence.


The first thing I'd try is to repeat the keystroke in script, which should do no harm because command + j does nothing when movie properties window is already open.


E.g., replace this part in remap_audio_channels() handler:



-- remap audio channel layouts as specified tell application "System Events" tell (process 1 whose bundle identifier = "com.apple.quicktimeplayer") -- open movie properties window keystroke "j" using {command down} tell (window 1 whose subrole = "AXDialog") -- properties for movie repeat until exists delay 0.2 end repeat



with this:



-- remap audio channel layouts as specified tell application "System Events" tell (process 1 whose bundle identifier = "com.apple.quicktimeplayer") -- open movie properties window keystroke "j" using {command down} delay 0.2 # added keystroke "j" using {command down} # added tell (window 1 whose subrole = "AXDialog") -- properties for movie repeat until exists delay 0.2 end repeat



or even with something like this:



-- remap audio channel layouts as specified tell application "System Events" tell (process 1 whose bundle identifier = "com.apple.quicktimeplayer") -- open movie properties window repeat 3 times # added; adjust the repeat count as is needed keystroke "j" using {command down} delay 0.2 # added end repeat tell (window 1 whose subrole = "AXDialog") -- properties for movie repeat until exists delay 0.2 end repeat




I don't like this sort of unreasonable ad-hoc coding but it is often required when scripting application via UI.


Good luck,

H

QuickTime Pro Scripting - Audio Channel Mapping

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.