Avidemux Forum

Avidemux => Windows => Topic started by: Ahari on March 28, 2012, 04:40:43 AM

Title: Batch processing AVI to MP4 (H.264)
Post by: Ahari on March 28, 2012, 04:40:43 AM
This is my first post so please be gentle! I am totally new to converting videos and Avidemux.

I have spent many, many hours searching for an answer and am now just confused! Please can someone help me with this awesome, but confusing piece of software (well, confusing for  a noob like me!).

My system is Windows 7 64 bit, Intel 2600K processor with 16GB RAM.

I am trying to use Avidemux 2.5.6 to batch convert about 1000 AVI home videos from my video camera to MP4 (H.264).

This is where I stand at the moment:
I have worked out my settings I want in Avidemux and saved the project file as avitomp4.js. I deleted the stuff at the beginning of the resulting file after "var app = new Avidemux();" and before "//** Postproc **" relating to the sample video I used to create the project file.

I then Created a "convert avi to mp4.bat" file with the following text:

SETLOCAL

set avidemux="C:\Program Files\Avidemux 2.5\avidemux2.exe"
set script=avitomp4.js
for %%f in (*.avi) do %avidemux% --load "%%f" --run %script% --save "%%f.mp4" --quit

ENDLOCAL


When I run the .bat file, Avidemux opens, loads the first video in the folder, just starts to process it, then crashes.

If I load the exact same file manually in Avidemux, then load the project file "avitomp4.js" and save it manually, the video converts perfectly!

I can't work out what I'm doing wrong!

Please can someone point me in the right direction. I thought I had it done right, but I am obviously missing something.

If it helps, here are the contents of my avitomp4.js file:

avitomp4.js:


//AD  <- Needed to identify//

var app = new Avidemux();


//** Postproc **
app.video.setPostProc(3,3,0);

app.video.fps1000 = 25000;

//** Filters **
app.video.addFilter("YADIF","mode=0","order=1");

//** Video Codec conf **
app.video.codecPlugin("32BCB447-21C9-4210-AE9A-4FCE6C8588AE", "x264", "2PASSBITRATE=9000", "<?xml version='1.0'?><x264Config><x264Options><fastFirstPass>true</fastFirstPass><threads>0</threads><deterministic>true</deterministic><sliceThreading>false</sliceThreading><threadedLookahead>-1</threadedLookahead><idcLevel>-1</idcLevel><vui><sarAsInput>true</sarAsInput><sarHeight>1</sarHeight><sarWidth>1</sarWidth><overscan>undefined</overscan><videoFormat>undefined</videoFormat><fullRangeSamples>true</fullRangeSamples><colorPrimaries>undefined</colorPrimaries><transfer>undefined</transfer><colorMatrix>smpte240m</colorMatrix><chromaSampleLocation>0</chromaSampleLocation></vui><referenceFrames>3</referenceFrames><gopMaximumSize>250</gopMaximumSize><gopMinimumSize>0</gopMinimumSize><scenecutThreshold>40</scenecutThreshold><periodicIntraRefresh>false</periodicIntraRefresh><bFrames>3</bFrames><adaptiveBframeDecision>2</adaptiveBframeDecision><bFrameBias>0</bFrameBias><bFrameReferences>normal</bFrameReferences><loopFilter>true</loopFilter><loopFilterAlphaC0>0</loopFilterAlphaC0><loopFilterBeta>0</loopFilterBeta><cabac>true</cabac><openGop>disabled</openGop><interlaced>disabled</interlaced><constrainedIntraPrediction>false</constrainedIntraPrediction><cqmPreset>flat</cqmPreset><intra4x4Luma><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value></intra4x4Luma><intraChroma><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value></intraChroma><inter4x4Luma><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value></inter4x4Luma><interChroma><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value></interChroma><intra8x8Luma><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value></intra8x8Luma><inter8x8Luma><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value></inter8x8Luma><analyse><partitionI4x4>true</partitionI4x4><partitionI8x8>true</partitionI8x8><partitionP8x8>true</partitionP8x8><partitionP4x4>false</partitionP4x4><partitionB8x8>true</partitionB8x8><dct8x8>true</dct8x8><weightedPredictionPframes>smart</weightedPredictionPframes><weightedPrediction>true</weightedPrediction><directPredictionMode>auto</directPredictionMode><chromaLumaQuantiserDifference>0</chromaLumaQuantiserDifference><motionEstimationMethod>multi-hexagonal</motionEstimationMethod><motionVectorSearchRange>24</motionVectorSearchRange><motionVectorLength>-1</motionVectorLength><motionVectorThreadBuffer>-1</motionVectorThreadBuffer><subpixelRefinement>10</subpixelRefinement><chromaMotionEstimation>true</chromaMotionEstimation><mixedReferences>true</mixedReferences><trellis>allModeDecisions</trellis><fastPSkip>true</fastPSkip><dctDecimate>true</dctDecimate><psychoRdo>1</psychoRdo><psychoTrellis>0</psychoTrellis><noiseReduction>0</noiseReduction><interLumaDeadzone>21</interLumaDeadzone><intraLumaDeadzone>11</intraLumaDeadzone></analyse><rateControl><quantiserMinimum>10</quantiserMinimum><quantiserMaximum>51</quantiserMaximum><quantiserStep>4</quantiserStep><maximumConstantRateFactor>0</maximumConstantRateFactor><averageBitrateTolerance>1</averageBitrateTolerance><vbvMaximumBitrate>0</vbvMaximumBitrate><vbvBufferSize>0</vbvBufferSize><vbvInitialOccupancy>0.9</vbvInitialOccupancy><ipFrameQuantiser>1.4</ipFrameQuantiser><pbFrameQuantiser>1.3</pbFrameQuantiser><adaptiveQuantiserMode>variance</adaptiveQuantiserMode><adaptiveQuantiserStrength>1</adaptiveQuantiserStrength><mbTree>true</mbTree><frametypeLookahead>40</frametypeLookahead><quantiserCurveCompression>0.6</quantiserCurveCompression><reduceFluxBeforeCurveCompression>20</reduceFluxBeforeCurveCompression><reduceFluxAfterCurveCompression>0.5</reduceFluxAfterCurveCompression></rateControl><accessUnitDelimiters>false</accessUnitDelimiters><spsIdentifier>0</spsIdentifier><sliceMaxSize>0</sliceMaxSize><sliceMaxMacroblocks>0</sliceMaxMacroblocks><sliceCount>0</sliceCount><hrd>none</hrd></x264Options></x264Config>");

//** Audio **
app.audio.reset();
app.audio.codec("Faac",224,4,"e0 00 00 00 ");
app.audio.normalizeMode=0;
app.audio.normalizeValue=0;
app.audio.delay=0;
app.audio.mixer="NONE";
app.setContainer("MP4");
setSuccess(1);
//app.Exit();

//End of script


I have also attached the last log file and crash.py file (whatever that is - it looked important!)

Any help would be greatly appreciated - this is driving me nuts!!
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Jan Gruuthuse on March 28, 2012, 06:45:04 AM
I'm linux not windows user. Perhaps omit: var app = new Avidemux();
#!/bin/bash
VIDEOCODEC="Copy"
AUDIOCODEC="copy"
CONTAINER="Matroska"
# MP4
for FIL in `ls *mp4 | sort` ; do
/usr/bin/avidemux3_cli --video-codec $VIDEOCODEC --audio-codec $AUDIOCODEC --force-alt-h264 --load "$FIL"  --run /home/jan/mp4TOmkv.js --save ${FIL%.*}.mkv --quit
done

change
Quoteset script=avitomp4.js
to
Quoteset script="avitomp4.js"
if that still not works maybe include path to avitomp4.js like in set avidemux?

very basic job scrip used for mp4 to mkv
//AD  <- Needed to identify//
//--automatically built--
//--Project: /home/jan/Videos/mp4TOmkv.js

//** Video **

//** Postproc **
adm.setPostProc(3,3,0);

//** Video Codec conf **
adm.videoCodec("Copy");

//** Audio **
adm.audioReset();
adm.audioCodec("copy",0);

//** Muxer **
adm.setContainer("MKV","forceDisplayWidth=False","displayWidth=1280");
setSuccess(1);
//adm.Exit();

//End of script


check that no strange avi are amongst the home videos? other codec used, ...
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Jan Gruuthuse on March 28, 2012, 06:55:13 AM
Other issue in windows could be the use of script as a variable, could be reserved word or something similar? replace set script by myjob:
set script=avitomp4.js
set  myjob="avitomp4.js"
for %%f in (*.avi) do %avidemux% --load "%%f" --run %myjob% --save "%%f.mp4" --quit
if the same job is used and not changed:
for %%f in (*.avi) do %avidemux% --load "%%f" --run avitomp4.js --save "%%f.mp4" --quit
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Ahari on March 28, 2012, 08:30:06 AM
Thanks Jan for the suggestions.

I tried changing the variable name to myjob and put the quotes around the script's name - good idea, but no effect. Will leave it as you suggest anyway (much better).

Interesting thing - I tried to omit the line "var app = new Avidemux();" from the script. Got an error that the app was not defined, then Avidemux just dumped the original file into an mp4 container, but no re-encoding was done! Weird. Apparently that line is quite important!

I'm afraid you lost me on the other suggestions! I am a total noob when it comes to scripts! I am just splashing around aimlessly in the deep end - so to speak!! they also look very different to the windows scripts (to me anyway!)

It would seem that since you are on Linux your scripts use "adm." instead of "app.video"

What is the --force-alt-h264 for? I have seen it before, but don't know what it is.
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Ahari on March 28, 2012, 08:48:45 AM
The weird thing is that the script works if I load it manually - open Avidemux, open sample video, open project (avitomp4.js) and save the file. Avidemux works fine like this - it is just the automation and running it from the batch file that is not working.

I even tried copying my whole test folder to a smaller drive - no joy. My main video drive is a 3TB drive and I thought that maybe the batch file didn't like that. No difference by working from a 500GB drive.

Could it be something to do with 64bit Windows 7 version and batch files?
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Jan Gruuthuse on March 28, 2012, 10:26:39 AM
Never mind the code from linux script, was only to document where It comes from.
SETLOCAL ENDLOCAL? remove those?
http://www.avidemux.org/admWiki/doku.php?id=tutorial:batch_processing
set avidemux="C:\Program Files\Avidemux 2.5\avidemux2.exe"
for %%f in (*.avi) do %avidemux% --force-alt-h264 --load "%%f" --run avitomp4.js --save "%%f.mp4" --quit

add new line at end of batch file: pause
Can you then check the status of avidemux and does it start?
Put only 2 or 3 short avi clips in folder for testing. Do you see parameters change in the avidemux boxes?
Create a simpler avitomp4.js just with video: copy and audio: copy and container format: MP4. If this one runs then you know the batch is working and you have to start looking in the job why that one fails?
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Ahari on March 28, 2012, 10:46:39 AM
I did exactly as you suggested and it works!! (I made totally new files with "test" in the names).

I get a plain mp4 file with the original file inside - no re-encoding. At least we are getting somewhere!

I presume this means there is something wrong with the job script?

convert avi to mp4 - test.bat:
set avidemux="C:\Program Files\Avidemux 2.5\avidemux2.exe"
for %%f in (*.avi) do %avidemux% --force-alt-h264 --load "%%f" --run avitomp4-test.js --save "%%f.mp4" --quit
pause


avitomp4-test.js:
//AD  <- Needed to identify//
//--automatically built--
//--Project: F:\My Videos\Working\Home movies from video cameras\Test\avitomp4-test.js

var app = new Avidemux();

//** Postproc **
app.video.setPostProc(3,3,0);

app.video.fps1000 = 25000;

//** Filters **

//** Video Codec conf **


Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Jan Gruuthuse on March 28, 2012, 10:57:46 AM
Yeah, the saved job script? Work the way up. Check every step if it still works. Would start with the audio setting. Change parameter save job script and run batch. Delete the test .mp4 or you get questions to overwrite :) at some point the job will crash again. At that stage either you know why or have to ask here again. And not sure that i will be able to answer on that one, but will others do.
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Ahari on March 28, 2012, 10:31:18 PM
Jan, I have done some testing and there is definitely something funny going on here!

Avidemux crashes when I try to save the project file! Even the simple one that I did on your instruction earlier today (my last post) is truncated. I posted the entire project file! Avidemux just exited without any warning when I saved the project. I didn't notice this earlier and just thought it was normal!

I was quite excited when I then ran the project and it gave me an mp4 file with the original avi basically inside it. My excitement faded very quickly when I realised what was going on as every time I tried to add some setting as you suggested, the project file was identical (truncated) and Avidemux crashed (rather just closed without warning!) when trying to save the project file.

All Avidemux was doing was renaming the file! I wondered why it went so fast!

When I have all my settings like when I first started, then Avidemux saves the project file, but crashes when I try to run it in a batch! I can't win!

I even tried this in Avidemux 2.6.0 (r7787) with slightly better, but very similar results. It would not let me change the audio at all amongst other strange things. I don't like 2.6 anyway as it doesn't allow you to change aspect ratio settings to be the same as input! It seems to default the settings to 1:1 no matter what you set them to! Don't know why they are there - obviously very much a work in progress still.

After a bit of Googling it would appear that I am not alone in that Avidemux just does not like PCM audio in the original and it has been like that for some time.

Is this correct? Am I wasting my time with Avidemux?
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Jan Gruuthuse on March 29, 2012, 05:57:30 AM
Wasting your time with avidemux, don't think so. Pinpointing where the problem is maybe a step forward. I've noticed there could be some issues with pcm. Just started to play myself with photo camera saved avi content and it could be a similar pcm issue. Not sure these are related, being a user like you are.

The 2.6 is more HD H264 content orientated and is not frame based like 2.5.6 very simplistic explained.

The test did move the video and audio (streams) content to another container (avi to mp4) leaving the encoding content intact.
The one thing I don't understand is the truncated bit: if this is with 2.6 or with 2.5.6 to. So every job saved the avitomp4.js has pieces missing?

My guess would be that for your avi home movies the 2.5.6 would be the tool. When you leave Audio: copy and just change the video parameters is that working in the batch file? That would indicate/confirm the PCM issue and not some more problems.

Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Ahari on March 29, 2012, 09:43:12 AM
I am willing to keep trying with Avidemux as it fits my needs perfectly - if I can just get it to work!

Thank you so much for your effort in trying to help me with this!! 8)

(Btw: Whilst fiddling, I have been trying some things in the background and I notice that Avidemux is also struggling with all my MKV movies - all ripped from the original for my media player (stuttering, black screen, green screen, no image and so on!!). That doesn't worry me too much as I only really want to use it for my home movies anyway. I only mention it as it would appear that Avidemux is far from perfect and full of bugs and incompatibilities. The only way it seems to actually work is for one off encodes done manually. 2.6 will save the project file, but won't load that same project file again!)

Back to our troubleshooting:
QuoteThe test did move the video and audio (streams) content to another container (avi to mp4) leaving the encoding content intact.
Yes it seemed to, but I think it was just saving a copy with the MP4 extension! MediaInfo says it is still an AVI file even though it has an MP4 extension.  The MediaInfo reports are identical between the MP4 and the original AVI right down to the recoded date. the only difference is the file extension.

QuoteThe one thing I don't understand is the truncated bit: if this is with 2.6 or with 2.5.6 to. So every job saved the avitomp4.js has pieces missing?
No - 2.5.6 saves the project truncated and batches it by changing the file extension only.

2.6 saves the project seemingly perfectly, but won't load it at all in the GUI. It does seem to run it partially from the batch file, but saves the video as an AVI without processing the audio at all. The 2.6 project file seems to be perfect (to me - noob!), showing x264 and all the settings, the audio seems correct using faac and the muxer is shown as MP4.
2.6 project file:
//AD  <- Needed to identify//
//--automatically built--
//--Project: F:/My Videos/Working/Home movies from video cameras/Test/avitomp4-2.6.js


//** Postproc **
adm.setPostProc(3,3,0);

//** Video Codec conf **
adm.videoCodec("x264","general.params=2PASSBITRATE=9000","general.threads=99","general.fast_first_pass=True","level=31","vui.sar_height=1","vui.sar_width=1","MaxRefFrames=2","MinIdr=100","MaxIdr=500","MaxBFrame=3","i_bframe_adaptive=2","i_bframe_bias=0","i_bframe_pyramid=2","b_deblocking_filter=False","i_deblocking_filter_alphac0=0","i_deblocking_filter_beta=0","cabac=True","interlaced=False","analyze.b_8x8=True","analyze.b_i4x4=True","analyze.b_i8x8=True","analyze.b_p8x8=False","analyze.b_p16x16=True","analyze.b_b16x16=True","analyze.weighted_pred=2","analyze.weighted_bipred=True","analyze.direct_mv_pred=3","analyze.chroma_offset=0","analyze.me_method=2","analyze.subpel_refine=10","analyze.chroma_me=True","analyze.mixed_references=True","analyze.trellis=2","analyze.fast_pskip=True","analyze.dct_decimate=True","analyze.noise_reduction=0","analyze.psy=True","ratecontrol.rc_method=0","ratecontrol.qp_constant=0","ratecontrol.qp_min=0","ratecontrol.qp_max=0","ratecontrol.qp_step=0","ratecontrol.bitrate=0","ratecontrol.vbv_max_bitrate=0","ratecontrol.vbv_buffer_size=0","ratecontrol.vbv_buffer_init=0","ratecontrol.ip_factor=0.000000","ratecontrol.pb_factor=0.000000","ratecontrol.aq_mode=0","ratecontrol.aq_strength=0.000000","ratecontrol.mb_tree=True","ratecontrol.lookahead=0");

//** Filters **
adm.addVideoFilter("yadif","mode=0","order=1");
adm.addVideoFilter("swscale","width=1024","height=576","algo=2","sourceAR=2","targetAR=0");

//** Audio **
adm.audioCodec(0,"Faac","bitrate=224");

//** Muxer **
adm.setContainer("MP4","muxerType=0","useAlternateMp3Tag=True");
setSuccess(1);
//adm.Exit();

//End of script

With 2.6, once the batch file has run, MediaInfo shows the file is really an AVI, re-encoded correctly to h264, but with an MP4 extension and audio unchanged. It would appear that 2.6 loads the project file (only from the batch file), but ignores the settings for audio and output format. It also won't correctly handle the anamorphic aspect ratio and I have to use the resize filter to change the video to 1024x576 to keep the aspect ratio correct - no biggie with that - just a pain.

I tried to load the 2.6 project file into 2.5.6, but of course it doesn't like that!

QuoteWhen you leave Audio: copy and just change the video parameters is that working in the batch file? That would indicate/confirm the PCM issue and not some more problems.
It doesn't matter as the project file is always saved truncated without the video settings. The processed result is always the same - changed file extension only!

I don't understand why, but the only project file I have managed to get 2.5.6 to save correctly is the one with all my settings in place. This is loaded correctly and processed correctly, but only from the GUI. As soon as I try to run it from the batch file, I get a Windows message that Avidemux has stopped working and Windows starts searching for a solution. Then Avidemux and the command window both just disappear!

I've been doing a bit of playing with this (while typing my post!) and the truncated project file seems to be generated when Avidemux crashes when the project file is saved. The only thing that stops the crashing when saving project files is that you have to at least click the video configure button then Okay for the video codec. Now I don't get truncated project files! And the batch file runs perfectly for the basic settings (as long as the video codec file has been "configured" as mentioned).

Yaaaayy! I am getting somewhere at last!!

Now I will try your suggestions to build up to my full settings to see what is freaking out the batch process with all settings in place.

Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Jan Gruuthuse on March 29, 2012, 09:51:47 AM
Try batch file with the avidemux cli and not GUI version?
2.5 branch:  avidemux2 with avidemux2_cli
2.6 branch:  avidemux3 with avidemux3_cli
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Ahari on March 29, 2012, 10:28:16 AM
Same error with cli versions!

Done a bit of testing and so far it would appear that as soon as I select 2 pass encoding, the batch process won't work crashing Avidemux for every video! Even if it works perfectly from the GUI one at a time.

This leads me back to the batch file or maybe the program doesn't like to be called to do 2 pass encoding from a batch file. maybe there is still something we are missing from the batch file that needs to be there for the program to accept such an instruction from the batch file?
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Jan Gruuthuse on March 29, 2012, 10:44:20 AM
Don't know if this is possible to have 2 command line in that loop? Or have avidemux executing twice? Where the first would be:
avidemux --help this resets avidemux everytime.
for %%f in (*.avi) do %avidemux% --help %avidemux% --force-alt-h264 --load "%%f" --run avitomp4-test.js --save "%%f.mp4" --quit
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Ahari on March 29, 2012, 11:28:59 AM
That doesn't seem to do anything.
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Jan Gruuthuse on March 29, 2012, 11:41:46 AM
avidemux should start and close while doing reset, then start avidemux and start processing your video. each time.
Not familiar with windows, don't even know if this can be done this way. Is far beyond me, not having windows.
Perhaps some more experienced people should step in here and see if there is still a user solution to this, or it has to be referred to the developers? In this case it might be useful you provide a sample of the used home video .avi approx. size 20 MB. Upload and provide a link to it.
I've done similar in this posting: only 1st time processing possible  (http://www.avidemux.org/smf/index.php?topic=10484.msg56348#msg56348)
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Ahari on March 29, 2012, 11:56:51 AM
So close and yet so far! I'm now stumped! I am about to give up and try another program - maybe a break will help!

Jan, you have been a great help 8) thank you for your enormous patience and time.

Maybe it is time for a bug report? I don't think a video sample would help as the issue is the encoder crashing Avidemux when run from a batch file?

Is there anyone out there advanced enough who can help with this issue which (as far as I can see) has basically dissolved down to:
How to get 2 pass (average bitrate) x264 encoding to work from a batch file.
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Ahari on March 30, 2012, 11:35:28 AM
I am in the company of experts!

My thanks to everyone for your patient help - especially Jan Gruuthuse! What a great forum.

By changing to CRF mode all my problems have disappeared!! After some tests, I have settled on CRF 18 - seems to work well for my videos. Processing is faster too. Wish I had thought of this long ago! Comments anyone?

Last question (I hope!): By de-interlacing, the frames appear much sharper, but the video playback is more jerky and not as smooth. I heard that if you deinterlace you should increase the fps from 25 to 50 (I'm on PAL).

Is that right and if so, what is the best way to do it?

Some Googling revealed lots of different opinions on whether to even de-interlace or not.

What to do?
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Jan Gruuthuse on March 30, 2012, 12:39:48 PM
if the output is on flatscreen tv (hdmi, ...) I would not deinterlace, deinterlace would sometimes help on computer displays. interlaced is most of the times TV originated and if the target is again the TV, I would keep it that way.
The best judge is of course yourself, make some sample clips and do test with these for comparing the best result in your opinion.
And this is just my opinion.
What is Deinterlacing? Facts, solutions, examples. (http://www.100fps.com/)
Rule of Thumb: deinterlacing blurrs picture. interlaced pictures show 'steps/lines'. whatever you do - you do wrong. (http://sites.google.com/site/theimovieoutputproject/chapter-3-to-deinterlace-or-not-to-deinterlace)
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Ahari on March 30, 2012, 12:44:40 PM
Thanks, I will do some experimenting.

Going on holiday for a week now, so please forgive my lack of response to any posts while away!
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Ahari on April 10, 2012, 10:27:03 AM
Well, I'm back from holiday and have sorted out my problems now!

Thanks Jan for the excellent link about "What is Deinterlacing?". A very good read.

My final settings:
I am using CRF 18 which gives me excellent quality and small file sizes.
The batch file runs perfectly.
SETLOCAL

set avidemux="C:\Program Files\Avidemux 2.5\avidemux2.exe"
set myjob="_avitomp4.js"
for %%f in (*.avi) do %avidemux% --force-alt-h264 --load "%%f" --run %myjob% --save "%%~nf.mp4" --quit
pause

ENDLOCAL

The name of my job file is titled like that so that it appears at the top of my folder when I run it - easier to find amongst my video files.
The "SETLOCAL" and "ENDLOCAL" are there to make sure the variables used are only used for this session and don't mess with the global variables in Windows - not really necessary, but keeps it clean.
I decided after much testing to deinterlace using the Yadif filter set to "Bob, Temporal & Spacial check, Bottom field first". This seemed to play back better on both my PC and TV and the file sizes were acceptably only a bit larger. By doing this the frame rate is increased to 50 fps and playback is very smooth and crisp.

For anyone who is interested these are the settings in my project file:
//AD  <- Needed to identify//
//--automatically built--
var app = new Avidemux();

//** Postproc **
app.video.setPostProc(3,3,0);

app.video.fps1000 = 25000;

//** Filters **
app.video.addFilter("YADIF","mode=1","order=0");

//** Video Codec conf **
app.video.codecPlugin("32BCB447-21C9-4210-AE9A-4FCE6C8588AE", "x264", "AQ=18", "<?xml version='1.0'?><x264Config><presetConfiguration><name>Alan's settings for converting Canon's DVCPro AVI files to H264 MP4 files for archiving</name><type>user</type></presetConfiguration><x264Options><fastFirstPass>true</fastFirstPass><threads>0</threads><deterministic>true</deterministic><sliceThreading>false</sliceThreading><threadedLookahead>-1</threadedLookahead><idcLevel>-1</idcLevel><vui><sarAsInput>true</sarAsInput><sarHeight>1</sarHeight><sarWidth>1</sarWidth><overscan>undefined</overscan><videoFormat>undefined</videoFormat><fullRangeSamples>true</fullRangeSamples><colorPrimaries>undefined</colorPrimaries><transfer>undefined</transfer><colorMatrix>smpte240m</colorMatrix><chromaSampleLocation>0</chromaSampleLocation></vui><referenceFrames>4</referenceFrames><gopMaximumSize>250</gopMaximumSize><gopMinimumSize>0</gopMinimumSize><scenecutThreshold>40</scenecutThreshold><periodicIntraRefresh>false</periodicIntraRefresh><bFrames>6</bFrames><adaptiveBframeDecision>2</adaptiveBframeDecision><bFrameBias>0</bFrameBias><bFrameReferences>normal</bFrameReferences><loopFilter>true</loopFilter><loopFilterAlphaC0>0</loopFilterAlphaC0><loopFilterBeta>0</loopFilterBeta><cabac>true</cabac><openGop>disabled</openGop><interlaced>disabled</interlaced><constrainedIntraPrediction>false</constrainedIntraPrediction><cqmPreset>flat</cqmPreset><intra4x4Luma><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value></intra4x4Luma><intraChroma><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value></intraChroma><inter4x4Luma><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value></inter4x4Luma><interChroma><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value></interChroma><intra8x8Luma><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value></intra8x8Luma><inter8x8Luma><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value><value>16</value></inter8x8Luma><analyse><partitionI4x4>true</partitionI4x4><partitionI8x8>true</partitionI8x8><partitionP8x8>true</partitionP8x8><partitionP4x4>false</partitionP4x4><partitionB8x8>true</partitionB8x8><dct8x8>true</dct8x8><weightedPredictionPframes>smart</weightedPredictionPframes><weightedPrediction>true</weightedPrediction><directPredictionMode>auto</directPredictionMode><chromaLumaQuantiserDifference>0</chromaLumaQuantiserDifference><motionEstimationMethod>multi-hexagonal</motionEstimationMethod><motionVectorSearchRange>28</motionVectorSearchRange><motionVectorLength>-1</motionVectorLength><motionVectorThreadBuffer>-1</motionVectorThreadBuffer><subpixelRefinement>10</subpixelRefinement><chromaMotionEstimation>true</chromaMotionEstimation><mixedReferences>true</mixedReferences><trellis>allModeDecisions</trellis><fastPSkip>true</fastPSkip><dctDecimate>true</dctDecimate><psychoRdo>1</psychoRdo><psychoTrellis>0</psychoTrellis><noiseReduction>0</noiseReduction><interLumaDeadzone>21</interLumaDeadzone><intraLumaDeadzone>11</intraLumaDeadzone></analyse><rateControl><quantiserMinimum>10</quantiserMinimum><quantiserMaximum>30</quantiserMaximum><quantiserStep>4</quantiserStep><maximumConstantRateFactor>0</maximumConstantRateFactor><averageBitrateTolerance>1</averageBitrateTolerance><vbvMaximumBitrate>0</vbvMaximumBitrate><vbvBufferSize>0</vbvBufferSize><vbvInitialOccupancy>0.9</vbvInitialOccupancy><ipFrameQuantiser>1.4</ipFrameQuantiser><pbFrameQuantiser>1.3</pbFrameQuantiser><adaptiveQuantiserMode>variance</adaptiveQuantiserMode><adaptiveQuantiserStrength>1</adaptiveQuantiserStrength><mbTree>true</mbTree><frametypeLookahead>40</frametypeLookahead><quantiserCurveCompression>0.6</quantiserCurveCompression><reduceFluxBeforeCurveCompression>20</reduceFluxBeforeCurveCompression><reduceFluxAfterCurveCompression>0.5</reduceFluxAfterCurveCompression></rateControl><accessUnitDelimiters>false</accessUnitDelimiters><spsIdentifier>0</spsIdentifier><sliceMaxSize>0</sliceMaxSize><sliceMaxMacroblocks>0</sliceMaxMacroblocks><sliceCount>0</sliceCount><hrd>none</hrd></x264Options></x264Config>");

//** Audio **
app.audio.reset();
app.audio.codec("Faac",224,4,"e0 00 00 00 ");
app.audio.normalizeMode=0;
app.audio.normalizeValue=0;
app.audio.delay=0;
app.audio.mixer="NONE";
app.setContainer("MP4");
setSuccess(1);
//app.Exit();

//End of script


May it be of use to someone - I derived the settings after much reading and they seem to work very nicely.

My batch file is running as I type - there are over 2500 video clips spanning 6 years totalling over 30 hours of video. At the rate it is going, it should take about 60 hours for everything! My machine is very fast! At least I think so!

These files will be my archive of all my home videos and will take up only about 20% of the space of the original DV camera files. They will play back better on TV and PC and my Mede8er media player will recognise and play them too! I am very pleased to say the least!

Unless there are any further posts with comments or constructive criticism about my chosen methods, this will be my last post on this thread.

So, huge thanks again to everyone (mostly Jan Gruuthuse) for the patient help.
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Jan Gruuthuse on April 10, 2012, 11:24:02 AM
Thanks for sharing this with us.
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Track11 on April 21, 2012, 01:59:02 PM
Thank you for this batch file.
I hope someone can read my english.

I've got a problem witch batchprocessing. It starts to convert the first .avi file in the home folder and save it in the right way. Then it will load the second .avi file and the "ruibuildframeindex" loops all the time with no error or something.
This problem appears only by multiple audiolines. I have set the trigger on halt on no errors in the avidemux settings.

I would be glad by fixing this issue :)


Greetings from germany with best wishes :)
Title: Re: Batch processing AVI to MP4 (H.264)
Post by: Jan Gruuthuse on April 22, 2012, 09:09:22 AM
have a different folder for the  multiple audio tracks.