[Tinypy] Tips & docs on Avidemux .py scripting

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

Previous topic - Next topic

butterw

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.

butterw


butterw

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

butterw



ext="mp4"

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:
    fnames.addItem(basename(fname_in))
dlgConfirm.addControl(fnames)
if not dlgConfirm.show(): return



eumagga0x2a

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.

butterw

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.



eumagga0x2a

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.

butterw

! 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"])
get_folder_content2(folder)


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
"""
filelist=[]
if not ext: raise("get_folder_content2: ext is None or ''")
try:
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

butterw

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 ?




eumagga0x2a

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.