Advertisement
Guest User

4ffmpeg-8.204

a guest
Oct 30th, 2015
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 170.23 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. '''
  5. ---------------------------------
  6. work in python2.7/3
  7. os: gnu/linux only
  8. ---------------------------------
  9. need:
  10. python, gtk3 (3.14|3.16), cairo, pango, libvte (2.90|2.91)
  11. --------------------------------
  12. packages in debian could be:
  13. libgtk-3-0
  14. python-gi
  15. python-gi-cairo
  16. python-gobject
  17. gir1.2-pango-1.0
  18. libvte9
  19. libvte-2.90-9 | libvte-2.91-0
  20. gir1.2-vte-2.90 | gir1.2-vte-2.91
  21. ---------------------------------
  22. ffmpeg executables:
  23. ffmpeg, ffplay, ffprobe >= 2.8
  24. build with:
  25. libfaac, libaacplus, libfdk-aac, libmp3lame,
  26. postproc, avfilter,
  27. libx264, libx265 multilib (8-10bit),
  28. libsoxr, libzimg
  29. ---------------------------------
  30. '''
  31.  
  32. import gi
  33. try:
  34.         gi.require_version('Vte', '2.90')
  35. except:
  36.         pass
  37. from gi.repository import Gtk, GObject, Vte, GLib, Pango
  38. import os, sys, subprocess, threading, time, re
  39. from subprocess import call
  40. from math import pow
  41.  
  42. # Abstract struct class      
  43. class Struct:
  44.        
  45.         def __init__ (self, *argv, **argd):
  46.                 if len(argd):
  47.                         # Update by dictionary
  48.                         self.__dict__.update (argd)
  49.                 else:
  50.                         # Update by position
  51.                         attrs = [x for x in dir(self) if x[0:2] != "__"]
  52.                         for n in range(len(argv)):
  53.                                 setattr(self, attrs[n], argv[n])
  54.  
  55. class Vars(Struct):
  56.        
  57.         version = "8.204"
  58.         ffmpeg_ex = 'ffmpeg'
  59.         ffplay_ex = 'ffplay'
  60.         ffprobe_ex = 'ffprobe'
  61.         final_vf_str = ""
  62.         final_af_str = ""
  63.         deint_str = ""
  64.         crop_str = ""
  65.         scalestr = ""
  66.         dn_str = ""
  67.         uns_str = ""
  68.         fr_str = ""
  69.         filter_test_str = ""
  70.         video_width = "0"
  71.         video_height = "0"
  72.         darin = "1"
  73.         add_1_1_dar = True
  74.         framerate = 25
  75.         maps_str = ""
  76.         time_final_str = ""
  77.         final_codec_str = ""
  78.         final_other_str = ""
  79.         acodec_is = ""
  80.         audio_channels = 0
  81.         audio_srate_in = ""
  82.         audio_codec_str = ""
  83.         vcodec_is = ""
  84.         video_codec_str = ""
  85.         video_codec_str_more = ""
  86.         container_str = ""
  87.         info_str = ''
  88.         blackdet_is_run = False
  89.         compinit = '.3 .3:1 1:-90/-90 -60/-40 -39/-30 -20/-14 -9/-9 0/-3:6:-5:0:.5'
  90.         compand_data = ''
  91.         compand_time = 0
  92.         dynaudnorm = "f=500:g=31:s=18:p=0.80"
  93.         dynaudnorm_data = ''
  94.         time_start = 0 # for cropdetect and test
  95.         p3_command = ""
  96.         filename = ""
  97.         dirname = ""
  98.         basename = ""
  99.         in_file_size = ""
  100.         ext = ""
  101.         outdir = ""
  102.         indir = ""
  103.         newname = ""
  104.         duration = ""
  105.         duration_in_sec = 0
  106.         time_done = 0
  107.         time_done_1 = 0
  108.         out_file_size = ""
  109.         debug = 0
  110.         first_pass = 0
  111.         n_pass = 1
  112.         p3_comm_first_p = ""
  113.         final_command1 = ""
  114.         final_command2 = ""
  115.         eff_pass = 0
  116.         BLACKDT_DONE = False
  117.         VOLDT_DONE = False
  118.         FRAMDT_DONE = False
  119.         ENCODING = False
  120.         ac3_drc = ""
  121.         have_subs = False
  122.         maps_ch = ['0:0', '0:1', '0:2']
  123.         XaCheck = ""
  124.         XvCheck = ""
  125.         acodec_list = ""
  126.         vcodec_list = ""
  127.         preset_list = ''
  128.         tune_list = ''
  129.         opt_list = ''
  130.         vrc_list = ''
  131.        
  132. class Tips(Struct):
  133.        
  134.         map_tooltip_str = ' use: 0:0  or  0:0,0:1,0:2 '
  135.         time_tooltip_str = '  use: 90  or  90.555  or  00:01:30  or  00:01:30.555   '
  136.         customscale_str = '   use:  scale=1014:432,setdar=235/100,setsar=1/1   '
  137.         time2frame_str = '  Convert time sec or hh:mm:ss (.decimal) to frames   '
  138.         black_dt_init_str = 'Detect black frames can take some time,\ndepending on the length of the video.'
  139.         compad_str = ' attacks attacks:decays decays: points dbin/dbout dbin/dbout:soft-knee:gain:initial volume:delay  '
  140.         dynaudnorm_str = ' f= 10 to 8000 - frame length ms (500)\n g= 3 to 301 - filter window size (31) must be odd number \n s= 3.00 to 30.0 - compress factor, 0 = disable, 3 = max comp \n p= 0 to 1 (0.95) - target peak value '
  141.         drc_str = '   -drc_scale percentage of dynamic range compression to apply (from 0 to 6) (default 1)   '
  142.         but_file_str = '  Choose input file   '
  143.         audio_samp_str = ' audio samplerate '
  144.         audio_channels_str = ' audio channels '
  145.         subcopy_tooltip_srt = ' false= srt->ass '
  146.         nometa_tooltip_srt = ' true= --map_metadata -1 '
  147.         debug_tooltip_srt = ' only print command in terminal '
  148.         preset_tooltip_str = ' x264/5 preset '
  149.         tune_tooltip_str = ' x264/5 tune '
  150.         opt_tooltip_str = ' x264/5 options/params '
  151.         x265_optscustom_str = '  x265 custom opts, use: rd=3:aq-mode=3:zones=300,1000,b=1.5\/5000,6000,q=50   '
  152.         ffplay_tooltip_str = ' ffplay keys: \n f - full screen \n a - audio stream \n v - video stream \n s - sub stream \n arrows - seek '
  153.         out_dir_tooltip_str = '  Change current out dir   \n  Default: same as input   '
  154.         container_tooltip_srt = '  Change out container   '
  155.  
  156. ################ AUDIO ##################################
  157.  
  158. class ACodec(object):
  159.         def __init__(self, label=None, codec=None, toolt=None, value=None, comm_str=None, kb=False, afterbrn=False, force_stereo=False, no_audio_enc=False):
  160.                 self.label = label
  161.                 self.codec = codec
  162.                 self.toolt = toolt
  163.                 self.value = value
  164.                 self.comm_str = comm_str
  165.                 self.kb = kb
  166.                 self.afterbrn = afterbrn
  167.                 self.force_stereo =  force_stereo
  168.                 self.no_audio_enc = no_audio_enc
  169.         def __str__(self):
  170.                 return '{}, {}, {}'.format(self.label, self.codec, self.toolt)
  171.  
  172.  
  173. class AudioEncoder():
  174.        
  175.         # audio encoder
  176.         # value=(defvalue, lower, upper, step_inc, page_inc)
  177.        
  178.         AEfaaq = ACodec(label='AAC (faac quality Q)', codec='faaq', toolt=' faac vbr: q 80 ~96k, 90 ~100k, 100 ~118k, 120 ~128k, 160 ~156k, 330 ~270k, def:100 ', value=(100.0, 80, 330, 10, 1), comm_str='-c:a libfaac -q:a ')
  179.        
  180.         AEfaacb = ACodec(label='AAC (faac ABR Kb/s)', codec='faacb', toolt=' faac abr: 32-320 Kb/s def:112 ', value=(112.0, 64, 320, 8, 2), comm_str='-c:a libfaac -b:a ', kb=True)
  181.        
  182.         AEfdkaac = ACodec(label='AAC (fdk CBR Kb/s)', codec='fdkaac', toolt=' aac_fdk cbr: 64-320 Kb/s def:128 ', value=(128.0, 32, 320, 8, 2), comm_str='-c:a libfdk_aac -b:a ', kb=True, afterbrn=True)
  183.        
  184.         AElame = ACodec(label='MP3 (lame CBR Kb/s)', codec='lame', toolt=' lame mp3: 32-320 Kb/s def:128 ', value=(128.0, 32, 320, 8, 2), comm_str='-c:a libmp3lame -b:a ', kb=True)
  185.        
  186.         AElameq = ACodec(label='MP3 (lame VBR Q)', codec='lameq', toolt=' lame mp3 vbr: q 0 ~245Kb/s, 5 ~130Kb/s, 6 ~115Kb/s, 9 ~65Kb/s, def:6 ', value=(6.0, 0, 9, 1, 1), comm_str='-c:a libmp3lame -q:a ')
  187.        
  188.         AEaacn = ACodec(label='AAC (native CBR Kb/s)', codec='aacn', toolt=' aac cbr: 32-320 Kb/s def:128 ', value=(128.0, 34, 320, 8, 2), comm_str='-c:a aac -strict -2 -b:a ', kb=True)
  189.        
  190.         AEacopy = ACodec(label='Audio Copy', codec='acopy', no_audio_enc=True, comm_str='-c:a copy')
  191.        
  192.         AEanone = ACodec(label='No Audio', codec='anone',  no_audio_enc=True, comm_str='-an')
  193.        
  194.         AEaap32 = ACodec(label='AAC-HEv1 (aac+ 32 Kb/s)', codec='aap32', comm_str='-c:a libaacplus -b:a 32k')
  195.        
  196.         AEaap64 = ACodec(label='AAC-HEv1 (aac+ 64 Kb/s)', codec='aap64', comm_str='-c:a libaacplus -b:a 64k', force_stereo=True)
  197.        
  198.         AEfdkaac_he = ACodec(label='AAC-HEv1 (fdk Kb/s)', codec='fdkaac_he', toolt=' aac_fdk_he1 cbr: 48-64 Kb/s def:64 ', value=(64.0, 48, 64 , 2, 2), comm_str='-c:a libfdk_aac -profile:a aac_he -b:a ', kb=True, afterbrn=True)
  199.        
  200.         AEfdkaac_vbr = ACodec(label='AAC (fdk VBR Q)', codec='fdkaac_vbr', toolt=' aac_fdk vbr: 5 ~160K, 4 ~120K, 3 ~100K, 2 ~80K, 1 ~70K ', value=(2.0, 1, 5, 1, 1), comm_str='-c:a libfdk_aac -vbr ', afterbrn=True)
  201.  
  202.         # groups: ------------------------------
  203.        
  204.         AEall = (AEfaaq, AEfaacb, AEfdkaac, AElame, AElameq, AEaacn, AEacopy, AEanone, AEaap32, AEaap64, AEfdkaac_he, AEfdkaac_vbr)
  205.        
  206.         #
  207.         AEmp4 = (AEfaaq, AEfaacb, AEaacn, AEfdkaac, AEfdkaac_vbr, AEfdkaac_he, AEaap64, AEaap32, AElame, AElameq, AEacopy, AEanone)
  208.        
  209.         AEmp4_default = AEmp4.index(AEfdkaac_vbr)
  210.        
  211.         #
  212.         AEmka = (AEfaaq, AEfaacb, AEaacn, AEfdkaac, AEfdkaac_vbr, AEfdkaac_he, AEaap64, AEaap32, AElame, AElameq, AEacopy)
  213.        
  214.         AEmka_default = AEmka.index(AEfaaq)
  215.        
  216.         #
  217.         AEavi = (AElame, AElameq, AEacopy, AEanone)
  218.        
  219.         AEavi_default = AEavi.index(AElame)
  220.  
  221.         ######## AUDIO SAMPLE RATE ########################
  222.         AEaudio_sample = [
  223.                 '48000',
  224.                 '44100'
  225.                 ]
  226.  
  227.         ######## AUDIO CHANNEL ############################
  228.         AEaudio_channels = [
  229.                 "2",
  230.                 "1"
  231.                 ]
  232.  
  233. # ##########################  VIDEO  #################################
  234.  
  235. class VCodec(object):
  236.         def __init__(self, label=None, codec=None, comm_str=None, crf_val=None, br_val=None, q_val=None, vrc_custom_comm=False, crf_comm=None, br_comm=None, q_comm=None, kb=False, vrc=False, br2pass=False, preset=False, tune=False, opts=False, opencl=False, is10bit=False, pool=False, threads=False, no_video_enc=False):
  237.                 self.label = label
  238.                 self.codec = codec
  239.                 self.comm_str = comm_str
  240.                 self.crf_val = crf_val
  241.                 self.br_val = br_val
  242.                 self.q_val = q_val
  243.                 self.vrc_custom_comm = vrc_custom_comm
  244.                 self.crf_comm = crf_comm
  245.                 self.br_comm = br_comm
  246.                 self.q_comm = q_comm
  247.                 self.kb = kb
  248.                 self.vrc = vrc
  249.                 self.br2pass = br2pass
  250.                 self.preset = preset
  251.                 self.tune = tune
  252.                 self.opts = opts
  253.                 self.opencl = opencl
  254.                 self.is10bit = is10bit
  255.                 self.pool = pool
  256.                 self.threads = threads
  257.                 self.no_video_enc = no_video_enc
  258.         def __str__(self):
  259.                 return '{}, {}, {}'.format(self.label, self.codec, self.comm_str)
  260.        
  261. class VideoEncoder():
  262.        
  263.         VEx264 = VCodec(label='AVC (x264)' , codec='x264', comm_str='-c:v libx264 ', crf_val=(21.3, 15, 40, 0.1, 1), br_val=(730.0, 100, 4000, 10, 100), kb=True, vrc=True, br2pass=True, preset=True, tune=True, opts=True, opencl=True,  threads=True )
  264.        
  265.         VEx265 = VCodec(label='HEVC (x265)' , codec='x265', comm_str='-c:v libx265 ', crf_val=(22.8, 15, 40, 0.1, 1), br_val=(400.0, 100, 4000, 10, 100), vrc_custom_comm=True, crf_comm='-x265-params crf=', br_comm='-x265-params bitrate=', vrc=True,  br2pass=True, preset=True, tune=True, opts=True, is10bit=True, pool=True )
  266.        
  267.         VEmpeg4 = VCodec(label='ASP (mpeg4)' , codec='mpeg4', comm_str='-c:v mpeg4 -mpv_flags strict_gop ', br_val=(1200.0, 300, 5000, 100, 100), q_val=(5.0, 1, 31, 1, 1), kb=True, vrc=True, br2pass=True )
  268.        
  269.         VEcopy = VCodec(label='Video Copy' , codec='vcopy', comm_str='-c:v copy', no_video_enc=True)
  270.        
  271.         VEnone = VCodec(label='No Video' , codec='none', comm_str='-vn', no_video_enc=True)
  272.        
  273.         # groups: ------------------------------
  274.        
  275.         VEall = (VEx264, VEx265, VEmpeg4, VEcopy, VEnone)
  276.        
  277.         #
  278.         VEmp4 = (VEx265, VEx264, VEmpeg4, VEcopy, VEnone)
  279.        
  280.         VEmp4_default = VEmp4.index(VEx265)
  281.        
  282.         #
  283.         VEavi = (VEmpeg4, VEcopy)
  284.        
  285.         VEavi_default = VEavi.index(VEmpeg4)
  286.        
  287.         #
  288.         VEmka = (VEnone, VEnone) # min 2 obj for self.cboxtxt_change2()
  289.        
  290.         VEmka_default = 0
  291.        
  292. ######################### OPTIONS ################################################
  293.  
  294. class VcOptions(object):
  295.         def __init__(self, label=None, comm_str=None, text_entry=False):
  296.                 self.label = label
  297.                 self.comm_str = comm_str
  298.                 self.text_entry = text_entry
  299.         def __str__(self):
  300.                 return '{}, {}'.format(self.label, self.comm_str)
  301.                
  302. class VcodecOptions():
  303.        
  304.         ### HEVC libx265 ############################################
  305.         OPThevc1 = VcOptions(label='none (ssim psnr)', comm_str=':ssim=1:psnr=1')
  306.        
  307.         OPThevc2 = VcOptions(label='db-4 psy0.5 no-sao', comm_str=':rd=3:psy-rd=.5:no-sao=1:rc-lookahead=40:deblock=-4:ssim=1:psnr=1')
  308.        
  309.         OPThevc3 = VcOptions(label='db-3 no-sao', comm_str=':deblock=-3:no-sao=1:ssim=1:psnr=1')
  310.        
  311.         OPThevc4 = VcOptions(label='1+aq-mode3', comm_str=':rd=3:psy-rd=.5:aq-mode=3:no-sao=1:rc-lookahead=40:deblock=-3:ssim=1:psnr=1')
  312.        
  313.         OPThevc5 = VcOptions(label='1+aq-mode3 rd2', comm_str=':rd=2:psy-rd=.5:aq-mode=3:no-sao=1:rc-lookahead=40:deblock=-3:ssim=1:psnr=1')
  314.        
  315.         OPThevc6 = VcOptions(label='custom ->', text_entry=True)
  316.         #
  317.         OPTx265 = (OPThevc1, OPThevc2, OPThevc3, OPThevc4, OPThevc5, OPThevc6)
  318.         OPTx265_default = OPTx265.index(OPThevc5)
  319.        
  320.         ### AVC libx264 #############################################
  321.         OPTavc1 = VcOptions(label='opts 1', comm_str=' -x264opts ref=4:bframes=4:direct=auto:aq-strength=1.3:ssim:psnr')
  322.        
  323.         OPTavc2 = VcOptions(label='no opts (ssim)', comm_str=' -x264opts ssim')
  324.         #
  325.         OPTx264 = (OPTavc1, OPTavc2)
  326.         OPTx264_default = OPTx264.index(OPTavc1)
  327.        
  328. ########## PRESET # TUNE # OUT CONTAINER ##########################################
  329.  
  330.  
  331. class AVContainer(object):
  332.         def __init__(self, label=None, cont=None, comm_str=None, ext=None, sub_stream=False, alist=None, vlist=None, audio_only=False):
  333.                 self.label = label
  334.                 self.cont = cont
  335.                 self.comm_str=comm_str
  336.                 self.ext = ext
  337.                 self.sub_stream = sub_stream
  338.                 self.alist = alist
  339.                 self.vlist = vlist
  340.                 self.audio_only = audio_only
  341.         def __str__(self):
  342.                 return '{}, {}'.format(self.label, self.ext)
  343.        
  344. class VideoRC(object):
  345.         def __init__(self, label=None):
  346.                 self.label = label
  347.         def __str__(self):
  348.                 return '{}'.format(self.label)
  349.        
  350. class VcodecOther():
  351.        
  352.         ### OUT CONTAINER ############################
  353.         CONTmkv = AVContainer(label='MKV', cont='mkv', comm_str='-f matroska', ext='.mkv', sub_stream=True, alist='mp4', vlist='mp4')
  354.        
  355.         CONTmp4 = AVContainer(label='MP4', cont='mp4', comm_str='-f mp4', ext='.mp4', alist='mp4', vlist='mp4')
  356.        
  357.         CONTavi = AVContainer(label='AVI', cont='avi', comm_str='-f avi', ext='.avi', alist='avi', vlist='avi')
  358.        
  359.         CONTmka = AVContainer(label='MKA', cont='mka', comm_str='-f matroska', ext='.mka', alist='mka', vlist='mka', audio_only=True)
  360.        
  361.         # group: ------------------------------
  362.         OutContainers = (CONTmkv, CONTmp4, CONTavi, CONTmka)
  363.        
  364.         OutContainers_default = OutContainers.index(CONTmkv)
  365.        
  366.         ### VIDEO RATE CONTROL ################################
  367.         VRCcrf = VideoRC(label='crf')
  368.         VRCbr = VideoRC(label='bitrate kb/s')
  369.         VRCq = VideoRC(label='qscale (1-31)')
  370.        
  371.         # groups: ------------------------------
  372.         VRCall = (VRCcrf, VRCbr, VRCq)
  373.         VRCx264 = (VRCcrf, VRCbr)
  374.         VRCx265 = (VRCcrf, VRCbr)
  375.         VRCmpeg4 = (VRCbr, VRCq)
  376.  
  377.         ### PRESET ################################
  378.         x264_preset = [
  379.                 "ultrafast",
  380.                 "superfast",
  381.                 "veryfast",
  382.                 "faster",
  383.                 "fast",
  384.                 "medium",
  385.                 "slow",
  386.                 "veryslow"
  387.                 ]
  388.        
  389.         x264_preset_default = x264_preset.index('faster')
  390.        
  391.         x265_preset = x264_preset
  392.        
  393.         x265_preset_default = x265_preset.index('superfast')
  394.        
  395.         ### TUNE ###################################
  396.         x264_tune = [
  397.                 "none",
  398.                 "film",
  399.                 "animation",
  400.                 "grain",
  401.                 "stillimage"
  402.                 ]
  403.        
  404.         x264_tune_default = x264_tune.index('film')
  405.        
  406.         x265_tune = [
  407.                 "none",
  408.                 "grain",
  409.                 "fastdecode",
  410.                 "zerolatency"
  411.                 ]
  412.        
  413.         x265_tune_default = x265_tune.index('none')
  414.        
  415. ###############################################################################
  416.  
  417. class ReuseInit(object):
  418.  
  419.         def make_label(self, text):
  420.                 label = Gtk.Label(text)
  421.                 label.set_use_underline(True)
  422.                 label.set_alignment(1.0, 0.5)
  423.                 label.show()
  424.                 return label
  425.  
  426.         def make_slider_and_spinner(self, init, min, max, step, page, digits):
  427.                 controls = {'adj':Gtk.Adjustment(init, min, max, step, page), 'slider':Gtk.HScale(), 'spinner':Gtk.SpinButton()}
  428.                 controls['slider'].set_adjustment(controls['adj'])
  429.                 controls['slider'].set_draw_value(False)
  430.                 controls['spinner'].set_adjustment(controls['adj'])
  431.                 controls['spinner'].set_digits(digits)
  432.                 controls['slider'].show()
  433.                 controls['spinner'].show()
  434.                 return controls
  435.        
  436.         def make_frame_ag(self, f_shadow_type, f_label, alig_pad, gri_row_sp, gri_colu_sp, gri_homog):
  437.                 controls =  {'frame':Gtk.Frame(), 'ali':Gtk.Alignment(), 'grid':Gtk.Grid()}
  438.                 controls['frame'].set_shadow_type(f_shadow_type) # 3 GTK_SHADOW_ETCHED_IN , 1 GTK_SHADOW_IN
  439.                 controls['frame'].set_label(f_label)
  440.                 controls['ali'].set_padding(alig_pad, alig_pad, alig_pad, alig_pad)
  441.                 controls['frame'].add(controls['ali'])
  442.                 controls['grid'].set_row_spacing(gri_row_sp)
  443.                 controls['grid'].set_column_spacing(gri_colu_sp)
  444.                 controls['grid'].set_column_homogeneous(gri_homog) # True
  445.                 controls['ali'].add(controls['grid'])
  446.                 controls['frame'].show()
  447.                 controls['ali'].show()
  448.                 controls['grid'].show()
  449.                 return controls
  450.        
  451.         def make_spinbut(self, init, min, max, step, page, digits, numeric):
  452.                 controls = {'adj':Gtk.Adjustment(init, min, max, step, page), 'spinner':Gtk.SpinButton()}
  453.                 controls['spinner'].set_adjustment(controls['adj'])
  454.                 controls['spinner'].set_digits(digits)
  455.                 controls['spinner'].set_numeric(numeric)
  456.                 controls['spinner'].show()
  457.                 return controls
  458.        
  459.         def make_combobox(self, *vals):
  460.                 controls = {'list':Gtk.ListStore(str), 'cbox':Gtk.ComboBox(), 'cellr':Gtk.CellRendererText()}
  461.                 for i, v in enumerate(vals):
  462.                         controls['list'].append([v])
  463.                 controls['cbox'].set_model(controls['list'])      
  464.                 controls['cbox'].pack_start(controls['cellr'], True)
  465.                 controls['cbox'].add_attribute(controls['cellr'], "text", 0)
  466.                 controls['cbox'].set_active(0)
  467.                 controls['cbox'].show()
  468.                 return controls
  469.        
  470.         def make_combobox_list(self, list):
  471.                 controls = {'list':Gtk.ListStore(str), 'cbox':Gtk.ComboBox(), 'cellr':Gtk.CellRendererText()}
  472.                 for i, v in enumerate(list):
  473.                         controls['list'].append([v])
  474.                 controls['cbox'].set_model(controls['list'])      
  475.                 controls['cbox'].pack_start(controls['cellr'], True)
  476.                 controls['cbox'].add_attribute(controls['cellr'], "text", 0)
  477.                 controls['cbox'].set_active(0)
  478.                 controls['cbox'].show()
  479.                 return controls
  480.        
  481.         def make_comboboxtext(self, list):
  482.                 ### list = [str, str]
  483.                 comboboxtext = Gtk.ComboBoxText()
  484.                 for i, v in enumerate(list):
  485.                         comboboxtext.append_text(v)
  486.                 comboboxtext.set_active(0)
  487.                 return comboboxtext
  488.        
  489.         def make_comboboxtext2(self, list):
  490.                 ### list = (obj, obj) min. 2 obj w .label property
  491.                 comboboxtext = Gtk.ComboBoxText()
  492.                 for i, v in enumerate(list):
  493.                         comboboxtext.append_text(v.label)
  494.                 comboboxtext.set_active(0)
  495.                 return comboboxtext
  496.        
  497.  
  498. class MyUtility():
  499.        
  500.         def hms2sec(self, hms):
  501.                 result = 0
  502.                 listin = hms.split(':')
  503.                 listin.reverse()
  504.                 for i in range(len(listin)):
  505.                         if listin[i].isdigit():
  506.                                 if i == 0:
  507.                                         mult = 1
  508.                                 if i == 1:
  509.                                         mult = 60
  510.                                 if i == 2:
  511.                                         mult = 3600
  512.                                 result += (int(listin[i])*mult)            
  513.                 return result
  514.        
  515.         def sec2hms(self, seconds):
  516.                 seconds = float(seconds)
  517.                 h = int(seconds/3600)
  518.                 if (h > 0):
  519.                         seconds = seconds - (h * 3600)
  520.                 m = int(seconds / 60)
  521.                 s = int(seconds - (m * 60))
  522.                 hms = "{0:0=2d}:{1:0=2d}:{2:0=2d}".format(h,m,s)
  523.                 return hms
  524.        
  525.         def check_out_file(self):
  526.                
  527.                 def check_codec_in_name(nameck):
  528.                         if not(Vars.XvCheck.no_video_enc): # no vcopy or vn
  529.                                 if not(Vars.XvCheck.codec in nameck):
  530.                                         clist = ('x265', 'x264', 'mpeg4', 'xvid', 'divx', 'XviD', 'DivX')
  531.                                         for i in range(0,len(clist)):
  532.                                                 if clist[i] != Vars.XvCheck.codec:
  533.                                                         if clist[i] in nameck:
  534.                                                                 nameck = nameck.replace(clist[i], Vars.XvCheck.codec)
  535.                                                                 break
  536.                                 if not(Vars.XvCheck.codec in nameck):
  537.                                         nameck = nameck + '.' + Vars.XvCheck.codec
  538.                         return nameck
  539.                
  540.                 name = os.path.splitext(Vars.basename)[0]
  541.                 name = check_codec_in_name(name)
  542.                 newname = Vars.outdir + '/' + name + Vars.ext
  543.                 if os.path.exists(newname):                    
  544.                         for i in range(2,20):
  545.                                 newname = Vars.outdir + '/' + name + '._' + str(i) + '_' + Vars.ext
  546.                                 if os.path.exists(newname) == False:
  547.                                         break
  548.                 Vars.newname = newname
  549.                 self.f3_run_outdir_label.set_tooltip_text(Vars.newname)
  550.                
  551.         def humansize(self, namefile):
  552.                 try:
  553.                         nbytes = os.path.getsize(namefile)
  554.                 except:
  555.                         return '0'
  556.                 suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
  557.                 if nbytes == 0: return '0 B'
  558.                 i = 0
  559.                 while nbytes >= 1024 and i < len(suffixes)-1:
  560.                         nbytes /= 1024.
  561.                         i += 1
  562.                 f = "{0:0.1f}".format(nbytes)
  563.                 return "{0:>5s} {1:2s}".format(f, suffixes[i])
  564.        
  565.         def version_from_filename(self):
  566.                 '''
  567.                filename must be:
  568.                4FFmpeg-n.nnn.py
  569.                '''
  570.                 try:
  571.                         #version = str(sys.argv[0])
  572.                         #version = os.path.basename(sys.argv[0])
  573.                         version = os.path.realpath(sys.argv[0]) # work w symlink
  574.                         version = os.path.basename(version)
  575.                 except:
  576.                         version = 'N/A'
  577.                         return version
  578.                 try:
  579.                         version = version.split('-')[1]
  580.                 except:
  581.                         version = 'N/A'
  582.                         return version
  583.                 if version[-3:] == ".py":
  584.                         try:
  585.                                 version = version[:-3]
  586.                         except:
  587.                                 version = 'N/A'
  588.                                 return version          
  589.                 return version
  590.  
  591.         def is_number(self, string):
  592.                 num_format = re.compile("^[\-]?[1-9][0-9]*\.?[0-9]+$")
  593.                 isnumber = re.match(num_format,string)
  594.                 return isnumber
  595.  
  596.  
  597. class UiElemController():
  598.        
  599.         def adj_change(self, adjustment, value, lower, upper , step_increment, page_increment):
  600.                 adjustment.set_value(value)
  601.                 adjustment.set_lower(lower)
  602.                 adjustment.set_upper(upper)
  603.                 adjustment.set_step_increment(step_increment)
  604.                 adjustment.set_page_increment(page_increment)
  605.                 #adjustment.set_page_size(page_size)
  606.  
  607.         def adj_change2(self, adjustment, tuple_5values):
  608.                 '''
  609.                tuple_5values=
  610.                (value , lower, upper, step_increment, page_increment)
  611.                or
  612.                [value , lower, upper, step_increment, page_increment]
  613.                '''
  614.                 adjustment.set_value(tuple_5values[0])
  615.                 adjustment.set_lower(tuple_5values[1])
  616.                 adjustment.set_upper(tuple_5values[2])
  617.                 adjustment.set_step_increment(tuple_5values[3])
  618.                 adjustment.set_page_increment(tuple_5values[4])
  619.                 #adjustment.set_page_size(page_size)
  620.  
  621.         def cboxtxt_change(self, the_cboxtext, the_function, item_list, item_selected, global_list, list_in_use):
  622.                 ### item_list = [str, str]
  623.                 the_cboxtext.disconnect_by_func(the_function)
  624.                 the_cboxtext.remove_all()
  625.                 for i, v in enumerate(item_list):
  626.                                 the_cboxtext.append_text(v)
  627.                 the_cboxtext.connect("changed", the_function)
  628.                 the_cboxtext.set_active(item_selected)
  629.                 objname = global_list.split('.')[0]
  630.                 glist = global_list.split('.')[1]
  631.                 setattr(globals()[objname], glist, list_in_use)
  632.                
  633.         def cboxtxt_change2(self, the_cboxtext, the_function, obj_list, item_selected, global_list, list_in_use):
  634.                 ### obj_list = (obj, obj) min. 2 obj w .label property
  635.                 the_cboxtext.disconnect_by_func(the_function)
  636.                 the_cboxtext.remove_all()
  637.                 for i, v in enumerate(obj_list):
  638.                                 the_cboxtext.append_text(v.label)
  639.                 the_cboxtext.connect("changed", the_function)
  640.                 the_cboxtext.set_active(item_selected)
  641.                 objname = global_list.split('.')[0]
  642.                 glist = global_list.split('.')[1]
  643.                 setattr(globals()[objname], glist, list_in_use)
  644.                
  645.         # old way ------------------------------------------------------------
  646.         #def x265_opt_list(self, selected):
  647.         #       self.box_3v_x264opts.disconnect_by_func(self.on_codec_clicked)
  648.         #       self.box_3v_x264opts.remove_all()
  649.         #       for i, v in enumerate(Vars.x265_opt):
  650.         #               self.box_3v_x264opts.append_text(v)
  651.         #       self.box_3v_x264opts.set_active(selected)
  652.         #       self.box_3v_x264opts.connect("changed", self.on_codec_clicked)
  653.         #       Vars.opt_list = 'x265'
  654.  
  655. #### MAIN #################################################################################################
  656.        
  657. class ProgrammaGTK(ReuseInit, UiElemController, MyUtility, AudioEncoder, VideoEncoder, VcodecOptions, VcodecOther):
  658.        
  659.         ## version ---------------------------------
  660.         #Vars.version = '8.166s'
  661.         ## -----------------------------------------
  662.        
  663.  
  664.         def __init__(self):
  665.        
  666.                 # initialize variables
  667.                
  668.                 if Vars.version == '':
  669.                         Vars.version = self.version_from_filename()
  670.  
  671.                 self.make_ui()
  672.                
  673.                 Vars.outdir = os.getcwd()
  674.                 Vars.indir = Vars.outdir
  675.                
  676.                 self.on_codec_audio_changed(0)
  677.                 self.on_codec_video_changed(0)
  678.                 self.on_f3_other_clicked(0)
  679.                 self.on_container_changed(0)
  680.                
  681.                 if len(sys.argv) == 2:
  682.                         try:
  683.                                 Vars.filename = str(sys.argv[1])
  684.                                 self.file_changed()
  685.                         except:
  686.                                 pass
  687.                
  688.                 # ----------------------------
  689.                
  690.                
  691.         def make_ui(self):
  692.  
  693.                 # ---------------------
  694.                 self.window =  Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
  695.                 self.window.connect("destroy", self.on_window_destroy)
  696.                 self.window.set_title("4FFmpeg")
  697.                 self.window.set_position(1) # 1 center, 0 none,
  698.                 self.window.set_border_width(3)
  699.                 self.window.set_default_size(500,-1)
  700.                 #----------------------------------
  701.                
  702.                 #page1 stuff VIDEO FILTERS------------------------------------------
  703.                                
  704.                 # page1 VBox -------------------------
  705.                 self.vbox1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2)
  706.                 #self.vbox1.set_orientation(Gtk.Orientation.VERTICAL) # Gtk.Orientation.HORIZONTAL
  707.                 #self.vbox1.set_spacing(2)
  708.                
  709.                 # map --------------------------------------
  710.                 self.make_map()        
  711.                 # add map frame
  712.                 self.vbox1.pack_start(self.f_map['frame'], 1, 0, 0)
  713.                
  714.                 #time cut ------------------------------------
  715.                 self.make_time_cut()
  716.                 # add time frame
  717.                 self.vbox1.pack_start(self.f_time['frame'], 1, 0, 0)
  718.                
  719.                 # deinterlace -----------------------
  720.                 self.make_deinterlace()
  721.                 # add deinterlace frame
  722.                 self.vbox1.pack_start(self.f_deint['frame'], 1, 0, 0)
  723.                
  724.                 # crop ----------------------------------------
  725.                 self.make_crop()        
  726.                 # add crop frame -------------------
  727.                 self.vbox1.pack_start(self.frame_crop['frame'], 1, 0, 0)
  728.        
  729.                 # scale ------------------------------
  730.                 self.make_scale()
  731.                 # add scale frame------------------
  732.                 self.vbox1.pack_start(self.frame_scale['frame'], 1, 0, 0)
  733.  
  734.                 # denoise ----------------------------
  735.                 self.make_denoise()
  736.                 # add denoise frame------------------------
  737.                 self.vbox1.pack_start(self.frame_dn['frame'], 1, 0, 0)
  738.                
  739.                 # page 1 filters------------------------
  740.                 self.frame_out = self.make_frame_ag(3, '  FFmpeg video filter string:  ' , 12, 8, 8, True)
  741.                 self.labelout = Gtk.Label("")
  742.                 self.labelout.set_selectable(1)
  743.                 self.labelout.set_width_chars(120)
  744.                 self.labelout.set_max_width_chars(130)
  745.                 self.labelout.set_line_wrap(True)
  746.                 self.frame_out['grid'].attach(self.labelout, 0, 0, 1 ,1)
  747.                 # add output frame ---------------------
  748.                 self.vbox1.pack_start(self.frame_out['frame'], 1, 0, 0)
  749.                 # end page1
  750.                
  751.                 # page2 stuff  UTILITY ------------------------------------------
  752.                
  753.                 # page2 VBox -------------------------
  754.                 self.vbox_pg2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2)
  755.                
  756.                 #volumedetect ------------------------------------
  757.                 self.make_volume_det()
  758.                 # add volumedetect frame        
  759.                 self.vbox_pg2.pack_start(self.f_volume_det['frame'], 1, 0, 0)
  760.                
  761.                 #frames detect
  762.                 self.make_frames_det()
  763.                 # add  frames detect frame      
  764.                 self.vbox_pg2.pack_start(self.f_frames_det['frame'], 1, 0, 0)
  765.                
  766.                
  767.                 #drc ------------------------------------
  768.                 self.make_volume_drc()
  769.                 # add volumedetect frame        
  770.                 self.vbox_pg2.pack_start(self.f_volume_drc['frame'], 1, 0, 0)
  771.                
  772.                 #compand ---------------------------------------
  773.                 self.make_compand()
  774.                 # add frame
  775.                 self.vbox_pg2.pack_start(self.f_compand['frame'], 1, 0, 0)
  776.                
  777.                 #dynaudnorm-------------------
  778.                 self.make_dynaudnorm()
  779.                 # add frame
  780.                 self.vbox_pg2.pack_start(self.f_dynaudnorm['frame'], 1, 0, 0)
  781.                
  782.                 # black detect ----------------------------------
  783.                 self.make_black_detect()
  784.                 # add black_detect frame
  785.                 self.vbox_pg2.pack_start(self.f_blackd['frame'], 1, 0, 0)
  786.                
  787.                 # info frame----------------------
  788.                 self.make_info_frame()
  789.                 # add info frame
  790.                 self.vbox_pg2.pack_start(self.f_info['frame'], 1, 0, 0)
  791.                
  792.                 # end page2 stuff
  793.                
  794.                 # page 3 stuff  ffmpeg commands -----------------------------------------
  795.                
  796.                 # page3 VBox -------------------------
  797.                 self.vbox_pg3 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2)
  798.                
  799.                 # audio codec -------------------
  800.                 self.make_audio_codec()
  801.                 #add frame audio codec
  802.                 self.vbox_pg3.pack_start(self.f_3acodec['frame'], 1, 0, 0)
  803.                
  804.                 # video codec -------------------
  805.                 self.make_video_codec()
  806.                 #add frame video codec
  807.                 self.vbox_pg3.pack_start(self.f_3vcodec['frame'], 1, 0, 0)
  808.                
  809.                 # other options ----------------
  810.                 self.make_other_opts()
  811.                 #add frame other options
  812.                 self.vbox_pg3.pack_start(self.f3_oth['frame'], 1, 0, 0)
  813.                
  814.                 # page3 output ---------------------
  815.                 self.f3_out = self.make_frame_ag(3, "  FFmpeg command  " , 6, 8, 8, True)
  816.                 self.f3_out_label = Gtk.Label("")
  817.                 self.f3_out_label.set_width_chars(106)
  818.                 self.f3_out_label.set_max_width_chars(106)
  819.                 self.f3_out_label.set_line_wrap(True)
  820.                 self.f3_out_label.set_selectable(1)
  821.                 self.f3_out['grid'].attach(self.f3_out_label, 0, 0, 1, 1)
  822.                 # add frame page3 output
  823.                 self.vbox_pg3.pack_start(self.f3_out['frame'], 1, 0, 0)
  824.                
  825.                 # run ffmpeg ---------------------------------
  826.                 self.make_run_ffmpeg()
  827.                 # add frame run ffmpeg
  828.                 self.vbox_pg3.pack_start(self.f3_run['frame'], 1, 0, 0)
  829.                
  830.                
  831.                 #---------------------------------------------------
  832.                 # main vbox
  833.                 self.main_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
  834.                
  835.                 # notebook      
  836.                 self.notebook = Gtk.Notebook()
  837.                 self.notebook.set_tab_pos(Gtk.PositionType.TOP)  #GTK_POS_LEFT = 0
  838.                 self.notebook.set_show_border (False)
  839.                 self.main_vbox.pack_start(self.notebook, 1, 0, 0)
  840.                
  841.                 #page 1
  842.                 self.tab1label = Gtk.Label("Video filters")
  843.                 self.page1_ali = Gtk.Alignment()
  844.                 self.page1_ali.set_padding(0, 6, 6, 6)
  845.                 self.page1_ali.add(self.vbox1)
  846.                 self.notebook.append_page(self.page1_ali, self.tab1label)
  847.                
  848.                 #page 2
  849.                 self.tab2label = Gtk.Label("Utility")
  850.                 self.page2_ali = Gtk.Alignment()
  851.                 self.page2_ali.set_padding(0, 6, 6, 6)
  852.                 self.page2_ali.add(self.vbox_pg2)
  853.                 self.notebook.append_page(self.page2_ali, self.tab2label)
  854.                
  855.                 #page 3
  856.                 self.tab3label = Gtk.Label("Encode")
  857.                 self.page3_ali = Gtk.Alignment()
  858.                 self.page3_ali.set_padding(0, 6, 6, 6)
  859.                 self.page3_ali.add(self.vbox_pg3)
  860.                 self.notebook.append_page(self.page3_ali, self.tab3label)
  861.                
  862.                 #---------------------------------------------------
  863.                
  864.                 # low part BUTTONS AND TERM --------------------------
  865.                 self.make_low_part()
  866.                 # add low part-----------------
  867.                 self.main_vbox.pack_start(self.gridterm, 1, 1, 0)
  868.                
  869.                 #---------------------------------------------------------
  870.                 self.window.add (self.main_vbox)
  871.                 #---------------------------------
  872.                 self.window.show_all()          
  873.  
  874.                
  875.         def make_deinterlace(self):
  876.                 self.f_deint = self.make_frame_ag(3, "" , 6, 8, 8, True)
  877.                 self.checkdeint = Gtk.CheckButton("deinterlace")
  878.                 self.checkdeint.connect("toggled", self.on_deint_clicked)
  879.                 self.f_deint['grid'].attach(self.checkdeint, 0, 0, 1, 1)
  880.                
  881.                 self.box_deint = self.make_combobox(
  882.                   "yadif",
  883.                   "postprocessing linear blend",
  884.                   "detect (use only with Test)"
  885.                   )
  886.                 self.f_deint['grid'].attach(self.box_deint['cbox'], 1, 0, 1, 1)
  887.                 self.box_deint['cbox'].connect("changed", self.on_deint_clicked)
  888.                 #
  889.                 self.f_deint['grid'].attach(self.make_label(""), 2, 0, 1, 1)
  890.        
  891.         def make_map(self):
  892.                 #
  893.                 self.f_map = self.make_frame_ag(3, "" , 6, 8, 8, False)
  894.                 #
  895.                 self.check_map = Gtk.CheckButton("map")
  896.                 self.check_map.connect("toggled", self.on_map_clicked) # toggled or activate (enter)
  897.                 self.f_map['grid'].attach(self.check_map, 0, 0, 1, 1)
  898.                 #
  899.                 self.mapstream_label = self.make_label("streams: ")
  900.                 self.f_map['grid'].attach(self.mapstream_label, 1, 0, 1, 1)
  901.                 #
  902.                 self.entry_map = Gtk.Entry()
  903.                 self.entry_map.set_tooltip_text(Tips.map_tooltip_str)
  904.                 self.entry_map.connect("changed", self.on_map_clicked)
  905.                 self.f_map['grid'].attach(self.entry_map, 2, 0, 1, 1)
  906.                 #
  907.                 self.map_label = Gtk.Label("")
  908.                 self.map_label.set_width_chars(70)
  909.                 self.f_map['grid'].attach(self.map_label, 3, 0, 2, 1)
  910.                 # placeholder
  911.                 self.f_map['grid'].attach(self.make_label("Version: " + Vars.version + "   "), 5, 0, 1, 1)
  912.                
  913.         def make_time_cut(self):
  914.                 #
  915.                 self.f_time = self.make_frame_ag(3, "" , 6, 8, 8, True)
  916.                 #
  917.                 self.check_time = Gtk.CheckButton("time")
  918.                 self.check_time.connect("toggled", self.on_time_clicked) # toggled or activate (enter)
  919.                 self.f_time['grid'].attach(self.check_time, 0, 0, 1, 1)
  920.                 #
  921.                 self.label_time_in = self.make_label("from: ")
  922.                 self.f_time['grid'].attach(self.label_time_in, 1, 0, 1, 1)
  923.                 self.entry_timein = Gtk.Entry()
  924.                 self.entry_timein.set_tooltip_text(Tips.time_tooltip_str)
  925.                 self.entry_timein.set_max_length(12)
  926.                 self.entry_timein.set_max_width_chars(12)
  927.                 self.entry_timein.set_width_chars(12)
  928.                 #self.entry_timein.set_halign(1)
  929.                 self.entry_timein.connect("changed", self.on_time_clicked)
  930.                 self.f_time['grid'].attach(self.entry_timein, 2, 0, 1, 1)
  931.                
  932.                 self.label_time_out = self.make_label("to: ")
  933.                 self.f_time['grid'].attach(self.label_time_out, 3, 0, 1, 1)
  934.                 self.entry_timeout = Gtk.Entry()
  935.                 self.entry_timeout.set_tooltip_text(Tips.time_tooltip_str)
  936.                 self.entry_timeout.set_max_length(12)
  937.                 self.entry_timeout.set_max_width_chars(12)
  938.                 self.entry_timeout.set_width_chars(12)
  939.                 self.entry_timeout.connect("changed", self.on_time_clicked)
  940.                 self.f_time['grid'].attach(self.entry_timeout, 4, 0, 1, 1)
  941.                 self.time_label = Gtk.Label('')
  942.                 self.f_time['grid'].attach(self.time_label, 5, 0, 2, 1)
  943.        
  944.         def make_scale(self):
  945.                 self.frame_scale = self.make_frame_ag(3, '  scale  ' , 6, 8, 8, False)
  946.                 # ------------------------------
  947.                 self.box_scale_side = self.make_combobox(
  948.                   "None",
  949.                   "W",
  950.                   "H"
  951.                   )
  952.                 self.box_scale_side['cbox'].set_size_request(180,-1)
  953.                 self.frame_scale['grid'].attach(self.box_scale_side['cbox'], 0, 0, 1, 1)
  954.                 self.box_scale_side['cbox'].connect("changed", self.on_scale_clicked)
  955.                 #------------------------------------
  956.                 self.box_scale_ar = self.make_combobox(
  957.                   "16/9",
  958.                   "4/3",
  959.                   "2.35/1"
  960.                   )
  961.                 self.frame_scale['grid'].attach(self.box_scale_ar['cbox'], 0, 1, 1, 1)
  962.                 self.box_scale_ar['cbox'].connect("changed", self.on_scale_clicked)
  963.                 #-----------------------------------------
  964.                 self.size_spinner = self.make_slider_and_spinner(720, 200, 2000, 8, 32, 0)
  965.                 self.frame_scale['grid'].attach(self.size_spinner['slider'], 1, 0, 1, 1)
  966.                 self.frame_scale['grid'].attach(self.size_spinner['spinner'], 2, 0, 1, 1)
  967.                 self.size_spinner['slider'].set_size_request(200,-1)
  968.                 self.size_spinner['adj'].set_value(720.001) #mettere decimali se no non si vede
  969.                 self.size_spinner['adj'].connect("value-changed", self.on_scale_clicked)
  970.                 #-------------------------------------------------------
  971.                 self.check_round = Gtk.CheckButton("round 8")
  972.                 self.check_round.connect("toggled", self.on_scale_clicked)
  973.                 self.frame_scale['grid'].attach(self.check_round, 1, 1, 1, 1)
  974.                 #
  975.                 self.check = Gtk.CheckButton("zscale")
  976.                 self.check.set_tooltip_text("  HQ resize with libzimg  ")
  977.                 self.check.connect("toggled", self.on_scale_clicked)
  978.                 self.frame_scale['grid'].attach(self.check, 2, 1, 1, 1)
  979.                 #custom scale string
  980.                 self.label_scalecustom = self.make_label("Custom scale filter (override all scale settings):")
  981.                 self.label_scalecustom.set_alignment(0.5, 0.5)
  982.                 self.frame_scale['grid'].attach(self.label_scalecustom, 3, 0, 1, 1)
  983.                 self.entry_scalecustom = Gtk.Entry()
  984.                 self.entry_scalecustom.set_tooltip_text(Tips.customscale_str)
  985.                 self.entry_scalecustom.connect("changed", self.on_scale_clicked)
  986.                 self.entry_scalecustom.set_max_length(100)
  987.                 self.entry_scalecustom.set_max_width_chars(60)
  988.                 self.frame_scale['grid'].attach(self.entry_scalecustom, 3, 1, 1, 1)
  989.                
  990.                
  991.         def make_crop(self):
  992.                 self.frame_crop = self.make_frame_ag(3, '' , 6, 2, 0, True)
  993.                 # -------
  994.                 self.checkcr = Gtk.CheckButton("crop")
  995.                 self.checkcr.connect("toggled", self.on_crop_clicked)
  996.                 self.frame_crop['grid'].attach(self.checkcr, 0, 0, 1, 1)
  997.                 #----------
  998.                 self.butcrode = Gtk.Button(label="Crop detect")
  999.                 self.butcrode.connect("clicked", self.on_butcrode_clicked)
  1000.                 self.butcrode.set_sensitive(False)
  1001.                 self.frame_crop['grid'].attach(self.butcrode, 0, 1, 1, 1)
  1002.                 #-----------
  1003.                 self.labelcropinw = self.make_label("input W: ")
  1004.                 self.frame_crop['grid'].attach(self.labelcropinw, 1, 0, 1, 1)
  1005.                 self.labelcropinh = self.make_label("input H: ")
  1006.                 self.frame_crop['grid'].attach(self.labelcropinh, 1, 1, 1, 1)
  1007.                 #
  1008.                 self.spincw = self.make_spinbut(640 , 100 , 1920 , 10 , 1 , 0, True )
  1009.                 self.spincw["adj"].connect("value-changed", self.on_crop_clicked)
  1010.                 self.frame_crop['grid'].attach(self.spincw["spinner"], 2, 0, 1, 1)
  1011.                 #
  1012.                 self.spinch = self.make_spinbut(480 , 100 , 1280 , 10 , 1 , 0, True )
  1013.                 self.spinch["adj"].connect("value-changed", self.on_crop_clicked)
  1014.                 self.frame_crop['grid'].attach(self.spinch["spinner"], 2, 1, 1, 1)
  1015.                 #
  1016.                
  1017.                 self.labelcroptop = self.make_label("crop Top: ")
  1018.                 self.frame_crop['grid'].attach(self.labelcroptop, 3, 0, 1, 1)
  1019.                 self.labelcropbot = self.make_label("crop Bottom: ")
  1020.                 self.frame_crop['grid'].attach(self.labelcropbot, 3, 1, 1, 1)
  1021.                 #
  1022.                
  1023.                 self.spinct = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  1024.                 self.spinct["adj"].connect("value-changed", self.on_crop_clicked)
  1025.                 self.frame_crop['grid'].attach(self.spinct["spinner"], 4, 0, 1, 1)
  1026.                 #
  1027.                 self.spincb = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  1028.                 self.spincb["adj"].connect("value-changed", self.on_crop_clicked)
  1029.                 self.frame_crop['grid'].attach(self.spincb["spinner"], 4, 1, 1, 1)
  1030.                 #
  1031.                
  1032.                 self.labelcroplef = self.make_label("crop Left: ")
  1033.                 self.frame_crop['grid'].attach(self.labelcroplef, 5, 0, 1, 1)
  1034.                 self.labelcroprig = self.make_label("crop Right: ")
  1035.                 self.frame_crop['grid'].attach(self.labelcroprig, 5, 1, 1, 1)
  1036.                 #
  1037.                 self.spincl = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  1038.                 self.spincl["adj"].connect("value-changed", self.on_crop_clicked)
  1039.                 self.frame_crop['grid'].attach(self.spincl["spinner"], 6, 0, 1, 1)
  1040.                 #
  1041.                 self.spincr = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  1042.                 self.spincr["adj"].connect("value-changed", self.on_crop_clicked)
  1043.                 self.frame_crop['grid'].attach(self.spincr["spinner"], 6, 1, 1, 1)
  1044.                
  1045.                
  1046.         def make_denoise(self):
  1047.                 self.frame_dn = self.make_frame_ag(3, '  denoise / unsharp luma chroma / frame rate   ' , 6, 8, 8, True)
  1048.                 # denoise ----------------------
  1049.                 self.checkdn = Gtk.CheckButton("hqdn3d:")
  1050.                 self.checkdn.set_alignment(1.0, 0.5)
  1051.                 self.checkdn.set_halign(2)
  1052.                 self.checkdn.connect("toggled", self.on_dn_clicked)
  1053.                 self.frame_dn['grid'].attach(self.checkdn, 0, 0, 1, 1)
  1054.                 #
  1055.                 self.spindn = self.make_spinbut(4 , 2 , 8 , 1 , 10 , 0, True )
  1056.                 self.spindn["adj"].connect("value-changed", self.on_dn_clicked)
  1057.                 #self.spindn['spinner'].set_max_length(1)
  1058.                 #self.spindn['spinner'].set_width_chars(1)
  1059.                 self.frame_dn['grid'].attach(self.spindn["spinner"], 1, 0, 1, 1)
  1060.                 # -----------------------
  1061.                 # unsharp unsharp=5:5:luma:5:5:chroma, luma chroma -1.5 to 1.5
  1062.                 self.checkuns = Gtk.CheckButton("unsharp l/c:")
  1063.                 self.checkuns.set_alignment(1.0, 0.5)
  1064.                 self.checkuns.set_halign(2)
  1065.                 self.checkuns.connect("toggled", self.on_uns_clicked)
  1066.                 self.frame_dn['grid'].attach(self.checkuns, 2, 0, 1, 1)
  1067.                 self.spinunsl = self.make_spinbut(0.0 , -1.5 , 1.5 , .1 , .01 , 2, True )
  1068.                 self.spinunsl["adj"].connect("value-changed", self.on_uns_clicked)
  1069.                 self.frame_dn['grid'].attach(self.spinunsl["spinner"], 3, 0, 1, 1)
  1070.                 self.spinunsc = self.make_spinbut(0.0 , -1.5 , 1.5 , .1 , .01 , 2, True )
  1071.                 self.spinunsc["adj"].connect("value-changed", self.on_uns_clicked)
  1072.                 self.frame_dn['grid'].attach(self.spinunsc["spinner"], 4, 0, 1, 1)
  1073.                 # framerate --------------------------
  1074.                 self.checkfr = Gtk.CheckButton("frame rate:")
  1075.                 self.checkfr.set_alignment(1.0, 0.5)
  1076.                 self.checkfr.set_halign(2)
  1077.                 self.checkfr.connect("toggled", self.on_fr_clicked)
  1078.                 self.frame_dn['grid'].attach(self.checkfr, 5, 0, 1, 1)
  1079.                 self.spinfr = self.make_spinbut(0 , 0 , 100 , 1 , 10 , 2, True )
  1080.                 self.spinfr["adj"].connect("value-changed", self.on_fr_clicked)
  1081.                 self.frame_dn['grid'].attach(self.spinfr["spinner"], 6, 0, 1, 1)
  1082.                
  1083.         def make_low_part(self):
  1084.                 # grid
  1085.                 self.gridterm = Gtk.Grid()
  1086.                 self.gridterm.set_row_spacing(2)
  1087.                 self.gridterm.set_column_spacing(2)
  1088.                 self.gridterm.set_column_homogeneous(True) # True
  1089.                 # filechooserbutton
  1090.                 self.but_file = Gtk.Button("Choose File")
  1091.                 self.but_file.connect("clicked", self.on_but_file)
  1092.                 self.but_file.set_tooltip_text(Tips.but_file_str)
  1093.                 #ff command button
  1094.                 self.butplay = Gtk.Button(label="FFplay")
  1095.                 self.butplay.connect("clicked", self.on_butplay_clicked)
  1096.                 self.butplay.set_sensitive(False)
  1097.                 self.butplay.set_tooltip_text(Tips.ffplay_tooltip_str)
  1098.                 #
  1099.                 self.butprobe = Gtk.Button(label="FFprobe")
  1100.                 self.butprobe.connect("clicked", self.on_butprobe_clicked)
  1101.                 self.butprobe.set_sensitive(False)
  1102.                 #
  1103.                 self.buttest = Gtk.Button(label="Test")
  1104.                 self.buttest.connect("clicked", self.on_buttest_clicked)
  1105.                 self.buttest.set_sensitive(False)
  1106.                 #
  1107.                 self.buttestspl = Gtk.Button(label="Test split")
  1108.                 self.buttestspl.connect("clicked", self.on_buttestspl_clicked)
  1109.                 self.buttestspl.set_sensitive(False)
  1110.                 # copy term button
  1111.                 self.butt_vtecopy = Gtk.Button(label="Copy term")
  1112.                 self.butt_vtecopy.connect("clicked", self.on_butt_vtecopy_clicked)
  1113.                 # vte terminal
  1114.                 self.terminal     = Vte.Terminal()
  1115.                 try: # vte 2.90
  1116.                         self.terminal.fork_command_full(
  1117.                                 Vte.PtyFlags.DEFAULT, #default is fine
  1118.                                 os.getcwd(), #where to start the command?   os.environ['HOME']
  1119.                                 ["/bin/sh"], #where is the emulator?
  1120.                                 [], #it's ok to leave this list empty
  1121.                                 GLib.SpawnFlags.DO_NOT_REAP_CHILD,
  1122.                                 None, #at least None is required
  1123.                                 None,
  1124.                         )
  1125.                 except: # vte 2.91
  1126.                         self.terminal.spawn_sync(
  1127.                                 Vte.PtyFlags.DEFAULT, #default is fine
  1128.                                 os.getcwd(), #where to start the command?   os.environ['HOME']
  1129.                                 ["/bin/sh"], #where is the emulator?
  1130.                                 [], #it's ok to leave this list empty
  1131.                                 GLib.SpawnFlags.DO_NOT_REAP_CHILD,
  1132.                                 None, #at least None is required
  1133.                                 None,
  1134.                                 )
  1135.                 # scroller
  1136.                 self.scroller = Gtk.ScrolledWindow()
  1137.                 self.scroller.set_hexpand(True)
  1138.                 self.scroller.set_vexpand(True)
  1139.                 self.scroller.set_min_content_height(90)
  1140.                 self.scroller.add(self.terminal)
  1141.                 # attach to grid
  1142.                 self.gridterm.attach(self.but_file, 0, 0, 2, 1)
  1143.                 self.gridterm.attach(self.butprobe, 2, 0, 1, 1)
  1144.                 self.gridterm.attach(self.butplay, 3, 0, 1, 1)
  1145.                 self.gridterm.attach(self.buttest, 4, 0, 1, 1)
  1146.                 self.gridterm.attach(self.buttestspl, 5, 0, 1, 1)
  1147.                 self.gridterm.attach(self.butt_vtecopy, 6, 0, 1, 1)
  1148.                 self.gridterm.attach(self.scroller, 0, 1, 7, 1)
  1149.  
  1150.         def make_volume_det(self):
  1151.                 self.f_volume_det = self.make_frame_ag(3, "" , 6, 8, 8, True)
  1152.                 #
  1153.                 self.but_volume_det = Gtk.Button(label="Volume detect")
  1154.                 self.but_volume_det.connect("clicked", self.on_but_volume_det_clicked)
  1155.                 self.f_volume_det['grid'].attach(self.but_volume_det, 0, 0, 1, 1)
  1156.                 self.but_volume_det.set_sensitive(False)
  1157.                 #
  1158.                 self.voldet_spin = Gtk.Spinner()
  1159.                 self.voldet_spin.set_sensitive(False)
  1160.                 self.f_volume_det['grid'].attach(self.voldet_spin, 1, 0, 1, 1)
  1161.                 #
  1162.                 self.label_maxvol = Gtk.Label("")
  1163.                 self.f_volume_det['grid'].attach(self.label_maxvol, 2, 0, 1, 1)
  1164.                 self.label_meanvol = Gtk.Label("")
  1165.                 self.f_volume_det['grid'].attach(self.label_meanvol, 3, 0, 1, 1)
  1166.                 #
  1167.                 self.check_vol = Gtk.CheckButton("volume")
  1168.                 self.check_vol.connect("toggled", self.on_volume_clicked)
  1169.                 self.f_volume_det['grid'].attach(self.check_vol, 0, 1, 1, 1)
  1170.                 #
  1171.                 self.label_db = self.make_label("dB: ")
  1172.                 self.f_volume_det['grid'].attach(self.label_db, 1, 1, 1, 1)
  1173.                 self.spin_db = self.make_spinbut(0 , -6 , 20 , 0.1 , 1 , 2, True )
  1174.                 self.spin_db["adj"].connect("value-changed", self.on_volume_clicked)
  1175.                 self.f_volume_det['grid'].attach(self.spin_db["spinner"], 2, 1, 1, 1)
  1176.                 self.label_ratio = self.make_label("ratio: ")
  1177.                 self.f_volume_det['grid'].attach(self.label_ratio, 3, 1, 1, 1)
  1178.                 self.label_ratio_val = Gtk.Label("1")
  1179.                 self.f_volume_det['grid'].attach(self.label_ratio_val, 4, 1, 1, 1)
  1180.                
  1181.         def make_frames_det(self):
  1182.                 self.f_frames_det = self.make_frame_ag(3, "" , 6, 8, 8, True)
  1183.                 #
  1184.                 self.but_frames_det = Gtk.Button(label="Total frames detect")
  1185.                 self.but_frames_det.connect("clicked", self.on_but_frames_det_clicked)
  1186.                 self.f_frames_det['grid'].attach(self.but_frames_det, 0, 0, 1, 1)
  1187.                 self.but_frames_det.set_sensitive(False)
  1188.                 #
  1189.                 self.framesdet_spin = Gtk.Spinner()
  1190.                 self.framesdet_spin.set_sensitive(False)
  1191.                 self.f_frames_det['grid'].attach(self.framesdet_spin, 1, 0, 1, 1)
  1192.                 #
  1193.                 self.label_framesdet = Gtk.Label("N/A")
  1194.                 self.f_frames_det['grid'].attach(self.label_framesdet, 2, 0, 1, 1)
  1195.                 self.label_framesdet.set_selectable(True)
  1196.                 #
  1197.                 #placeholder
  1198.                 #self.f_frames_det['grid'].attach(Gtk.Label(''), 3, 0, 2, 1)
  1199.                 ###
  1200.                 self.entry_time2frame = Gtk.Entry()
  1201.                 self.entry_time2frame.set_tooltip_text(Tips.time2frame_str)
  1202.                 self.entry_time2frame.set_max_length(12)
  1203.                 self.entry_time2frame.set_max_width_chars(12)
  1204.                 self.entry_time2frame.set_width_chars(12)
  1205.                 self.entry_time2frame.connect("changed", self.on_time2frame_clicked)
  1206.                 self.f_frames_det['grid'].attach(self.entry_time2frame, 3, 0, 1, 1)
  1207.                 self.label_time2frame = Gtk.Label('')
  1208.                 self.label_time2frame.set_selectable(True)
  1209.                 self.label_time2frame.set_tooltip_text(" calculated frames  ")
  1210.                 self.f_frames_det['grid'].attach(self.label_time2frame, 4, 0, 2, 1)
  1211.                
  1212.         def make_volume_drc(self):
  1213.                 self.f_volume_drc = self.make_frame_ag(3, "" , 6, 8, 8, True)
  1214.                 self.check_drc = Gtk.CheckButton("ac3 input drc scale")
  1215.                 self.check_drc.connect("toggled", self.on_drc_clicked)
  1216.                 self.f_volume_drc['grid'].attach(self.check_drc, 0, 0, 1, 1)
  1217.                 self.check_drc.set_sensitive(False)
  1218.                 #
  1219.                 self.spin_drc = self.make_spinbut(1 , 0 , 6 , 1 , 1 , 0, True )
  1220.                 self.spin_drc["adj"].connect("value-changed", self.on_drc_clicked)
  1221.                 self.spin_drc['spinner'].set_tooltip_text(Tips.drc_str)
  1222.                 self.f_volume_drc['grid'].attach(self.spin_drc["spinner"], 1, 0, 1, 1)
  1223.                 self.spin_drc["spinner"].set_sensitive(False)
  1224.                 #
  1225.                
  1226.                 #placeholder
  1227.                 self.f_volume_drc['grid'].attach(Gtk.Label(''), 2, 0, 3, 1)
  1228.                        
  1229.         def make_compand(self):
  1230.                 #
  1231.                 self.f_compand = self.make_frame_ag(3, "" , 6, 8, 8, False)
  1232.                 #
  1233.                 self.check_compand = Gtk.CheckButton("compand")
  1234.                 self.check_compand.connect("toggled", self.on_compand_clicked)
  1235.                 self.f_compand['grid'].attach(self.check_compand, 0, 0, 1, 1)
  1236.                 #
  1237.                 self.entry_compand = Gtk.Entry()
  1238.                 self.entry_compand.set_text(Vars.compinit)
  1239.                 self.entry_compand.set_width_chars(60)
  1240.                 self.entry_compand.connect("changed", self.on_compand_clicked)
  1241.                 self.entry_compand.set_tooltip_text(Tips.compad_str)
  1242.                 self.f_compand['grid'].attach(self.entry_compand, 1, 0, 2, 1)
  1243.                 #
  1244.                 self.compand_reset = Gtk.Button(label="reset")
  1245.                 self.compand_reset.set_size_request(110,-1)
  1246.                 self.compand_reset.connect("clicked", self.on_compand_reset)
  1247.                 self.f_compand['grid'].attach(self.compand_reset, 3, 0, 1, 1)
  1248.                 self.compand_test = Gtk.Button(label="test ebur128")
  1249.                 self.compand_test.set_size_request(110,-1)
  1250.                 self.compand_test.set_sensitive(False)
  1251.                 self.compand_test.connect("clicked", self.on_compand_test)
  1252.                 self.f_compand['grid'].attach(self.compand_test, 4, 0, 1, 1)
  1253.                 self.compand_volume = Gtk.Button(label="test volume")
  1254.                 self.compand_volume.set_size_request(110,-1)
  1255.                 self.compand_volume.set_sensitive(False)
  1256.                 self.compand_volume.connect("clicked", self.on_compand_volume)
  1257.                 self.f_compand['grid'].attach(self.compand_volume, 5, 0, 1, 1)
  1258.                
  1259.                
  1260.         def make_dynaudnorm(self):
  1261.                 #
  1262.                 self.f_dynaudnorm = self.make_frame_ag(3, "" , 6, 8, 8, False)
  1263.                 #
  1264.                 self.check_dynaudnorm = Gtk.CheckButton("dynaudnorm")
  1265.                 self.check_dynaudnorm.connect("toggled", self.on_dynaudnorm_clicked)
  1266.                 self.f_dynaudnorm['grid'].attach(self.check_dynaudnorm, 0, 0, 1, 1)
  1267.                 #
  1268.                 self.entry_dynaudnorm = Gtk.Entry()
  1269.                 self.entry_dynaudnorm.set_text(Vars.dynaudnorm)
  1270.                 self.entry_dynaudnorm.set_width_chars(57)
  1271.                 self.entry_dynaudnorm.connect("changed", self.on_dynaudnorm_clicked)
  1272.                 self.entry_dynaudnorm.set_tooltip_text(Tips.dynaudnorm_str)
  1273.                 self.f_dynaudnorm['grid'].attach(self.entry_dynaudnorm, 1, 0, 2, 1)
  1274.                 #
  1275.                 self.compand_dynaudnorm = Gtk.Button(label="reset")
  1276.                 self.compand_dynaudnorm.set_size_request(110,-1)
  1277.                 self.compand_dynaudnorm.connect("clicked", self.on_dynaudnorm_reset)
  1278.                 self.f_dynaudnorm['grid'].attach(self.compand_dynaudnorm, 3, 0, 1, 1)
  1279.                 self.dynaudnorm_test = Gtk.Button(label="test ebur128")
  1280.                 self.dynaudnorm_test.set_size_request(110,-1)
  1281.                 self.dynaudnorm_test.set_sensitive(False)
  1282.                 self.dynaudnorm_test.connect("clicked", self.on_dynaudnorm_test)
  1283.                 self.f_dynaudnorm['grid'].attach(self.dynaudnorm_test, 4, 0, 1, 1)
  1284.                 self.dynaudnorm_volume = Gtk.Button(label="test volume")
  1285.                 self.dynaudnorm_volume.set_size_request(110,-1)
  1286.                 self.dynaudnorm_volume.set_sensitive(False)
  1287.                 self.dynaudnorm_volume.connect("clicked", self.on_dynaudnorm_volume)
  1288.                 self.f_dynaudnorm['grid'].attach(self.dynaudnorm_volume, 5, 0, 1, 1)
  1289.  
  1290.         def make_black_detect(self):
  1291.                 self.f_blackd = self.make_frame_ag(3, "" , 6, 8, 8, True)
  1292.                 #
  1293.                 self.but_black_det = Gtk.Button(label="Black detect")
  1294.                 self.but_black_det.connect("clicked", self.on_but_black_det_clicked)
  1295.                 self.but_black_det.set_sensitive(False)
  1296.                 self.f_blackd['grid'].attach(self.but_black_det, 0, 0, 1, 1)
  1297.                 #
  1298.                 self.blackdet_spin = Gtk.Spinner()
  1299.                 self.blackdet_spin.set_sensitive(False)
  1300.                 self.f_blackd['grid'].attach(self.blackdet_spin, 1, 0, 1, 1)
  1301.                 #
  1302.                 scrolledwindow = Gtk.ScrolledWindow()
  1303.                 #scrolledwindow.set_hexpand(True)
  1304.                 scrolledwindow.set_vexpand(True)
  1305.                 scrolledwindow.set_min_content_height(60)
  1306.                 self.textview = Gtk.TextView()
  1307.                 self.textbuffer = self.textview.get_buffer()
  1308.                 self.textview.set_editable(False)
  1309.                 self.textview.set_cursor_visible(False)
  1310.                 self.textview.modify_font(Pango.font_description_from_string('Monospace 9'))
  1311.                 scrolledwindow.add(self.textview)
  1312.                 self.textbuffer.set_text(Tips.black_dt_init_str)
  1313.                 self.f_blackd['grid'].attach(scrolledwindow, 2, 0, 3, 3)
  1314.                 #
  1315.                 self.progressbar_black_det = Gtk.ProgressBar()
  1316.                 self.f_blackd['grid'].attach(self.progressbar_black_det, 0, 1, 1, 1)
  1317.                
  1318.         def make_info_frame(self):
  1319.                 self.f_info = self.make_frame_ag(3, "  info  " , 6, 8, 8, True)
  1320.                 scrolledwindow1 = Gtk.ScrolledWindow()
  1321.                 scrolledwindow1.set_hexpand(True)
  1322.                 scrolledwindow1.set_vexpand(True)
  1323.                 scrolledwindow1.set_min_content_height(50)
  1324.                 self.textview_info = Gtk.TextView()
  1325.                 self.textbuffer_info = self.textview_info.get_buffer()
  1326.                 self.textview_info.set_editable(False)
  1327.                 self.textview_info.set_cursor_visible(False)
  1328.                 self.textview_info.modify_font(Pango.font_description_from_string('Monospace 9'))
  1329.                 scrolledwindow1.add(self.textview_info)
  1330.                 self.f_info['grid'].attach(scrolledwindow1, 0, 0, 3, 3)
  1331.  
  1332.         def make_audio_codec(self):
  1333.                 #
  1334.                 self.f_3acodec = self.make_frame_ag(3, "  audio codec  " , 6, 8, 8, False)
  1335.                 #
  1336.                 self.box_ac = self.make_comboboxtext2(AudioEncoder.AEmp4)
  1337.                 self.box_ac.set_active(AudioEncoder.AEmp4_default)
  1338.                 self.f_3acodec['grid'].attach(self.box_ac, 0, 0, 1, 1)
  1339.                 self.box_ac.connect("changed", self.on_codec_audio_changed)
  1340.                 #
  1341.                 self.spin_ac = self.make_spinbut(100 , 80 , 160 , 10 , 1 , 0, True )
  1342.                 self.spin_ac["adj"].connect("value-changed", self.on_audio_clicked)
  1343.                 self.f_3acodec['grid'].attach(self.spin_ac["spinner"], 1, 0, 1, 1)
  1344.                 #
  1345.                 label = self.make_label('sample: ')
  1346.                 self.f_3acodec['grid'].attach(label, 3, 0, 1, 1)
  1347.                 self.box_audio_rate = self.make_comboboxtext(AudioEncoder.AEaudio_sample)
  1348.                 self.box_audio_rate.set_tooltip_text(Tips.audio_samp_str)
  1349.                 self.box_audio_rate.connect("changed", self.on_codec_audio_changed)
  1350.                 self.f_3acodec['grid'].attach(self.box_audio_rate, 4, 0, 1, 1)
  1351.                 #
  1352.                 self.check_soxr = Gtk.CheckButton("soxr")
  1353.                 self.check_soxr.set_tooltip_text('  use SoX Resampler (libsoxr)   ')
  1354.                 self.check_soxr.set_active(False)
  1355.                 self.check_soxr.set_sensitive(False)
  1356.                 self.check_soxr.connect("toggled", self.on_codec_audio_changed)
  1357.                 self.f_3acodec['grid'].attach(self.check_soxr, 5, 0, 1, 1)
  1358.                 #
  1359.                 #
  1360.                 label = self.make_label('ch: ')
  1361.                 self.f_3acodec['grid'].attach(label, 6, 0, 1, 1)
  1362.                 self.box_audio_ch = self.make_comboboxtext(AudioEncoder.AEaudio_channels)
  1363.                 self.box_audio_ch.set_tooltip_text(Tips.audio_channels_str)
  1364.                 self.box_audio_ch.connect("changed", self.on_codec_audio_changed)
  1365.                 self.f_3acodec['grid'].attach(self.box_audio_ch, 7, 0, 1, 1)
  1366.                 self.check_prologic = Gtk.CheckButton("prologic2")
  1367.                 self.check_prologic.set_sensitive(False)
  1368.                 self.check_prologic.connect("toggled", self.on_codec_audio_changed)
  1369.                 self.f_3acodec['grid'].attach(self.check_prologic, 8, 0, 1, 1)
  1370.                 self.check_afterb = Gtk.CheckButton("fdk afterburner")
  1371.                 self.check_afterb.set_active(True)
  1372.                 self.check_afterb.set_sensitive(False)
  1373.                 self.check_afterb.connect("toggled", self.on_codec_audio_changed)
  1374.                 self.f_3acodec['grid'].attach(self.check_afterb, 9, 0, 1, 1)
  1375.  
  1376.         def make_video_codec(self):
  1377.                 self.f_3vcodec = self.make_frame_ag(3, "  video codec  " , 6, 8, 8, False)
  1378.                 self.box_vcodec = self.make_comboboxtext2(VideoEncoder.VEmp4)
  1379.                 self.box_vcodec.set_active(VideoEncoder.VEmp4_default)
  1380.                 self.box_vcodec.set_size_request(180,-1)
  1381.                 self.f_3vcodec['grid'].attach(self.box_vcodec, 0, 0, 1, 1)
  1382.                 self.box_vcodec.connect("changed", self.on_codec_video_changed)
  1383.                 #
  1384.                 self.box_vrc = self.make_comboboxtext2(VcodecOther.VRCall)
  1385.                 self.box_vrc.set_size_request(180,-1)
  1386.                 self.f_3vcodec['grid'].attach(self.box_vrc, 1, 0, 1, 1)
  1387.                 self.box_vrc.connect("changed", self.on_codec_vrc_changed)
  1388.                 #
  1389.                 self.spin_vc = self.make_spinbut(21.3 , 15 , 40 , 0.1 , 1 , 1, True )
  1390.                 self.spin_vc["adj"].connect("value-changed", self.on_codec_vrc_value_change)
  1391.                 self.f_3vcodec['grid'].attach(self.spin_vc["spinner"], 2, 0, 1, 1)
  1392.                 #
  1393.                 # x265 pools 3 x264 threads
  1394.                 self.check_3v_pool = Gtk.CheckButton("threads/pools 3")
  1395.                 self.check_3v_pool.connect("toggled", self.on_codec_clicked)
  1396.                 self.f_3vcodec['grid'].attach(self.check_3v_pool, 3, 0, 1, 1)
  1397.                 # x26510bit
  1398.                 self.check_3v_10bit = Gtk.CheckButton("x265 10bit")
  1399.                 self.check_3v_10bit.connect("toggled", self.on_codec_clicked)
  1400.                 self.f_3vcodec['grid'].attach(self.check_3v_10bit, 4, 0, 1, 1)
  1401.                 # opencl
  1402.                 self.check_3v_opencl = Gtk.CheckButton("opencl")
  1403.                 self.check_3v_opencl.connect("toggled", self.on_codec_clicked)
  1404.                 self.f_3vcodec['grid'].attach(self.check_3v_opencl, 5, 0, 1, 1)
  1405.                 # x264 preset
  1406.                 self.box_3v_preset = self.make_comboboxtext(VcodecOther.x264_preset)
  1407.                 #self.box_3v_preset.set_active(3)
  1408.                 self.box_3v_preset.set_tooltip_text(Tips.preset_tooltip_str)
  1409.                 self.f_3vcodec['grid'].attach(self.box_3v_preset, 0, 1, 1, 1)
  1410.                 self.box_3v_preset.connect("changed", self.on_preset_changed)
  1411.                 # x264 tune
  1412.                 self.box_3v_tune = self.make_comboboxtext(VcodecOther.x264_tune) # film,animation,grain,stillimage
  1413.                 self.box_3v_tune.set_tooltip_text(Tips.tune_tooltip_str)
  1414.                 self.f_3vcodec['grid'].attach(self.box_3v_tune, 1, 1, 1, 1)
  1415.                 self.box_3v_tune.connect("changed", self.on_preset_changed)
  1416.                 # x264 opts
  1417.                 self.box_3v_x264opts = self.make_comboboxtext2(VcodecOptions.OPTx264)
  1418.                 self.box_3v_x264opts.set_tooltip_text(Tips.opt_tooltip_str)
  1419.                 self.box_3v_x264opts.set_size_request(180,-1)
  1420.                 self.f_3vcodec['grid'].attach(self.box_3v_x264opts, 2, 1, 1, 1)
  1421.                 self.box_3v_x264opts.connect("changed", self.on_codec_clicked)
  1422.                 #opts custom
  1423.                 self.entry_optscustom = Gtk.Entry()
  1424.                 self.entry_optscustom.set_tooltip_text(Tips.x265_optscustom_str)
  1425.                 self.entry_optscustom.set_text("psnr=1")
  1426.                 self.entry_optscustom.connect("changed", self.on_codec_clicked)
  1427.                 self.f_3vcodec['grid'].attach(self.entry_optscustom, 3, 1, 3, 1)
  1428.                
  1429.                
  1430.                
  1431.         def make_other_opts(self):
  1432.                 #
  1433.                 self.f3_oth = self.make_frame_ag(3, "  other options  " , 6, 8, 8, True)
  1434.                 #
  1435.                 self.check_2pass = Gtk.CheckButton("2 pass")
  1436.                 self.check_2pass.connect("toggled", self.on_f3_other_clicked)
  1437.                 self.f3_oth['grid'].attach(self.check_2pass, 0, 0, 1, 1)
  1438.                 self.check_2pass.set_sensitive(False)
  1439.                 #
  1440.                 self.check_nometa = Gtk.CheckButton("no metatag")
  1441.                 self.check_nometa.set_active(True)
  1442.                 self.check_nometa.connect("toggled", self.on_f3_other_clicked)
  1443.                 self.check_nometa.set_tooltip_text(Tips.nometa_tooltip_srt)
  1444.                 self.f3_oth['grid'].attach(self.check_nometa, 1, 0, 1, 1)
  1445.                 #
  1446.                 #
  1447.                 self.check_scopy = Gtk.CheckButton("sub copy")
  1448.                 self.check_scopy.connect("toggled", self.on_f3_other_clicked)
  1449.                 self.check_scopy.set_tooltip_text(Tips.subcopy_tooltip_srt)
  1450.                 self.f3_oth['grid'].attach(self.check_scopy, 2, 0, 1, 1)
  1451.                 #
  1452.                 self.check_debug = Gtk.CheckButton("debug")
  1453.                 self.check_debug.connect("toggled", self.on_f3_other_clicked)
  1454.                 self.check_debug.set_tooltip_text(Tips.debug_tooltip_srt)
  1455.                 self.f3_oth['grid'].attach(self.check_debug, 4, 0, 1, 1)
  1456.                 #
  1457.                 self.box_oth_container = self.make_comboboxtext2(VcodecOther.OutContainers)
  1458.                 self.box_oth_container.set_active(VcodecOther.OutContainers_default)
  1459.                 self.box_oth_container.set_tooltip_text(Tips.container_tooltip_srt)
  1460.                 self.f3_oth['grid'].attach(self.box_oth_container, 5, 0, 1, 1)
  1461.                 self.box_oth_container.connect("changed", self.on_container_changed)
  1462.                
  1463.         def make_run_ffmpeg(self):
  1464.                 self.f3_run = self.make_frame_ag(3, "  execute in terminal  " , 6, 8, 8, True)
  1465.                 #
  1466.                 self.f3_run_indir_label = Gtk.Label("")
  1467.                 self.f3_run_indir_label.set_margin_left(6)
  1468.                 self.f3_run_indir_label.set_halign(1) # 1 left 2 right 3 center
  1469.                 self.f3_run_indir_label.set_ellipsize(2) # need for set_max_width_chars: 1 start 2 middle 3 end
  1470.                 self.f3_run_indir_label.set_max_width_chars(30)
  1471.                 self.f3_run['grid'].attach(self.f3_run_indir_label, 0, 0, 1, 1)
  1472.                 #
  1473.                 self.f3_run_file = Gtk.Label("no input file")
  1474.                 self.f3_run_file.set_margin_left(6)
  1475.                 self.f3_run_file.set_halign(3) # 1 left 2 right 3 center
  1476.                 self.f3_run_file.set_ellipsize(2) # need for set_max_width_chars: 1 start 2 middle 3 end
  1477.                 self.f3_run_file.set_max_width_chars(42)
  1478.                 self.f3_run_file.set_tooltip_text('')
  1479.                 self.f3_run['grid'].attach(self.f3_run_file, 1, 0, 2, 1)
  1480.                 self.f3_dur_file = Gtk.Label("")
  1481.                 self.f3_run['grid'].attach(self.f3_dur_file, 3, 0, 1, 1)
  1482.                 #
  1483.                 self.but_f3_run = Gtk.Button(label="RUN")
  1484.                 self.but_f3_run.connect("clicked", self.on_but_f3_run_clicked)
  1485.                 self.but_f3_run.set_sensitive(False)
  1486.                 self.f3_run['grid'].attach(self.but_f3_run, 3, 1, 1, 1)
  1487.                 #
  1488.                 self.f3_run_outdir_label = Gtk.Label("")
  1489.                 self.f3_run_outdir_label.set_margin_left(6)
  1490.                 self.f3_run_outdir_label.set_halign(1)
  1491.                 self.f3_run_outdir_label.set_ellipsize(2) # need for set_max_width_chars: 1 start 2 middle 3 end
  1492.                 self.f3_run_outdir_label.set_max_width_chars(54)
  1493.                 self.f3_run_outdir_label.set_markup("<b>out dir:  </b>" + os.getcwd())
  1494.                 self.f3_run['grid'].attach(self.f3_run_outdir_label, 0, 1, 2, 1)
  1495.                 #
  1496.                 # filechooserbutton
  1497.                 self.but_folder = Gtk.Button("Choose out dir")
  1498.                 self.but_folder.set_tooltip_text(Tips.out_dir_tooltip_str)
  1499.                 self.but_folder.connect("clicked", self.on_folder_clicked)
  1500.                 self.f3_run['grid'].attach(self.but_folder, 2, 1, 1, 1)
  1501.                 #
  1502.                 self.reportdata = Gtk.Label('')
  1503.                 self.f3_run['grid'].attach(self.reportdata, 0, 3, 4, 1)
  1504.                
  1505.                
  1506.         # event handlers -----------------------------------------------
  1507.        
  1508.         def on_window_destroy(self, *args):
  1509.                 Gtk.main_quit(*args)
  1510.  
  1511.         def on_map_clicked(self, button):
  1512.                 self.map_label.set_label("")
  1513.                 Vars.maps_str = ""
  1514.                 if self.check_map.get_active():
  1515.                         map_in = self.entry_map.get_chars(0, -1)
  1516.                         if map_in != "":
  1517.                                 map_l = map_in.split(",")
  1518.                                 for i in range(len(map_l)):
  1519.                                         if map_l[i] in Vars.maps_ch:
  1520.                                                 if Vars.maps_str != "":
  1521.                                                         Vars.maps_str += " "
  1522.                                                 Vars.maps_str += "-map " + map_l[i]
  1523.                                 self.map_label.set_label(Vars.maps_str)
  1524.                 self.outfilter()
  1525.                 self.make_p3_out_command()
  1526.  
  1527.         def on_time_clicked(self, button):
  1528.                 Vars.time_final_str = ""
  1529.                 Vars.time_start = 0
  1530.                 if self.check_time.get_active():
  1531.                         timein = 0
  1532.                         timeout = 0
  1533.                         timedur = 0
  1534.                         timein_ent = self.entry_timein.get_chars(0, -1)
  1535.                         if timein_ent != "":
  1536.                                 if self.is_number(timein_ent):
  1537.                                         timein = float(timein_ent.split('.')[0])
  1538.                                         if len(timein_ent.split('.')) == 2:
  1539.                                                 decimal = timein_ent.split('.')[1][:3]
  1540.                                                 decimal = float('0.' + decimal)
  1541.                                                 timein += decimal
  1542.                                         if Vars.duration_in_sec != 0:
  1543.                                                 if timein > Vars.duration_in_sec:
  1544.                                                         self.entry_timein.set_text(str(Vars.duration_in_sec -1))
  1545.                                                         return
  1546.                                 else:  
  1547.                                         timein = float(self.hms2sec(timein_ent.split('.')[0]))
  1548.                                         if len(timein_ent.split('.')) == 2:
  1549.                                                 decimal = timein_ent.split('.')[1][:3]
  1550.                                                 decimal = float('0.' + decimal)
  1551.                                                 timein += decimal
  1552.                                         if Vars.duration_in_sec != 0:
  1553.                                                 if timein > Vars.duration_in_sec:
  1554.                                                         self.entry_timein.set_text(str(self.sec2hms(Vars.duration_in_sec -1)))
  1555.                                                         return
  1556.                         timeout_ent = self.entry_timeout.get_chars(0, -1)
  1557.                         if timeout_ent != "":
  1558.                                 if self.is_number(timeout_ent):
  1559.                                         timeout = float(timeout_ent.split('.')[0])
  1560.                                         if len(timeout_ent.split('.')) == 2:
  1561.                                                 decimal = timeout_ent.split('.')[1][:3]
  1562.                                                 decimal = float('0.' + decimal)
  1563.                                                 timeout += decimal
  1564.                                         if Vars.duration_in_sec != 0:
  1565.                                                 if timeout > Vars.duration_in_sec:
  1566.                                                         self.entry_timeout.set_text(str(Vars.duration_in_sec))
  1567.                                                         return
  1568.                                                 if timeout == Vars.duration_in_sec:
  1569.                                                         timeout = 0
  1570.                                         timedur = timeout - timein
  1571.                                 else:  
  1572.                                         timeout = float(self.hms2sec(timeout_ent.split('.')[0]))
  1573.                                         if len(timeout_ent.split('.')) == 2:
  1574.                                                 decimal = timeout_ent.split('.')[1][:3]
  1575.                                                 decimal = float('0.' + decimal)
  1576.                                                 timeout += decimal
  1577.                                         if Vars.duration_in_sec != 0:
  1578.                                                 if timeout > Vars.duration_in_sec:
  1579.                                                         self.entry_timeout.set_text(Vars.duration)
  1580.                                                         return
  1581.                                                 if timeout == Vars.duration_in_sec:
  1582.                                                         timeout = 0
  1583.                                         timedur = timeout - timein
  1584.                         if timein != 0:
  1585.                                 Vars.time_final_str += " -ss " + str(timein)
  1586.                                 Vars.time_start = timein
  1587.                         if timedur > 0:
  1588.                                 Vars.time_final_str += " -t " + str(timedur)
  1589.                 self.time_label.set_text(Vars.time_final_str)
  1590.                 self.outfilter()
  1591.                 self.make_p3_out_command()
  1592.  
  1593.         def on_deint_clicked(self, button):
  1594.                 Vars.deint_str = ""
  1595.                 if self.checkdeint.get_active():
  1596.                         deint_val = self.box_deint['cbox'].get_active()
  1597.                         if deint_val == 0:
  1598.                                 Vars.deint_str = "yadif"
  1599.                         elif deint_val == 1:
  1600.                                 Vars.deint_str = "pp=lb"
  1601.                         elif deint_val == 2:
  1602.                                 Vars.deint_str = "idet"
  1603.                 self.outfilter()
  1604.  
  1605.         def on_scale_clicked(self, button):
  1606.                 customscale_in = ""
  1607.                 customscale_in = self.entry_scalecustom.get_chars(0, -1)
  1608.                 if customscale_in != "":
  1609.                         Vars.scalestr = customscale_in
  1610.                         self.outfilter()
  1611.                 elif self.box_scale_side['cbox'].get_active() != 0:
  1612.                         self.scale_calc()
  1613.                 else:
  1614.                         Vars.scalestr = ""
  1615.                         self.outfilter()
  1616.  
  1617.         def on_dn_clicked(self, button):
  1618.                 Vars.dn_str = ""
  1619.                 if self.checkdn.get_active():
  1620.                         dn_val = int(self.spindn['adj'].get_value())
  1621.                         Vars.dn_str = "hqdn3d=" + str(dn_val)
  1622.                 self.outfilter()
  1623.                
  1624.         def on_uns_clicked(self, button):
  1625.                 Vars.uns_str = ""
  1626.                 if self.checkuns.get_active():
  1627.                         luma = self.spinunsl['adj'].get_value()
  1628.                         chroma = self.spinunsc['adj'].get_value()
  1629.                         Vars.uns_str = "unsharp=5:5:" + "{0:0.2f}".format(luma) + ":5:5:" + "{0:0.2f}".format(chroma)
  1630.                 self.outfilter()
  1631.                        
  1632.         def on_fr_clicked(self, button):
  1633.                 Vars.fr_str = ""
  1634.                 if self.checkfr.get_active():
  1635.                         fr_val = self.spinfr['adj'].get_value()
  1636.                         Vars.fr_str = "-r " + "{0:0.2f}".format(fr_val)
  1637.                 self.outfilter()
  1638.                    
  1639.         def on_crop_clicked(self, button):
  1640.                 ok = 0
  1641.                 Vars.crop_str = ""
  1642.                 if self.checkcr.get_active():
  1643.                         ok = 1
  1644.                 if ok:
  1645.                         inW = int(self.spincw['adj'].get_value())
  1646.                         inH = int(self.spinch['adj'].get_value())
  1647.                         crT = int(self.spinct['adj'].get_value())
  1648.                         crB = int(self.spincb['adj'].get_value())
  1649.                         crL = int(self.spincl['adj'].get_value())
  1650.                         crR = int(self.spincr['adj'].get_value())      
  1651.                         finW = inW - crL - crR
  1652.                         finH = inH - crT - crB
  1653.                         if ( (finW < 100) or (finH < 100) ):
  1654.                                 Vars.crop_str = ""
  1655.                         else:
  1656.                                 Vars.crop_str = "crop=" + str(finW) + ":" \
  1657.                                  + str(finH) + ":" \
  1658.                                  + str(crL)  + ":" \
  1659.                                  + str(crT)
  1660.                 if self.box_scale_ar['cbox'].get_active() != 2:
  1661.                         self.outfilter()
  1662.                 else:
  1663.                         self.on_scale_clicked(button)
  1664.  
  1665.         def on_but_file(self,button):
  1666.                 if Vars.ENCODING:
  1667.                                 return
  1668.                 dialog = Gtk.FileChooserDialog("Please choose a file", self.window,
  1669.                 Gtk.FileChooserAction.OPEN,
  1670.                 ("_Cancel", Gtk.ResponseType.CANCEL,
  1671.                 "_Open", Gtk.ResponseType.OK))
  1672.                 #
  1673.                 filter = Gtk.FileFilter()
  1674.                 filter.set_name("Video")
  1675.                 filter.add_mime_type("video/x-matroska")
  1676.                 filter.add_mime_type("video/mp4")
  1677.                 filter.add_mime_type("video/x-flv")
  1678.                 filter.add_mime_type("video/avi")
  1679.                 filter.add_mime_type("video/mpg")
  1680.                 filter.add_mime_type("video/mpeg")
  1681.                 filter.add_mime_type("video/x-ms-wmv")
  1682.                 filter.add_mime_type("video/webm")
  1683.                 filter.add_mime_type("video/ogg")
  1684.                 filter.add_mime_type("video/quicktime")
  1685.                 dialog.add_filter(filter)
  1686.                 #
  1687.                 dialog.set_current_folder(Vars.indir)
  1688.                 response = dialog.run()
  1689.                 if response == Gtk.ResponseType.OK:
  1690.                         Vars.filename = dialog.get_filename()
  1691.                         self.file_changed()
  1692.                 dialog.destroy()
  1693.  
  1694.         def file_changed(self):
  1695.                
  1696.                 #def reduce_string(the_string, left_part, right_part):
  1697.                         #a = the_string[:left_part]
  1698.                         #b = '...'
  1699.                         #c = the_string[-right_part:]
  1700.                         #rlabel = a + b + c
  1701.                         #return rlabel
  1702.                
  1703.                 self.butplay.set_sensitive(True) # low part ---------
  1704.                 self.butprobe.set_sensitive(True)
  1705.                 self.preview_logic() # test and testsplit
  1706.                 self.check_time.set_active(False)
  1707.                 self.butcrode.set_sensitive(True) # crop ----------
  1708.                 self.spinct['adj'].set_value(0)
  1709.                 self.spincb['adj'].set_value(0)
  1710.                 self.spincl['adj'].set_value(0)
  1711.                 self.spincr['adj'].set_value(0)                
  1712.                 self.but_volume_det.set_sensitive(True) # volume detect
  1713.                 Vars.VOLDT_DONE = False
  1714.                 #self.but_volume_det.set_label("Volume detect")
  1715.                 self.label_meanvol.set_label("")
  1716.                 self.label_maxvol.set_label("")
  1717.                 self.check_vol.set_active(False) #volume
  1718.                 self.spin_db["adj"].set_value(0)
  1719.                 # framesdet
  1720.                 Vars.FRAMDT_DONE = False
  1721.                 self.but_frames_det.set_sensitive(True)
  1722.                 self.label_framesdet.set_label("N/A")
  1723.                 self.label_time2frame.set_label('')
  1724.                 #
  1725.                 self.check_drc.set_active(False) #drc
  1726.                 self.check_drc.set_sensitive(False)
  1727.                 self.spin_drc["adj"].set_value(1)
  1728.                 self.spin_drc["spinner"].set_sensitive(False)
  1729.                 Vars.ac3_drc = ""
  1730.                 self.compand_test.set_sensitive(True) #compand test
  1731.                 self.compand_volume.set_sensitive(True)
  1732.                 if self.check_compand.get_active():
  1733.                         self.check_compand.set_active(False)
  1734.                 self.dynaudnorm_test.set_sensitive(True) #dynaudnorm test
  1735.                 self.dynaudnorm_volume.set_sensitive(True)
  1736.                 if self.check_dynaudnorm.get_active():
  1737.                         self.check_dynaudnorm.set_active(False)
  1738.                 self.but_black_det.set_sensitive(True) # black  detect
  1739.                 self.but_black_det.set_label("Black detect")
  1740.                 self.textbuffer.set_text(Tips.black_dt_init_str)
  1741.                 self.progressbar_black_det.set_fraction(0.0)
  1742.                 self.check_prologic.set_sensitive(False) #check_prologic
  1743.                 self.check_prologic.set_active(False)
  1744.                 self.but_f3_run.set_sensitive(True) # ffmpeg run
  1745.                 Vars.BLACKDT_DONE = False
  1746.                 Vars.have_subs = False # subs
  1747.                 self.check_map.set_active(False) # map
  1748.                 #
  1749.                 command = "clear" + "\n"
  1750.                 length = len(command)
  1751.                 self.terminal.feed_child(command, length)
  1752.                 Vars.dirname = os.path.dirname(Vars.filename)
  1753.                 Vars.basename = os.path.basename(Vars.filename)
  1754.                 Vars.indir = os.path.dirname(Vars.filename)
  1755.                 #out same as in
  1756.                 Vars.outdir = Vars.indir
  1757.                 command = "cd " + "\"" + Vars.outdir + "\"" + "\n"
  1758.                 length = len(command)
  1759.                 self.terminal.feed_child(command, length)
  1760.                 # label outdir
  1761.                 self.f3_run_outdir_label.set_markup("<b>out dir:  </b>" + Vars.outdir)
  1762.                 #
  1763.                 self.check_out_file()
  1764.                 # label indir
  1765.                 self.f3_run_indir_label.set_label(Vars.dirname)
  1766.                 self.f3_run_indir_label.set_tooltip_text(Vars.dirname)
  1767.                 # label filename
  1768.                 self.f3_run_file.set_label(Vars.basename)
  1769.                 # label button openfile
  1770.                 if len(Vars.basename) > 36:
  1771.                         self.but_file.set_label(Vars.basename[0:33] + '...')
  1772.                 else:
  1773.                         self.but_file.set_label(Vars.basename)
  1774.                 #
  1775.                 self.but_f3_run.set_tooltip_text("")
  1776.                 self.reportdata.set_text('')
  1777.                 command = [Vars.ffprobe_ex, '-show_format', '-show_streams', '-pretty', '-loglevel', 'quiet', Vars.filename]
  1778.                 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  1779.                 out, err =  p.communicate()
  1780.                 out = out.decode() # python3
  1781.                 self.get_info(out)
  1782.  
  1783.         def get_info(self, out):
  1784.                
  1785.                 def form_to_3(in_str):
  1786.                         '''
  1787.                        bitrate and size info formatting
  1788.                        '''
  1789.                         a = in_str.split(' ')[0]
  1790.                        
  1791.                         if len(in_str.split(' ')) == 2:
  1792.                                 b = in_str.split(' ')[1]
  1793.                                 a = float(a)
  1794.                                 result = "{0:.3f}".format(a ) + " " + b
  1795.                         else:
  1796.                                 result = 'N/A'
  1797.                         return result
  1798.  
  1799.                 def set_w_h_video_scale():
  1800.                         self.spincw['adj'].set_value(float(Vars.video_width)) #mettere decimali se no non si vede
  1801.                         self.spincw['spinner'].set_sensitive(False)
  1802.                         self.spinch['adj'].set_value(float(Vars.video_height)) #mettere decimali se no non si vede
  1803.                         self.spinch['spinner'].set_sensitive(False)
  1804.                         if Vars.add_1_1_dar:
  1805.                                 self.box_scale_ar['list'].append(["as input"])
  1806.                         Vars.add_1_1_dar = False        
  1807.                
  1808.                 def set_dar_in(info):
  1809.                         try:
  1810.                                 darw = info.split(':')[0]
  1811.                                 darh = info.split(':')[1]
  1812.                                 darw = int(darw)
  1813.                                 darh = int(darh)
  1814.                                 if darh > 0 and darw > 0:
  1815.                                         darin = float(darw)/darh
  1816.                                         Vars.darin = "{0:.3f}".format(darin)
  1817.                                 else:
  1818.                                         darin = float(Vars.video_width)/float(Vars.video_height)
  1819.                                         Vars.darin = "{0:.3f}".format(darin)
  1820.                         except:
  1821.                                 darin = float(Vars.video_width)/float(Vars.video_height)
  1822.                                 Vars.darin = "{0:.3f}".format(darin)
  1823.                
  1824.                 def maps_choises(num_streams):
  1825.                         maps = []
  1826.                         for i in range(0,num_streams):
  1827.                                 m = '0:' + str(i)
  1828.                                 maps.append(m)
  1829.                         Vars.maps_ch = maps
  1830.                        
  1831.                        
  1832.  
  1833.                 #x Vars.info_str
  1834.                 Vars.info_str = ""
  1835.                 is_stream = 0
  1836.                 is_format = 0
  1837.                 is_video = 0
  1838.                 for line in out.split('\n'):
  1839.                         line = line.strip()
  1840.                         if line.startswith('[STREAM]'):
  1841.                                 Vars.info_str += "STREAM "
  1842.                                 is_stream = 1
  1843.                         elif line.startswith('[/STREAM]'):
  1844.                                 Vars.info_str += "\n"
  1845.                                 is_stream = 0
  1846.                         elif line.startswith('index=') and is_stream == 1:
  1847.                                 s = line
  1848.                                 info = s.split('=')[1]  
  1849.                                 Vars.info_str += info + ": "
  1850.                         elif line.startswith('codec_name=') and is_stream == 1:
  1851.                                 s = line
  1852.                                 info = s.split('=')[1]
  1853.                                 if info == 'ac3':
  1854.                                         self.check_drc.set_sensitive(True)
  1855.                                         self.spin_drc["spinner"].set_sensitive(True)
  1856.                                 Vars.info_str += info + "  "
  1857.                         elif line.startswith('profile=') and is_stream == 1:
  1858.                                 s = line
  1859.                                 info = s.split('=')[1]  
  1860.                                 Vars.info_str = Vars.info_str + "profile=" +info + "  "
  1861.                         elif line.startswith('codec_type=') and is_stream == 1:
  1862.                                 s = line
  1863.                                 info = s.split('=')[1]
  1864.                                 if info == 'video':
  1865.                                         is_video = 1
  1866.                                 else:
  1867.                                         is_video = 0
  1868.                                 Vars.info_str += info + "  "
  1869.                                 # auto -c:s copy if subtitles streams
  1870.                                 if info == 'subtitle':
  1871.                                         Vars.have_subs = True
  1872.                                 self.on_container_changed(0)
  1873.                         elif line.startswith('width=') and is_stream == 1:
  1874.                                 s = line
  1875.                                 info = s.split('=')[1]
  1876.                                 if is_video:
  1877.                                         Vars.video_width = info
  1878.                                         Vars.info_str += info + "x"
  1879.                         elif line.startswith('height=') and is_stream == 1:
  1880.                                 s = line
  1881.                                 info = s.split('=')[1]
  1882.                                 if is_video:
  1883.                                         Vars.video_height = info
  1884.                                         Vars.info_str += info + "  "
  1885.                         elif line.startswith('sample_aspect_ratio=') and is_stream == 1:
  1886.                                 s = line
  1887.                                 if is_video:
  1888.                                         info = s.split('=')[1]  
  1889.                                         Vars.info_str += "SAR=" + info + "  "
  1890.                         elif line.startswith('display_aspect_ratio=') and is_stream == 1:
  1891.                                 s = line
  1892.                                 if is_video:
  1893.                                         info = s.split('=')[1]  
  1894.                                         Vars.info_str += "DAR=" + info + "  "
  1895.                                         set_dar_in(info)
  1896.                         elif line.startswith('pix_fmt=') and is_stream == 1:
  1897.                                 s = line
  1898.                                 if is_video:
  1899.                                         info = s.split('=')[1]  
  1900.                                         Vars.info_str += info + "  "
  1901.                         elif line.startswith('sample_rate=') and is_stream == 1:
  1902.                                 s = line
  1903.                                 info = s.split('=')[1]
  1904.                                 info = form_to_3(info)
  1905.                                 Vars.audio_srate_in = info
  1906.                                 Vars.info_str += "samplerate=" + info + "  "
  1907.                                 if Vars.audio_srate_in == '44.100 KHz':
  1908.                                         self.box_audio_rate.set_active(1)
  1909.                                 else:
  1910.                                         self.box_audio_rate.set_active(0)
  1911.                                 self.on_audio_clicked(1)
  1912.                         elif line.startswith('channels=') and is_stream == 1:
  1913.                                 s = line
  1914.                                 info = s.split('=')[1]
  1915.                                 Vars.audio_channels = int(info)
  1916.                                 Vars.info_str += "channels=" + info + "  "
  1917.                                 if Vars.audio_channels == 6:
  1918.                                         self.check_prologic.set_sensitive(True)
  1919.                                         self.check_prologic.set_active(True)
  1920.                         elif line.startswith('r_frame_rate=') and is_stream == 1:
  1921.                                 if is_video:
  1922.                                         s = line
  1923.                                         info = s.split('=')[1]
  1924.                                         a = info.split('/')[0]
  1925.                                         b = info.split('/')[1]
  1926.                                         a = float(a)
  1927.                                         b = float(b)
  1928.                                         if (a > 0) and (b > 0):
  1929.                                                 c = float(a)/float(b)
  1930.                                                 Vars.framerate = c
  1931.                                                 info = "{0:0.2f}".format(c)
  1932.                                                 self.spinfr["adj"].set_value(c)
  1933.                                                 Vars.info_str += info + " fps  "
  1934.                         elif line.startswith('bit_rate=') and is_stream == 1:
  1935.                                 s = line
  1936.                                 info = s.split('=')[1]
  1937.                                 info = form_to_3(info)
  1938.                                 Vars.info_str += "bitrate=" + info + "  "
  1939.                         elif line.startswith('nb_frames=') and is_stream == 1:
  1940.                                 s = line
  1941.                                 info = s.split('=')[1]
  1942.                                 if is_video:
  1943.                                         if self.is_number(info):
  1944.                                                 self.label_framesdet.set_label(info)
  1945.                         elif line.startswith('TAG:NUMBER_OF_FRAMES=') and is_stream == 1:
  1946.                                 s = line
  1947.                                 info = s.split('=')[1]
  1948.                                 if is_video:
  1949.                                         if self.is_number(info):
  1950.                                                 self.label_framesdet.set_label(info)
  1951.                         elif line.startswith('TAG:language=') and is_stream == 1:
  1952.                                 s = line
  1953.                                 info = s.split('=')[1]  
  1954.                                 Vars.info_str += "lang=" + info + "  "
  1955.                         elif line.startswith('[FORMAT]'):
  1956.                                 Vars.info_str = Vars.info_str + "FORMAT "
  1957.                                 is_format = 1
  1958.                         elif line.startswith('[/FORMAT]'):
  1959.                                 is_format = 0
  1960.                         elif line.startswith('nb_streams=') and is_format == 1:
  1961.                                 s = line
  1962.                                 info = s.split('=')[1]
  1963.                                 Vars.info_str += "streams=" + info + "  "
  1964.                                 # possible map [tuple] Vars.maps_ch
  1965.                                 maps_choises(int(info))
  1966.                         elif line.startswith('duration=') and is_format == 1:
  1967.                                 s = line
  1968.                                 infoor = s.split('=')[1]        
  1969.                                 info = infoor.split('.')[0]
  1970.                                 Vars.duration_in_sec = self.hms2sec(info)
  1971.                                 Vars.duration = info
  1972.                                 if len (infoor.split('.')) == 2:
  1973.                                         decimal = infoor.split('.')[1][:3]
  1974.                                         info += '.' + decimal
  1975.                                         Vars.duration = info
  1976.                                         decimal = float('0.' + decimal)
  1977.                                         Vars.duration_in_sec += decimal
  1978.                                 self.entry_timein.set_text('0')
  1979.                                 self.entry_timeout.set_text(info)
  1980.                                 Vars.info_str += "duration=" + info + "  "
  1981.                         elif line.startswith('size=') and is_format == 1:
  1982.                                 s = line
  1983.                                 info = s.split('=')[1]
  1984.                                 info = form_to_3(info)
  1985.                                 Vars.info_str += "size=" + info + "  "
  1986.                         elif line.startswith('bit_rate=') and is_format == 1:
  1987.                                 s = line
  1988.                                 info = s.split('=')[1]
  1989.                                 info = form_to_3(info)
  1990.                                 Vars.info_str += "bitrate=" + info
  1991.                                
  1992.                 set_w_h_video_scale()
  1993.                 self.f3_dur_file.set_label(Vars.duration)
  1994.                 self.textbuffer_info.set_text(Vars.info_str)
  1995.                 self.f3_run_file.set_tooltip_text(Vars.info_str)
  1996.                 self.check_map.set_tooltip_text(Vars.info_str)
  1997.                 self.check_time.set_tooltip_text(Vars.info_str)
  1998.                 Vars.in_file_size = self.humansize(Vars.filename)
  1999.        
  2000.         def on_butplay_clicked(self, button):
  2001.                 if Vars.ENCODING:
  2002.                         return
  2003.                 command = Vars.ffplay_ex + " -hide_banner" + " \"" + Vars.filename + "\"" +"\n"
  2004.                 length = len(command)
  2005.                 self.terminal.feed_child(command, length)
  2006.                
  2007.         def on_butprobe_clicked(self, button):
  2008.                 if Vars.ENCODING:
  2009.                         return
  2010.                 command = Vars.ffprobe_ex + " \"" + Vars.filename + "\""  + " 2>&1 | grep 'Input\|Duration\|Stream'" + "\n"
  2011.                 length = len(command)
  2012.                 self.terminal.feed_child(command, length)        
  2013.                
  2014.         def on_butcrode_clicked(self, button):
  2015.                 self.butcrode.set_sensitive(False)
  2016.                 if Vars.time_start == 0:
  2017.                         command = Vars.ffmpeg_ex + " -i " + "\"" + Vars.filename + "\"" + " -ss 60 -t 1 -vf cropdetect -f null - 2>&1 | awk \'/crop/ { print $NF }\' | tail -1"
  2018.                 else:
  2019.                         command = Vars.ffmpeg_ex + " -i " + "\"" + Vars.filename + "\"" + " -ss " + str(Vars.time_start) + " -t 1 -vf cropdetect -f null - 2>&1 | awk \'/crop/ { print $NF }\' | tail -1"
  2020.                 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
  2021.                 out, err =  p.communicate()
  2022.                 out = out.decode()
  2023.                 for line in out.split('\n'):
  2024.                         line = line.strip()
  2025.                         if "crop=" in line:  
  2026.                                 aa = line.split('crop=', 1)
  2027.                                 aaa = aa[1]
  2028.                                 listdata = aaa.split(':')
  2029.                                 w = listdata[0]
  2030.                                 h = listdata[1]
  2031.                                 offx = listdata[2]
  2032.                                 offy = listdata[3]
  2033.                                 ctop = int(offy)
  2034.                                 cbot = int(Vars.video_height) - int(offy) -int(h)
  2035.                                 cleft = int(offx)
  2036.                                 cright = int(Vars.video_width) - int(offx) -int(w)
  2037.                                 self.spinct['adj'].set_value(float(ctop))
  2038.                                 self.spincb['adj'].set_value(float(cbot))
  2039.                                 self.spincl['adj'].set_value(float(cleft))
  2040.                                 self.spincr['adj'].set_value(float(cright))  
  2041.                                 break
  2042.                 self.butcrode.set_sensitive(True)
  2043.                
  2044.         def on_buttest_clicked(self, button):
  2045.                 if Vars.ENCODING:
  2046.                         return
  2047.                 # -map preview: only with none -vf option  
  2048.                 if Vars.maps_str == "":
  2049.                         command = Vars.ffplay_ex + " -hide_banner" + " \"" + Vars.filename + "\" " \
  2050.                          + " " + Vars.time_final_str + " " \
  2051.                          + "-vf "  + Vars.filter_test_str + "\n"
  2052.                 else:
  2053.                         command = Vars.ffmpeg_ex + " -i \"" + Vars.filename + "\" " \
  2054.                          + Vars.maps_str  + " " + Vars.time_final_str + " "
  2055.                         if Vars.filter_test_str != "":
  2056.                                 command = command + " -vf "  + Vars.filter_test_str
  2057.                         command = command +  " -c copy -f matroska - | ffplay -" + "\n"
  2058.                 length = len(command)
  2059.                 self.terminal.feed_child(command, length)
  2060.                
  2061.         def on_buttestspl_clicked(self, button):
  2062.                 if Vars.ENCODING:
  2063.                         return
  2064.                 command = Vars.ffplay_ex + " -hide_banner" + " \"" + Vars.filename + "\" " \
  2065.                   + " " + Vars.time_final_str + " " \
  2066.                   + " -vf \"split[a][b]; [a]pad=iw:(ih*2)+4:color=888888 [src]; [b]" \
  2067.                   + Vars.filter_test_str + " [filt]; [src][filt]overlay=((main_w - w)/2):main_h/2\"" + "\n"
  2068.                 length = len(command)
  2069.                 self.terminal.feed_child(command, length)
  2070.                
  2071.         def on_butt_vtecopy_clicked(self, widget):
  2072.                 self.terminal.select_all()
  2073.                 self.terminal.copy_clipboard()
  2074.                 try: # only vte2.9
  2075.                         self.terminal.select_none()
  2076.                 except:
  2077.                         return
  2078.        
  2079.         def on_but_volume_det_clicked(self, button):
  2080.                
  2081.                 def set_other_butt(boolean):
  2082.                         if Vars.FRAMDT_DONE != True:
  2083.                                 self.but_frames_det.set_sensitive(boolean)
  2084.                         if Vars.BLACKDT_DONE != True:
  2085.                                 self.but_black_det.set_sensitive(boolean)
  2086.  
  2087.                 def finish_voldet(meanv, maxv, max_vol_det):
  2088.                         self.voldet_spin.stop()
  2089.                         self.voldet_spin.set_sensitive(False)
  2090.                         self.but_volume_det.set_label("Volume detect")
  2091.                         set_other_butt(True)
  2092.                         self.label_meanvol.set_label(meanv)
  2093.                         self.label_maxvol.set_label(maxv)
  2094.                         max_vol_det = max_vol_det.split(' ')[1]
  2095.                         volgain = float(max_vol_det) + 0.9
  2096.                         if volgain < -0.75:
  2097.                                 volgain=abs(volgain)
  2098.                                 volgain=float(volgain)
  2099.                                 self.spin_db["adj"].set_value(volgain)
  2100.  
  2101.                        
  2102.                 def my_thread_voldet():
  2103.                         command = [Vars.ffmpeg_ex, '-i', Vars.filename, '-vn', '-af', 'volumedetect', '-f', 'null', '/dev/null']
  2104.                         p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
  2105.                         GLib.idle_add(self.but_volume_det.set_label, "Wait")
  2106.                         GLib.idle_add(set_other_butt, False)
  2107.                         time.sleep(0.02)
  2108.                         while True:
  2109.                                 line = p.stderr.read()
  2110.                                 if not line:
  2111.                                         break
  2112.                                 out = line.decode()
  2113.                                 for line in out.split('\n'):
  2114.                                         line = line.strip()
  2115.                                         if "mean_volume:" in line:  
  2116.                                                 aa = line.split('mean_volume:', 1)
  2117.                                                 mea_vol_det = aa[1]
  2118.                                                 meanv = "Mean vol: " + mea_vol_det
  2119.                                         if "max_volume:" in line:  
  2120.                                                 aa = line.split('max_volume:', 1)
  2121.                                                 max_vol_det = aa[1]
  2122.                                                 maxv = "Max vol: " + max_vol_det
  2123.                         p.communicate()
  2124.                         GLib.idle_add(finish_voldet, meanv, maxv, max_vol_det)
  2125.                         time.sleep(0.1)
  2126.                
  2127.                 if Vars.VOLDT_DONE:
  2128.                         return
  2129.                 Vars.VOLDT_DONE = True
  2130.                 self.voldet_spin.set_sensitive(True)
  2131.                 self.voldet_spin.start()
  2132.                 thread=threading.Thread(target=my_thread_voldet)
  2133.                 thread.daemon = True
  2134.                 thread.start()
  2135.                
  2136.                
  2137.         def on_but_frames_det_clicked(self, button):
  2138.                        
  2139.                 def finish_framesdet(frames):
  2140.                         self.label_framesdet.set_label(frames)
  2141.                         self.framesdet_spin.stop()
  2142.                         self.framesdet_spin.set_sensitive(False)
  2143.                         self.but_frames_det.set_label("Total frames detect")
  2144.                         set_other_butt(True)
  2145.  
  2146.                 def set_other_butt(boolean):
  2147.                         if Vars.VOLDT_DONE != True:
  2148.                                 self.but_volume_det.set_sensitive(boolean)
  2149.                         if Vars.BLACKDT_DONE != True:
  2150.                                 self.but_black_det.set_sensitive(boolean)
  2151.  
  2152.                 def my_thread_framedet():
  2153.                         #ffprobe2 -show_packets  ac3-sd.mkv  2>/dev/null | grep video | wc -l
  2154.                         command = Vars.ffprobe_ex + " -show_packets  \"" + Vars.filename + "\" 2>/dev/null | grep video | wc -l"
  2155.                         p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
  2156.                         GLib.idle_add(self.but_frames_det.set_label, "Wait")
  2157.                         GLib.idle_add(set_other_butt, False)
  2158.                         time.sleep(0.02)
  2159.                         while True:
  2160.                                 line = p.stdout.read()
  2161.                                 if not line:
  2162.                                         break
  2163.                                 out = line.decode()
  2164.                                 for line in out.split('\n'):
  2165.                                         if line != "":
  2166.                                                 line = line.strip()
  2167.                                                 frames = line
  2168.                         p.communicate()
  2169.                         GLib.idle_add(finish_framesdet, frames)
  2170.                         time.sleep(0.3)
  2171.                
  2172.                 if Vars.FRAMDT_DONE:
  2173.                         return
  2174.                 Vars.FRAMDT_DONE = True
  2175.                 self.framesdet_spin.set_sensitive(True)
  2176.                 self.framesdet_spin.start()    
  2177.                 thread=threading.Thread(target=my_thread_framedet)
  2178.                 thread.daemon = True
  2179.                 thread.start()
  2180.  
  2181.         def on_time2frame_clicked(self, button):
  2182.                 timein_ent = self.entry_time2frame.get_chars(0, -1)
  2183.                 if timein_ent != "":                    
  2184.                         if self.is_number(timein_ent):
  2185.                                 timein = float(timein_ent.split('.')[0])
  2186.                                 if len(timein_ent.split('.')) == 2:
  2187.                                         decimal = timein_ent.split('.')[1][:3]
  2188.                                         decimal = float('0.' + decimal)
  2189.                                         timein += decimal
  2190.                                 if Vars.duration_in_sec != 0:
  2191.                                         if timein > Vars.duration_in_sec:
  2192.                                                 self.entry_timein.set_text(str(Vars.duration_in_sec -1))
  2193.                                                 return
  2194.                         else:  
  2195.                                 timein = float(self.hms2sec(timein_ent.split('.')[0]))
  2196.                                 if len(timein_ent.split('.')) == 2:
  2197.                                         decimal = timein_ent.split('.')[1][:3]
  2198.                                         decimal = float('0.' + decimal)
  2199.                                         timein += decimal
  2200.                                 if Vars.duration_in_sec != 0:
  2201.                                         if timein > Vars.duration_in_sec:
  2202.                                                 self.entry_timein.set_text(str(self.sec2hms(Vars.duration_in_sec -1)))
  2203.                                                 return
  2204.                         t2frames = int(round(float(timein)*Vars.framerate))
  2205.                         self.label_time2frame.set_label(str(t2frames))
  2206.  
  2207.         def on_volume_clicked(self, button):
  2208.                 ratio = 1
  2209.                 self.label_ratio_val.set_label("1")
  2210.                 Vars.final_af_str = ""
  2211.                 db = self.spin_db["adj"].get_value()
  2212.                 if db != 0.00:
  2213.                         ratio = pow(10, (db/20.0))
  2214.                         ratio = float("{0:.3f}".format(ratio))    
  2215.                         self.label_ratio_val.set_label(str(ratio))
  2216.                         if self.check_vol.get_active():
  2217.                                 Vars.final_af_str = "volume=" + str(ratio)
  2218.                         else:
  2219.                                 Vars.final_af_str = ""
  2220.                 self.make_p3_out_command()
  2221.  
  2222.         def on_drc_clicked(self, buttom):
  2223.                 Vars.ac3_drc = ""
  2224.                 if self.check_drc.get_active():
  2225.                         val = self.spin_drc["adj"].get_value()
  2226.                         Vars.ac3_drc = "-drc_scale " + str(int(val))
  2227.                        
  2228.         def on_compand_reset(self, button):
  2229.                 self.entry_compand.set_text(Vars.compinit)
  2230.                 self.on_compand_clicked(button)
  2231.  
  2232.         def on_compand_clicked(self, button):
  2233.                 Vars.compand_data = ""
  2234.                 if self.check_compand.get_active():
  2235.                         if self.check_dynaudnorm.get_active():
  2236.                                 self.check_dynaudnorm.set_active(False)
  2237.                         compand_data = self.entry_compand.get_chars(0, -1)
  2238.                         if Vars.audio_channels == 6:
  2239.                                 Vars.compand_data = "aformat=channel_layouts=stereo,aresample=matrix_encoding=dplii,compand=" + compand_data
  2240.                         else:
  2241.                                 Vars.compand_data = "aformat=channel_layouts=stereo,compand=" + compand_data
  2242.                 self.make_p3_out_command()
  2243.  
  2244.         def on_compand_test(self, button):
  2245.                 if Vars.compand_data != "":
  2246.                         command = Vars.ffplay_ex + " -hide_banner" + " -f lavfi \'amovie=" + Vars.filename + " :sp=" + str(Vars.time_start) + " , " + Vars.compand_data + "  ,ebur128=video=1:meter=18:peak=true [out0][out1]\'" + "\n"
  2247.                 else:
  2248.                         command = Vars.ffplay_ex + " -hide_banner" + " -f lavfi \'amovie=" + Vars.filename + " :sp=" + str(Vars.time_start) + "  ,ebur128=video=1:meter=18:peak=true [out0][out1]\'" + "\n"
  2249.                 length = len(command)
  2250.                 self.terminal.feed_child(command, length)
  2251.  
  2252.         def on_compand_volume(self, button):
  2253.                 if Vars.compand_data != "":                    
  2254.                         command = \
  2255.                         Vars.ffplay_ex + " -hide_banner" + " -f lavfi \'movie=" + Vars.filename + ":sp=" + str(Vars.time_start) + "[vid];"\
  2256.                         + "amovie=" + Vars.filename + ":sp=" + str(Vars.time_start) + "[aud];"\
  2257.                         + "[aud]asplit=[2][3];"\
  2258.                         + "[2]aformat=channel_layouts=stereo,showvolume=h=20:t=0[volin];"\
  2259.                         + "[3]" + Vars.compand_data + ",asplit[c2][out1];"\
  2260.                         + "[c2]showvolume=h=40[volout];"\
  2261.                         + "[vid][volin]overlay=6:6[int1];"\
  2262.                         + "[int1][volout]overlay=6:56,setdar=" + Vars.darin + "[out]\'"\
  2263.                         + " -window_title \"compand test, volume in,out\"" + "\n"
  2264.                 else:
  2265.                         command = Vars.ffplay_ex + " -hide_banner" + " -f lavfi \'movie=" + Vars.filename + ":sp=" + str(Vars.time_start)\
  2266.                         + "[vid];amovie=" + Vars.filename + ":sp=" + str(Vars.time_start) + "[aud];"\
  2267.                         + "[aud]aformat=channel_layouts=stereo,"\
  2268.                         + "asplit[out1][2] ; [2]showvolume=h=60[3]; [vid][3]overlay=6:6,setdar=" + Vars.darin + "[out]\'"\
  2269.                         + " -window_title \"input volume\"" + "\n"
  2270.                 length = len(command)
  2271.                 self.terminal.feed_child(command, length)
  2272.                
  2273.         def on_dynaudnorm_reset(self, button):
  2274.                 self.entry_dynaudnorm.set_text(Vars.dynaudnorm)
  2275.                 self.on_dynaudnorm_clicked(button)
  2276.  
  2277.         def on_dynaudnorm_clicked(self, button):
  2278.                 Vars.dynaudnorm_data = ""
  2279.                 if self.check_dynaudnorm.get_active():
  2280.                         if self.check_compand.get_active():
  2281.                                 self.check_compand.set_active(False)
  2282.                         dynaudnorm_data = self.entry_dynaudnorm.get_chars(0, -1)
  2283.                         if Vars.audio_channels == 6:
  2284.                                 Vars.dynaudnorm_data = "aformat=channel_layouts=stereo,aresample=matrix_encoding=dplii,dynaudnorm=" + dynaudnorm_data
  2285.                         else:
  2286.                                 Vars.dynaudnorm_data = "aformat=channel_layouts=stereo,dynaudnorm=" + dynaudnorm_data
  2287.                 self.make_p3_out_command()
  2288.  
  2289.         def on_dynaudnorm_test(self, button):
  2290.                 if Vars.dynaudnorm_data != "":
  2291.                         command = Vars.ffplay_ex + " -hide_banner" + " -f lavfi \'amovie=" + Vars.filename + " :sp=" + str(Vars.time_start) + " , " + Vars.dynaudnorm_data + "  ,ebur128=video=1:meter=18:peak=true [out0][out1]\'" + "\n"
  2292.                 else:
  2293.                         command = Vars.ffplay_ex + " -hide_banner" + " -f lavfi \'amovie=" + Vars.filename + " :sp=" + str(Vars.time_start) + "  ,ebur128=video=1:meter=18:peak=true [out0][out1]\'" + "\n"
  2294.                 length = len(command)
  2295.                 self.terminal.feed_child(command, length)
  2296.  
  2297.         def on_dynaudnorm_volume(self, button):
  2298.                 if Vars.dynaudnorm_data != "":
  2299.                         command = Vars.ffplay_ex + " -hide_banner" + " -f lavfi \'movie=" + Vars.filename + ":sp=" + str(Vars.time_start)\
  2300.                         + "[vid];amovie=" + Vars.filename + ":sp=" + str(Vars.time_start) + "[aud];"\
  2301.                         + "[aud]" + Vars.dynaudnorm_data \
  2302.                         + ", asplit[out1][2];"\
  2303.                         + "[2]showvolume=h=15:w=240:f=120:r=15:t=0,"\
  2304.                         + "drawgrid=width=15:height=30:thickness=2:color=white@0.2,crop=225:31:0:0[3];"\
  2305.                         + "[vid][3]overlay=6:6:format=yuv420,setdar=" + Vars.darin +"[out]\'"\
  2306.                         + " -window_title \"dynaudnorm test, volume out\"" + "\n"
  2307.                 else:
  2308.                         command = Vars.ffplay_ex + " -hide_banner" + " -f lavfi \'movie=" + Vars.filename + ":sp=" + str(Vars.time_start)\
  2309.                         + "[vid];amovie=" + Vars.filename + ":sp=" + str(Vars.time_start) + "[aud];"\
  2310.                         + "[aud]aformat=channel_layouts=stereo,"\
  2311.                         + "asplit[out1][2] ; [2]showvolume=h=60[3]; [vid][3]overlay=6:6,setdar=" + Vars.darin +"[out]\'"\
  2312.                         + " -window_title \"input volume\"" + "\n"
  2313.                 length = len(command)
  2314.                 self.terminal.feed_child(command, length)
  2315.  
  2316.         def on_audio_clicked(self, button):
  2317.                 #audio
  2318.                 Vars.audio_codec_str = self.audio_codec()
  2319.                 self.make_p3_out_command()
  2320.  
  2321.         def on_codec_audio_changed(self, button):
  2322.                
  2323.                 def no_afterburn():
  2324.                         if self.check_afterb.get_sensitive():
  2325.                                 self.check_afterb.set_active(True)
  2326.                                 self.check_afterb.set_sensitive(False)
  2327.                
  2328.                 def yes_afterburn():
  2329.                         self.check_afterb.set_sensitive(True)
  2330.  
  2331.                 #prologic2
  2332.                 if Vars.audio_channels == 6 and self.box_audio_ch.get_active_text() == '2':
  2333.                         self.check_prologic.set_sensitive(True)
  2334.                 else:
  2335.                         self.check_prologic.set_sensitive(False)
  2336.                 #
  2337.                 selected_audio_codec = self.box_ac.get_active_text()
  2338.                
  2339.                 for i in range(0,len(AudioEncoder.AEall)):
  2340.                         if AudioEncoder.AEall[i].label == selected_audio_codec:
  2341.                                 Vars.XaCheck = AudioEncoder.AEall[i]
  2342.                                 #Vars.XaCheck now is the selected AEobject
  2343.                                 break
  2344.                
  2345.                 if Vars.acodec_is != Vars.XaCheck.codec:
  2346.                         self.box_audio_ch.set_sensitive(True)
  2347.                         self.box_audio_rate.set_sensitive(True)
  2348.                         #
  2349.                         if Vars.XaCheck.value:
  2350.                                 self.spin_ac['spinner'].set_sensitive(True)
  2351.                                 self.adj_change2(self.spin_ac['adj'], Vars.XaCheck.value)
  2352.                                 self.spin_ac['adj'].set_value(Vars.XaCheck.value[0])
  2353.                         else:
  2354.                                 self.spin_ac['spinner'].set_sensitive(False)
  2355.                         #
  2356.                         if Vars.XaCheck.toolt:
  2357.                                 self.spin_ac['spinner'].set_tooltip_text(Vars.XaCheck.toolt)
  2358.                         else:
  2359.                                 self.spin_ac['spinner'].set_tooltip_text('')
  2360.                         #
  2361.                         if Vars.XaCheck.afterbrn:
  2362.                                 yes_afterburn()
  2363.                         else:
  2364.                                 no_afterburn()
  2365.                         #
  2366.                         if Vars.XaCheck.no_audio_enc:
  2367.                                 self.box_audio_ch.set_sensitive(False)
  2368.                                 self.box_audio_rate.set_sensitive(False)
  2369.                                 self.check_prologic.set_sensitive(False)
  2370.                                 self.check_soxr.set_sensitive(False)
  2371.                         elif Vars.XaCheck.force_stereo: # aacplus
  2372.                                 self.box_audio_ch.set_sensitive(False)
  2373.                                 self.box_audio_ch.set_active(0)
  2374.                         #
  2375.                         Vars.acodec_is = Vars.XaCheck.codec
  2376.                 self.on_audio_clicked(button)  
  2377.  
  2378.  
  2379.         def audio_codec(self):
  2380.                
  2381.                 # channels
  2382.                 audio_codec_str = ""
  2383.                 channel_str = "-ac 2"
  2384.                 channel = self.box_audio_ch.get_active_text()
  2385.                 if channel == "1":
  2386.                         channel_str = "-ac 1"
  2387.                 # sample rate e soxr
  2388.                 sample_str = ""
  2389.                 sample = self.box_audio_rate.get_active_text()
  2390.                 if not(Vars.XaCheck.no_audio_enc):
  2391.                         if sample == "44100":
  2392.                                 out_s = '44.100 KHz'
  2393.                                 if out_s != Vars.audio_srate_in:
  2394.                                         sample_str = "-ar 44.1k"
  2395.                                         self.check_soxr.set_sensitive(True)
  2396.                                 else:
  2397.                                         self.check_soxr.set_sensitive(False)
  2398.                         elif sample == "48000":
  2399.                                 out_s = '48.000 KHz'
  2400.                                 if out_s != Vars.audio_srate_in:
  2401.                                         sample_str = "-ar 48k"
  2402.                                         self.check_soxr.set_sensitive(True)
  2403.                                 else:
  2404.                                         self.check_soxr.set_sensitive(False)
  2405.                 # acodec
  2406.                 def on_afterburner(ac_str):
  2407.                         if (self.check_afterb.get_active() == False):
  2408.                                 ac_str = ac_str + " -afterburner 0 "
  2409.                         return ac_str
  2410.                
  2411.                 audio_codec_str = Vars.XaCheck.comm_str
  2412.                 if not(Vars.XaCheck.no_audio_enc):
  2413.                         if Vars.XaCheck.value != None:
  2414.                                 input_par = self.spin_ac['adj'].get_value()
  2415.                                 audio_codec_str += str(int(input_par))
  2416.                         if Vars.XaCheck.kb:
  2417.                                 audio_codec_str += 'k '
  2418.                         else:
  2419.                                 audio_codec_str = audio_codec_str + ' '
  2420.                         audio_codec_str += sample_str + " " + channel_str
  2421.                         if Vars.XaCheck.afterbrn:
  2422.                                 audio_codec_str = on_afterburner(audio_codec_str)
  2423.                 return audio_codec_str
  2424.  
  2425.         def on_codec_video_changed(self, button):
  2426.                 self.on_codec_clicked(button)
  2427.  
  2428.         def on_preset_changed(self, button):
  2429.                 self.on_codec_clicked(button)
  2430.  
  2431.         def on_codec_clicked(self, button):
  2432.                 Vars.final_codec_str = ""
  2433.                 # video codec
  2434.                 selected_video_codec = self.box_vcodec.get_active_text()
  2435.                 for i in range(0,len(VideoEncoder.VEall)):
  2436.                         if VideoEncoder.VEall[i].label == selected_video_codec:
  2437.                                 Vars.XvCheck = VideoEncoder.VEall[i]
  2438.                                 #Vars.XvCheck now is the selected VEobject
  2439.                                 break
  2440.                 self.set_video_encoder()
  2441.                 Vars.video_codec_str_more = self.make_video_codec_str()
  2442.                 self.check_out_file()
  2443.                 self.on_codec_vrc_value_change(button)
  2444.  
  2445.         def on_codec_vrc_changed(self, button):
  2446.                 video_rc = self.box_vrc.get_active_text()
  2447.                 if not(Vars.XvCheck.no_video_enc):
  2448.                         if video_rc == VcodecOther.VRCcrf.label: # crf
  2449.                                 self.adj_change2(self.spin_vc['adj'], Vars.XvCheck.crf_val)
  2450.                                 self.spin_vc['adj'].set_value(Vars.XvCheck.crf_val[0])
  2451.                                 self.check_2pass.set_active(False)
  2452.                                 self.check_2pass.set_sensitive(False)
  2453.                         elif video_rc == VcodecOther.VRCbr.label: # bitrate
  2454.                                 self.adj_change2(self.spin_vc['adj'], Vars.XvCheck.br_val)
  2455.                                 self.spin_vc['adj'].set_value(Vars.XvCheck.br_val[0])
  2456.                                 if Vars.XvCheck.br2pass:
  2457.                                         self.check_2pass.set_sensitive(True)
  2458.                                 else:
  2459.                                         self.check_2pass.set_sensitive(False)
  2460.                         elif video_rc == VcodecOther.VRCq.label: # q-scale
  2461.                                 self.adj_change2(self.spin_vc['adj'], Vars.XvCheck.q_val)
  2462.                                 self.spin_vc['adj'].set_value(Vars.XvCheck.q_val[0])
  2463.                                 self.check_2pass.set_active(False)
  2464.                                 self.check_2pass.set_sensitive(False)
  2465.  
  2466.         def on_codec_vrc_value_change(self, button):
  2467.                 Vars.video_codec_str = ""
  2468.                 video_rc = self.box_vrc.get_active_text() #0 crf, 1 kb/s
  2469.                 if not(Vars.XvCheck.no_video_enc):
  2470.                         in_data = str(self.spin_vc['adj'].get_value())
  2471.                         if video_rc == VcodecOther.VRCcrf.label: #crf
  2472.                                 if Vars.XvCheck.crf_comm:
  2473.                                         crf_comm = Vars.XvCheck.crf_comm #-x265-params
  2474.                                 else:
  2475.                                         crf_comm = '-crf:v ' # default ffmpeg
  2476.                                 video_codec_str = Vars.XvCheck.comm_str + crf_comm + in_data
  2477.                                 if not(Vars.XvCheck.vrc_custom_comm): # x265 vrc in opts
  2478.                                         video_codec_str += ' '
  2479.                         elif video_rc == VcodecOther.VRCbr.label: #bitrate
  2480.                                 in_data = str(int(self.spin_vc['adj'].get_value()))
  2481.                                 if Vars.XvCheck.br_comm:
  2482.                                         br_comm = Vars.XvCheck.br_comm #-x265-params
  2483.                                 else:
  2484.                                         br_comm = '-b:v ' # default ffmpeg
  2485.                                 video_codec_str = Vars.XvCheck.comm_str + br_comm + in_data
  2486.                                 if Vars.XvCheck.kb:
  2487.                                         video_codec_str += 'k '
  2488.                         elif video_rc == VcodecOther.VRCq.label: #q scale
  2489.                                 q_comm = '-q:v '
  2490.                                 video_codec_str = Vars.XvCheck.comm_str + q_comm + in_data
  2491.                         video_codec_str += Vars.video_codec_str_more
  2492.                 else:
  2493.                         video_codec_str = Vars.video_codec_str_more
  2494.  
  2495.                 Vars.video_codec_str = video_codec_str
  2496.                 self.make_p3_out_command()
  2497.  
  2498.         def set_video_encoder(self):
  2499.                 if Vars.vcodec_is != Vars.XvCheck.codec:
  2500.                         Vars.vcodec_is = Vars.XvCheck.codec
  2501.                         # no video encoding
  2502.                         if Vars.XvCheck.no_video_enc:
  2503.                                 self.video_ui_widg_false_all()
  2504.                                 return
  2505.                         # set ui widgets
  2506.                         if Vars.XvCheck.is10bit:
  2507.                                 self.check_3v_10bit.set_sensitive(True)
  2508.                         else:
  2509.                                 self.check_3v_10bit.set_sensitive(False)
  2510.                         if Vars.XvCheck.pool or Vars.XvCheck.threads:
  2511.                                 self.check_3v_pool.set_sensitive(True)
  2512.                         else:
  2513.                                 self.check_3v_pool.set_active(False)
  2514.                                 self.check_3v_pool.set_sensitive(False)
  2515.                         if Vars.XvCheck.opencl:
  2516.                                 self.check_3v_opencl.set_sensitive(True)
  2517.                         else:
  2518.                                 self.check_3v_opencl.set_active(False)
  2519.                                 self.check_3v_opencl.set_sensitive(False)
  2520.                         # vrc
  2521.                         if Vars.XvCheck.vrc:
  2522.                                 self.box_vrc.set_sensitive(True)
  2523.                                 self.spin_vc['spinner'].set_sensitive(True)
  2524.                                 self.cboxtxt_change2(
  2525.                                         self.box_vrc,
  2526.                                         self.on_codec_vrc_changed,
  2527.                                         eval('VcodecOther.VRC' + Vars.XvCheck.codec),
  2528.                                         0,
  2529.                                         'Vars.vrc_list',
  2530.                                         Vars.XvCheck.codec)
  2531.                         else:
  2532.                                 self.spin_vc['spinner'].set_sensitive(False)
  2533.                                 self.box_vrc.set_sensitive(False)
  2534.                         # preset
  2535.                         if Vars.XvCheck.preset:
  2536.                                 self.box_3v_preset.set_sensitive(True)
  2537.                                 self.cboxtxt_change(
  2538.                                         self.box_3v_preset,
  2539.                                         self.on_preset_changed,
  2540.                                         eval('VcodecOther.' + Vars.XvCheck.codec + '_preset'),
  2541.                                         eval('VcodecOther.' + Vars.XvCheck.codec + '_preset_default'),
  2542.                                         'Vars.preset_list',
  2543.                                         Vars.XvCheck.codec)
  2544.                         else:
  2545.                                 self.box_3v_preset.set_sensitive(False)
  2546.                         # tune
  2547.                         if Vars.XvCheck.tune:
  2548.                                 self.box_3v_tune.set_sensitive(True)
  2549.                                 self.cboxtxt_change(
  2550.                                         self.box_3v_tune,
  2551.                                         self.on_preset_changed,
  2552.                                         eval('VcodecOther.' + Vars.XvCheck.codec + '_tune'),
  2553.                                         eval('VcodecOther.' + Vars.XvCheck.codec + '_tune_default'),
  2554.                                         'Vars.tune_list',
  2555.                                         Vars.XvCheck.codec)
  2556.                         else:
  2557.                                 self.box_3v_tune.set_sensitive(False)
  2558.                         # opts
  2559.                         if Vars.XvCheck.opts:
  2560.                                 self.box_3v_x264opts.set_sensitive(True)
  2561.                                 self.cboxtxt_change2(
  2562.                                         self.box_3v_x264opts,
  2563.                                         self.on_codec_clicked,
  2564.                                         eval('VcodecOptions.OPT' + Vars.XvCheck.codec),
  2565.                                         eval('VcodecOptions.OPT' + Vars.XvCheck.codec + '_default'),
  2566.                                         'Vars.opt_list',
  2567.                                         Vars.XvCheck.codec)
  2568.                         else:
  2569.                                 self.box_3v_x264opts.set_sensitive(False)
  2570.                                
  2571.         def make_video_codec_str(self):
  2572.                 video_codec_str = ""
  2573.                 ## no video encoding
  2574.                 if Vars.XvCheck.no_video_enc:
  2575.                                 video_codec_str = Vars.XvCheck.comm_str
  2576.                                 return video_codec_str
  2577.                 # opts
  2578.                 if Vars.XvCheck.opts:
  2579.                         selected_opt = self.box_3v_x264opts.get_active_text()
  2580.                         options_obj = eval('VcodecOptions.OPT' + Vars.XvCheck.codec)
  2581.                         for i in range(0,len(options_obj)):
  2582.                                 if options_obj[i].label == selected_opt:
  2583.                                         XoptCheck = options_obj[i]
  2584.                                         break
  2585.                                 else:
  2586.                                         XoptCheck = options_obj[0]
  2587.                                         # protection on OPT change
  2588.                                         # next ui main loop will find selected_opt label
  2589.                         if Vars.XvCheck.vrc_custom_comm: # x265 vrc commands and pool in -params
  2590.                                 if XoptCheck.text_entry:
  2591.                                         self.entry_optscustom.set_sensitive(True)
  2592.                                         video_codec_str += ":" + self.entry_optscustom.get_chars(0, -1)
  2593.                                 else:
  2594.                                         self.entry_optscustom.set_sensitive(False)
  2595.                                         video_codec_str += XoptCheck.comm_str
  2596.                                 # pools 3
  2597.                                 if Vars.XvCheck.pool:
  2598.                                         if self.check_3v_pool.get_active():
  2599.                                                 video_codec_str += ":pools=3"
  2600.                         else: # standard ffmpeg vrc commands
  2601.                                 video_codec_str += XoptCheck.comm_str
  2602.                                 # opencl
  2603.                                 if Vars.XvCheck.opencl:
  2604.                                         if self.check_3v_opencl.get_active():
  2605.                                                 video_codec_str += ":opencl"
  2606.                 # preset
  2607.                 if Vars.XvCheck.preset:
  2608.                         preset = self.box_3v_preset.get_active_text()
  2609.                         video_codec_str += " -preset " + preset + " "
  2610.                 # tune
  2611.                 if Vars.XvCheck.tune:
  2612.                         tune = self.box_3v_tune.get_active_text()
  2613.                         if tune != "none":
  2614.                                 video_codec_str += "-tune " + tune
  2615.                 # threads
  2616.                 if Vars.XvCheck.threads:
  2617.                         if self.check_3v_pool.get_active():
  2618.                                 video_codec_str += " -threads 3"
  2619.                 # 10bit -pix_fmt yuv420p10le
  2620.                 if Vars.XvCheck.is10bit:
  2621.                         if self.check_3v_10bit.get_active():
  2622.                                 video_codec_str += " -pix_fmt yuv420p10le "
  2623.                 ##
  2624.                 return video_codec_str
  2625.  
  2626.         def video_ui_widg_false_all(self):
  2627.                 # deactivate widget
  2628.                 self.box_vrc.set_sensitive(False)
  2629.                 self.spin_vc['spinner'].set_sensitive(False)
  2630.                 self.box_3v_preset.set_sensitive(False)
  2631.                 self.box_3v_tune.set_sensitive(False)
  2632.                 self.box_3v_x264opts.set_sensitive(False)
  2633.                 self.entry_optscustom.set_sensitive(False)
  2634.                 self.check_3v_opencl.set_active(False)
  2635.                 self.check_3v_opencl.set_sensitive(False)
  2636.                 self.check_2pass.set_active(False)
  2637.                 self.check_2pass.set_sensitive(False)
  2638.                 self.check_3v_10bit.set_sensitive(False)
  2639.                 self.check_3v_pool.set_sensitive(False)
  2640.  
  2641.         def on_f3_other_clicked(self, button):
  2642.                 Vars.final_other_str = ""
  2643.                 Vars.debug = 0
  2644.                 Vars.first_pass = 0
  2645.                 Vars.n_pass = 1
  2646.                 if self.check_nometa.get_active():
  2647.                         Vars.final_other_str = "-map_metadata -1"
  2648.                 if self.check_2pass.get_active():
  2649.                                 Vars.first_pass = 1
  2650.                                 Vars.n_pass = 2
  2651.                 if self.check_scopy.get_active():
  2652.                         if (Vars.final_other_str == ""):
  2653.                                 Vars.final_other_str = "-c:s copy"
  2654.                         else:
  2655.                                 Vars.final_other_str += " " + "-c:s copy"      
  2656.                 if self.check_debug.get_active():
  2657.                                 Vars.debug = 1
  2658.                 self.make_p3_out_command()
  2659.                
  2660.         def on_container_changed(self,button):
  2661.                
  2662.                 selected_container = self.box_oth_container.get_active_text()
  2663.                 for i in range(0,len(VcodecOther.OutContainers)):
  2664.                         if VcodecOther.OutContainers[i].label == selected_container:
  2665.                                 XocCheck = VcodecOther.OutContainers[i]
  2666.                                 #XocCheck now is the selected container obj
  2667.                                 break
  2668.                 #set generals
  2669.                 Vars.container_str = XocCheck.comm_str
  2670.                 Vars.ext = XocCheck.ext
  2671.                 if XocCheck.sub_stream and Vars.have_subs:
  2672.                         self.check_scopy.set_sensitive(True)
  2673.                         self.check_scopy.set_active(True)
  2674.                 else:  
  2675.                         self.check_scopy.set_active(False)
  2676.                         self.check_scopy.set_sensitive(False)
  2677.                 #set audio choises
  2678.                 if Vars.acodec_list != XocCheck.alist: # alist is changed
  2679.                         self.cboxtxt_change2(
  2680.                                 self.box_ac,
  2681.                                 self.on_codec_audio_changed,
  2682.                                 eval('AudioEncoder.AE' + XocCheck.alist),
  2683.                                 eval('AudioEncoder.AE' + XocCheck.alist + '_default'),
  2684.                                 'Vars.acodec_list',
  2685.                                 XocCheck.alist
  2686.                                 )
  2687.                         ########### OLD WAY ####################
  2688.                         #self.cboxtxt_change2(
  2689.                                 #self.box_ac,
  2690.                                 #self.on_codec_audio_changed,
  2691.                                 #AudioEncoder.AEmp4,
  2692.                                 #AudioEncoder.AEmp4_default,
  2693.                                 #'Vars.acodec_list',
  2694.                                 #"mp4")
  2695.                         ########################################
  2696.                 #set video choises
  2697.                 if Vars.vcodec_list != XocCheck.vlist: # vlist is changed
  2698.                         self.cboxtxt_change2(
  2699.                                 self.box_vcodec,
  2700.                                 self.on_codec_video_changed,
  2701.                                 eval('VideoEncoder.VE' + XocCheck.vlist),
  2702.                                 eval('VideoEncoder.VE' + XocCheck.vlist + '_default'),
  2703.                                 'Vars.vcodec_list',
  2704.                                 XocCheck.vlist
  2705.                                 )
  2706.                         if XocCheck.audio_only:
  2707.                                 self.box_vcodec.set_sensitive(False)
  2708.                         else:
  2709.                                 self.box_vcodec.set_sensitive(True)
  2710.                 self.check_out_file()
  2711.                 self.make_p3_out_command()
  2712.                
  2713.         def on_but_f3_run_clicked(self, button):
  2714.                                
  2715.                 def clear_ff_file():
  2716.                         if os.path.exists(Vars.outdir + '/' + 'ffmpeg2pass-0.log'):
  2717.                                 os.remove(Vars.outdir + '/' + 'ffmpeg2pass-0.log')
  2718.                         if os.path.exists(Vars.outdir + '/' + 'ffmpeg2pass-0.log.mbtree'):
  2719.                                 os.remove(Vars.outdir + '/' + 'ffmpeg2pass-0.log.mbtree')
  2720.                         if os.path.exists(Vars.outdir + '/' + 'x264_lookahead.clbin'):
  2721.                                 os.remove(Vars.outdir + '/' + 'x264_lookahead.clbin')
  2722.                         if os.path.exists(Vars.outdir + '/' + 'x265_2pass.log'):
  2723.                                 os.remove(Vars.outdir + '/' + 'x265_2pass.log')
  2724.                
  2725.                 def end_run():
  2726.                         if Vars.eff_pass == 0 and Vars.final_command1 == "":
  2727.                                 Vars.out_file_size = self.humansize(Vars.newname)
  2728.                                 stri = " Done in: " + self.sec2hms(Vars.time_done) + " " + "\n"\
  2729.                                         + " in:  " + Vars.in_file_size + "\n"\
  2730.                                         + " out: " + Vars.out_file_size
  2731.                                 self.but_f3_run.set_tooltip_text(stri)
  2732.                                 stri2 = " Done in: " + self.sec2hms(Vars.time_done) + " "\
  2733.                                         + " input size:  " + Vars.in_file_size + " "\
  2734.                                         + " output size: " + Vars.out_file_size
  2735.                                 self.reportdata.set_text(stri2)
  2736.                                 self.but_f3_run.set_label('RUN')
  2737.                                 self.window.set_deletable(True)
  2738.                                 clear_ff_file()
  2739.                                 Vars.ENCODING = False
  2740.                         elif Vars.eff_pass == 0 and Vars.final_command1 != "":
  2741.                                 Vars.eff_pass = 1
  2742.                                 Vars.ENCODING = False
  2743.                                 self.on_but_f3_run_clicked(1)
  2744.                         elif Vars.eff_pass == 1:
  2745.                                 Vars.out_file_size = self.humansize(Vars.newname)
  2746.                                 stri = " Done in: " + self.sec2hms(Vars.time_done + Vars.time_done_1) + " " + "\n"\
  2747.                                         + " pass 1: " + self.sec2hms(Vars.time_done) + " " + "\n"\
  2748.                                         + " pass 2: " + self.sec2hms(Vars.time_done_1) + " " + "\n"\
  2749.                                         + " in:  " + Vars.in_file_size + "\n"\
  2750.                                         + " out: " + Vars.out_file_size
  2751.                                 self.but_f3_run.set_tooltip_text(stri)
  2752.                                 stri2 = " Done in: " + self.sec2hms(Vars.time_done + Vars.time_done_1) + " "\
  2753.                                         + " pass 1: " + self.sec2hms(Vars.time_done) + " "\
  2754.                                         + " pass 2: " + self.sec2hms(Vars.time_done_1) + " "\
  2755.                                         + " input size:  " + Vars.in_file_size + " "\
  2756.                                         + " output size: " + Vars.out_file_size
  2757.                                 self.reportdata.set_text(stri2)
  2758.                                 Vars.eff_pass = 0
  2759.                                 self.but_f3_run.set_label('RUN')
  2760.                                 self.window.set_deletable(True)
  2761.                                 clear_ff_file()
  2762.                                 Vars.ENCODING = False
  2763.                
  2764.                 def check_run(name):
  2765.                        
  2766.                         def win_controls(label, boolean):
  2767.                                 self.but_f3_run.set_label(label)
  2768.                                 self.window.set_deletable(boolean)
  2769.                                 self.but_f3_run.set_tooltip_text('  Abort current encoding  ')
  2770.  
  2771.                         def encod_time(startime):
  2772.                                 if Vars.time_done == 0:
  2773.                                         et = self.sec2hms(time.time() - startime)
  2774.                                 else:
  2775.                                         et = self.sec2hms((time.time() - startime) + Vars.time_done)
  2776.                                 self.but_f3_run.set_label(et + ' - STOP' )
  2777.  
  2778.                         GLib.idle_add(win_controls, 'ENCODING ...' , False)
  2779.                         time.sleep(0.02)
  2780.                         t0 = time.time()
  2781.                         processname = name
  2782.                         for line in subprocess.Popen(["ps", "xa"], shell=False, stdout=subprocess.PIPE).stdout:
  2783.                                 line = line.decode()
  2784.                                 fields = line.split()
  2785.                                 pid = fields[0]
  2786.                                 process = fields[4]
  2787.                                 if process.find(processname) >= 0:              
  2788.                                         if line.find(Vars.filename) >= 0:
  2789.                                                 mypid = pid
  2790.                                                 break
  2791.                         finn = True
  2792.                         while finn == True:
  2793.                                 GLib.idle_add(encod_time, t0)
  2794.                                 time.sleep(1)
  2795.                                 try:
  2796.                                         finn = os.path.exists("/proc/" + mypid)
  2797.                                 except:
  2798.                                         Vars.eff_pass = 0
  2799.                                         GLib.idle_add(win_controls, 'RUN' , True)
  2800.                                         time.sleep(0.02)
  2801.                                         Vars.ENCODING = False
  2802.                                         return
  2803.                         if Vars.eff_pass == 0:  
  2804.                                 tfin = time.time() - t0
  2805.                                 Vars.time_done = int(tfin)
  2806.                         else:
  2807.                                 tfin = time.time() - t0
  2808.                                 Vars.time_done_1 = int(tfin)
  2809.                         GLib.idle_add(end_run)
  2810.                         time.sleep(0.5)
  2811.                        
  2812.                 if Vars.ENCODING: # STOP pressed
  2813.                         Vars.final_command1 = "" # prevent 2 pass start
  2814.                         command = "q"+ "\n"
  2815.                         length = len(command)
  2816.                         self.terminal.feed_child(command, length)
  2817.                         return
  2818.                
  2819.                 if Vars.eff_pass == 0:
  2820.                         self.check_out_file()
  2821.                         Vars.time_done = 0
  2822.                         Vars.time_done_1 = 0
  2823.                         if Vars.n_pass == 1:
  2824.                                 Vars.final_command1 = ""
  2825.                                 Vars.final_command2 = Vars.ffmpeg_ex + " -hide_banner"
  2826.                                 if Vars.ac3_drc != "":
  2827.                                         Vars.final_command2 += " " + Vars.ac3_drc
  2828.                                 Vars.final_command2 += " -i \"" \
  2829.                                         + Vars.filename + "\" " \
  2830.                                         + Vars.p3_command \
  2831.                                         +  " \"" + Vars.newname + "\"" \
  2832.                                         + "\n"
  2833.                                 command = Vars.final_command2
  2834.                        
  2835.                         if Vars.n_pass == 2:
  2836.                                 Vars.final_command1 = Vars.ffmpeg_ex + " -hide_banner" + " -i \"" \
  2837.                                         + Vars.filename + "\" " \
  2838.                                         + Vars.p3_comm_first_p \
  2839.                                         + "\n"
  2840.                                 Vars.final_command2 = Vars.ffmpeg_ex + " -hide_banner"
  2841.                                 if Vars.ac3_drc != "":
  2842.                                         Vars.final_command2 += " " + Vars.ac3_drc
  2843.                                 Vars.final_command2 += " -i \"" \
  2844.                                         + Vars.filename + "\" " \
  2845.                                         + Vars.p3_command \
  2846.                                         +  " \"" + Vars.newname + "\"" \
  2847.                                         + "\n"
  2848.                                 command = Vars.final_command1
  2849.                 else:
  2850.                         command = Vars.final_command2
  2851.                        
  2852.                 if Vars.debug == 1:
  2853.                         if Vars.n_pass == 1:
  2854.                                 command = "echo $\'\n\n\n" + Vars.final_command2  + "\' \n"
  2855.                         if Vars.n_pass == 2:
  2856.                                 command = "echo $\'\n\n\n" + Vars.final_command1 + "\n" + Vars.final_command2 + "\' \n"
  2857.                 length = len(command)
  2858.  
  2859.                 #
  2860.                 if Vars.debug == 0:
  2861.                         if Vars.eff_pass != 1:
  2862.                                 self.but_f3_run.set_tooltip_text('')
  2863.                                 self.reportdata.set_text('')
  2864.                         Vars.ENCODING = True
  2865.                
  2866.                 self.terminal.feed_child(command, length)
  2867.                
  2868.                 if Vars.debug == 0:
  2869.                         t = threading.Thread(name='child procs', target=check_run, args=(Vars.ffmpeg_ex,))
  2870.                         t.daemon = True
  2871.                         t.start()
  2872.                        
  2873.                
  2874.         def on_folder_clicked(self, button):
  2875.                 if Vars.ENCODING:
  2876.                         return
  2877.                 dialog = Gtk.FileChooserDialog("Please choose a folder", self.window,
  2878.                 Gtk.FileChooserAction.SELECT_FOLDER,
  2879.                 ("_Cancel", Gtk.ResponseType.CANCEL,
  2880.                 "_Select", Gtk.ResponseType.OK))
  2881.                 dialog.set_default_size(800, 400)
  2882.                 dialog.set_current_folder(Vars.outdir)
  2883.  
  2884.                 response = dialog.run()
  2885.                 if response == Gtk.ResponseType.OK:
  2886.                         Vars.outdir = dialog.get_filename()
  2887.                         command = "cd " + "\"" + Vars.outdir + "\"" + "\n"
  2888.                         length = len(command)
  2889.                         self.terminal.feed_child(command, length)
  2890.                         self.f3_run_outdir_label.set_markup("<b>out dir:  </b>" + Vars.outdir)
  2891.                         self.check_out_file()
  2892.                        
  2893.                 dialog.destroy()
  2894.                                
  2895.         def on_but_black_det_clicked(self, button):
  2896.        
  2897.                 def update_progress(pprog):
  2898.                         self.progressbar_black_det.set_fraction(pprog)
  2899.                         return False
  2900.                
  2901.                 def update_textv(stri):
  2902.                         self.textbuffer.insert_at_cursor(stri, -1)
  2903.                         i = self.textbuffer.get_end_iter()
  2904.                         self.textview.scroll_to_iter(i, 0.0, True, 0.0, 1.0)
  2905.                         return False
  2906.  
  2907.                 def stopped():
  2908.                         stri = "Stopped by user.\n"
  2909.                         self.textbuffer.insert_at_cursor(stri, -1)
  2910.                         i = self.textbuffer.get_end_iter()
  2911.                         self.textview.scroll_to_iter(i, 0.0, True, 0.0, 1.0)
  2912.                         self.but_black_det.set_label("Black detect")
  2913.                         self.blackdet_spin.stop()
  2914.                         self.blackdet_spin.set_sensitive(False)
  2915.                         self.progressbar_black_det.set_fraction(0.0)
  2916.                         Vars.blackdet_is_run = False
  2917.                         set_other_butt(True)
  2918.                        
  2919.                 def bd_finish(detected):
  2920.                         if detected == 0:
  2921.                                 stri = "none black gap found"
  2922.                                 self.textbuffer.insert_at_cursor(stri, -1)
  2923.                         self.blackdet_spin.stop()
  2924.                         self.blackdet_spin.set_sensitive(False)
  2925.                         self.but_black_det.set_label("black detectet")
  2926.                         self.progressbar_black_det.set_fraction(1.0)
  2927.                         Vars.blackdet_is_run = False
  2928.                         Vars.BLACKDT_DONE = True
  2929.                         set_other_butt(True)
  2930.  
  2931.                 def set_other_butt(boolean):
  2932.                         if Vars.VOLDT_DONE != True:
  2933.                                 self.but_volume_det.set_sensitive(boolean)
  2934.                         if Vars.FRAMDT_DONE != True:
  2935.                                 self.but_frames_det.set_sensitive(boolean)
  2936.                
  2937.                 def my_thread_blackdet():
  2938.                         Vars.blackdet_is_run = True
  2939.                         command = [Vars.ffmpeg_ex, '-i', Vars.filename, '-y', '-an', '-vf', 'blackdetect=d=.5', '-f', 'null', '/dev/null']
  2940.                         p = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, universal_newlines=True)
  2941.                         self.bd_th = False
  2942.                         detected = 0
  2943.                         time_step = 0
  2944.                         pprog = 0.0
  2945.                         stri = ""
  2946.                         GLib.idle_add(set_other_butt, False)
  2947.                         time.sleep(0.01)
  2948.                        
  2949.                         while True:
  2950.                                 line = p.stderr.readline()
  2951.                                
  2952.                                 if 'time=' in line:
  2953.                                         if time_step == 12:
  2954.                                                 tml = line.split('time=')[1]
  2955.                                                 tml2 = tml.split(' ')[0]
  2956.                                                 time_n = tml2.split('.')[0]
  2957.                                                 time_n = self.hms2sec(time_n)
  2958.                                                 time_step = 0
  2959.                                                 pprog = float(time_n)/Vars.duration_in_sec
  2960.                                                 GLib.idle_add(update_progress, pprog)
  2961.                                                 time.sleep(0.002)
  2962.                                         else:
  2963.                                                 time_step += 1
  2964.                                                
  2965.                                 if 'blackdetect ' in line:
  2966.                                                 a = line
  2967.                                                 b = a.split('black_start:')[1]
  2968.                                                 start = b.split(' ')[0]
  2969.                                                 st_in_s = float(start)
  2970.                                                 st_in_s = int(st_in_s)
  2971.                                                 start_in_s = ("%4.1i"% (st_in_s))  
  2972.                                                 start = self.sec2hms(start)
  2973.                                                 stri = "black start at: " + start_in_s + " s, " + start + " "
  2974.                                                 c = b.split('black_duration:')[1]
  2975.                                                 durat = c.split(' ')[0]
  2976.                                                 dur_s = float(durat)
  2977.                                                 dur_s = "{0:0=3.1f}".format(dur_s)
  2978.                                                 stri += "duration: " + dur_s + "s\n"
  2979.                                                 detected = 1
  2980.                                                 GLib.idle_add(update_textv, stri)
  2981.                                                 time.sleep(0.002)
  2982.                                 if line == '' and p.poll() != None:
  2983.                                         break
  2984.                                 if self.bd_th:
  2985.                                         p.communicate("q")
  2986.                                         break
  2987.                         try:
  2988.                                 p.communicate()
  2989.                         except:
  2990.                                 GLib.idle_add(stopped)
  2991.                                 time.sleep(0.1)
  2992.                                 return
  2993.                         GLib.idle_add(bd_finish, detected)
  2994.                         time.sleep(0.1)
  2995.                        
  2996.                 if Vars.BLACKDT_DONE:
  2997.                         return          
  2998.                        
  2999.                 if Vars.blackdet_is_run == False:
  3000.                         self.but_black_det.set_label("Stop")
  3001.                         self.textbuffer.set_text('') # clear for insert from start
  3002.                         stri = "Detected:\n\n"
  3003.                         start = self.textbuffer.get_start_iter()
  3004.                         self.textbuffer.insert(start, stri, -1)
  3005.                         self.blackdet_spin.set_sensitive(True)
  3006.                         self.blackdet_spin.start()                              
  3007.                         thread = threading.Thread(target=my_thread_blackdet)
  3008.                         thread.daemon = True
  3009.                         thread.start()
  3010.                        
  3011.                 elif Vars.blackdet_is_run == True:
  3012.                         self.bd_th = True
  3013.        
  3014.                
  3015.         # -------------------------------------  
  3016.        
  3017.         def preview_logic(self):
  3018.                 if not('-map ' in Vars.p3_command or '-vf ' in Vars.p3_command):
  3019.                         self.buttest.set_sensitive(False)
  3020.                         self.buttestspl.set_sensitive(False)
  3021.                 elif '-map ' in Vars.p3_command and '-vf ' in Vars.p3_command:
  3022.                         self.buttest.set_sensitive(False)
  3023.                         self.buttestspl.set_sensitive(False)
  3024.                 elif '-map ' in Vars.p3_command:
  3025.                         self.buttest.set_sensitive(True)
  3026.                         self.buttestspl.set_sensitive(False)
  3027.                 elif '-vf ' in Vars.p3_command:
  3028.                         self.buttest.set_sensitive(True)
  3029.                         self.buttestspl.set_sensitive(True)
  3030.                
  3031.         def scale_calc(self):
  3032.                 dim_round = 2
  3033.                 if self.check_round.get_active():
  3034.                         dim_round = 8
  3035.                 Vars.scalestr = ""
  3036.                 # dar
  3037.                 dar = self.box_scale_ar['cbox'].get_active()
  3038.                 if dar == 0: # 16/9
  3039.                         scale_factor = 1.777777778
  3040.                         setdar = ",setdar=16/9,setsar=1/1"
  3041.                 elif dar == 1: # 4/3
  3042.                         scale_factor = 1.333333333
  3043.                         setdar = ",setdar=4/3,setsar=1/1"
  3044.                 elif dar == 2: # 235/100
  3045.                         scale_factor = 2.35
  3046.                         setdar = ",setdar=235/100,setsar=1/1"
  3047.                 elif dar == 3: #1/1 same as input  
  3048.                         w = int(Vars.video_width)
  3049.                         h = int(Vars.video_height)
  3050.                         # cropped?
  3051.                         if self.checkcr.get_active():
  3052.                                 crT = int(self.spinct['adj'].get_value())
  3053.                                 crB = int(self.spincb['adj'].get_value())
  3054.                                 crL = int(self.spincl['adj'].get_value())
  3055.                                 crR = int(self.spincr['adj'].get_value())
  3056.                                 h = h - crT - crB
  3057.                                 w = w - crL - crR
  3058.                         scale_factor = (float(w) / h)
  3059.                         setdar = ""
  3060.                 #input number
  3061.                 num_in = self.size_spinner['adj'].get_value()
  3062.                 #side in
  3063.                 side = self.box_scale_side['cbox'].get_active() # 0 none, 1 W, 2 H
  3064.                 if side == 1:
  3065.                         wout = num_in
  3066.                         hout = wout / float(scale_factor)
  3067.                 elif side == 2:
  3068.                         hout = num_in
  3069.                         wout = hout * float(scale_factor)
  3070.                 wout = int(round(float(wout)/dim_round)*dim_round)
  3071.                 hout = int(round(float(hout)/dim_round)*dim_round)
  3072.                 # scale string
  3073.                 scalestr = str(wout) + ":" + str(hout)
  3074.                 #                    
  3075.                 zscale = self.check.get_active()  
  3076.                 if zscale:
  3077.                         Vars.scalestr = "zscale=" + scalestr + ":f=lanczos"  + setdar  
  3078.                 else:
  3079.                         Vars.scalestr = "scale=" + scalestr + ":flags=lanczos" + setdar  
  3080.                 self.outfilter()
  3081.                
  3082.                      
  3083.         def outfilter(self):
  3084.                 final_str = ""
  3085.                 if Vars.deint_str != "":
  3086.                         final_str += Vars.deint_str
  3087.                 if Vars.crop_str != "":
  3088.                         if final_str == "":
  3089.                                 final_str += Vars.crop_str
  3090.                         else:
  3091.                                         final_str +=  "," + Vars.crop_str
  3092.                 if Vars.scalestr != "":
  3093.                         if final_str == "":
  3094.                                 final_str += Vars.scalestr
  3095.                         else:
  3096.                                 final_str += "," + Vars.scalestr
  3097.                 if Vars.dn_str != "":
  3098.                         if final_str == "":
  3099.                                 final_str += Vars.dn_str
  3100.                         else:
  3101.                                 final_str += "," + Vars.dn_str
  3102.                 if Vars.uns_str != "":
  3103.                         if final_str == "":
  3104.                                 final_str += Vars.uns_str
  3105.                         else:
  3106.                                 final_str += "," + Vars.uns_str
  3107.                 Vars.filter_test_str = final_str
  3108.                
  3109.                 if final_str != "":
  3110.                         Vars.final_vf_str = "-vf " + final_str
  3111.                 else:
  3112.                         Vars.final_vf_str = ""
  3113.                
  3114.                 label_str = ""          
  3115.                 if Vars.maps_str != "":
  3116.                         label_str += Vars.maps_str + " "  
  3117.                 if Vars.time_final_str != "":
  3118.                         label_str += Vars.time_final_str + " "
  3119.                 if Vars.fr_str != "":
  3120.                         label_str += Vars.fr_str + " "
  3121.                 if Vars.final_vf_str != "":
  3122.                         label_str += Vars.final_vf_str
  3123.                        
  3124.                 self.labelout.set_text(label_str)      
  3125.                 self.make_p3_out_command()
  3126.                 if Vars.info_str != "":
  3127.                         self.preview_logic()
  3128.        
  3129.         def make_p3_out_command(self):
  3130.                
  3131.                 def x265_pass_com(string_eval, npass): # string , int (1-2)
  3132.                         datainfo = string_eval.split(' ')
  3133.                         pointer = datainfo.index('-x265-params')
  3134.                         x265opts0 = datainfo[pointer+1]
  3135.                         x265opts1 = x265opts0 + ":pass=" + str(npass) + " "
  3136.                         string_eval = string_eval.replace(x265opts0, x265opts1)
  3137.                         return string_eval
  3138.                
  3139.                 def libsoxr_apply(string_eval):
  3140.                         if 'aresample=matrix_encoding=dplii' in string_eval:
  3141.                                 string_eval = string_eval.replace('aresample=matrix_encoding=dplii', 'aresample=matrix_encoding=dplii:resampler=soxr')
  3142.                         elif 'aformat=channel_layouts=stereo' in string_eval:
  3143.                                 string_eval = string_eval.replace('aformat=channel_layouts=stereo', 'aformat=channel_layouts=stereo,aresample=resampler=soxr')
  3144.                         else:
  3145.                                 string_eval = 'aresample=resampler=soxr,' + string_eval
  3146.                         return string_eval
  3147.                
  3148.                 # encoding video? audio?
  3149.                 v_encod = Vars.vcodec_is != "vcopy" and Vars.vcodec_is != "none"  # vcopy vn
  3150.                 a_encod = Vars.acodec_is != "acopy" and Vars.acodec_is != "anone" # acopy an
  3151.                        
  3152.                 Vars.p3_command = ""
  3153.                 Vars.p3_comm_first_p = ""
  3154.                 self.f3_out_label.set_label("")
  3155.                
  3156.                 if Vars.maps_str != "":
  3157.                         Vars.p3_command = Vars.maps_str + " "  
  3158.                 if Vars.time_final_str != "":
  3159.                         Vars.p3_command += Vars.time_final_str + " "
  3160.                 if Vars.fr_str != "" and v_encod:
  3161.                         Vars.p3_command += Vars.fr_str + " "            
  3162.                 if Vars.final_vf_str != "" and v_encod: # check -vcopy
  3163.                         Vars.p3_command += Vars.final_vf_str + " "
  3164.                        
  3165.                 # first pass    
  3166.                 if Vars.first_pass:
  3167.                         Vars.p3_comm_first_p = Vars.p3_command + Vars.video_codec_str + " "
  3168.                         if Vars.vcodec_is == "x265":
  3169.                                 Vars.p3_comm_first_p = x265_pass_com(Vars.p3_comm_first_p, 1)
  3170.                         else:
  3171.                                 Vars.p3_comm_first_p += "-pass 1 "
  3172.                                 if Vars.vcodec_is == "x264":
  3173.                                         Vars.p3_comm_first_p += "-fastfirstpass 1 "
  3174.                         Vars.p3_comm_first_p += "-an -f null /dev/null"
  3175.                 else:
  3176.                         Vars.p3_comm_first_p = ""
  3177.                 # -af
  3178.                 audiof = ""
  3179.                 if Vars.final_af_str != "" and a_encod:  # check -acopy -an
  3180.                         audiof_1 = Vars.final_af_str
  3181.                 else:
  3182.                         audiof_1 = ""
  3183.                 if (Vars.compand_data != "" or Vars.dynaudnorm_data != "") and a_encod:  # check -acopy -an
  3184.                         if Vars.compand_data != "":
  3185.                                 audiof_2 = Vars.compand_data
  3186.                         elif Vars.dynaudnorm_data != "":
  3187.                                 audiof_2 = Vars.dynaudnorm_data
  3188.                 else:
  3189.                         audiof_2 = ""
  3190.                
  3191.                 if a_encod:
  3192.                         if audiof_1 != "" and audiof_2 != "":
  3193.                                 audiof = audiof_1 + "," + audiof_2
  3194.                         elif audiof_1 != "" and audiof_2 == "":
  3195.                                 if Vars.audio_channels == 6 and self.box_audio_ch.get_active_text() == '2' and self.check_prologic.get_active():
  3196.                                         audiof = 'aformat=channel_layouts=stereo,aresample=matrix_encoding=dplii,' + audiof_1
  3197.                                 else:
  3198.                                         audiof = audiof_1
  3199.                         elif audiof_1 == "" and audiof_2 != "":
  3200.                                 audiof = audiof_2
  3201.                         elif audiof_1 == "" and audiof_2 == "":
  3202.                                 if Vars.audio_channels == 6 and self.box_audio_ch.get_active_text() == '2' and self.check_prologic.get_active():
  3203.                                         audiof = 'aformat=channel_layouts=stereo,aresample=matrix_encoding=dplii'
  3204.                         # libsoxr              
  3205.                         if self.check_soxr.get_sensitive() and self.check_soxr.get_active():
  3206.                                 if audiof == "":
  3207.                                         audiof = 'aresample=resampler=soxr'
  3208.                                 else:
  3209.                                         audiof = libsoxr_apply(audiof)
  3210.                         #
  3211.                         if audiof != "":        
  3212.                                 Vars.p3_command += "-af \'" + audiof + "\' "
  3213.                        
  3214.                 Vars.final_codec_str = Vars.audio_codec_str + " " + Vars.video_codec_str
  3215.                 if Vars.final_codec_str != "":
  3216.                         Vars.p3_command += Vars.final_codec_str + " "
  3217.                
  3218.                 #second pass
  3219.                 if Vars.n_pass == 2:
  3220.                         if Vars.vcodec_is != "x265":
  3221.                                 Vars.p3_command += "-pass 2" + " "
  3222.                         elif Vars.vcodec_is == "x265":
  3223.                                 Vars.p3_command = x265_pass_com(Vars.p3_command, 2)
  3224.                 if Vars.container_str != "":
  3225.                         Vars.p3_command += Vars.container_str + " "
  3226.                 if Vars.final_other_str != "":
  3227.                         Vars.p3_command += Vars.final_other_str + " "
  3228.                 self.f3_out_label.set_label(Vars.p3_command)
  3229.                
  3230.         def main(self):
  3231.                 Gtk.main()
  3232.  
  3233. if __name__ == "__main__":
  3234.         GObject.threads_init()
  3235.         ProgrammaGTK()
  3236.         Gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement