Advertisement
Guest User

4ffmpeg-8.180

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