Avidemux Forum

Avidemux => Main version 2.6 => Topic started by: dramedev on July 10, 2020, 05:02:48 AM

Title: Folder Conversion Python Script Issue
Post by: dramedev on July 10, 2020, 05:02:48 AM
Hi,

I am trying to write a Python script for folder conversion from .mkv to .mp4. Using the examples in Youtube and wiki, I have come up with the following. However when I actually run it the video does not get loaded and I get an exception. I seem to be missing something really basic here. Any suggestions? 
 
#
# Load all the files in selected folder with .mkv.
#
gui = Gui()
adm = Avidemux()
ext = "mkv"
sep = "\\"


#
def convert(filein):

if(0 == adm.loadVideo(filein)):
ui.displayError("oops","cannot load "+filein)
raise
filename = basename(filein)
dir = dirname(filein)
adm.setPostProc(3, 3, 0)
adm.videoCodec("Copy")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"")
adm.audioAddTrack(0)
adm.audioCodec(0, "copy");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0, 0)
adm.setContainer("MP4", "muxerType=0", "useAlternateMp3Tag=True", "forceAspectRatio=False", "aspectRatio=1", "rotation=0")
adm.save(filein + "-conv.mp4")
print("Done")


inputFolder = gui.dirSelect("Select the source folder")

list=get_folder_content(inputFolder,ext)
if(list is None):
raise
for i in list:
convert(i)
print("Done")
Title: Re: Folder Conversion Python Script Issue
Post by: eumagga0x2a on July 10, 2020, 08:03:10 AM
The script works for me as-is with a .mkv video which I know that it can be successfully loaded.

If the folder doesn't contain a .mkv file or if loading fails, the script tells Avidemux to trigger an exception (it could do something less rude instead). So the first thing to clarify is the question whether the list comes back empty or loading the video fails.
Title: Re: Folder Conversion Python Script Issue
Post by: dramedev on July 10, 2020, 09:16:51 AM
Oops. I think there was a folder security issue.  :-[  The script does work as is. Woohoo!  8)
Title: Re: Folder Conversion Python Script Issue
Post by: dramedev on July 10, 2020, 09:25:49 AM
Scrap that too! The real issue was that the files I was using it on could not be opened by Avidemux for some weird reason (although I can open them using VLC).  >:(
When I tried on a different set of files, the script worked.  ???
Title: Re: Folder Conversion Python Script Issue
Post by: eumagga0x2a on July 10, 2020, 09:39:23 AM
Assuming you use Windows: please start Avidemux afresh, load one of these files which fail to load, close Avidemux, compress (zip or 7z) and attach the admlog.txt from %localappdata%\avidemux\ to your reply.

Obviously, using the latest version of Avidemux is required.
Title: Re: Folder Conversion Python Script Issue
Post by: dramedev on July 10, 2020, 10:33:01 AM
Quote from: eumagga0x2a on July 10, 2020, 09:39:23 AM
Assuming you use Windows: please start Avidemux afresh, load one of these files which fail to load, close Avidemux, compress (zip or 7z) and attach the admlog.txt from %localappdata%\avidemux\ to your reply.

Obviously, using the latest version of Avidemux is required.

Attached.
Title: Re: Folder Conversion Python Script Issue
Post by: eumagga0x2a on July 10, 2020, 10:50:54 AM
You use 2.7.3, current is 2.7.6. Please update and re-test.
Title: Re: Folder Conversion Python Script Issue
Post by: dramedev on July 10, 2020, 12:06:53 PM
Thanks. That solved it!