News:

--

Main Menu

How_To_Batch_File_Proccessing?

Started by pulsarstar, April 14, 2021, 08:57:30 AM

Previous topic - Next topic

eumagga0x2a

Quote from: chucknolan on April 29, 2021, 06:53:09 PMI actually figured out the audio loop by playing around with the previous template when I changed "if adm.audioTracksCount() > 0" to "if adm.audioTracksCount() < 0".

This makes the test to always evaluate to false, so the whole block configuring audio encoders gets simply skipped.

Quote from: chucknolan on April 29, 2021, 06:53:09 PMCan you create one more for me to complete my set of AviDemux conversions presets? I was wondering if you can use the previous template or the current template that you just uploaded yesterday and assign video conversions on them.

I don't get, do you want the choice of video encoder to be independent or linked to specific audio encoder and muxer configurations?

chucknolan

Quote from: eumagga0x2a on April 29, 2021, 08:46:07 PM
Quote from: chucknolan on April 29, 2021, 06:53:09 PMI actually figured out the audio loop by playing around with the previous template when I changed "if adm.audioTracksCount() > 0" to "if adm.audioTracksCount() < 0".

This makes the test to always evaluate to false, so the whole block configuring audio encoders gets simply skipped.

Quote from: chucknolan on April 29, 2021, 06:53:09 PMCan you create one more for me to complete my set of AviDemux conversions presets? I was wondering if you can use the previous template or the current template that you just uploaded yesterday and assign video conversions on them.

I don't get, do you want the choice of video encoder to be independent or linked to specific audio encoder and muxer configurations?

I want the video encoder to be independent and linked to a specific audio encoder and muxer configuration for each output preset.  This way, I can add more presets in the future.  Example below using the output preset from your template

outputs = ["x265 (MKV) High@4.1, 1080p, HE-AAC @ 56 kbps (FDK-AAC)","x264 (MP4) High@3.1, 720p, AAC LC @ 128 kbps (FDK-AAC)","x264 (MKV) High@5.1, 720p, AAC LC @ 192 kbps (FDK-AAC)"]

3 individual video with audio conversions profiles linked into the output preset menu.  If it's possible to do so, I will really appreciate it.  If not, thank you for everything because you saved me a ton of time and organizing.


eumagga0x2a

Quote from: chucknolan on April 29, 2021, 09:15:04 PMI want the video encoder to be independent and linked to a specific audio encoder and muxer configuration for each output preset.

They can be either independent or linked. Not both at the same time.

eumagga0x2a

Just to be clear: in your example they are linked.

chucknolan

Quote from: eumagga0x2a on April 29, 2021, 09:38:06 PMJust to be clear: in your example they are linked.

Yes sir. I guess that I want them linked, according to my example.  Thank you.  Now you have me curious on what an independent video encoder will look like.  I guess I will investigate that on my own. Thanks, again.

eumagga0x2a

Quote from: chucknolan on April 29, 2021, 09:46:44 PMNow you have me curious on what an independent video encoder will look like.

You would add one more array (e.g. "videncs") as well as a menu similar to what I did with outputs. However, I don't think this is much more comfortable than just setting up the encoder in the main window.

As there is no "High" profile for HEVC, I would really prefer to let you figure out which configuration you actually want.

chucknolan

Quote from: eumagga0x2a on April 29, 2021, 09:52:36 PM
Quote from: chucknolan on April 29, 2021, 09:46:44 PMNow you have me curious on what an independent video encoder will look like.

You would add one more array (e.g. "videncs") as well as a menu similar to what I did with outputs. However, I don't think this is much more comfortable than just setting up the encoder in the main window.

As there is no "High" profile for HEVC, I would really prefer to let you figure out which configuration you actually want.

Oh ok. Yeah the independent method seems far more complex.  The linked method would be my preference, and no worries regarding the HEVC because I just added various video codecs as a placeholder to present the individuality of what I was hoping you could code for me.  I tried to place as much detail as possible on the request.  Thanks again.

eumagga0x2a

Using your examples, I can suggest the following example script:

#PY  <- Needed to identify #
#
ui = Gui()
adm = Avidemux()
ext = "mp4"
outputs = ["MKV, xvid4, HE-AAC @ 56 kbps (FDK-AAC)","MP4, x265, AAC LC @ 128 kbps (FDK-AAC)","MOV, x264, AAC LC @ 192 kbps (FDK-AAC)"]
sep = "\\"
#
# Function to convert an individual video
#
def convert(filein,outdir,outidx):
    if not adm.loadVideo(filein):
        ui.displayError("oops","cannot load "+filein)
        return 0

    if outidx == 0:
        adm.videoCodec("xvid4", "params=CQ=2", "profile=244", "rdMode=3", "motionEstimation=3", "cqmMode=0", "arMode=1", "maxBFrame=2", "maxKeyFrameInterval=200", "nbThreads=99", "qMin=2", "qMax=25", "rdOnBFrame=True", "hqAcPred=True"
, "optimizeChrome=True", "trellis=True", "useXvidFCC=True", "enableFrameDrop=False", "frameDropRatio=50")
    elif outidx == 1:
        adm.videoCodec("x265", "useAdvancedConfiguration=True", "general.params=AQ=20", "general.poolThreads=99", "general.frameThreads=99", "general.output_bit_depth=0", "general.preset=", "general.tuning=", "general.profile=", "level=-1"
, "vui.sar_idc=0", "vui.sar_height=1", "vui.sar_width=1", "vui.color_primaries=2", "vui.transfer_characteristics=2", "vui.matrix_coeffs=2", "MaxRefFrames=3", "MinIdr=25", "MaxIdr=250", "i_scenecut_threshold=40"
, "MaxBFrame=3", "i_bframe_adaptive=2", "i_bframe_bias=0", "i_bframe_pyramid=1", "b_deblocking_filter=True", "b_open_gop=False", "interlaced_mode=0", "constrained_intra=False", "b_intra=True", "lookahead=40"
, "weighted_pred=2", "weighted_bipred=True", "rect_inter=False", "amp_inter=False", "limit_modes=False", "cb_chroma_offset=0", "cr_chroma_offset=0", "me_method=3", "me_range=16", "subpel_refine=5", "limit_refs=3"
, "rd_level=3", "psy_rd=1.000000", "rdoq_level=0", "psy_rdoq=0.000000", "fast_pskip=True", "dct_decimate=True", "noise_reduction_intra=0", "noise_reduction_inter=0", "strong_intra_smoothing=True", "ratecontrol.rc_method=0"
, "ratecontrol.qp_constant=0", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=1", "ratecontrol.ip_factor=1.400000"
, "ratecontrol.pb_factor=1.300000", "ratecontrol.aq_mode=2", "ratecontrol.aq_strength=1.000000", "ratecontrol.cu_tree=True", "ratecontrol.strict_cbr=False")
    elif outidx == 2:
        adm.videoCodec("x264", "useAdvancedConfiguration=False", "general.params=AQ=20", "general.threads=0", "general.preset=veryfast", "general.tuning=none", "general.profile=high", "general.fast_decode=False", "general.zero_latency=False"
, "general.fast_first_pass=True", "general.blueray_compatibility=False", "general.fake_interlaced=False", "level=-1", "vui.sar_height=1", "vui.sar_width=1", "MaxRefFrames=3", "MinIdr=25", "MaxIdr=250"
, "i_scenecut_threshold=40", "intra_refresh=False", "MaxBFrame=3", "i_bframe_adaptive=1", "i_bframe_bias=0", "i_bframe_pyramid=1", "b_deblocking_filter=True", "i_deblocking_filter_alphac0=0", "i_deblocking_filter_beta=0"
, "cabac=True", "interlaced=False", "constrained_intra=False", "tff=True", "fake_interlaced=False", "analyze.b_8x8=True", "analyze.b_i4x4=True", "analyze.b_i8x8=True", "analyze.b_p8x8=True", "analyze.b_p16x16=False"
, "analyze.b_b16x16=False", "analyze.weighted_pred=2", "analyze.weighted_bipred=True", "analyze.direct_mv_pred=1", "analyze.chroma_offset=0", "analyze.me_method=1", "analyze.me_range=16", "analyze.mv_range=-1"
, "analyze.mv_range_thread=-1", "analyze.subpel_refine=7", "analyze.chroma_me=True", "analyze.mixed_references=True", "analyze.trellis=1", "analyze.psy_rd=1.000000", "analyze.psy_trellis=0.000000", "analyze.fast_pskip=True"
, "analyze.dct_decimate=True", "analyze.noise_reduction=0", "analyze.psy=True", "analyze.intra_luma=11", "analyze.inter_luma=21", "ratecontrol.rc_method=0", "ratecontrol.qp_constant=0", "ratecontrol.qp_min=10"
, "ratecontrol.qp_max=51", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.rate_tolerance=1.000000", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=1"
, "ratecontrol.ip_factor=1.400000", "ratecontrol.pb_factor=1.300000", "ratecontrol.aq_mode=1", "ratecontrol.aq_strength=1.000000", "ratecontrol.mb_tree=True", "ratecontrol.lookahead=40")
    else:
        ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
        return 0
    nbTracks = adm.audioTracksCount()
    if nbTracks > 0:
        adm.audioClearTracks()
        for track in range(nbTracks):
            adm.audioAddTrack(track)
            if outidx == 0:
                adm.audioCodec(track, "FDK_AAC", "bitrate=56", "afterburner=True", "profile=5", "sbr=False")
            elif outidx == 1:
                adm.audioCodec(track, "FDK_AAC", "bitrate=128", "afterburner=True", "profile=2", "sbr=False")
            elif outidx == 2:
                adm.audioCodec(track, "FDK_AAC", "bitrate=192", "afterburner=True", "profile=2", "sbr=False")
            else:
                ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
                return 0
    filename = (splitext(filein))[0]
    if outidx == 0:
        adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")
        filename += ".mkv"
    elif outidx == 1:
        adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mp4"
    elif outidx == 2:
        adm.setContainer("MOV", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mov"
    else:
        ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
        return 0
    filename = basename(filename)
    return adm.save(outdir + sep + filename)
#
# Main
#
# -------- select extension and output preset --------
extensions = ["avi","m2ts","mkv","mov","mp4","mpg","ts","vob","webm","wmv"]
mxExt = len(extensions)

menuExt = DFMenu("Select extension:")
for entry in range(0, mxExt):
    menuExt.addItem(extensions[entry])

mxOut = len(outputs)

menuOut = DFMenu("Select output preset:")
for entry in range(0, mxOut):
    menuOut.addItem(outputs[entry])

dia = DialogFactory("Configuration")
dia.addControl(menuExt)
dia.addControl(menuOut)
if not dia.show():
    return

idxExt = menuExt.index

if idxExt < 0 or idxExt >= mxExt:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

ext = extensions[idxExt]

idxOut = menuOut.index

if idxOut < 0 or idxOut >= mxOut:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

# -------- select input directory --------
inputFolder = ui.dirSelect("Select source folder")
if inputFolder is None:
    ui.displayError("Error", "No source folder selected")
    return

# -------- read content --------
list = get_folder_content(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

# -------- select output directory --------
outputFolder = ui.dirSelect("Select output folder")
if outputFolder is None:
    ui.displayError("Error", "No output folder selected")
    return

if(inputFolder == outputFolder):
    ui.displayError("Error","Output folder cannot be the same as the input one")
    return

# -------- process --------
total = 0
counter = 0

for i in list:
    total += 1
    counter += convert(i, outputFolder, idxOut)

if not counter:
    ui.displayInfo("Warning", "No files converted")
    return

if counter == 1:
    ui.displayInfo("Finished", "One file out of " + str(total) + " converted")
    return

ui.displayInfo("Finished", str(counter) + " files out of " + str(total) + " converted")

I didn't verify that video encoder configuration makes sense, please replace it with whatever suits your needs. I think that special cases like interlaced source videos should be handled manually anyway.

chucknolan

Quote from: eumagga0x2a on April 30, 2021, 11:54:56 AMUsing your examples, I can suggest the following example script:

#PY  <- Needed to identify #
#
ui = Gui()
adm = Avidemux()
ext = "mp4"
outputs = ["MKV, xvid4, HE-AAC @ 56 kbps (FDK-AAC)","MP4, x265, AAC LC @ 128 kbps (FDK-AAC)","MOV, x264, AAC LC @ 192 kbps (FDK-AAC)"]
sep = "\\"
#
# Function to convert an individual video
#
def convert(filein,outdir,outidx):
    if not adm.loadVideo(filein):
        ui.displayError("oops","cannot load "+filein)
        return 0

    if outidx == 0:
        adm.videoCodec("xvid4", "params=CQ=2", "profile=244", "rdMode=3", "motionEstimation=3", "cqmMode=0", "arMode=1", "maxBFrame=2", "maxKeyFrameInterval=200", "nbThreads=99", "qMin=2", "qMax=25", "rdOnBFrame=True", "hqAcPred=True"
, "optimizeChrome=True", "trellis=True", "useXvidFCC=True", "enableFrameDrop=False", "frameDropRatio=50")
    elif outidx == 1:
        adm.videoCodec("x265", "useAdvancedConfiguration=True", "general.params=AQ=20", "general.poolThreads=99", "general.frameThreads=99", "general.output_bit_depth=0", "general.preset=", "general.tuning=", "general.profile=", "level=-1"
, "vui.sar_idc=0", "vui.sar_height=1", "vui.sar_width=1", "vui.color_primaries=2", "vui.transfer_characteristics=2", "vui.matrix_coeffs=2", "MaxRefFrames=3", "MinIdr=25", "MaxIdr=250", "i_scenecut_threshold=40"
, "MaxBFrame=3", "i_bframe_adaptive=2", "i_bframe_bias=0", "i_bframe_pyramid=1", "b_deblocking_filter=True", "b_open_gop=False", "interlaced_mode=0", "constrained_intra=False", "b_intra=True", "lookahead=40"
, "weighted_pred=2", "weighted_bipred=True", "rect_inter=False", "amp_inter=False", "limit_modes=False", "cb_chroma_offset=0", "cr_chroma_offset=0", "me_method=3", "me_range=16", "subpel_refine=5", "limit_refs=3"
, "rd_level=3", "psy_rd=1.000000", "rdoq_level=0", "psy_rdoq=0.000000", "fast_pskip=True", "dct_decimate=True", "noise_reduction_intra=0", "noise_reduction_inter=0", "strong_intra_smoothing=True", "ratecontrol.rc_method=0"
, "ratecontrol.qp_constant=0", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=1", "ratecontrol.ip_factor=1.400000"
, "ratecontrol.pb_factor=1.300000", "ratecontrol.aq_mode=2", "ratecontrol.aq_strength=1.000000", "ratecontrol.cu_tree=True", "ratecontrol.strict_cbr=False")
    elif outidx == 2:
        adm.videoCodec("x264", "useAdvancedConfiguration=False", "general.params=AQ=20", "general.threads=0", "general.preset=veryfast", "general.tuning=none", "general.profile=high", "general.fast_decode=False", "general.zero_latency=False"
, "general.fast_first_pass=True", "general.blueray_compatibility=False", "general.fake_interlaced=False", "level=-1", "vui.sar_height=1", "vui.sar_width=1", "MaxRefFrames=3", "MinIdr=25", "MaxIdr=250"
, "i_scenecut_threshold=40", "intra_refresh=False", "MaxBFrame=3", "i_bframe_adaptive=1", "i_bframe_bias=0", "i_bframe_pyramid=1", "b_deblocking_filter=True", "i_deblocking_filter_alphac0=0", "i_deblocking_filter_beta=0"
, "cabac=True", "interlaced=False", "constrained_intra=False", "tff=True", "fake_interlaced=False", "analyze.b_8x8=True", "analyze.b_i4x4=True", "analyze.b_i8x8=True", "analyze.b_p8x8=True", "analyze.b_p16x16=False"
, "analyze.b_b16x16=False", "analyze.weighted_pred=2", "analyze.weighted_bipred=True", "analyze.direct_mv_pred=1", "analyze.chroma_offset=0", "analyze.me_method=1", "analyze.me_range=16", "analyze.mv_range=-1"
, "analyze.mv_range_thread=-1", "analyze.subpel_refine=7", "analyze.chroma_me=True", "analyze.mixed_references=True", "analyze.trellis=1", "analyze.psy_rd=1.000000", "analyze.psy_trellis=0.000000", "analyze.fast_pskip=True"
, "analyze.dct_decimate=True", "analyze.noise_reduction=0", "analyze.psy=True", "analyze.intra_luma=11", "analyze.inter_luma=21", "ratecontrol.rc_method=0", "ratecontrol.qp_constant=0", "ratecontrol.qp_min=10"
, "ratecontrol.qp_max=51", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.rate_tolerance=1.000000", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=1"
, "ratecontrol.ip_factor=1.400000", "ratecontrol.pb_factor=1.300000", "ratecontrol.aq_mode=1", "ratecontrol.aq_strength=1.000000", "ratecontrol.mb_tree=True", "ratecontrol.lookahead=40")
    else:
        ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
        return 0
    nbTracks = adm.audioTracksCount()
    if nbTracks > 0:
        adm.audioClearTracks()
        for track in range(nbTracks):
            adm.audioAddTrack(track)
            if outidx == 0:
                adm.audioCodec(track, "FDK_AAC", "bitrate=56", "afterburner=True", "profile=5", "sbr=False")
            elif outidx == 1:
                adm.audioCodec(track, "FDK_AAC", "bitrate=128", "afterburner=True", "profile=2", "sbr=False")
            elif outidx == 2:
                adm.audioCodec(track, "FDK_AAC", "bitrate=192", "afterburner=True", "profile=2", "sbr=False")
            else:
                ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
                return 0
    filename = (splitext(filein))[0]
    if outidx == 0:
        adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")
        filename += ".mkv"
    elif outidx == 1:
        adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mp4"
    elif outidx == 2:
        adm.setContainer("MOV", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mov"
    else:
        ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
        return 0
    filename = basename(filename)
    return adm.save(outdir + sep + filename)
#
# Main
#
# -------- select extension and output preset --------
extensions = ["avi","m2ts","mkv","mov","mp4","mpg","ts","vob","webm","wmv"]
mxExt = len(extensions)

menuExt = DFMenu("Select extension:")
for entry in range(0, mxExt):
    menuExt.addItem(extensions[entry])

mxOut = len(outputs)

menuOut = DFMenu("Select output preset:")
for entry in range(0, mxOut):
    menuOut.addItem(outputs[entry])

dia = DialogFactory("Configuration")
dia.addControl(menuExt)
dia.addControl(menuOut)
if not dia.show():
    return

idxExt = menuExt.index

if idxExt < 0 or idxExt >= mxExt:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

ext = extensions[idxExt]

idxOut = menuOut.index

if idxOut < 0 or idxOut >= mxOut:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

# -------- select input directory --------
inputFolder = ui.dirSelect("Select source folder")
if inputFolder is None:
    ui.displayError("Error", "No source folder selected")
    return

# -------- read content --------
list = get_folder_content(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

# -------- select output directory --------
outputFolder = ui.dirSelect("Select output folder")
if outputFolder is None:
    ui.displayError("Error", "No output folder selected")
    return

if(inputFolder == outputFolder):
    ui.displayError("Error","Output folder cannot be the same as the input one")
    return

# -------- process --------
total = 0
counter = 0

for i in list:
    total += 1
    counter += convert(i, outputFolder, idxOut)

if not counter:
    ui.displayInfo("Warning", "No files converted")
    return

if counter == 1:
    ui.displayInfo("Finished", "One file out of " + str(total) + " converted")
    return

ui.displayInfo("Finished", str(counter) + " files out of " + str(total) + " converted")

I didn't verify that video encoder configuration makes sense, please replace it with whatever suits your needs. I think that special cases like interlaced source videos should be handled manually anyway.

THANK YOU. I really appreciate it.  Managed to attach over 40 output presets within 4 individual scripts, and it's all thanks to you.  Thanks again.

chucknolan

Apologies for bothering you, but I am not sure if you answered this previous question regarding how to apply the preset to a specific file via selection.  I was wondering, below, if you can help me with the script because it gives me a loading error each time I want to select a specific file instead of the folder:

# -------- select input directory --------
inputFolder = ui.dirSelect("Select source folder")
if inputFolder is None:
    ui.displayError("Error", "No source folder selected")
    return
   
# -------- read content --------
list = get_folder_content(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

# -------- read content commanding --------
list = ui.fileReadSelect(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

# -------- write content commanding --------
list = ui.fileWriteSelect(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

eumagga0x2a

You cannot use dirSelect() for single file selection, it also doesn't make sense to use a list to hold a single string. You could use the following not exactly pretty script which adds an additional dialog to switch between directory and single file modes:

#PY  <- Needed to identify #
#
ui = Gui()
adm = Avidemux()
ext = "mp4"
outputs = ["MKV, xvid4, HE-AAC @ 56 kbps (FDK-AAC)","MP4, x265, AAC LC @ 128 kbps (FDK-AAC)","MOV, x264, AAC LC @ 192 kbps (FDK-AAC)"]
mxOut = len(outputs)
sep = "\\"
#
# Function to convert an individual video
#
def convert(filein,outdir,outidx):
    if not adm.loadVideo(filein):
        ui.displayError("oops","cannot load "+filein)
        return 0

    if outidx == 0:
        adm.videoCodec("xvid4", "params=CQ=2", "profile=244", "rdMode=3", "motionEstimation=3", "cqmMode=0", "arMode=1", "maxBFrame=2", "maxKeyFrameInterval=200", "nbThreads=99", "qMin=2", "qMax=25", "rdOnBFrame=True", "hqAcPred=True"
, "optimizeChrome=True", "trellis=True", "useXvidFCC=True", "enableFrameDrop=False", "frameDropRatio=50")
    elif outidx == 1:
        adm.videoCodec("x265", "useAdvancedConfiguration=True", "general.params=AQ=20", "general.poolThreads=99", "general.frameThreads=99", "general.output_bit_depth=0", "general.preset=", "general.tuning=", "general.profile=", "level=-1"
, "vui.sar_idc=0", "vui.sar_height=1", "vui.sar_width=1", "vui.color_primaries=2", "vui.transfer_characteristics=2", "vui.matrix_coeffs=2", "MaxRefFrames=3", "MinIdr=25", "MaxIdr=250", "i_scenecut_threshold=40"
, "MaxBFrame=3", "i_bframe_adaptive=2", "i_bframe_bias=0", "i_bframe_pyramid=1", "b_deblocking_filter=True", "b_open_gop=False", "interlaced_mode=0", "constrained_intra=False", "b_intra=True", "lookahead=40"
, "weighted_pred=2", "weighted_bipred=True", "rect_inter=False", "amp_inter=False", "limit_modes=False", "cb_chroma_offset=0", "cr_chroma_offset=0", "me_method=3", "me_range=16", "subpel_refine=5", "limit_refs=3"
, "rd_level=3", "psy_rd=1.000000", "rdoq_level=0", "psy_rdoq=0.000000", "fast_pskip=True", "dct_decimate=True", "noise_reduction_intra=0", "noise_reduction_inter=0", "strong_intra_smoothing=True", "ratecontrol.rc_method=0"
, "ratecontrol.qp_constant=0", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=1", "ratecontrol.ip_factor=1.400000"
, "ratecontrol.pb_factor=1.300000", "ratecontrol.aq_mode=2", "ratecontrol.aq_strength=1.000000", "ratecontrol.cu_tree=True", "ratecontrol.strict_cbr=False")
    elif outidx == 2:
        adm.videoCodec("x264", "useAdvancedConfiguration=False", "general.params=AQ=20", "general.threads=0", "general.preset=veryfast", "general.tuning=none", "general.profile=high", "general.fast_decode=False", "general.zero_latency=False"
, "general.fast_first_pass=True", "general.blueray_compatibility=False", "general.fake_interlaced=False", "level=-1", "vui.sar_height=1", "vui.sar_width=1", "MaxRefFrames=3", "MinIdr=25", "MaxIdr=250"
, "i_scenecut_threshold=40", "intra_refresh=False", "MaxBFrame=3", "i_bframe_adaptive=1", "i_bframe_bias=0", "i_bframe_pyramid=1", "b_deblocking_filter=True", "i_deblocking_filter_alphac0=0", "i_deblocking_filter_beta=0"
, "cabac=True", "interlaced=False", "constrained_intra=False", "tff=True", "fake_interlaced=False", "analyze.b_8x8=True", "analyze.b_i4x4=True", "analyze.b_i8x8=True", "analyze.b_p8x8=True", "analyze.b_p16x16=False"
, "analyze.b_b16x16=False", "analyze.weighted_pred=2", "analyze.weighted_bipred=True", "analyze.direct_mv_pred=1", "analyze.chroma_offset=0", "analyze.me_method=1", "analyze.me_range=16", "analyze.mv_range=-1"
, "analyze.mv_range_thread=-1", "analyze.subpel_refine=7", "analyze.chroma_me=True", "analyze.mixed_references=True", "analyze.trellis=1", "analyze.psy_rd=1.000000", "analyze.psy_trellis=0.000000", "analyze.fast_pskip=True"
, "analyze.dct_decimate=True", "analyze.noise_reduction=0", "analyze.psy=True", "analyze.intra_luma=11", "analyze.inter_luma=21", "ratecontrol.rc_method=0", "ratecontrol.qp_constant=0", "ratecontrol.qp_min=10"
, "ratecontrol.qp_max=51", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.rate_tolerance=1.000000", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=1"
, "ratecontrol.ip_factor=1.400000", "ratecontrol.pb_factor=1.300000", "ratecontrol.aq_mode=1", "ratecontrol.aq_strength=1.000000", "ratecontrol.mb_tree=True", "ratecontrol.lookahead=40")
    else:
        ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
        return 0
    nbTracks = adm.audioTracksCount()
    if nbTracks > 0:
        adm.audioClearTracks()
        for track in range(nbTracks):
            adm.audioAddTrack(track)
            if outidx == 0:
                adm.audioCodec(track, "FDK_AAC", "bitrate=56", "afterburner=True", "profile=5", "sbr=False")
            elif outidx == 1:
                adm.audioCodec(track, "FDK_AAC", "bitrate=128", "afterburner=True", "profile=2", "sbr=False")
            elif outidx == 2:
                adm.audioCodec(track, "FDK_AAC", "bitrate=192", "afterburner=True", "profile=2", "sbr=False")
            else:
                ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
                return 0
    filename = (splitext(filein))[0]
    if outidx == 0:
        adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")
        filename += ".mkv"
    elif outidx == 1:
        adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mp4"
    elif outidx == 2:
        adm.setContainer("MOV", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mov"
    else:
        ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
        return 0
    filename = basename(filename)
    return adm.save(outdir + sep + filename)
#
# Main
#
# -------- select mode --------
menuMode = DFMenu("Select mode:")
menuMode.addItem("Process directory")
menuMode.addItem("Process single file")

diaMode = DialogFactory("Type of operation")
diaMode.addControl(menuMode)
if not diaMode.show():
    return

idxMode = menuMode.index

if idxMode < 0 or idxMode > 1:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

if idxMode == 1:
    # select output preset for single-file operation
    mxOut = len(outputs)
    menuOut = DFMenu("Select output preset:")
    for entry in range(mxOut):
        menuOut.addItem(outputs[entry])
    diaSingle = DialogFactory("Configuration")
    diaSingle.addControl(menuOut)
    if not diaSingle.show():
        return
    idxOut = menuOut.index
    if idxOut < 0 or idxOut >= mxOut:
        ui.displayError("Oops", "Internal error: invalid menu index")
        return
    # select input file
    fileToProcess = ui.fileReadSelect("Select file to process")
    if fileToProcess is None:
        return
    # select output directory
    outputFolder = ui.dirSelect("Select output folder")
    if outputFolder is None:
        ui.displayError("Error", "No output folder selected")
        return
    if outputFolder == dirname(fileToProcess):
        ui.displayError("Error","Output folder and the directory of the input file must be different")
        return
    # process!
    if not convert(fileToProcess, outputFolder, idxOut):
        ui.displayError("Error","Error processing \"" + fileToProcess + "\"")
        return
    ui.displayInfo("Finished","File \"" + fileToProcess + "\" processed successfully")
    return

# -------- select extension and output preset --------
extensions = ["avi","m2ts","mkv","mov","mp4","mpg","ts","vob","webm","wmv"]
mxExt = len(extensions)

menuExt = DFMenu("Select extension:")
for entry in range(0, mxExt):
    menuExt.addItem(extensions[entry])

menuOut = DFMenu("Select output preset:")
for entry in range(0, mxOut):
    menuOut.addItem(outputs[entry])

diaMulti = DialogFactory("Configuration")
diaMulti.addControl(menuExt)
diaMulti.addControl(menuOut)
if not diaMulti.show():
    return

idxExt = menuExt.index

if idxExt < 0 or idxExt >= mxExt:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

ext = extensions[idxExt]

idxOut = menuOut.index

if idxOut < 0 or idxOut >= mxOut:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

# -------- select input directory --------
inputFolder = ui.dirSelect("Select source folder")
if inputFolder is None:
    ui.displayError("Error", "No source folder selected")
    return

# -------- read content --------
list = get_folder_content(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

# -------- select output directory --------
outputFolder = ui.dirSelect("Select output folder")
if outputFolder is None:
    ui.displayError("Error", "No output folder selected")
    return

if(inputFolder == outputFolder):
    ui.displayError("Error","Output folder cannot be the same as the input one")
    return

# -------- process --------
total = 0
counter = 0

for i in list:
    total += 1
    counter += convert(i, outputFolder, idxOut)

if not counter:
    ui.displayInfo("Warning", "No files converted")
    return

if counter == 1:
    ui.displayInfo("Finished", "One file out of " + str(total) + " converted")
    return

ui.displayInfo("Finished", str(counter) + " files out of " + str(total) + " converted")

Honestly, I would rather move single-file processing to a completely different script.

butterw

#41
Tinypy is quite limited. This is how you can create a list from a single filepath variable:

f_list = []
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\""); return
f_ path = ui.fileReadSelect(inputFolder, ext)
f_list.append[f_path]
or
f_list = [ui.fileReadSelect(inputFolder, ext)]
if f_list[0] is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\""); return

list is a built-in function name in python, even though it's not available in TinyPy, I don't think it is a good idea to use it as a variable name.


chucknolan

#42
Quote from: eumagga0x2a on May 03, 2021, 11:11:42 PMYou cannot use dirSelect() for single file selection, it also doesn't make sense to use a list to hold a single string. You could use the following not exactly pretty script which adds an additional dialog to switch between directory and single file modes:

#PY  <- Needed to identify #
#
ui = Gui()
adm = Avidemux()
ext = "mp4"
outputs = ["MKV, xvid4, HE-AAC @ 56 kbps (FDK-AAC)","MP4, x265, AAC LC @ 128 kbps (FDK-AAC)","MOV, x264, AAC LC @ 192 kbps (FDK-AAC)"]
mxOut = len(outputs)
sep = "\\"
#
# Function to convert an individual video
#
def convert(filein,outdir,outidx):
    if not adm.loadVideo(filein):
        ui.displayError("oops","cannot load "+filein)
        return 0

    if outidx == 0:
        adm.videoCodec("xvid4", "params=CQ=2", "profile=244", "rdMode=3", "motionEstimation=3", "cqmMode=0", "arMode=1", "maxBFrame=2", "maxKeyFrameInterval=200", "nbThreads=99", "qMin=2", "qMax=25", "rdOnBFrame=True", "hqAcPred=True"
, "optimizeChrome=True", "trellis=True", "useXvidFCC=True", "enableFrameDrop=False", "frameDropRatio=50")
    elif outidx == 1:
        adm.videoCodec("x265", "useAdvancedConfiguration=True", "general.params=AQ=20", "general.poolThreads=99", "general.frameThreads=99", "general.output_bit_depth=0", "general.preset=", "general.tuning=", "general.profile=", "level=-1"
, "vui.sar_idc=0", "vui.sar_height=1", "vui.sar_width=1", "vui.color_primaries=2", "vui.transfer_characteristics=2", "vui.matrix_coeffs=2", "MaxRefFrames=3", "MinIdr=25", "MaxIdr=250", "i_scenecut_threshold=40"
, "MaxBFrame=3", "i_bframe_adaptive=2", "i_bframe_bias=0", "i_bframe_pyramid=1", "b_deblocking_filter=True", "b_open_gop=False", "interlaced_mode=0", "constrained_intra=False", "b_intra=True", "lookahead=40"
, "weighted_pred=2", "weighted_bipred=True", "rect_inter=False", "amp_inter=False", "limit_modes=False", "cb_chroma_offset=0", "cr_chroma_offset=0", "me_method=3", "me_range=16", "subpel_refine=5", "limit_refs=3"
, "rd_level=3", "psy_rd=1.000000", "rdoq_level=0", "psy_rdoq=0.000000", "fast_pskip=True", "dct_decimate=True", "noise_reduction_intra=0", "noise_reduction_inter=0", "strong_intra_smoothing=True", "ratecontrol.rc_method=0"
, "ratecontrol.qp_constant=0", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=1", "ratecontrol.ip_factor=1.400000"
, "ratecontrol.pb_factor=1.300000", "ratecontrol.aq_mode=2", "ratecontrol.aq_strength=1.000000", "ratecontrol.cu_tree=True", "ratecontrol.strict_cbr=False")
    elif outidx == 2:
        adm.videoCodec("x264", "useAdvancedConfiguration=False", "general.params=AQ=20", "general.threads=0", "general.preset=veryfast", "general.tuning=none", "general.profile=high", "general.fast_decode=False", "general.zero_latency=False"
, "general.fast_first_pass=True", "general.blueray_compatibility=False", "general.fake_interlaced=False", "level=-1", "vui.sar_height=1", "vui.sar_width=1", "MaxRefFrames=3", "MinIdr=25", "MaxIdr=250"
, "i_scenecut_threshold=40", "intra_refresh=False", "MaxBFrame=3", "i_bframe_adaptive=1", "i_bframe_bias=0", "i_bframe_pyramid=1", "b_deblocking_filter=True", "i_deblocking_filter_alphac0=0", "i_deblocking_filter_beta=0"
, "cabac=True", "interlaced=False", "constrained_intra=False", "tff=True", "fake_interlaced=False", "analyze.b_8x8=True", "analyze.b_i4x4=True", "analyze.b_i8x8=True", "analyze.b_p8x8=True", "analyze.b_p16x16=False"
, "analyze.b_b16x16=False", "analyze.weighted_pred=2", "analyze.weighted_bipred=True", "analyze.direct_mv_pred=1", "analyze.chroma_offset=0", "analyze.me_method=1", "analyze.me_range=16", "analyze.mv_range=-1"
, "analyze.mv_range_thread=-1", "analyze.subpel_refine=7", "analyze.chroma_me=True", "analyze.mixed_references=True", "analyze.trellis=1", "analyze.psy_rd=1.000000", "analyze.psy_trellis=0.000000", "analyze.fast_pskip=True"
, "analyze.dct_decimate=True", "analyze.noise_reduction=0", "analyze.psy=True", "analyze.intra_luma=11", "analyze.inter_luma=21", "ratecontrol.rc_method=0", "ratecontrol.qp_constant=0", "ratecontrol.qp_min=10"
, "ratecontrol.qp_max=51", "ratecontrol.qp_step=4", "ratecontrol.bitrate=0", "ratecontrol.rate_tolerance=1.000000", "ratecontrol.vbv_max_bitrate=0", "ratecontrol.vbv_buffer_size=0", "ratecontrol.vbv_buffer_init=1"
, "ratecontrol.ip_factor=1.400000", "ratecontrol.pb_factor=1.300000", "ratecontrol.aq_mode=1", "ratecontrol.aq_strength=1.000000", "ratecontrol.mb_tree=True", "ratecontrol.lookahead=40")
    else:
        ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
        return 0
    nbTracks = adm.audioTracksCount()
    if nbTracks > 0:
        adm.audioClearTracks()
        for track in range(nbTracks):
            adm.audioAddTrack(track)
            if outidx == 0:
                adm.audioCodec(track, "FDK_AAC", "bitrate=56", "afterburner=True", "profile=5", "sbr=False")
            elif outidx == 1:
                adm.audioCodec(track, "FDK_AAC", "bitrate=128", "afterburner=True", "profile=2", "sbr=False")
            elif outidx == 2:
                adm.audioCodec(track, "FDK_AAC", "bitrate=192", "afterburner=True", "profile=2", "sbr=False")
            else:
                ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
                return 0
    filename = (splitext(filein))[0]
    if outidx == 0:
        adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")
        filename += ".mkv"
    elif outidx == 1:
        adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mp4"
    elif outidx == 2:
        adm.setContainer("MOV", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")
        filename += ".mov"
    else:
        ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
        return 0
    filename = basename(filename)
    return adm.save(outdir + sep + filename)
#
# Main
#
# -------- select mode --------
menuMode = DFMenu("Select mode:")
menuMode.addItem("Process directory")
menuMode.addItem("Process single file")

diaMode = DialogFactory("Type of operation")
diaMode.addControl(menuMode)
if not diaMode.show():
    return

idxMode = menuMode.index

if idxMode < 0 or idxMode > 1:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

if idxMode == 1:
    # select output preset for single-file operation
    mxOut = len(outputs)
    menuOut = DFMenu("Select output preset:")
    for entry in range(mxOut):
        menuOut.addItem(outputs[entry])
    diaSingle = DialogFactory("Configuration")
    diaSingle.addControl(menuOut)
    if not diaSingle.show():
        return
    idxOut = menuOut.index
    if idxOut < 0 or idxOut >= mxOut:
        ui.displayError("Oops", "Internal error: invalid menu index")
        return
    # select input file
    fileToProcess = ui.fileReadSelect("Select file to process")
    if fileToProcess is None:
        return
    # select output directory
    outputFolder = ui.dirSelect("Select output folder")
    if outputFolder is None:
        ui.displayError("Error", "No output folder selected")
        return
    if outputFolder == dirname(fileToProcess):
        ui.displayError("Error","Output folder and the directory of the input file must be different")
        return
    # process!
    if not convert(fileToProcess, outputFolder, idxOut):
        ui.displayError("Error","Error processing \"" + fileToProcess + "\"")
        return
    ui.displayInfo("Finished","File \"" + fileToProcess + "\" processed successfully")
    return

# -------- select extension and output preset --------
extensions = ["avi","m2ts","mkv","mov","mp4","mpg","ts","vob","webm","wmv"]
mxExt = len(extensions)

menuExt = DFMenu("Select extension:")
for entry in range(0, mxExt):
    menuExt.addItem(extensions[entry])

menuOut = DFMenu("Select output preset:")
for entry in range(0, mxOut):
    menuOut.addItem(outputs[entry])

diaMulti = DialogFactory("Configuration")
diaMulti.addControl(menuExt)
diaMulti.addControl(menuOut)
if not diaMulti.show():
    return

idxExt = menuExt.index

if idxExt < 0 or idxExt >= mxExt:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

ext = extensions[idxExt]

idxOut = menuOut.index

if idxOut < 0 or idxOut >= mxOut:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

# -------- select input directory --------
inputFolder = ui.dirSelect("Select source folder")
if inputFolder is None:
    ui.displayError("Error", "No source folder selected")
    return

# -------- read content --------
list = get_folder_content(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

# -------- select output directory --------
outputFolder = ui.dirSelect("Select output folder")
if outputFolder is None:
    ui.displayError("Error", "No output folder selected")
    return

if(inputFolder == outputFolder):
    ui.displayError("Error","Output folder cannot be the same as the input one")
    return

# -------- process --------
total = 0
counter = 0

for i in list:
    total += 1
    counter += convert(i, outputFolder, idxOut)

if not counter:
    ui.displayInfo("Warning", "No files converted")
    return

if counter == 1:
    ui.displayInfo("Finished", "One file out of " + str(total) + " converted")
    return

ui.displayInfo("Finished", str(counter) + " files out of " + str(total) + " converted")

Honestly, I would rather move single-file processing to a completely different script.

Thank you, sir.  Last question, regarding INDEPENDENT presets.  Would the script, below, be classified as INDEPENDENT because I utilized a cumulative of all the templates that you provided for me?  Nonetheless, the three output presets worked on the script below.


#PY  <- Needed to identify #
#
ui = Gui()
adm = Avidemux()
ext = "mp4"
outputs = ["MKV, xvid4, HE-AAC @ 56 kbps (FDK-AAC)","MP4, AAC LC @ 128 kbps (FDK-AAC)","MOV, HE-AACv2 @ 56 kbps (FDK-AAC)"]
mxOut = len(outputs)
sep = "\\"
#
# Function to convert an individual video
#
def convert(filein,outdir,outidx):
    if not adm.loadVideo(filein):
        ui.displayError("oops","cannot load "+filein)
        return 0

    if outidx == 0:
        adm.videoCodec("xvid4", "params=CQ=2", "profile=244", "rdMode=3", "motionEstimation=3", "cqmMode=0", "arMode=1", "maxBFrame=2", "maxKeyFrameInterval=200", "nbThreads=99", "qMin=2", "qMax=25", "rdOnBFrame=True", "hqAcPred=True"
, "optimizeChrome=True", "trellis=True", "useXvidFCC=True", "enableFrameDrop=False", "frameDropRatio=50")
        if adm.audioTracksCount() > 0:
            adm.audioClearTracks()
            adm.audioAddTrack(0)
            adm.audioCodec(0, "FDK_AAC", "bitrate=56", "afterburner=True", "profile=5", "sbr=False")
            adm.audioSetDrc(0, 0)
            adm.audioSetShift(0, 0, 0)
            adm.audioSetNormalize2(0, 2, 120, -30)
        adm.setContainer("MKV", "forceAspectRatio=False", "displayWidth=1280", "displayAspectRatio=2", "addColourInfo=False", "colMatrixCoeff=2", "colRange=0", "colTransfer=2", "colPrimaries=2")

        filename = (splitext(filein))[0]
        filename += ".mkv"
        filename = basename(filename)
        return adm.save(outdir + sep + filename)
    elif outidx == 1:
        adm.videoCodec("copy")
        if adm.audioTracksCount() > 0:
            adm.audioClearTracks()
            adm.audioAddTrack(0)
            adm.audioCodec(0, "FDK_AAC", "bitrate=128", "afterburner=True", "profile=2", "sbr=False")
        adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")

        filename = (splitext(filein))[0]
        filename += ".mp4"
        filename = basename(filename)
        return adm.save(outdir + sep + filename)
    elif outidx == 2:
        adm.videoCodec("copy")
        nbTracks = adm.audioTracksCount()
        if nbTracks > 0:
            adm.audioClearTracks()
            for track in range(nbTracks):
                adm.audioAddTrack(track)
                adm.audioCodec(track, "FDK_AAC", "bitrate=56", "afterburner=True", "profile=29", "sbr=False")
        adm.setContainer("MOV", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "displayWidth=1280", "rotation=0", "clockfreq=0")

        filename = (splitext(filein))[0]
        filename += ".mov"
        filename = basename(filename)
        return adm.save(outdir + sep + filename)
    else:
        ui.displayError("Error", "Invalid output preset index \"" + str(outidx) + "\"")
        return 0
#
# Main
#
# -------- select mode --------
menuMode = DFMenu("Select mode:")
menuMode.addItem("Process directory")
menuMode.addItem("Process single file")

diaMode = DialogFactory("Type of operation")
diaMode.addControl(menuMode)
if not diaMode.show():
    return

idxMode = menuMode.index

if idxMode < 0 or idxMode > 1:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

if idxMode == 1:
    # select output preset for single-file operation
    mxOut = len(outputs)
    menuOut = DFMenu("Select output preset:")
    for entry in range(mxOut):
        menuOut.addItem(outputs[entry])
    diaSingle = DialogFactory("Configuration")
    diaSingle.addControl(menuOut)
    if not diaSingle.show():
        return
    idxOut = menuOut.index
    if idxOut < 0 or idxOut >= mxOut:
        ui.displayError("Oops", "Internal error: invalid menu index")
        return
    # select input file
    fileToProcess = ui.fileReadSelect("Select file to process")
    if fileToProcess is None:
        return
    # select output directory
    outputFolder = ui.dirSelect("Select output folder")
    if outputFolder is None:
        ui.displayError("Error", "No output folder selected")
        return
    if outputFolder == dirname(fileToProcess):
        ui.displayError("Error","Output folder and the directory of the input file must be different")
        return
    # process!
    if not convert(fileToProcess, outputFolder, idxOut):
        ui.displayError("Error","Error processing \"" + fileToProcess + "\"")
        return
    ui.displayInfo("Finished","File \"" + fileToProcess + "\" processed successfully")
    return

# -------- select extension and output preset --------
extensions = ["avi","m2ts","mkv","mov","mp4","mpg","ts","vob","webm","wmv"]
mxExt = len(extensions)

menuExt = DFMenu("Select extension:")
for entry in range(0, mxExt):
    menuExt.addItem(extensions[entry])

menuOut = DFMenu("Select output preset:")
for entry in range(0, mxOut):
    menuOut.addItem(outputs[entry])

diaMulti = DialogFactory("Configuration")
diaMulti.addControl(menuExt)
diaMulti.addControl(menuOut)
if not diaMulti.show():
    return

idxExt = menuExt.index

if idxExt < 0 or idxExt >= mxExt:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

ext = extensions[idxExt]

idxOut = menuOut.index

if idxOut < 0 or idxOut >= mxOut:
    ui.displayError("Oops", "Internal error: invalid menu index")
    return

# -------- select input directory --------
inputFolder = ui.dirSelect("Select source folder")
if inputFolder is None:
    ui.displayError("Error", "No source folder selected")
    return

# -------- read content --------
list = get_folder_content(inputFolder, ext)
if list is None:
    ui.displayError("Oops", "No " + ext + " files found in \"" + inputFolder + "\"")
    return

# -------- select output directory --------
outputFolder = ui.dirSelect("Select output folder")
if outputFolder is None:
    ui.displayError("Error", "No output folder selected")
    return

if(inputFolder == outputFolder):
    ui.displayError("Error","Output folder cannot be the same as the input one")
    return

# -------- process --------
total = 0
counter = 0

for i in list:
    total += 1
    counter += convert(i, outputFolder, idxOut)

if not counter:
    ui.displayInfo("Warning", "No files converted")
    return

if counter == 1:
    ui.displayInfo("Finished", "One file out of " + str(total) + " converted")
    return

ui.displayInfo("Finished", str(counter) + " files out of " + str(total) + " converted")

eumagga0x2a

Quote from: chucknolan on May 06, 2021, 07:48:00 PMWould the script, below, be classified as INDEPENDENT because I utilized a cumulative of all the templates that you provided for me?

"Independent" vs "linked" meant the ability to specify video encoder independently from muxer. Obviously, both are linked in your script.

chucknolan

Quote from: eumagga0x2a on May 06, 2021, 09:33:58 PM"Independent" vs "linked" meant the ability to specify video encoder independently from muxer. Obviously, both are linked in your script.


They were linked to only reassure the drop-down menu output preset selection.  Nonetheless, I'm still confused about how an independent script would look like, and was hoping, at your leisure, if you can write one for me?