How to remove reference to specific videos in Project scripts

Started by Fozzie Bear, January 08, 2021, 01:09:05 PM

Previous topic - Next topic

Fozzie Bear

I have followed the guidance on these forums to create and save a .py Project script and save it in the correct location. However I have tried to remove the reference to the original video so I can use it on other videos but when I load it I get errors. Below is the content of the script. Please could you advise which lines should be deleted or commented out.

#PY  <- Needed to identify #
#--automatically built--

adm = Avidemux()
if not adm.loadVideo("/home/john/Accused_A_Mother_on_Trial_Series_1_-_02._Episode_2_p08z39tr_editorial.mp4"):
    raise("Cannot load /home/john/Accused_A_Mother_on_Trial_Series_1_-_02._Episode_2_p08z39tr_editorial.mp4")
adm.clearSegments()
adm.addSegment(0, 0, 2465740000)
adm.markerA = 0
adm.markerB = 2465740000
adm.setPostProc(3, 3, 0)
adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=AQ=20", "general.threads=99", "general.preset=", "general.tuning=", "general.profile=", "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.addVideoFilter("swscale", "width=1280", "height=720", "algo=0", "sourceAR=0", "targetAR=0", "lockAR=True", "roundup=False")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"und")
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")
I deleted all the content between brackets after the line(s) "if not adm.loadVideo" and "raise" but when loading it I get the Tiny.py Exception error

Also when working correctly should you load the project script and then browse for and open the video file, or open the video file first and then open the project?
Many thanks
Fozzie

eumagga0x2a

Quote from: Fozzie Bear on January 08, 2021, 01:09:05 PMwhen working correctly should you load the project script and then browse for and open the video file, or open the video file first and then open the project?

It all depends on what you want and need. The following script opens a file dialog to select a source video, another file dialog to select output video, then performs the encoding:

adm = Avidemux()
gui = Gui()

infile = gui.fileReadSelect("Select source video")
if infile is None:
    return 0
if not adm.loadVideo(infile):
    gui.displayError("Oops","Cannot load " + infile)
    return 0
outfile = gui.fileWriteSelect("Select output file")
if outfile is None:
    return 0
adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=AQ=20", "general.threads=99", "general.preset=", "general.tuning=", "general.profile=", "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.addVideoFilter("swscale", "width=1280", "height=720", "algo=0", "sourceAR=0", "targetAR=0", "lockAR=True", "roundup=False")
if adm.audioTotalTracksCount() > 0:
    adm.setSourceTrackLanguage(0,"und")
    adm.audioAddTrack(0)
    adm.audioCodec(0, "copy")
    adm.audioSetShift(0, 0, 0)
adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")
return adm.save(outfile)

Please note that cancelling a file dialog will trigger a tinyPy exception unless you use a future  nightly where I've changed this particular behaviour. You need to add file extension yourself, the current interface doesn't allow to pass a default extension to the file dialog from Python scripts.

If you want just to set encoder, video filter and muxer, you can use

adm.videoCodec("x264", "useAdvancedConfiguration=True", "general.params=AQ=20", "general.threads=99", "general.preset=", "general.tuning=", "general.profile=", "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.addVideoFilter("swscale", "width=1280", "height=720", "algo=0", "sourceAR=0", "targetAR=0", "lockAR=True", "roundup=False")
adm.audioClearTracks()
if adm.audioTotalTracksCount() > 0:
    adm.setSourceTrackLanguage(0,"und")
    adm.audioAddTrack(0)
    adm.audioCodec(0, "copy")
    adm.audioSetShift(0, 0, 0)
adm.setContainer("MP4", "muxerType=0", "optimize=1", "forceAspectRatio=False", "aspectRatio=1", "rotation=0", "clockfreq=0")

In both examples all audio tracks except of the first one are dropped.

By the way, I would recommend to disable post-processing in Avidemux generally unless you really know what you are doing and why you need it.

Fozzie Bear

Sorry for delayed reply. Thank you so much for this. I will try each version and see which suits my needs best.
As for post processing I have not knowingly selected this? I cant find a setting in preferences which selects this by default only on the main menu which is greyed out with most files. Is there a setting somewhere i need to un-check or is you advice just a cautionary warning?
Fozzie

eumagga0x2a

Quote from: Fozzie Bear on January 13, 2021, 10:49:38 AMAs for post processing I have not knowingly selected this?

Post-processing was always enabled by default in Avidemux, I changed the default to disabled only very recently. At the same time, post-processing was always skipped when hardware acceleration for video decoding was active (the menu entry is disabled to reflect this), so chances are that the setting had no effect.

Quote from: Fozzie Bear on January 13, 2021, 10:49:38 AMI cant find a setting in preferences which selects this by default

Preferences --> Display --> Default Postprocessing.