Advertisement
Guest User

4ffmpeg-8.158

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