[Tinypy] Tips & docs on Avidemux .py scripting

Started by butterw, January 17, 2021, 01:18:41 PM

Previous topic - Next topic


Would it be possible to add a save_project(filepath) Tinypy binding ?

Some edits performed by user scripts (ex: vThumb.py my automatic video thumbnail generator) can't be undone, so it would be good to be able to autosave the current project before starting the edit perfomed by the script.



Attempting to show a DialogFactory without any control widgets causes an Avidemux Crash:

dlgConfirm = DialogFactory("Please Confirm")
# display = DFMenu("test"); dlgConfirm.addControl(display)
if not dlgConfirm.show(): return



adm=Avidemux(); gui=Gui()
# -------- select input directory --------
inputFolder = gui.dirSelect("Select " +ext+ " source folder")
# inputFolder = gui.fileReadSelectEx("Select input file", ext)

if inputFolder is None:
    gui.displayError(header_str, "No source folder selected"); return
# inputFolder = dirname(inputFolder)

# -------- get filelist with extension --------
filelist = get_folder_content(inputFolder, ext)
if filelist is None:
    gui.displayError(header_str, "No "+ ext +" files found in: "+ inputFolder); return

# -------- confirm dialog before batch --------
dlgConfirm = DialogFactory(inputFolder)
label_str = "Batch process " +str(len(filelist))+ " (" +ext+ ") Files in folder ?"
label = DFToggle(label_str); label.value=True; dlgConfirm.addControl(label)
fnames = DFMenu("in:")
for fname_in in filelist:
if not dlgConfirm.show(): return


Quote from: butterw on May 13, 2021, 11:14:02 AMAttempting to show a DialogFactory without any control widgets causes an Avidemux Crash

The number of controls being zero should trigger an assert failure either in qt4DiaFactoryPrepare or in qt4DiaFactoryTabsPrepare. The easiest way to catch this may be not very helpful for the user as no dialog will be shown at all and the method will just return false. Of course, it can be modified in a way that a dialog box with just OK and Cancel buttons will be shown. Might match the expectations better.


Either the user forgot to add his widget or he just needed a confirmation dialog with title.

I've noticed "_" doesn't display in the widget label, only in the dialog title and the Menu widget entry, which is troublesome because it is commonly used in filenames.


Underscore in titles is reinterpreted as a keyboard accelerator. This was done so to ensure compatibility with GTK. The design won't work with arbitrary strings in dialog element constructors.

I think that the real problem is that diaElemReadOnlyText is not exposed to scripting.


! get_folder_content(folder, "") crashes Avidemux

here's my wrapper version which can handle multiple extensions:
get_folder_content2(folder, "mp4")
get_folder_content2(folder, ["mp4", "mkv"])

def get_folder_content2(folder, ext=["mp4","mkv","webm","mov","avi","ts","m2ts","vob","mpg","wmv"]):
"""returns a filepath list
ext: "mp4", ["mp4", "mkv"],
by default get_folder_content2(folder): All video files
if not ext: raise("get_folder_content2: ext is None or ''")
ext.replace("ab", "cd")
if ext: filelist = get_folder_content(folder, ext)
except TypeError:
for elt in ext:
flist = get_folder_content(folder, elt)
if flist: filelist.extend(flist)
return filelist


I am trying to save processed images with Avidemux.saveJpeg("filepath") but unless "Play filtered" is set in the GUI each time, the output is the source image.

Is it possible via scripting to set the state of "Play filtered" or to save the filtered output ?


I guess (cannot verify ATM) that using the "Mjpeg" encoder and the "raw" muxer for a selection starting at the time of the wanted image and ending at of before the next one will do exactly what you need.

Will look into API extension in the next release cycle, thanks for raising the topic.