Batch convert leaves wrong video duration

Started by pan, December 08, 2013, 02:50:54 PM

Previous topic - Next topic

pan

I am trying to batch convert the Audio in a batch of mkv's. When I convert them individually with the GUI it works fine, but if I try to batch convert in a command line the duration of the video goes from 1hr 30 minutes to 400+hrs.
Here is my batch file
set avidemux="O:\installed\avidemux_2.6.0_win64\avidemux.exe"
for %%f in (*.mkv) do %avidemux% --load "%%f" --runpy project1.py --save "%%f_fixed.mkv" --quit


and this is my script
#PY  <- Needed to identify #
#--automatically built--

adm = Avidemux()
adm.loadVideo("")
adm.clearSegments()
adm.videoCodec("Copy")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"")
adm.audioAddTrack(0)
adm.audioCodec(0, "Faac", "bitrate=128");
adm.audioSetDrc(0, 1)
adm.audioSetShift(0, 0,0)
adm.audioSetNormalize(0, 1, 10)
adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280")


Any ideas what could be going wrong?

mean

No idea what's wrong, but
you can do it directly in the py script

root="/work/samples/avi"
ext="mkv"
list=get_folder_content(root,ext)
for i in list:
   print(">>"+i)
print("Done")


pan

If I understand you correctly are you saying change the bat and script file to
set avidemux="O:\installed\avidemux_2.6.0_win64\avidemux.exe"
%avidemux% --runpy project1.py --quit


#PY  <- Needed to identify #
#--automatically built--
root="/movies"
ext="mkv"
list=get_folder_content(root,ext)
for i in list:
   print(">>"+i)
print("Done")

adm = Avidemux()
adm.loadVideo("")
adm.clearSegments()
adm.videoCodec("Copy")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"")
adm.audioAddTrack(0)
adm.audioCodec(0, "Faac", "bitrate=128");
adm.audioSetDrc(0, 1)
adm.audioSetShift(0, 0,0)
adm.audioSetNormalize(0, 1, 10)
adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280")

mean

Almost, something like

#PY  <- Needed to identify #
def processOneFile(i):
  adm = Avidemux()
  adm.loadVideo(i)
  adm.clearSegments()
  adm.videoCodec("Copy")
  adm.audioClearTracks()
  adm.setSourceTrackLanguage(0,"")
  adm.audioAddTrack(0)
  adm.audioCodec(0, "Faac", "bitrate=128");
  adm.audioSetDrc(0, 1)
  adm.audioSetShift(0, 0,0)
  adm.audioSetNormalize(0, 1, 10)
  adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280")


#--automatically built--
root="/movies"
ext="mkv"
list=get_folder_content(root,ext)
for i in list:
   print(">>"+i)
   processOneFile(str(root)+"/"+str(i)) # not sure
print("Done")


mean


pan

Ok so I got it working with your help and the help of Anubioz script.
I still have 2 problems.
Running the script from abatch file doesnt work Avidemux opens and just sits there.
set avidemux="O:\installed\avidemux_2.6.0_win64\avidemux.exe"
%avidemux% --runpy project.py


I can run the script from within Avidemux it runs but gives an error after each video for the length being too short. This is because of the high values in adm.addsegment. If I remove these the script crashes. Is there any command to get the framecount form the video and put that value in?

#FILL IN THE VARIABLES & ENABLE SILENT MODE IF YOU WANT

targetfileextension = "mkv"
targetdirectory = "O:\\installed\\movies\\"
outputdirectory = "O:\\installed\\movies\\movies\\"
stringtoappend=".converted.mkv"

convertedlist=[]

adm = Avidemux()
gui = Gui()

ext=targetfileextension
folder=targetdirectory
outputfolder=outputdirectory




filelist=get_folder_content(folder, ext)
if(filelist is None):
gui.displayError("Error","No files")
raise
quit()
for i in filelist:
if (basename(i)[-len(stringtoappend):]==stringtoappend):
skippedlist.append(basename(i))
else:
adm.loadVideo(i)
rezultfile=outputfolder+basename(i)+stringtoappend
adm.clearSegments()
adm.addSegment(0, 0, 29644980000)
adm.markerA = 0
adm.markerB = 29644980000
adm.videoCodec("copy")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"")
adm.audioAddTrack(0)
adm.audioCodec(0, "Faac", "bitrate=128");
adm.audioSetDrc(0, 1)
adm.audioSetShift(0, 0,0)
adm.audioSetNormalize(0, 1, 10)
adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280")
adm.save(rezultfile)
convertedlist.append(basename(i))

convertedfiles='\r\n'.join(convertedlist)


gui.displayInfo("The following files were successfully converted",convertedfiles)

mean

Remove them+ the adm.clearSegements() part
you 'll have the full video

pan

Quote from: mean on December 09, 2013, 12:25:15 PM
Remove them+ the adm.clearSegements() part
you 'll have the full video

Works perfectly. Thanks.