News:

--

Main Menu

How to convert all files in a folder?

Started by Vendeur, June 06, 2016, 04:04:29 PM

Previous topic - Next topic

mean

* indentation is wrong
* you forgot the \  at the end of the split lines

That seems to work


#
# Load all the files with .mkv extension in a selected directory, convert with x265 video codec at 2000cbr, aac 128kb audio codec + noise reduction

#
gui = Gui()
adm = Avidemux()
ext = "mkv"
#
def convert(filein):   

    if(0 == adm.loadVideo(filein)):
        ui.displayError("oops","cannot load "+filein)
        raise
    adm.videoCodec("x265", "useAdvancedConfiguration=True", "general.params=CBR=2000", "general.poolThreads=0", "general.frameThreads=0", "general.preset=ultrafast", "general.tuning=psnr", "general.profile=main", "level=-1", "vui.sar_height=1"\
, "vui.sar_width=1", "MaxRefFrames=3", "MinIdr=25", "MaxIdr=250", "i_scenecut_threshold=40", "MaxBFrame=3", "i_bframe_adaptive=1", "i_bframe_bias=0", "i_bframe_pyramid=2", "b_deblocking_filter=True", "interlaced_mode=0"\
, "constrained_intra=False", "lookahead=40", "weighted_pred=2", "weighted_bipred=True", "cb_chroma_offset=0", "cr_chroma_offset=0", "me_method=3", "me_range=16", "subpel_refine=5", "trellis=1", "psy_rd=1.000000"\
, "fast_pskip=True", "dct_decimate=True", "noise_reduction=0", "noise_reduction_intra=0", "noise_reduction_inter=0", "ratecontrol.rc_method=0", "ratecontrol.qp_constant=0", "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=0", "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")
    adm.addVideoFilter("fluxsmooth", "temporal_threshold=7", "spatial_threshold=7")
    adm.audioClearTracks()
    adm.setSourceTrackLanguage(0,"unknown")
    adm.audioAddTrack(0)
    adm.audioCodec(0, "Faac", "bitrate=128");
    adm.audioSetDrc(0, 0)
    adm.audioSetShift(0, 0,0)
    adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280")
    adm.save(filein + ".converted.mkv") # save the file
    print("Done")
 
#
# Main
#

inputFolder = gui.dirSelect("Select folder")
#
list=get_folder_content(inputFolder,ext)
if(list is None):
    raise
for i in list:
        convert(i)
print("Done")


RoadRanger

I do this with just Ffmpeg, let me know what exactly you need to do and I'll try to adapt one - here's a sample batch file that creates small MP4 files from FLV files that already have a usable audio stream:

for /R %%f in (*.flv) do call :flv2mp4 "%%f"
goto :eof

:flv2mp4
start "FLV2MP4" /belownormal /min /wait C:/ffmpeg -i %1 -c:v libx264 -crf 30 -c:a copy -movflags +faststart %1.mp4
exit /b

Vendeur

Thank you mean, all is working now well!

I hope one day that simple option will be available just in menu.

Vendeur

Hello, again...

I'm trying to do same thing, as 5 years ago, just a little different. I saved new bath from new project, and inserted this bath code to the old one. But after starting it I'm getting error:




#
# Load all the files with .mp4 extension in a selected directory, convert with x264 video codec at 2000cbr, aac 128kb audio codec

#
gui = Gui()
adm = Avidemux()
ext = "mkv"
#
def convert(filein): 

    if(0 == adm.loadVideo(filein)):
        ui.displayError("oops","cannot load "+filein)
        raise
    aadm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=CBR=2000", "general.threads=0", "general.preset=ultrafast", "general.tuning=none", "general.profile=baseline", "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=2", "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")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"und")
adm.audioAddTrack(0)
adm.audioCodec(0, "LavAAC", "bitrate=128");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0, 0)
adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")

    adm.save(filein + ".converted.mp4") # save the file
    print("Done")
 
#
# Main
#

inputFolder = gui.dirSelect("Select folder")
#
list=get_folder_content(inputFolder,ext)
if(list is None):
    raise
for i in list:
        convert(i)
print("Done")


Vendeur


butterw

indentation is an element of syntax in python.

The content of the convert function needs to be indented with the same level of indentation throughout (and you can't mix tabs and spaces).

Select the bloc of text to indent + press tab in your text editor.

butterw

Quote from: Vendeur on June 22, 2016, 11:26:35 AMI hope one day that simple option will be available just in menu.

Batch processing could either be achieved with a project menu function that auto-generates a batch script based on the current settings.
or it could be an integrated job-list type feature (would make it simpler to cancel a started job).

scripts can be added to the custom menu in the Gui.

Vendeur

Quote from: butterw on May 12, 2021, 10:40:27 AM
Quote from: Vendeur on June 22, 2016, 11:26:35 AMI hope one day that simple option will be available just in menu.

Batch processing could either be achieved with a project menu function that auto-generates a batch script based on the current settings.
or it could be an integrated job-list type feature (would make it simpler to cancel a started job).

scripts can be added to the custom menu in the Gui.

Yeah, this is so stupid, that such a good software have not so simple feture to convert all files in the a folder... After so many years...

I still can't run .py file. Even tried the old one (above in the topic) and do not work.
I reworked on my new one (below) and still got some error:



#
# Load all the files with .mp4 extension in a selected directory, convert with x264 video codec at 2000cbr, aac 128kb audio codec

#
gui = Gui()
adm = Avidemux()
ext = "mkv"
#
def convert(filein):   

    if(0 == adm.loadVideo(filein)):
        ui.displayError("oops","cannot load "+filein)
        raise
    adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=CBR=2000", "general.threads=0", "general.preset=ultrafast", "general.tuning=none", "general.profile=baseline", "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=2", "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")

    adm.audioClearTracks()

    adm.setSourceTrackLanguage(0,"und")

    adm.audioAddTrack(0)

    adm.audioCodec(0,);

    adm.audioSetDrc(0, 0)

    adm.audioSetShift(0, 0, 0)
    adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")

    adm.save(filein + ".converted.mp4") # save the file
    print("Done")
 
#
# Main
#

inputFolder = gui.dirSelect("Select folder")
#
list=get_folder_content(inputFolder,ext)
if(list is None):
    raise
for i in list:
        convert(i)
print("Done")

eumagga0x2a

The exception is raised because the list, returned by get_folder_content is empty.

butterw

#25
No mkv file in folder >> raise

raise("No file in folder !") in your script would be more helpful as it would provide a meaningful error message.

There are other errors in your script however:
adm.audioCodec(0, "FDK_AAC", "bitrate=128", "afterburner=True", "profile=2", "sbr=False")

ui.displayError should be gui.displayError

eumagga0x2a

Quote from: butterw on May 12, 2021, 08:06:10 PMraise("No file in folder !") in your script would be more helpful.

Or just avoiding raise alltogether, at least in the Main part:

inputFolder = gui.dirSelect("Select folder")
if inputFolder is None:
    return
list = get_folder_content(inputFolder, ext)
if list is None:
    gui.displayError("Error", "Folder \"" + inputFolder + "\" contains no files with ending \"" + ext + "\"")
    return
for i in list:
    convert(i)
gui.displayInfo("Info","Operation completed")

I posted more sophisticated scripts on different occasions, e.g. in https://avidemux.org/smif/index.php/topic,19507.0.html

Vendeur

Oh my god, I'm stupid... Forgot to change ext to mp4...

Final script seems working and looks like this:

THANK YOU for your help! :)

#
# Load all the files with .mp4 extension in a selected directory, convert with x264 video codec at 2000cbr, audio copy and set to polish.

#
gui = Gui()
adm = Avidemux()
ext = "mp4"
#
def convert(filein):   

    if(0 == adm.loadVideo(filein)):
        gui.displayError("oops","cannot load "+filein)
        raise
    adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=CBR=2000", "general.threads=0", "general.preset=ultrafast", "general.tuning=none", "general.profile=baseline", "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=2", "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")

    adm.audioClearTracks()

    adm.setSourceTrackLanguage(0,"pol")

    adm.audioAddTrack(0)

    adm.audioCodec(0, "copy")
    adm.audioSetDrc(0, 0)

    adm.audioSetShift(0, 0, 0)
    adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")

    adm.save(filein + ".converted.mp4") # save the file
    print("Done")
 
#
# Main
#

inputFolder = gui.dirSelect("Select folder")
if inputFolder is None:
    return
list = get_folder_content(inputFolder, ext)
if list is None:
    gui.displayError("Error", "Folder \"" + inputFolder + "\" contains no files with ending \"" + ext + "\"")
    return
for i in list:
    convert(i)
gui.displayInfo("Info","Operation completed")