Background
I mentioned in the WizZilla thread that I use the ProjectX post commands to automatically run Avidemux after ProjectX finishes its demux.
Netmask asked how this is done and whether it could be used for other programs like Handbrake or Womble. I'm not familiar with those but if they have command line versions I guess they could use the same technique.
I've split this into a separate thread since it's not really about WizZilla (although I did ask in the WizZilla thread if the Two Wizards could add post commands to WizZilla so I could automatically run ProjectX and Avidemux on each downloaded file).
If you are not already familiar with ProjectX, you should read Netmask's guide to using it with the Wiz
http://www.openwiz.org/wiki/ProjectX
Maybe postprocess commands will end up in that guide?
Currently netmask says "Postprocess: Another tab I haven?t needed to use".
The ProjectX version I'm using is 0.90.4.00, same as Netmask's guide.
ProjectX Postprocessing
In the ProcessWindow (click "prepare>>"), make sure you have "enable post processing" checked under the Edit menu.
To automatically run your favourite encoding program after a demux you enter its full path name in
ProjectX > PreSettings > postprocess > post commands > demux
There is one argument that you can pass to it. If you put a trailing " ?" followed by a number, projectx will replace it with the name(s) of your output file(s).
So ?1 will be the .m2v video file
(?2 passes the second file produced, .ac3 or .mp2, ?0 passes both)
Originally you were not able to directly run a windows batch file from here but could use a windows program launcher like launch.exe and pass it the batch file you want to run and the first ProjectX output file.
Later versions of Java/Windows can run the batch file directly (best to not have any spaces in the path).
So I created a windows batch file SD16x9.cmd which accepts one argument, the m2v file and calls avidemux with my favourite settings to create an avi file.
You can see from the script that I've hard coded the Avidemux settings file as "%APPDATA%\avidemux\custom\SD16x9 to XVID16x9.js"
For someone else to use this they'd have to substitute their own settings file.
I guess it might have been better to have also passed this as an argument.
Code: Select all
@echo off
echo.
IF NOT [%1]==[] GOTO Args
:NoArgs
echo.
echo This script is meant to be run demuxing with ProjectX. To use
echo it, open the PreSettings and on the postprocess demux line put
echo. {pathToThisScript}\SD16x9.cmd ?1
echo. If your Java or Windows version doesn't allow batch commands
echo. to run directly from ProjectX use
echo. "{pathTo}\launch.exe" open "{pathToThisScript}\SD16x9.cmd" ?1
echo.
echo Also, on the ProcessWindow (click "prepare>>"),
echo make sure you have "enable post processing" checked under the Edit menu.
echo.
echo.Update 24/4/2013 Java Development Kit 7 Update 21 changed decoding of command
echo.strings specified to Runtime.exec(String) which resulted in error
echo."java.lang.IllegalArgumentException:
echo.Executable name has embedded quote, split the arguments"
echo.So don't use launch.exe anymore
echo.Changed code to trim quotes off filename
pause
GOTO end
:Args
set STRIPTIN=%~dp0
::the only thing you can pass is a filename, so if there are
::more "args" then assume it's a filename with spaces.
set INFILE=%1
:getname
shift
IF "%1"=="" GOTO gotname
set INFILE=%INFILE% %1
GOTO getname
:gotname
::launch.exe seems to put quotes around the filename
::so trim the double quotes off both ends
for /f "useback tokens=*" %%a in ('%INFILE%') do set INFILE=%%~a
echo. Source File: %INFILE%
:: trim the file extension off the end
set OUTFILE=%INFILE:~0,-4%
echo. Output Base: %OUTFILE%
:: Rename subtitle file if any
IF EXIST "%OUTFILE%[801].srt" MOVE "%OUTFILE%[801].srt" "%OUTFILE%.srt"
:: Rename audio track[1] file if any for ABC1 with two audio tracks
IF EXIST "%OUTFILE%.mp2" GOTO NoRenameAudio
IF EXIST "%OUTFILE%.ac3" GOTO NoRenameAudio
IF EXIST "%OUTFILE%[1].mp2" MOVE "%OUTFILE%[1].mp2" "%OUTFILE%.mp2"
IF EXIST "%OUTFILE%[1].ac3" MOVE "%OUTFILE%[1].ac3" "%OUTFILE%.ac3"
:NoRenameAudio
set AVIDEMUX="C:\Program Files\Avidemux 2.4\avidemux2_qt4.exe"
set ARGS=--load "%INFILE%" --autoindex
:: add the audio track to the Avidemux arguments, prefer MP2 over AC3
IF NOT EXIST "%OUTFILE%.mp2" GOTO NoMP3
set ARGS=%ARGS% --external-mp3 "%OUTFILE%.mp2"
GOTO EndAudio
:NoMP3
IF EXIST "%OUTFILE%.ac3" set ARGS=%ARGS% --external-ac3 "%OUTFILE%.ac3"
:EndAudio
:: add arguments to run a particular script, save as AVI and quit
set ARGS=%ARGS% --run "%APPDATA%\avidemux\custom\SD16x9 to XVID16x9.js" --save "%OUTFILE%.avi" --quit
echo on
IF NOT EXIST %AVIDEMUX% GOTO NoAvidemux
echo. Launching avidemux...
echo %AVIDEMUX% %ARGS%
echo.
%AVIDEMUX% %ARGS%
echo.
:NoAvidemux
:end
::exit
<batchfile_path>\SD16x9.cmd ?1
If that doesn't work with your version of Java/windows try
"<program_path>\Launch.exe" open "<batchfile_path>\SD16x9.cmd" ?1
I have another windows batch file SD4x3.cmd which is almost the same except it crops off the black bars on 4x3 programs. I distinguish the two batch files by saving different ProjectX .ini files with the different post commands and then starting ProjectX with different shortcuts which specify the .ini file with the -ini parameter.
Batch conversion of Wiz recordings using ProjectX collections
To encode multiple Wiz recordings overnight I queue them up using ProjectX collections.
Once you have editted out the unwanted parts of one recording, normally you'd press the QuickStart button. Instead press the + button underneath it in the Collection panel to advance the collection number "coll.#" from 0 to 1. Then you can load a new recording and take out the ads. You can repeat for more recordings. When you have prepared them all, then press QuickStart.
ProjectX will demux each one in turn and launch the postprocess command after finishing each demux. So my Avidemux sessions end up running in parallel which may not be the most efficient method as it chews up more RAM and slows each down but they all finish eventually (I think I've run at least 6 in parallel with no problems). I guess to use other encoders like this you'd have to check if they can be run as multiple parallel instances.
Conclusion
I've saved heaps of time and eliminated many manual errors by automating the Avidemux encoding directly from ProjectX.
Acknowledgement
I learnt how to do this by studying
http://forum.doom9.org/archive/index.php/t-123417.html
Edit 24/4/2013: Java Development Kit 7 Update 21 changed decoding of command strings specified to Runtime.exec(String) which resulted in error
java.lang.IllegalArgumentException: Executable name has embedded quote, split the arguments
So don't use launch.exe anymore, just put this in ProjectX postprocess demux post command
<pathtoscript>\SD16x9.cmd ?1
Changed code to trim quotes off filename since quotes may not be there if launch.exe not used.