View Full Version : x264+aac+mkv Batcher v0.18 ;)
redfordxx
1st December 2011, 17:36
EDIT: I deleted my questions in this first post and I am adding fruits of my work (with huge help of guys in this thread) for whoever might wanna use it.
Updates
Hi, guys, muxing stopped to work after I upgraded mkvmerge. Just letting you know, before I figure it out and publish update. Probably some change in CLI syntax, which is really not what I would expect.
Batch VAMD.18.rar (http://www.mediafire.com/?edl5ml9a62fu9hx) + ini-file, sourcefilter-file, lot of small improvements
Batch VAMD.15.rar (http://www.mediafire.com/?dcnt1k47s1gu4qz)
What it does:
- gets filelists with name like list23.txt, where 23 is desired encoding quality (in the list can be various types of video files and also *.avs files!)
- processes the listed files in "test"or "full" mode as set at the beginning of the batchfile
- autocrops video
- resizes video to mod16 or whatever mod you like
- encodes with x264 at constant quality according your wish
- logs parameter to adjustments file where it can be overriden for the next pass (for example autocrop is applied only first pass, next time it uses parameters from the adjustments file)
- converts audio to 48000kHz
- encodes with neroaacenc
- removes the (annoying and everywherebeing) neroaacenc delay, so the audio and video are perfectly in sync (unless there is other reason for being out of sync)
- muxes audio and video to mkv
- deletes some intermediate files
- creates lot of files with lot if info, warnings and error reports (thats why I recommend it to run from empty directory)
What it does not...todo's?:
- MPEG2Source not yet implemented (could be done via directsource but I would prefer not to, but I havent figured that yet ...maybe something like Call (DGDecode)?)
- aspect ratio not kept if the source is anamorph...need to get that info from mediainfo and feed it to avs somehow
- additional filtering and deinterlacing
NEEDS:
bat:neroaacenc, x264, mkvtoolnix, wavi,
avs:Autocrop,masktools2,RedAverage
FIRST TIME:
put files to some directory where you'll keep it safe.
In Batch VAMD.18.bat replace the path to VAMD.ini.bat file, in the VAMD.ini.bat file set all the parameters relevant for your comp.
USAGE:
1. create file list to encode (you can use make_dirs.bat for that purpose)
2. split the list into files named list??.txt (like list20.txt, list25.txt) where ?? stands for encoding quality
3. in the beginning of the ini file write SET process="test"
this will enable fast first run to create encoded samples of the sources
4. run the batch file (the batch produces video and various other files) (lists need to be in current directory)
5. look on the results. If you are not satistied you can override values of processing for each file in SourceFilter.avsi and adjustmentsX_?.avsi
look also into file dim*.txt where you see some warnings and report and also look into other files produced in the working directory.
6. change the values in SourceFilter.avsi and adjustmentsX_?.avsi if necessary, change SET process="full" and run again, and again and again (or you can run test twice)
7. if you wanna reencode some file, you need to delete it
8. if there was error encoding a file, the excact avs script which caused the error is copied to the source file directory and you can open it in some previewer and editor to see what happened. Mostly the problem is codecs if tyou have some exotic source.
9. the automatically created adjustmentsX_?.avsi format is basically set of avisynth expressions delimited with $$ so feel free to write there whatever you want if you know the consequence. It is applied immediately after opening the file, cropping and everything else happens after.
10. the automatically created SourceFilter.avsi format is source filter decided in form of string strSF="FFVideoSource(srcfile, threads=1)" etc to eval()
EXAMPLE 1:
You have lot of videos from your digital camera. You run in test mode and for each file is created line in adjustmentsX. But, one of your video you were shooting with camera vertically (turned 90 degree). So, you find the line for that specific video, change it as below. If you are not sure, you can delete the sample video and run again.
"cl=0 $$ ct=0 $$ cr=0 $$ cb=0 $$ modx=16 $$ mody=8 $$ maxwidth=1280 $$ fpsn=1000000 $$ fpsd=33333 $$ ovrsize=0 $$ logadj=0 $$ ACMode=-1 $$ " #before
"TurnRight() $$ cl=0 $$ ct=0 $$ cr=0 $$ cb=0 $$ modx=16 $$ mody=8 $$ maxwidth=1280 $$ fpsn=1000000 $$ fpsd=33333 $$ ovrsize=0 $$ logadj=0 $$ ACMode=-1 $$" #after
FILE FORMAT:
cl=0 $$ ct=0 $$ cr=0 $$ cb=0 $$ modx=16 $$ mody=8 $$ maxwidth=1280 $$ aw2=640 $$ ah2=360 $$ aw3=640 $$ ah3=360 $$ fpsn=22800 $$ fpsd=1001 $$ ovrsize=0 $$ logadj=0 $$ ACMode=-1 $$ # showcrop=1
crop... modulo dim... downsize? display dim... resize dim... framerate... size override? log this line again? autocrop?
CUSTOMIZATION OF SOURCE FILTER:
It you wanna change the way the script reads input video you have three options:
1. Change SourceFilterTmp.txt - here is how is source handled by default.
2. Change function ChooseMediaFilter() in video_processing_fileX.txt. This is how the video is handled if there is no default settings in 1. or if there was error and retryerr=true in the ini file.
3. Change SourceFilter.avsi which is the file imported during processing. For example add lines like this (strSF should contain the source filter):
strSF=(srcfile!="path1.mp4") ? strSF
\ : "DirectShowSource(srcfile)"
strSF=(srcfile!="path2.mpg") ? strSF
\ : "MPEG2Source(path2.d2v)"
CUSTOMIZATION OF PROCESSING:
1. You can change adjustmentsX_?.avsi in following way: Find the line which is related to particular source you want to process differently and you can:
a) change crop via c?=x
b) change modulo resizing via mod?=x
c) AssumeFPS via setting fps?=x
d) override resizing via a??=x and setting ovrsize=1
e) enable autocrop with ACMode=0
f) add any avs commands to the line separated by $$ as in example 1
g) enable to log new parameters to the file with logadj=1 (this will override the settings in f)
Running these changes is recommended in test mode first.
2. Change video_processing_fileX.txt preferably in the dedicated area, like #[universal progressive filtering here] etc
mbcd
1st December 2011, 17:41
I searched such way too.
You can go another way.
Make a fixed name for videofile in avs-script e.g. "video.wmv".
When you want to convertt a file copy them into dir with avs-script and rename it to "video.wmv".
For this example it works, but of course not for other parameters in your avs-script.
gyth
1st December 2011, 18:25
for %%A in (*.wmv) do call :encode %%A
goto:eof
:encode
:: %1 - file to encode
(
echo FFVideoSource^("%1", threads=1^)
type basic_processing_file.txt
) > tmp.avs
"C:\Program Files (x86)\MeGUI\tools\x264\x264_64.exe" --crf 23.0 --output "%~n1.mkv" tmp.avs
goto:eof
redfordxx
1st December 2011, 18:27
When you want to convertt a file copy them into dir with avs-script and rename it to "video.wmv".
For this example it works, but of course not for other parameters in your avs-script.
Interesting...do you maybe happen to have still somewhere the batch file or something you used handy as a starting example for me?
redfordxx
1st December 2011, 22:27
for %%A in (*.wmv) do call :encode %%A
goto:eof
:encode
:: %1 - file to encode
(
echo FFVideoSource^("%1", threads=1^)
type basic_processing_file.txt
) > tmp.avs
"C:\Program Files (x86)\MeGUI\tools\x264\x264_64.exe" --crf 23.0 --output "%~n1.mkv" tmp.avs
goto:eof
OMG :confused: I have to take day off on this... ;-)
gyth
2nd December 2011, 00:49
for %%A in (*.wmv) do call :encode %%A
*.wmv makes a list of all the .wmv files in the directory the batch file is called from.
The for loop calls the encode function on each of the files.
goto:eof
This indicates that the main function is done.
:encode
This is a label, it marks the start of the encode function.
:: %1 - file to encode
This is a comment, it indicates that the function has one argument, the file to be encoded.
(
This marks the start of a block.
echo FFVideoSource^("%1", threads=1^)
This is the first line of your "generalVideoscript.avs" file.
%1 is one of the file names being passed in from the for loop.
type basic_processing_file.txt
Instead of echoing each line of "#some basic processing here", just have it in a text file.
) > tmp.avs
This closes the block and catches any output to the tmp.avs file.
"C:\Program Files (x86)\MeGUI\tools\x264\x264_64.exe" --crf 23.0 --output "%~n1.mkv" tmp.avs
This gets x264 to encode the .avs we just made.
%~n1 is the base name of the .wmv, the base name of File1.wmv is File1
goto:eof
This ends the function.
redfordxx
2nd December 2011, 16:28
Thank you, the most confusing was goto:eof, I assumed it means goto endoffile.
So, I guess when it is in function, it returns to the calling place, right?
redfordxx
2nd December 2011, 17:10
So I ended up with following script, which does the job.
del all.log
for %%A in (*.wmv) do call :encode %%A
goto:eof
:encode
:: %1 - file to encode
echo ****************************************************************************** >> all.log
echo %1 >> all.log
echo ****************************************************************************** >> all.log
echo * >> all.log
echo * >> all.log
(
echo LoadPlugin^("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2-x64.dll"^)
echo FFIndex^("%1"^)
echo FFVideoSource^("%1", threads=1^)
type basic_video_processing_file.txt
) > tmp.avs
(
echo LoadPlugin^("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2.dll"^)
echo FFIndex^("%1"^)
echo FFAudioSource^("%1", 0^)
type basic_audio_processing_file11.txt
) > tmpa.avs
"C:\Program Files (x86)\MeGUI\tools\x264\x264_64.exe" --crf 23.0 --bframes 8 --b-adapt 2 --ref 8 --qpmin 10 --qpmax 51 --subme 10 --partitions all --trellis 2 --sar 1:1 --output "%~n1.video.mkv" tmp.avs >> all.log
"C:\Program Files (x86)\MeGUI\tools\besplit\wavi.exe" "tmpa.avs" - | "C:\Program Files (x86)\MeGUI\tools\neroaacenc\neroaacenc.exe" -q 0.15 -if - -of "%~n1.audio.mp4" >> all.log
"C:\Program Files (x86)\MeGUI\tools\mkvmerge\mkvmerge.exe" -o "%~n1.new.mkv" "--language" "1:eng" "--default-track" "1:yes" "--forced-track" "1:no" "-d" "1" "-A" "-S" "-T" "--no-global-tags" "--no-chapters" "%~n1.video.mkv" "--sync" "1:-128" "--forced-track" "1:no" "-a" "1" "-D" "-S" "-T" "--no-global-tags" "--no-chapters" "%~n1.audio.mp4" "--track-order" "0:1,1:1" >> all.log
"C:\Program Files (x86)\MeGUI\tools\mkvmerge\mkvmerge.exe" -o "%~n1.audio.mka" "--forced-track" "1:no" "-a" "1" "-D" "-S" "-T" "--no-global-tags" "%~n1.audio.mp4" "--track-order" "0:1" >> all.log
"C:\Program Files (x86)\MeGUI\tools\mkvmerge\mkvinfo.exe" "%~n1.audio.mka" >> all.log
del "%~n1.video.mkv"
del "%~n1.audio.mka"
echo * >> all.log
echo * >> all.log
echo * >> all.log
goto:eof
But there are still improvements possible and I appreciate your further help:
1 Spaces in filenames: %1 seems to have really problem with that. It returns only the part of the filename before first space. How to solve it?
2 Filelist as an input: how should I modify the script to process files in a filelist I specify, instead of *.wmv? The filelist will be something like dir * /b/s > f.txt and then manually deleted files which I dont want to process.
3 Logging x264 and neroaacenc do not write to the logfile. I think it is because they do not output text report to stdout but to stderr...my guess... is there anything to do with tthat?
4 Deleting I am deleting the intermediate video file. However, if there is a problem in muxing (it means *.new.mkv doesnot exist) I want to keep it. How to do it?
5 If I want to filter the output of mkvinfo and for example to log only line, which contains only one of these expressions "+ Duration:", "+ Default duration:" and "ChapterTimeStart", how to do that.
6 Is it possible to have date and time as a part of the name of the logfile?
7 In the avs script I will resize the video to 1280x???, if it is bigger, while keeping the size otherwise. Since I have to stick to mod 16, that can introduce aspect ratio error. I will calculate that error or the correct display dimensions in avs, but how do I pass it to x264 or mkvmerge?
BTW I am on Win7, in case it matters.
I am sorry, lot of question. I you dont have time, please at least number one, which is critical.
Thank you again
splinter98
2nd December 2011, 17:54
1 Spaces in filenames: %1 seems to have really problem with that. It returns only the part of the filename before first space. How to solve it?
Use "%~1" instead of "%1"
if %1 contains spaces it should automatically have ", however %~1 removes the " so "%~1" will ensure all paths are inside
2 Filelist as an input: how should I modify the script to process files in a filelist I specify, instead of *.wmv? The filelist will be something like dir * /b/s > f.txt and then manually deleted files which I dont want to process.
try using: For /F %%A in (f.txt) do call :encode %%A
3 Logging x264 and neroaacenc do not write to the logfile. I think it is because they do not output text report to stdout but to stderr...my guess... is there anything to do with tthat?
Use 2>> all.log instead of >> all.log - 2> redirects stderr
4 Deleting I am deleting the intermediate video file. However, if there is a problem in muxing (it means *.new.mkv doesnot exist) I want to keep it. How to do it?
Use:
IF EXISTS "%~n1.new.mkv" do (
del "%~n1.video.mkv"
del "%~n1.audio.mka"
)
This checks if the *.new.mkv exists and then deletes the intermittent files
5 If I want to filter the output of mkvinfo and for example to log only line, which contains only one of these expressions "+ Duration:", "+ Default duration:" and "ChapterTimeStart", how to do that.
You need some from of grep - not sure the best way to do that in batch files (one method probably would be to get a windows version of grep and then pipe the output to grep before putting into the log file)
6 Is it possible to have date and time as a part of the name of the logfile?
%TIME% will give you the current time - so maybe a function like:
:timelog
echo %TIME% %1 >> log.txt
goto:EOF
7 In the avs script I will resize the video to 1280x???, if it is bigger, while keeping the size otherwise. Since I have to stick to mod 16, that can introduce aspect ratio error. I will calculate that error or the correct display dimensions in avs, but how do I pass it to x264 or mkvmerge?
set /A height=<calculation>
will create a variable %height% with the result of <calculation>
NOTE: I haven't tested most of the code here but they should work - if not try typing the the command (so if,for etc) followed by a /? to get the help from these commands.
redfordxx
2nd December 2011, 19:31
1] echo FFIndex^("%~1"^)
doesnot help...
3] 2>> gives me line per line progress of the encoding...so I guess this is not the way, but its not that important:D
6] but I meant the time part of the filename. Like
echo text >> log_2011-12-02-10-00.txt
btw: What exactly %~n1 does? Seems like the name part of the file.
But what when there is whole path in the variable?
StainlessS
2nd December 2011, 19:43
From Command Prompt type "help for".
EDIT: or eg, 'help for >c:\For.txt'
gyth
2nd December 2011, 19:43
for %%A in (*.wmv) do call :encode %%A
If there are spaces in the file names then you need to quote the second %%A, then use %~1 to removes the quote in the encode function.
for /F %%A in (f.txt) do call :encode "%%A"
gyth
2nd December 2011, 20:08
6] but I meant the time part of the filename. Like
echo text >> log_2011-12-02-10-00.txt
Here is a rewrite of some code I found at http://www.dostips.com
@echo off
call :log_name log
echo %log%
pause
goto:eof
:log_name
:: %1 - variable that the log name will be returned to
SETLOCAL
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('"echo.|date"') do (
for /f "tokens=1-3 delims=/.- " %%A in ("%date:* =%") do (
set %%a=%%A&set %%b=%%B&set %%c=%%C))
set /a "yy=10000%yy% %%10000,mm=100%mm% %% 100,dd=100%dd% %% 100"
for /f "tokens=1-4 delims=:. " %%A in ("%time: =0%") do set log_name=log_%yy%-%mm%-%dd%-%%A-%%B-%%C-%%D.txt
ENDLOCAL & SET %~1=%log_name%
goto:eof
So set the log_name before the for and redirect everything to it >> %log%
call :log_name log
for /F %%A in (f.txt) do call :encode "%%A"
goto:eof
:encode
:: %1 - file to encode
echo ****************************************************************************** >> %log%
...
gyth
2nd December 2011, 21:26
7 In the avs script I will resize the video to 1280x???
x264 can resize
--video-filter resize:1280,,,width
but that would upsize things smaller than 1280 as well.
"C:\Program Files (x86)\anrichan3.3\x264.exe" "%~nx1" --frames 1 -o NUL 2>tmp.txt
:: avs [info]: 1920x1080p 0:0 @ 60001/1001 fps (cfr)
FOR /F "tokens=3 delims=x " %%B IN ('TYPE tmp.txt ^| FIND "avs [info]: "') DO (
SET vf=
if %%B GTR 1280 SET "vf= --video-filter resize:1280,,,width "
)
Add %vf% to your x264 line, if the width is greater than 1280 it will be set and do the resizing.
Hum, but that doesn't seem to set the SAR right. It gets as close to 1:1 as it can (mod8?) and then sets it to 1:1 even it is a little bit off.
Resizing to 1280x720 "--video-filter resize:1280,720" gets the SAR set correctly, but it is possibly far from square pixels depending on how wacky your sources are.
redfordxx
2nd December 2011, 23:11
EDIT:Ooops, I didn't refresh the browser since your post 12. So maybe here is something off.
Well here is the script as of now in case anyone finds this thread and would like to use it
@IF EXIST batchlog.log del batchlog.log
@IF EXIST all.log del all.log
@for %%A in (*.wmv) do call :encode "%%A"
::@for /F "tokens=* " %%A in (list.txt) do call :encode "%%A"
@goto:finish
:encode
:: %1 - file to encode
@IF EXIST "%~dpn1.new.mkv" (
echo ********************************************************* >> batchlog.log
echo "%~dpn1.new.mkv" exists and was fully skipped >> batchlog.log
echo ********************************************************* >> batchlog.log
goto:eof)
@echo ********************************************************* >> all.log
@echo %1 >> all.log
@echo ********************************************************* >> all.log
@echo * >> all.log
@echo * >> all.log
@(
echo LoadPlugin^("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2-x64.dll"^)
echo FFIndex^("%~1"^)
echo FFVideoSource^("%~1", threads=1^)
type "D:\video\_process\_processing\basic_video_processing_file.txt"
) > tmp.avs
@IF EXIST "%~dpn1.video.mkv" (
echo ********************************************************* >> batchlog.log
echo "%~dpn1.video.mkv" exists and was not encoded >> batchlog.log
echo ********************************************************* >> batchlog.log
) ELSE (
"C:\Program Files (x86)\MeGUI\tools\x264\x264_64.exe" --crf 23.0 --bframes 8 --b-adapt 2 --ref 8 --qpmin 10 --qpmax 51 --subme 10 --partitions all --trellis 2 --sar 1:1 --output "%~dpn1.video.mkv" tmp.avs >> all.log
)
@(
echo LoadPlugin^("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2.dll"^)
echo FFIndex^("%~1"^)
echo FFAudioSource^("%~1"^)
type "D:\video\_process\_processing\basic_audio_processing_file11.txt"
) > tmpa.avs
@IF EXIST "%~dpn1.audio.mp4" (
echo ********************************************************* >> batchlog.log
echo "%~dpn1.audio.mp4" was overwritten >> batchlog.log
echo ********************************************************* >> batchlog.log
)
@"C:\Program Files (x86)\MeGUI\tools\besplit\wavi.exe" "tmpa.avs" - | "C:\Program Files (x86)\MeGUI\tools\neroaacenc\neroaacenc.exe" -q 0.15 -if - -of "%~dpn1.audio.mp4" >> all.log
@"C:\Program Files (x86)\MeGUI\tools\mkvmerge\mkvmerge.exe" -o "%~dpn1.new.mkv" "--language" "1:eng" "--default-track" "1:yes" "--forced-track" "1:no" "-d" "1" "-A" "-S" "-T" "--no-global-tags" "--no-chapters" "%~dpn1.video.mkv" "--sync" "1:-128" "--forced-track" "1:no" "-a" "1" "-D" "-S" "-T" "--no-global-tags" "--no-chapters" "%~dpn1.audio.mp4" "--track-order" "0:1,1:1" >> all.log
@"C:\Program Files (x86)\MeGUI\tools\mkvmerge\mkvmerge.exe" -o "%~dpn1.audio.mka" "--forced-track" "1:no" "-a" "1" "-D" "-S" "-T" "--no-global-tags" "%~dpn1.audio.mp4" "--track-order" "0:1" >> all.log
@"C:\Program Files (x86)\MeGUI\tools\mkvmerge\mkvinfo.exe" "%~dpn1.audio.mka" >> all.log
@IF EXIST "%~dpn1.new.mkv" (
del "%~dpn1.video.mkv"
del "%~dpn1.audio.mp4"
)
@del "%~dpn1.audio.mka"
@del "%~1.ffindex"
@echo * >> all.log
@echo * >> all.log
@echo * >> all.log
@goto:eof
:finish
@pause
basic_audio_processing_file11.txt: this should be processed in case mkvinfo contains following string + ChapterTimeStart: 00:00:00.117000000
DelayAudio(11.0/1000.0)
SSRC(48000)
return last
basic_audio_processing_file31.txt: this should be processed in case mkvinfo contains following string + ChapterTimeStart: 00:00:00.097000000
DelayAudio(31.0/1000.0)
SSRC(48000)
return last
basic_video_processing_file.txt
o=last
w=o.width
w2=(w>1280 ? 1280 : w)
w3=((w2+15)/16)*16
w3=(w3>w ? w3-16 : w3)
h=o.height
h2=h*w2/w
h3=((h2+15)/16)*16
h3=(h3>h ? h3-16 : h3)
#display dimensions are w2 , h2
(w<=1280) ? o : o.BicubicResize(w3,h3,0,0.75)
So, for now I am leaving two things to manual work and todo later:
1) checking the nero's audiodelay (because it requires the grep function)
2) checking aspect ratio in case of resizing (the variable is calculated in avs environment and I have to use it in commandline)
But besides that, I think it does everything fine....thanks again
gyth
2nd December 2011, 23:16
@echo off
at the start will keep it from talking back at you without needing @s everywhere.
w3=((w2+15)/16)*16
w3=(w3>w ? w3-16 : w3)
Don't add 15 if you want it to round down.
redfordxx
3rd December 2011, 00:15
@echo off
at the start will keep it from talking back at you without needing @s everywhere.
w3=((w2+15)/16)*16
w3=(w3>w ? w3-16 : w3)
Don't add 15 if you want it to round down.
If want to round up if that will not be bigger than original. That depends on whether the video is downsized.
redfordxx
3rd December 2011, 00:55
the date and time thing seems to more or less work, but how the hell happened that the variables in this lineset /a "yy=10000%yy% %%10000,mm=100%mm% %% 100,dd=100%dd% %% 100"
have any value. They are nowhere before assigned...
gyth
3rd December 2011, 01:30
set %%a=%%A
The capitalization matters there.
One of the for loops is going through yy, mm, dd while the other is their values.
This is used because not everyone uses the same date format; MM/DD/YYYY, YYYY/MM/DD, DD/MM/YYY
On my system it is
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('"echo.|date"') do (
:: The current date is: Fri 12/02/2011
:: Enter the new date: (mm-dd-yy)
for /f "tokens=1-3 delims=/.- " %%A in ("%date:* =%") do (
:: 12/02/2011
redfordxx
3rd December 2011, 02:07
I see, so %%a is not variable here but it is name of the variable...this is crazy ;-)
btw, this %% modulo thing later destroys the leading zero, so I wonder why it is there...
redfordxx
3rd December 2011, 04:24
I got the idea how to solve the audio delay thing but I got stuck on pretty simple thing.
I need to convert time in seconds which is in the variable %%b to ms. in this case it is 00:00:00.097000000
I tried all possible and impossible combinations of set statement an some of them are here.
for /f "tokens=3-4 delims=:." %%c in ("%%b") do (
set chapter=%%c
echo %chapter% >> f
set /a chapter="1%%c%%d / 1000000) %% 100000"
echo %chapter% >> f
set chapter=1%%c%%d
echo %chapter% >> f
set /a "chapter=%chapter% / 1000000)"
echo %chapter% >> f
echo %%c >> f
echo %%d >> f
)
However with no result. But the input variables are set as following output shows...
ECHO is on.
ECHO is on.
ECHO is on.
ECHO is on.
00
097000000
The idea is to get frame size(in token %%a) and delay(in %%b) and estimate delay correction.
In this example
%%a=42.667ms (23.438 fps for a video track)
%%b= 00:00:00.097000000
The goal is:
correction=framesize*int(delay/framesize+1)-delay
and result should be in miliseconds...but I even cannot assign variable...btw, can SET command deal with floats or I must stick with integers?
gyth
3rd December 2011, 04:48
If want to round up if that will not be bigger than original.
If it doesn't start mod 16 then the only rounding that isn't bigger than the original is rounding down. ;)
When you downsize to 1280 it is mod 16, you aren't rounding it.
However with no result. But the input variables are set as following output shows...
Yes, now we're getting into the particular hell which is why most sane people avoid coding in batch.
At the start of the for loop chapter is unset, and so as the batch processor reads through the loop all the %chapter%s are given that value.
To get around this, there is SETLOCAL ENABLEDELAYEDEXPANSION and then refer to the variable by !chapter! instead of %chapter%.
Batch can't do math on numbers bigger than ~2000000000, and no floats.
SETLOCAL ENABLEDELAYEDEXPANSION
set b=00:00:00.097000000
for /f "tokens=3-4 delims=:." %%c in ("%b%") do (
set chapter=%%c
echo !chapter! >> f
set /a chapter="1%%c%%d / 1000000) %% 100000"
echo !chapter! >> f
set chapter=1%%c%%d
echo !chapter! >> f
set /a "chapter=!chapter! / 1000000)"
echo !chapter! >> f
echo %%c >> f
echo %%d >> f
)
redfordxx
3rd December 2011, 06:07
I think part of my problems may be caused that the variable is last token on the line. And the end of line, of some reason out of mkvinfo is 0D 0D 0A.
For example expression in the batch file
IF "%%b"==" 00:00:00.097000000" (
displays in the commandline window when the batch is running as
"==" 00:00:00.097000000" (
Whatever it means, I am pretty sure that the content of the if block is not executed when it should.
redfordxx
3rd December 2011, 18:42
Well, I would say this is pretty close to final solution:@echo off
@call :log_name log
:: for %%A in (*.mpg) do call :encode "%%A" %%q
@for /L %%q in (10,1,40) do (
for /F "tokens=* " %%A in (list%%q.txt) do call :encode "%%A" %%q
)
@goto:finish
:encode
:: %1 - file to encode
:: %2 - compression quality
IF EXIST "%~dpn1.new%2.mkv" (
echo ********************************************************* >> batch_%log%
echo "%~dpn1.new%2.mkv" exists and was fully skipped >> batch_%log%
echo ********************************************************* >> batch_%log%
goto:eof)
IF NOT EXIST "%~1" (
echo ********************************************************* >> batch_%log%
echo "%~1" not found >> batch_%log%
echo ********************************************************* >> batch_%log%
goto:eof)
@echo ********************************************************* >> progs_%log%
@echo %1 >> progs_%log%
@echo ********************************************************* >> progs_%log%
@echo * >> progs_%log%
@echo * >> progs_%log%
@echo ***** starting "%~1" *****
@(
echo srcfile="%~1"
type "D:\video\_process\_processing\video_processing_file.txt"
) > tmp.avs
IF EXIST "%~dpn1.video%2.mkv" (
echo ********************************************************* >> batch_%log%
echo "%~dpn1.video%2.mkv" exists and won't be encoded >> batch_%log%
echo ********************************************************* >> batch_%log%
) ELSE (
"C:\Program Files (x86)\MeGUI\tools\x264\x264_64.exe" --crf %2.0 --bframes 8 --b-adapt 2 --ref 8 --qpmin 10 --qpmax 51 --subme 10 --partitions all --trellis 2 --sar 1:1 --output "%~dpn1.video%2.mkv" tmp.avs >> progs_%log%
echo * >> progs_%log%
)
:: todo:"%~dpn1.video%2.mkv" on following line can be zero size file in case of error instead of being missing.
IF EXIST "%~dpn1.video%2.mkv" (
call :processaudio %1
"C:\Program Files (x86)\MeGUI\tools\mkvmerge\mkvmerge.exe" -o "%~dpn1.new%2.mkv" "--language" "1:eng" "--default-track" "1:yes" "--forced-track" "1:no" "-d" "1" "-A" "-S" "-T" "--no-global-tags" "--no-chapters" "%~dpn1.video%2.mkv" "--sync" "1:-%mkvdelay%" "--forced-track" "1:no" "-a" "1" "-D" "-S" "-T" "--no-global-tags" "--no-chapters" "%~dpn1.audio.mp4" "--track-order" "0:1,1:1" >> progs_%log%
) ELSE (
echo ********************************************************* >> batch_%log%
echo Creating "%~dpn1.video%2.mkv" not successful >> batch_%log%
echo ********************************************************* >> batch_%log%
)
@IF EXIST "%~dpn1.new%2.mkv" (
del "%~dpn1.video%2.mkv"
del "%~dpn1.audio.mp4"
echo "%~dpn1.new%2.mkv" ... OK >> error_%log%
) ELSE (
echo ********************************************************* >> error_%log%
echo "%~dpn1.new%2.mkv" error >> error_%log%
echo ********************************************************* >> error_%log%
copy tmp.avs "%~dpn1.new%2.error.avs"
)
@del "%~1.ffindex"
@IF EXIST "finalcommand.bat" (
"finalcommand.bat"
del "finalcommand.bat"
)
@echo * >> progs_%log%
@echo * >> progs_%log%
@echo * >> progs_%log%
@goto:eof
:log_name
:: %1 - variable that the log name will be returned to
SETLOCAL
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('"echo.|date"') do (
for /f "tokens=1-3 delims=/.- " %%A in ("%date:* =%") do (
set %%a=%%A&set %%b=%%B&set %%c=%%C))
::delims depend on local format setting
for /f "tokens=1-4 delims=:, " %%A in ("%time: =0%") do set log_name=%yy%-%mm%-%dd%_%%A-%%B-%%C.log
ENDLOCAL & SET %~1=%log_name%
goto:eof
:processaudio
:: %1 - file to encode
IF EXIST "%~dpn1.audio.mp4" (
echo ********************************************************* >> batch_%log%
echo "%~dpn1.audio.mp4" will be overwritten >> batch_%log%
echo ********************************************************* >> batch_%log%
del "%~dpn1.audio.mp4"
)
SET audiodelay=11
::SET audiodelay=31
call :delayandencode %1
(
echo LoadPlugin^("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2.dll"^)
echo FFIndex^("%~1"^)
echo FFAudioSource^("%~1"^)
type "D:\video\_process\_processing\basic_audio_processing_file%audiodelay%.txt"
) > tmpa.avs
SETLOCAL ENABLEDELAYEDEXPANSION
for /F "tokens=2,* delims=:+" %%a in (tmp%log%) do (
IF "%%a"==" ChapterTimeStart" (
for /f "tokens=3-4 delims=:." %%c in ("%%b") do (
set /a chapter="((1%%d / 1000000) + 1%%c000 - 101000)*1000"
)
)
IF "%%a"==" Default duration" (
for /f "tokens=1-2 delims=m. " %%c in ("%%b") do (
set framelen=%%c%%d
)
)
)
set /a frameceil="(((!chapter!/%framelen%)+1)*%framelen%)/1000"
set /a newdelay="(!frameceil!-!chapter!/1000)"
IF "%newdelay%"=="" (
echo ********************************************************* >> error_%log%
echo "%~dpn1.audio.mp4" delay calculation error >> error_%log%
echo ********************************************************* >> error_%log%
) ELSE (
IF NOT "%newdelay%"=="%audiodelay%" (
echo ********************************************************* >> batch_%log%
echo "%~dpn1.audio.mp4" has different delay...reencoding >> batch_%log%
echo chapter: !chapter! >> batch_%log%
echo parameters: %newdelay%/!frameceil! >> batch_%log%
echo ********************************************************* >> batch_%log%
set audiodelay=%newdelay%
call :delayandencode %1
))
type tmp%log% >> progs_%log%
@del "%~dpn1.audio.mka"
@del tmp%log%
ENDLOCAL & SET mkvdelay=%frameceil%
IF NOT EXIST "%~dpn1.audio.mp4" (
echo ********************************************************* >> error_%log%
echo "%~dpn1.audio.mp4" error >> error_%log%
echo ********************************************************* >> error_%log%
copy tmpa.avs "%~dpn1.audio.error.avs"
)
goto:eof
:delayandencode
(
echo srcfile="%~1"
echo adl=%audiodelay%.0
type "D:\video\_process\_processing\audio_processing_file.txt"
) > tmpa.avs
"C:\Program Files (x86)\MeGUI\tools\besplit\wavi.exe" "tmpa.avs" - | "C:\Program Files (x86)\MeGUI\tools\neroaacenc\neroaacenc.exe" -q 0.15 -if - -of "%~dpn1.audio.mp4" >> progs_%log%
echo * >> progs_%log%
@"C:\Program Files (x86)\MeGUI\tools\mkvmerge\mkvmerge.exe" -o "%~dpn1.audio.mka" "--forced-track" "1:no" "-a" "1" "-D" "-S" "-T" "--no-global-tags" "%~dpn1.audio.mp4" "--track-order" "0:1" >> progs_%log%
echo * >> progs_%log%
@"C:\Program Files (x86)\MeGUI\tools\mkvmerge\mkvinfo.exe" "%~dpn1.audio.mka" > tmp%log%
goto:eof
:finish
@pausemake_dirs.bat::dir *.mkv /b/s%1 > mkvlist.txt
dir *.wmv /b/s%1 > list.txt
dir *.avi /b/s%1 >> list.txt
dir *.mp4 /b/s%1 >> list.txt
dir *.mpg /b/s%1 >> list.txt
dir *.mpeg /b/s%1 >> list.txt
dir *.m2v /b/s%1 >> list.txt
dir *.flv /b/s%1 >> list.txt
dir *.vlc /b/s%1 >> list.txt
dir *.divx /b/s%1 >> list.txt
dir *.mov /b/s%1 >> list.txt
dir *.asf /b/s%1 >> list.txt
dir *.3gp /b/s%1 >> list.txt
dir *.vob /b/s%1 >> voblist.txt
audio_processing_file.txt
# adl,srcfile=parameter defined in batch file
LoadPlugin("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2.dll")
try{
#FFIndex(srcfile)
FFAudioSource(srcfile)
}
catch (err_msg) {
(RightStr(srcfile,4)==".avi") ? AviSource(srcfile, audio=true) : NOP()
EnsureVBRMP3Sync()
}
outfile="audioerror.txt"
DelayAudio(adl/1000.0)
try{SSRC(48000)}
catch (err_msg) {
WriteFileStart(outfile, """ srcfile+" : "+err_msg """, append=true)
SSRC(44100)
SSRC(48000)
}
return last
video_processing_file.txt
# srcfile=parameter defined in batch file
# x64 version
modx=16
mody=16
function AlignText(string s,int n)
{
return(RightStr(" "+s,Max(n,StrLen(s))))
}
try{LoadPlugin("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2-x64.dll")}
catch (err_msg) {LoadPlugin("C:\Program Files (x86)\MeGUI\tools\ffms\ffms2.dll")}
try{
FFIndex(srcfile)
FFVideoSource(srcfile, threads=1)
}
catch (err_msg) {
(RightStr(srcfile,4)==".avi") ? AviSource(srcfile, audio=false) : DirectShowSource(srcfile)
}
#return last
w0=width
h0=height
fps0=FrameRate
#here can be special treatment of certain files
try{Import("adjustments.avsi")}
catch (err_msg) {}
o=last
w=o.width
w2=(w>1280 ? 1280 : w)
w3=((w2+modx-1)/modx)*modx
w3=(w3>w ? w3-modx : w3)
h=o.height
h2=h*w2/w
h3=((h2+mody-1)/mody)*mody
h3=(h3>h ? h3-mody : h3)
#display dimensions are w2 , h2
outfile="dim.txt"
adjfile="adjustments.tmp.avsi"
finfile="finalcommand.bat"
(w2*h3!=w3*h2) ? WriteFileStart(adjfile, """ "(srcfile=="+Chr(34)+srcfile+Chr(34)+") ? last.crop(***,***,***,***).AssumeFPS(*****) : last # FPS="+string(fps0)+", current dimensions processing: "+String(w0)+"x"+String(h0)+"-->"+String(w3)+"x"+String(h3) """, append=true) : NOP()
(w2*h3!=w3*h2) ? WriteFileStart(adjfile, """ "modx=(srcfile=="+Chr(34)+srcfile+Chr(34)+") ? "+string(modx)+" : modx" """, append=true) : NOP()
(w2*h3!=w3*h2) ? WriteFileStart(adjfile, """ "mody=(srcfile=="+Chr(34)+srcfile+Chr(34)+") ? "+string(mody)+" : mody" """, append=true) : NOP()
(w2*h3!=w3*h2) ? WriteFileStart(finfile, """ "copy "+Chr(34)+"tmp.avs"+Chr(34)+" "+Chr(34)+srcfile+".adjustDAR.avs"+Chr(34) """, append=true) : NOP()
d0=String(w0)+"x"+String(h0)
d=String(w)+"x"+String(h)
d2=String(w2)+"x"+String(h2)
d3=String(w3)+"x"+String(h3)
(w2*h3!=w3*h2) ? WriteFileStart(outfile, """ "************************Aspect ratio error: file needs to be manually remuxed ******************* (see "+adjfile+")" """, append=true) : NOP()
WriteFileStart(outfile, """ "Processing "+AlignText(d0,9)+" -->"+AlignText((d==d0 ? "" : d),9)+" -->"+AlignText((d==d3 ? "" : d3),9)+" DAR:"+AlignText(((w2*h3==w3*h2) ? " OK" : d2),9)+" "+srcfile""" , append=true)
#(w2*h3!=w3*h2) ? WriteFileStart(outfile, """ "************************************************************************************************* " """, append=true) : NOP()
((h==h3)&&(w==w3)) ? o : o.BicubicResize(w3,h3,0,0.75)
I think it is usable...there is lot of woodoo with this variables thing, so it got really long and I only hope there is no serios bug in this confision.
But it should take case of downsizing to 720p, mod16, audio sync and should report if there is an aspect ratio error and remuxing is necesarry.
There are some framerate and samplerate issues...
I think the only way to make it even more reliable is to use some information about the source file...that means probably mediaifno usage...somehow
redfordxx
3rd December 2011, 18:48
Except the output video, there are some batch file working files in current directory:
file inputs:
list??.txt ...?? is number
list20.txt ...files listed here will be encoded -crf 20
list23.txt ...dtto 23
list23i.txt ...intended for list of interlaced inputs... not implemented and no idea ever will
list25.txt
mkvlist.txt ...list of input files, not implemented
voblist.txt ...list of input files, not implemented
special preprocessing of video files:
adjustments.avsi ...will be imported to script while processing
output and logs:
adjustments.tmp.avsi ...automatically generated template for adjustments.avsi
audioerror.txt ... some error reports from audio avs
dim.txt ...resizing log
batch_2011-12-04_19-02-14.log ... batch file log
error_2011-12-04_19-02-14.log ... batch file errors
progs_2011-12-04_19-02-14.log ... redirected stdout of used programs
temporary
tmp2011-12-04_19-02-14.log
tmp.avs
tmpa.avs
finalcommand.bat
I suppose meaning of input files list is clear. The number always means the quality of encoding of all files listed.
Usage of other files be explained on example.
error_2011-12-04_19-02-14.log shows where were problems noticed. If error occures, avs files are saved to source location for later review with names like *.audio.error.avs, *.new23.error.avs
*********************************************************
"V:\video\_other\_dance\200609 Berlin\x\D2H4L2 Supermario - Combinations on1.audio.mp4" delay calculation error
*********************************************************
*********************************************************
"V:\video\_other\_dance\200609 Berlin\x\D2H4L2 Supermario - Combinations on1.audio.mp4" error
*********************************************************
*********************************************************
"V:\video\_other\_dance\200609 Berlin\x\D2H4L2 Supermario - Combinations on1.new20.mkv" error
*********************************************************
"V:\video\_other\_dance\200609 Berlin\x\D1H3L1 Supermario - Combinations on1.new20.mkv" ... OK
"V:\video\_other\_dance\200609 Berlin\x\D2H4L3 Neeraj Maskara - Combinations on1.new20.mkv" ... OK
"V:\video\_other\_dance\200609 Berlin\x\D1H2L2 Neeraj Maskara - Bodymovement.new20.mkv" ... OK
"V:\video\_other\_dance\200709 Berlin\070916_Berlin_on1_Supermario Adv Fig2.new20.mkv" ... OK
*********************************************************
"V:\video\_other\_dance\200610 Bratislava\PICT4126.new20.mkv" error
*********************************************************
dim.txt can show how was video resized (input --> adjustment size --> final script size mod16 or custom DAR: <DAR if differs>) and whether there was aspect ratio error introduced:
Processing 1920x1080 --> --> 1280x720 DAR: OK V:\video\_other\_dance\200609 Berlin\x\D2H4L3 Neeraj Maskara - Combinations on1.AVI
Processing 640x480 --> --> DAR: OK V:\video\_other\_dance\200609 Berlin\x\Party1 - Ismael.AVI
************************Aspect ratio error: file needs to be manually remuxed ******************* (see adjustments.tmp.avsi)
Processing 700x360 --> 696x356 --> 696x352 DAR: 696x356 V:\video\_other\_dance\200510 Bratislava\MVI_5518.AVI
Processing 640x480 --> --> DAR: OK V:\video\_other\_dance\200609 Berlin\x\D1H5L3 Supermario - Combinations on1.avi
Processing 640x480 --> 480x640 --> DAR: OK V:\video\_other\_dance\200609 Berlin\x\D1H1L2 Raul Kambel - Combinations on1 - 2.avi
adjustments.tmp.avsi(srcfile=="V:\video\_other\_dance\200510 Bratislava\MVI_5518.AVI") ? last.crop(***,***,***,***).AssumeFPS(*****) : last # FPS=25.000000, current dimensions processing: 700x360-->696x352
modx=(srcfile=="V:\video\_other\_dance\200510 Bratislava\MVI_5518.AVI") ? 16: modx
mody=(srcfile=="V:\video\_other\_dance\200510 Bratislava\MVI_5518.AVI") ? 16 : mody
(Not only) based on this template file could be written some avs function into to adjustments.avsi then deleted the output videos and run script again: (srcfile=="V:\video\_other\_dance\200510 Bratislava\MVI_5518.AVI") ? last.crop(2,2,-2,-2) : last # FPS=25.000000, current dimensions processing: 700x360-->696x352
modx=(srcfile=="V:\video\_other\_dance\200510 Bratislava\MVI_5518.AVI") ? 8 : modx
mody=(srcfile=="V:\video\_other\_dance\200510 Bratislava\MVI_5518.AVI") ? 8 : mody
(srcfile=="V:\video\_other\_dance\200609 Berlin\x\D1H1L2 Raul Kambel - Combinations on1 - 2.avi") ? last.TurnRight() : last # was shot with camera on height
StainlessS
3rd December 2011, 22:31
@Redfox,
I'm not trying to be nasty or anything, but you call for help way too often.
Rome was not built in a day (was not there but I believe that is so).
As an innocent bystander, it seems that you want to force people
to do your plug for you. Take your time, puzzle it out and if you still cannot
do it I am quite confident that people will want to help out. You seem to be in
way big a hurry. I aplologise if I'm wrong, but it does seem that you squeal a lot.
Peace Bro :)
redfordxx
4th December 2011, 02:52
@StainlessS
On one hand I see your point on other hand, do not think I am not doing lot of puzzling myself. But there are situations I got stuck: I know how to call for example help if or if /? but I cannot write help %~ . And when I write SET /A var=11 and the %var% remains empty, I am lost.
Anyway I don't know if you noticed, the last post was publishing the results so others can use it later and not call for help...
StainlessS
4th December 2011, 22:06
Anyway I don't know if you noticed, the last post was publishing the results so others can use it later and not call for help...
This is true, anyway, again, no offence intended. :)
redfordxx
5th December 2011, 04:29
no offence intended. :)Don't worry, I understood.
redfordxx
5th December 2011, 04:38
This is weird and I don't know if anyone has idea why:"C:\Program Files (x86)\MeGUI\tools\besplit\wavi.exe" "tmpa.avs" - | "C:\Program Files (x86)\MeGUI\tools\neroaacenc\neroaacenc.exe" -q 0.15 -if - -of "%~dpn1.audio.mp4" >> progs_%log%
This line takes care of encoding in the batch. However, in certain cases there is corrupted audio output. I think the certain cases are when these conditions are met:
- it is not the first video processed (everytime I restart the batch, first processed audio is OK)
- input is 11kHz mono channel, which seems to invoke the Try-Catch in the avs:try{SSRC(48000)}
catch (err_msg) {
WriteFileStart(outfile, """ srcfile+" : "+err_msg """, append=true)
SSRC(44100)
SSRC(48000)
}
BTW I updated posts 24,25
Gavino
5th December 2011, 10:52
input is 11kHz mono channel, which seems to invoke the Try-Catch in the avs:try{SSRC(48000)}
catch (err_msg) {
WriteFileStart(outfile, """ srcfile+" : "+err_msg """, append=true)
SSRC(44100)
SSRC(48000)
}
What error message is written to the file?
Is your source exactly 11kHz (11000Hz) or 11025Hz?
SSRC only accepts certain combinations of input and output rates (see docs (http://avisynth.org/mediawiki/SSRC)), and 11000 to 48000 does not satisfy the requirements (but 11025 to 48000 is OK).
redfordxx
5th December 2011, 15:48
What error message is written to the file?
Is your source exactly 11kHz (11000Hz) or 11025Hz?
SSRC only accepts certain combinations of input and output rates (see docs (http://avisynth.org/mediawiki/SSRC)), and 11000 to 48000 does not satisfy the requirements (but 11025 to 48000 is OK).
That exactly was the error, that it cannot convert between these two. That's why I have in the error handling converting first to 44.1 and then to 48.
The frequency was 11024Hz by the way, so it was either really 11024 or there was some rounding error in the info and in fact it was 11025. But more important was the fact, that always one or first encoding worked and rest was b0rked.
So I don't know, maybe it messed up memory somehow or I dont know, so the next file had squeeks...and was 1% bigger than it should be...probably it was the size of the squeeks;-)
redfordxx
5th December 2011, 16:47
one question for the batch file.
How do I check filesize?
I am checking for errors after processing like: IF NOT EXIST "%~dpn1.video%2.mkv" ()
But usually it does not help, because when there is error in x264, it creates file of size 0 or very small.
splinter98
5th December 2011, 17:28
one question for the batch file.
How do I check filesize?
I am checking for errors after processing like: IF NOT EXIST "%~dpn1.video%2.mkv" ()
But usually it does not help, because when there is error in x264, it creates file of size 0 or very small.
This template gets the filesize and checks if it is greater than 0 (adjust for your needs)
set filesize=
call :getfilesize "somefile.mkv" filesize
if /I %filesize% GTR 0 (
echo File is greater than 0
)
goto :EOF
:getfilesize
set %~2=%~z1
goto :EOF
redfordxx
6th December 2011, 01:00
Thank you for tip, I used it little changed in my code. However, in some situations there are wierd things and I don't know whether it is because I changed something wrongly or I am missing something else in syntax.
In certain situations there is delayed variable setting. In this example the filesize4 is set much later than necessary. There are three spots in red.
-calling the function
-using the variable (bad thing is that this variable here has still the old value)
-spot where this variaable has new value (tested via echo)
Part of my code:
:encode
:: %1 - file to encode
:: %2 - compression quality
....
....
...
call :checkfile "%~dpn1.video%2.mkv" filesize3
IF "%filesize3%"=="0" (
echo Creating "%~dpn1.video%2.mkv" not successful >> batch_%log%
echo ********************************************************* >> error_%log%
echo "%~1" video encoding error >> error_%log%
echo ********************************************************* >> error_%log%
copy tmp.avs "%~1.video%2.error.avs"
goto:eof
) ELSE (
call :processaudio %1
del "%~1.ffindex"
call :checkfile "%~dpn1.audio.mp4" filesize4
IF "%filesize4%"=="0" (
echo ********************************************************* >> error_%log%
echo "%~1" audio encoding error >> error_%log%
echo ********************************************************* >> error_%log%
copy tmpa.avs "%~1.audio.error.avs"
goto:eof
) ELSE (
"C:\Program Files (x86)\MeGUI\tools\mkvmerge\mkvmerge.exe" -o "%~dpn1.new%2.mkv" ....... "%~dpn1.video%2.mkv" "--sync" "1:-%mkvdelay%" ..... "%~dpn1.audio.mp4" "--track-order" "0:1,1:1" >> progs_%log%
)
)
:: Here is value %filesize4% set
call :checkfile "%~dpn1.new%2.mkv" filesize5
IF "%filesize5%"=="0" (
echo ********************************************************* >> error_%log%
echo "%~1" AV muxing error >> error_%log%
echo ********************************************************* >> error_%log%
copy tmp.avs "%~1.video%2.error.avs"
copy tmpa.avs "%~1.audio.error.avs"
) ELSE (
del "%~dpn1.video%2.mkv"
del "%~dpn1.audio.mp4"
echo "%~dpn1.new%2.mkv" ... OK >> error_%log%
)
@goto:eof
:checkfile
:: %1 - filename
:: %2 - variable
IF EXIST "%~1" (
set %~2=%~z1
) ELSE (
set %~2=0
)
goto:eofThis delay actually causes that the condition for clip1 is applied on clip2 etc. Which causes completely wrong handling of data.
EDIT: If I put it out of the else block, it seems to work fine.
But if you see any reason why it didnt work, I appreciate sharing it, coz I am afraid similar thing could happen somewhere else and I cannot spot it like here.
splinter98
6th December 2011, 13:19
Thank you for tip, I used it little changed in my code. However, in some situations there are wierd things and I don't know whether it is because I changed something wrongly or I am missing something else in syntax.
In certain situations there is delayed variable setting. In this example the filesize4 is set much later than necessary. There are three spots in red.
-calling the function
-using the variable (bad thing is that this variable here has still the old value)
-spot where this variaable has new value (tested via echo)
...
This delay actually causes that the condition for clip1 is applied on clip2 etc. Which causes completely wrong handling of data.
Woops that's my bad, try adding the following after @echo off
SETLOCAL ENABLEDELAYEDEXPANSION
and then use:
IF "!filesize4!"=="0" (
This is due to you calling it inside the If/Else statement and the set command only makes the changes once it has exited the If/Else clause. using ENABLEDELAYEDEXPANSION and !var! fixes this (I think - haven't tested it)
redfordxx
6th December 2011, 16:24
Woops that's my bad, try adding the following after @echo off
SETLOCAL ENABLEDELAYEDEXPANSION
Letme check if I understand it correctly:
I can put SETLOCAL ENABLEDELAYEDEXPANSION on the very beginning of the clip
and ENDLOCAL at the end of the clip
Then I have nothing to worry about anymore and I don't need the SETLOCAL in any procedure again as I have it now (provided I am now afraid of overwriting my own variables)
I access the variables which I expect to change during the processing with ! like !filesize!
I access the variables which I expect not to change during the processing with % like %filesize%
I access the variables in the FOR cycle always with %% like %%a %%b
I access the variables in the subrouting via CALL statement always with % like %1 %2
If I have
call :sub1 %%a %%b
:sub1
call :sub2 %%c
:sub2In sub2 I cannot reach the orginal %1=%%a %2=%%b (unless I pass it explicitly again) and %2 does not exist?
gyth
6th December 2011, 17:38
It will automatically endlocal at the goto:eof.
Setlocal defines its own scope for variables, so if you want to use a value set in a setlocal block you need to do a bit of work.
ENDLOCAL & SET out_var=%out_var%
You need to set the variable into the outer scope at the same time as endlocal.
But for this particular case it isn't needed.
Your else clause isn't doing anything. The proceeding if clause exits with goto:eof.
I don't think the nested if blocks were adding anything to the code, but use them if it is clearer to you.
:encode
:: %1 - file to encode
:: %2 - compression quality
....
....
...
call :checkfile "%~dpn1.video%2.mkv" filesize3
IF "%filesize3%"=="0" (
echo Creating "%~dpn1.video%2.mkv" not successful >> batch_%log%
echo ********************************************************* >> error_%log%
echo "%~1" video encoding error >> error_%log%
echo ********************************************************* >> error_%log%
copy tmp.avs "%~1.video%2.error.avs"
goto:eof
)
call :processaudio %1
del "%~1.ffindex"
call :checkfile "%~dpn1.audio.mp4" filesize4
IF "%filesize4%"=="0" (
echo ********************************************************* >> error_%log%
echo "%~1" audio encoding error >> error_%log%
echo ********************************************************* >> error_%log%
copy tmpa.avs "%~1.audio.error.avs"
goto:eof
)
"C:\Program Files (x86)\MeGUI\tools\mkvmerge\mkvmerge.exe" -o "%~dpn1.new%2.mkv" ....... "%~dpn1.video%2.mkv" "--sync" "1:-%mkvdelay%" ..... "%~dpn1.audio.mp4" "--track-order" "0:1,1:1" >> progs_%log%
call :checkfile "%~dpn1.new%2.mkv" filesize5
IF "%filesize5%"=="0" (
echo ********************************************************* >> error_%log%
echo "%~1" AV muxing error >> error_%log%
echo ********************************************************* >> error_%log%
copy tmp.avs "%~1.video%2.error.avs"
copy tmpa.avs "%~1.audio.error.avs"
goto:eof
)
del "%~dpn1.video%2.mkv"
del "%~dpn1.audio.mp4"
echo "%~dpn1.new%2.mkv" ... OK >> error_%log%
@goto:eof
redfordxx
6th December 2011, 17:51
I don't think the nested if blocks
Yeah, I figured that also already.
So, in fact, with % it is usually possible to access changed variables, only in the case of IF block and maybe something else, the variable is assigned later.
redfordxx
6th December 2011, 21:40
Now, as it is intended to process lot of files without first looking at them I added few types of warning. One of it should be warning for interlaced video.
So I am testing for ifb=IsFrameBased, and then log a message. However, I get always true, which does not help much.
Anyone with more insight can get me on the right path?
gyth
6th December 2011, 22:41
So, in fact, with % it is usually possible to access changed variables, only in the case of IF block and maybe something else, the variable is assigned later.
Batch evaluates %variables% with their value at the time it enters a ( block ). Changes to the value within the block aren't reflected because they have already been "expanded". Using enabledelayedexpansion and !! can get you around that, but it is added complexity that is best avoided when not needed.
Gavino
6th December 2011, 23:52
Now, as it is intended to process lot of files without first looking at them I added few types of warning. One of it should be warning for interlaced video.
So I am testing for ifb=IsFrameBased, and then log a message. However, I get always true, which does not help much.
Anyone with more insight can get me on the right path?
IsFrameBased doesn't tell you whether a clip is interlaced or progressive (which Avisynth doesn't know anyway). It just means that each frame is a complete frame rather than a field previously split by using SeparateFields(). So most clips are frame-based, even if interlaced.
See http://avisynth.org/mediawiki/Interlaced_fieldbased.
redfordxx
9th December 2011, 08:01
release;-)
redfordxx
10th December 2011, 13:29
Hi anybody can see reason of following?
I have mp4 file where mediainfo says it is Quicktime AVC. FFVideo source cannot handle it and DIrectShowSource can. But why is first method working and second gets crash?
First:
DirectShowSource(srcfile)
Second:try{FFVideoSource(srcfile, threads=1)}
catch (err_msg) {DirectShowSource(srcfile)}
gyth
10th December 2011, 17:20
Looks like ffvideo isn't recognizing it as a file it can't process, so it doesn't throw an error and chokes on the data later.
Check for an update to ffvideo/ffmpeg/libav
redfordxx
10th December 2011, 21:00
Looks like ffvideo isn't recognizingIt is, because without try FFIndex reports System Exception - Access Violation
I believe MeGui takes care of updating of FFSource...?
gyth
10th December 2011, 23:20
System Exception - Access Violation
Is it in a directory that you have write privileges?
Did you have the file open in another program?!?
Make sure ffvideo is erroring the way you are expecting
try{FFVideoSource(srcfile, threads=1)}
catch(err_msg) {WriteFileStart(blankclip,"error.log","err_msg")}
Make sure it isn't something with try/catch
try{assert(false)}
catch(err_msg) {DirectShowSource(srcfile)}
redfordxx
12th December 2011, 18:37
So, for the first of your tests I did something different already before: I put AviSource in the catch part. And I got Nice AviSource error message. That means, that the error handling took place.
However, for your second test (nice idea), it worked fine.
Besides this, I did another test:
try{FFVideoSource(srcfile, threads=1)}
catch (err_msg) {}
DirectShowSource(srcfile)...CRASH!
I don't see ant obvious conclusion here...so, if not anyone else does, let's not waste more time on that.
I would better have (I hope) easier and more useful question which would lead to improving some bad habits of my batch file:
How the batch file can learn it's own location (path). I would like to pass the path to the avs.
Thank you.
StainlessS
12th December 2011, 18:51
Hi redfordxx, dont know if this helps but CD displays current directory or CD > Dir.txt to a file.
EDIT: sorry, CD is a dos command and that is what I thought you were asking about,
dont know if there is an equivalent in AVS script.
If your question was about AVS script then I think I recently saw a thread/post that,
that enquiry would involve a try/catch thing also.
redfordxx
14th December 2011, 01:51
Hi redfordxx, dont know if this helps but CD displays current directory or CD > Dir.txt to a file.
EDIT: sorry, CD is a dos command and that is what I thought you were asking about,
dont know if there is an equivalent in AVS script.
If your question was about AVS script then I think I recently saw a thread/post that,
that enquiry would involve a try/catch thing also.
No, it's OK. Now, after your post I am thinking that CD is currently what I need and not *.bat location. Because all these echo x > tmp.avs commands are directed to current directory I guess.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.