Page 1 of 1

Batch script equivalent for conversion on Mac for VLC

Posted: 29 Feb 2012 00:40
by aitte
Hey, I was hoping someone could help me on this issue. I currently use windows for a batch script conversion where I can just drag and drop a video file onto my batch file and it will run the conversion and output the file with the same name. Is it possible to do something similar to this on osx lion? I would like to be able to drag and drop the video file onto the script and allow it to run and output the newly converted video file with the same name. I currently use the latest vlc 2.0 on both systems.

My script is "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" %1 --sout=#transcode{vcodec=h264,vb=800,acodec=mp4a,ab=192,channels=2}:standard{access=file,mux=mp4,dst=%1.mp4}

I understand that the location for vlc will to /Applications/VLC.app/Contents/MacOS/VLC but how can I make the script executable by dragging and dropping the video file.

Im not as proficient on OSX as I am on windows so any help would be much appreciated.

Thank you.

Re: Batch script equivalent for conversion on Mac for VLC

Posted: 01 Mar 2012 01:41
by nkoriyama
AppleScript, droplet

Re: Batch script equivalent for conversion on Mac for VLC

Posted: 01 Mar 2012 02:05
by kemuel
This AppleScript should do the trick:

Code: Select all

on open these_items try process_item(these_items) end try end open -- this sub-routine processes files on process_item(this_item) set full_path to the POSIX path of this_item do shell script "/Applications/VLC.app/Contents/MacOS/VLC" & " '" & full_path & "' --sout=#transcode{vcodec=h264,vb=800,acodec=mp4a,ab=192,channels=2}:standard{access=file,mux=mp4,dst='" & full_path & ".mp4'}" end process_item
Open the AppleScript editor in the Utilities folder. Write the script above. Click the Compile button to check the script. Then save the script as an application. Now you can drop videofiles onto the App and it should open VLC and transcode. At least it should. I haven't tried it since I'm not at home on my own computer.

Re: Batch script equivalent for conversion on Mac for VLC

Posted: 01 Mar 2012 03:48
by aitte
Thank you for taking the time to answer kemual, I tried your script and it does open vlc and add the file but it does not commence the encoding process. Ill try looking into it some more and see why it doesnt begin the process. Any more help would be greatly appreciated however.

Re: Batch script equivalent for conversion on Mac for VLC

Posted: 01 Mar 2012 12:44
by kemuel
I tried it at home and found an error in my code..
So here comes something that works:

Code: Select all

on open these_items try process_item(these_items) end try end open -- this sub-routine processes files on process_item(this_item) set full_path to the POSIX path of this_item do shell script "/Applications/VLC.app/Contents/MacOS/VLC" & " '" & full_path & "' --sout='#transcode{vcodec=h264,vb=800,acodec=mp4a,ab=192}:standard{access=file,mux=mp4,dst=" & full_path & ".mp4}'" end process_item
The change is very subtle so you may not be able to tell the difference between this and the first one.
Actually I just moved the single quotation-marks. I tested this and it works perfectly :)

Re: Batch script equivalent for conversion on Mac for VLC

Posted: 01 Mar 2012 22:23
by aitte
Thank you so so much. It worked perfectly, I cant thank you enough.

Re: Batch script equivalent for conversion on Mac for VLC

Posted: 02 Oct 2013 19:56
by sigbhu
this doesn't work for me. there are to problems:

1) with one file, it runs, and converts it, but then refuses to quit. it just stays there. if I keep VLC open and play the converted file, it is fine, but if i quit VLC, it adds something to the converted file and corrupts it. ( I know because after conversion, if i copy the file, only the original is corrupted and the copy of the converted is fine)

2) if i drag more than one file onto it, it fails. crashes instantly.

Re: Batch script equivalent for conversion on Mac for VLC

Posted: 09 Jan 2014 20:47
by jacky97531
Hi, I have the same problem, when I drag the files onto it, it crashes instantly. Could someone help me with this problem, please?

Thanks!

Re: Batch script equivalent for conversion on Mac for VLC

Posted: 21 Jan 2014 01:52
by Raptor25
The script [/b]WORKS[/b] but only with a single file.

Is there some simple way of allowing it to accept multiple files dropped on it?

Please make any solution easy to understand. I am not a programmer. I did complete a Diploma of IT in 2001 but I learnt only a little programming, and learnt to hate it. Java programming caused me to quit uni a few weeks after starting. Just some background info to let you know I do know computers, but not in the realm of programming.

thank you in advance

Re: Batch script equivalent for conversion on Mac for VLC

Posted: 25 Apr 2021 01:29
by Luiz Siqueira Neto
This code does what you ask, processes more than one file dropped on it. Important: it also moves the original file to the trash, you can recover it if you want.

Code: Select all

on open theDroppedItems repeat with a from 1 to length of theDroppedItems set theCurrentDroppedItem to item a of theDroppedItems try process_item(theCurrentDroppedItem) end try delete_file(theCurrentDroppedItem) end repeat end open -- this sub-routine processes files on process_item(this_item) set full_path to the POSIX path of this_item do shell script "/Applications/VLC.app/Contents/MacOS/VLC" & " '" & full_path & "' --sout='#transcode{vcodec=h264,vb=800,acodec=mp4a,ab=192}:standard{access=file,mux=mp4,dst=" & remove_file_suffix(full_path) & ".mp4}' vlc://quit" end process_item on remove_file_suffix(theText) if length of theText = 0 then error "Can't trim empty text." number -1728 else if length of theText = 1 then return "" else return text 1 thru -5 of theText end if end remove_file_suffix on delete_file(file_to_delete) tell application "Finder" move file_to_delete to trash end tell end delete_file