2008-03-30, 03:34 PM
I had a look around for automated transcoding solutions and found them to either overkill:eek: or underkill, hence this is what I came up with.
It uses the following steps
Step 1. - postprocessing.bat to write recorded filename to a file containing a a list of files for processing. This is referred to as the queue.
Step 2. - run a batch file at low priority at scheduled time using scheduler. The scheduler to abort the batch after ? number of hours.
batch is called with:
Step 3. the batch will loop through each file in the queue and process it;
Step 4 - check to see if the in or out files exist
Step 5. - determine the crop size and scale size. First get the length and divide by 20. Then using mencoder, step through first frame of each of the 20 blocks to determine the optimum crop size. The scale size auomatically determined to be aspect and divisible by 16. This is what the :-10 does.
Step 6. then run mencoder to transcode/process the files
Step 7. if success, change the file name and delete the original; note the xml is about keeping the xml file stuff which is stored as a seperate stream by GB
Step 8.
if transcode failed, just cleanup
Step 9. cleanup. remove the just processed file name from the queue file and delete temporary files.
Does anyone having any further suggestions for improving it. Remember this is intended as strictly simplistic. Anything more complex, will defeat what I am trying to achieve,
Things I would like to do next:
- before processing, check if another instance of the batch is running and if so, abort.
- avoid scaling during transcoding, this should be done during decoding but most decoders dont seem do this properly with AVI files. I have tried using autoaspect parameter in mencoder but not sure if it is working?
Notes; what I like about this is;
if the transcoding fails it skips over it, and does not reattempt it.
If the transcoding is interupted (say a reboot), it will start again for that file to be processed.
It only deletes the file after the transcoding has been completed.
It uses the following steps
Step 1. - postprocessing.bat to write recorded filename to a file containing a a list of files for processing. This is referred to as the queue.
Code:
@echo "%~1" >> "c:\batch\transcode.txt"
Step 2. - run a batch file at low priority at scheduled time using scheduler. The scheduler to abort the batch after ? number of hours.
batch is called with:
Code:
%windir%\system32\cmd.exe /c start "transcodeit3" /min /low "C:\batch\transcodeit3.cmd"
Step 3. the batch will loop through each file in the queue and process it;
Code:
cd "%_mplayerpath%"
copy "%_quepath%transcode.txt" "%_quepath%transcode.tmp"
for /f "delims==" %%a in ('type ^"%_quepath%transcode.tmp^"') do call :process %%a
del "%_quepath%transcode.tmp"
goto :eof
Step 4 - check to see if the in or out files exist
Code:
:process
@echo %date% %time% "MESSAGE:processing %~1" >> "%_logpath%transcode.log"
if not exist "%~1" @echo %date% %time% "ERROR:%~1 not found;abort transcode" >> "%_logpath%transcode.log" & goto :failed
if exist "%~dpn1.avi" @echo %date% %time% "ERROR:%~dpn1.avi already exists;abort transcode" >> "%_logpath%transcode.log" & goto :failed
if exist "%~dpn1.new.avi" @echo %date% %time% "WARNING: %~dpn1.new.avi already exists;try again..." >> "%_logpath%transcode.log"
Step 5. - determine the crop size and scale size. First get the length and divide by 20. Then using mencoder, step through first frame of each of the 20 blocks to determine the optimum crop size. The scale size auomatically determined to be aspect and divisible by 16. This is what the :-10 does.
Code:
:identifyit
"%_mplayerpath%mplayer.exe" "%~1" -msglevel all=0:identify=6 -vo null -frames 1 > "%_logpath%%~n1.info"
FOR %%p in ("ID_") DO (
FOR /f "usebackq tokens=1*" %%g in (`findstr %%p "%_logpath%%~n1.info"`) DO SET "%%g %%h"
)
@echo %date% %time% "MESSAGE:length is %ID_LENGTH%" >> "%_logpath%transcode.log"
set /A _showlength=%ID_LENGTH%
set /A _steps=_showlength / 20
"%_mplayerpath%mplayer.exe" "%~1" -vf cropdetect -nosound -vo null -frames 20 -sstep %_steps% > "%_logpath%%~n1.crop"
FOR /f "usebackq tokens=5-8 delims==:^)" %%g in (`find ^"[CROP]^" ^"%_logpath%%~n1.crop^"`) DO (
(set _cx=%%g:%%h:%%i:%%j)
(set _sx=%%g)
)
(set _crop=%_cx%)
(set _scale=%_sx%:-10)
Step 6. then run mencoder to transcode/process the files
Code:
"%_mencoderpath%mencoder.exe" "%~1" -vf pullup,softskip,pp=fd,crop=%_crop%,scale=%_scale%,hqdn3d,harddup -profile %_profile% -o "%~dpn1_new.avi"
if errorlevel 1 goto :failed
Step 7. if success, change the file name and delete the original; note the xml is about keeping the xml file stuff which is stored as a seperate stream by GB
Code:
:success
@echo %date% %time% "MESSAGE:transcode OK" >> "%_logpath%transcode.log"
more < "%~1:metadata.xml" > "%~dpn1_new.avi:metadata.xml"
move "%~dpn1_new.avi" "%~dpn1.avi"
del "%~1"
goto :cleanup
Step 8.
if transcode failed, just cleanup
Step 9. cleanup. remove the just processed file name from the queue file and delete temporary files.
Code:
:cleanup
@echo %date% %time% "MESSAGE:doing cleanup" >> "%_logpath%transcode.log"
find /v "%~1" < "%_quepath%transcode.txt" > "%_quepath%transcode.new"
del /q "%_quepath%transcode.txt"
move "%_quepath%transcode.new" "%_quepath%transcode.txt"
del /q "%~dpn1_new.avi"
del /q "%_logpath%%~n1.crop"
del /q "%_logpath%%~n1.info"
goto :eof
Does anyone having any further suggestions for improving it. Remember this is intended as strictly simplistic. Anything more complex, will defeat what I am trying to achieve,
Things I would like to do next:
- before processing, check if another instance of the batch is running and if so, abort.
- avoid scaling during transcoding, this should be done during decoding but most decoders dont seem do this properly with AVI files. I have tried using autoaspect parameter in mencoder but not sure if it is working?
Notes; what I like about this is;
if the transcoding fails it skips over it, and does not reattempt it.
If the transcoding is interupted (say a reboot), it will start again for that file to be processed.
It only deletes the file after the transcoding has been completed.