News:

--

Main Menu

Batch processing AVI to MP4 (H.264)

Started by Ahari, March 28, 2012, 04:40:43 AM

Previous topic - Next topic

Ahari

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!!

Jan Gruuthuse

#1
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, ...

Jan Gruuthuse

#2
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

Ahari

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.

Ahari

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?

Jan Gruuthuse

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?

Ahari

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 **



Jan Gruuthuse

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.

Ahari

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?

Jan Gruuthuse

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.


Ahari

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.


Jan Gruuthuse

#11
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

Ahari

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?

Jan Gruuthuse

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

Ahari