[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.

tripunto

#70
Quote from: butterw on May 14, 2021, 01:25:39 PM

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

I'm trying to change the output file extension with:
dlgTitle = "Found "+str(nbSeg)+" segment(s) in "+str(e.nbVideos())+" video file(s)";
dlgConfirm = DialogFactory(dlgTitle);

out_ext = "mp4"
ext_list = ["mkv","webm","mov","avi","ts","m2ts","vob","mpg","wmv","mp4"]
set_ext = DFMenu("Output the segments in individual files with extension")
set_ext.addItem(out_ext)
for ext in ext_list:
    if not ext is out_ext:
        set_ext.addItem(str(ext))
dlgConfirm.addControl(set_ext)

But I get an error when trying to get the value of:
set_ext.value
For now, to avoid the error I have had to use:
if not dlgConfirm.show():
    g.displayInfo("CANCEL", "Canceled by user")
    return
else:
    try:
        if set_ext.value:
            out_ext = set_ext.value
    except TypeError:
        out_ext = "mp4"

How can you get the value of the DFMenu?


I'm also having trouble with appendVideo()
It doesn't return an exception, and I can't prevent the error window from appearing if I cut too short.You cannot view this attachment.

eumagga0x2a

Quote from: tripunto on April 28, 2025, 11:28:50 AMHow can you get the value of the DFMenu?

You don't. All you have is set_ext.index (as an integer).

eumagga0x2a

Quote from: tripunto on April 28, 2025, 11:28:50 AMI'm also having trouble with appendVideo()

The idea of "smart copy" (re-encoding the remainder of the previous GOP, appending video starting with keyframe and exporting in copy mode) is entirely not viable with codecs like H.264 and HEVC. It may work with Xvid, but who needs Xvid now?

Warnings and errors from appendVideo() are suppressed in silent mode. There is no way to enable silent mode from scripts, but it can be enabled via command line using the --nogui option.

tripunto

Most of the videos I edit with Avidemux are streaming videos, downloaded with JD2. Many others are simply clips downloaded with YTD.

Format: MPEG-4
Format Profile: MediaBase
Codec ID: isom (isom/avc1) or (isom/iso2/avc1/mp41)
General Bitrate: 1000 to 5000 kb/s
Frame Rate: 25,000 to 60,000 FPS
Writer Application: Lavf62.0.100

Format/Info: Advanced Video Codec
Format Profile: High to L3.1
Format Settings: CABAC / 5 Reference Frames

I know some formats cause problems during this process, but I don't usually have any problems joining a re-encoded fragment with an un-re-encoded one, which is why this script is so handy for me.

I've been using Avidemux for at least a decade. It's lightweight, easy to use, and, most importantly, very precise in its cuts.

Until recently, I only had a custom script to adjust the re-encoding settings so that all my cuts had the same format, which I could merge into a new project without having to re-encode them. I re-encode videos from 60 to 25 fps to save disk space.

I've never used the CLI version; I like using the graphical interface and am learning how to use custom scripts to get the most out of this powerful tool.

I barely know how to program in Python, nor do I understand Tinypy's limitations, and there isn't much information or examples to learn from.

 I can't find any information about ID3 tags. I don't know if I could copy the metadata from the original file to the cut files with a script.

I'd like to know if there's a way to add a text field to edit that metadata and add a button to open an additional dialog to choose an image or select optional options, but based on the commands listed in the help, I'm afraid it's not possible.

What I would like is for an exception to be added to the appendVideo command in a future version.