Advertisement
Guest User

4ffmpeg-8.148

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