Advertisement
Guest User

4ffmpeg-8.051

a guest
Dec 11th, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 126.36 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # work in python3.4 ---
  5. # from urllib.request import url2pathname
  6. #----------------------
  7.  
  8. from gi.repository import Gtk, GObject, Vte
  9. from gi.repository import GLib
  10. import os
  11. import sys, subprocess, shlex, re
  12. from subprocess import call
  13. from math import pow
  14. try:
  15.         from urllib import url2pathname
  16. except ImportError:
  17.         from urllib.request import url2pathname
  18. from gi.repository import Pango
  19. import threading
  20. import time
  21.                
  22. class reuse_init(object):
  23.  
  24.  
  25.         def make_label(self, text):
  26.                 label = Gtk.Label(text)
  27.                 label.set_use_underline(True)
  28.                 label.set_alignment(1.0, 0.5)
  29.                 label.show()
  30.                 return label
  31.  
  32.         def make_slider_and_spinner(self, init, min, max, step, page, digits):
  33.                 controls = {'adj':Gtk.Adjustment(init, min, max, step, page), 'slider':Gtk.HScale(), 'spinner':Gtk.SpinButton()}
  34.                 controls['slider'].set_adjustment(controls['adj'])
  35.                 controls['slider'].set_draw_value(False)
  36.                 controls['spinner'].set_adjustment(controls['adj'])
  37.                 controls['spinner'].set_digits(digits)
  38.                 controls['slider'].show()
  39.                 controls['spinner'].show()
  40.                 return controls
  41.        
  42.         def make_frame_ag(self, f_shadow_type, f_label, alig_pad, gri_row_sp, gri_colu_sp, gri_homog):
  43.                 controls =  {'frame':Gtk.Frame(), 'ali':Gtk.Alignment(), 'grid':Gtk.Grid()}
  44.                 controls['frame'].set_shadow_type(f_shadow_type) # 3 GTK_SHADOW_ETCHED_IN , 1 GTK_SHADOW_IN
  45.                 controls['frame'].set_label(f_label)
  46.                 controls['ali'].set_padding(alig_pad, alig_pad, alig_pad, alig_pad)
  47.                 controls['frame'].add(controls['ali'])
  48.                 controls['grid'].set_row_spacing(gri_row_sp)
  49.                 controls['grid'].set_column_spacing(gri_colu_sp)
  50.                 controls['grid'].set_column_homogeneous(gri_homog) # True
  51.                 controls['ali'].add(controls['grid'])
  52.                 controls['frame'].show()
  53.                 controls['ali'].show()
  54.                 controls['grid'].show()
  55.                 return controls
  56.        
  57.         def make_spinbut(self, init, min, max, step, page, digits, numeric):
  58.                 controls = {'adj':Gtk.Adjustment(init, min, max, step, page), 'spinner':Gtk.SpinButton()}
  59.                 controls['spinner'].set_adjustment(controls['adj'])
  60.                 controls['spinner'].set_digits(digits)
  61.                 controls['spinner'].set_numeric(numeric)
  62.                 controls['spinner'].show()
  63.                 return controls
  64.        
  65.         def make_combobox(self, *vals):
  66.                 controls = {'list':Gtk.ListStore(str), 'cbox':Gtk.ComboBox(), 'cellr':Gtk.CellRendererText()}
  67.                 for i, v in enumerate(vals):
  68.                         controls['list'].append([v])
  69.                 controls['cbox'].set_model(controls['list'])      
  70.                 controls['cbox'].pack_start(controls['cellr'], True)
  71.                 controls['cbox'].add_attribute(controls['cellr'], "text", 0)
  72.                 controls['cbox'].set_active(0)
  73.                 controls['cbox'].show()
  74.                 return controls
  75.        
  76.         def hms2sec(self, hms):
  77.                 result = 0
  78.                 listin = hms.split(':')
  79.                 listin.reverse()
  80.                 for i in range(len(listin)):
  81.                         if listin[i].isdigit():
  82.                                 if i == 0:
  83.                                         mult = 1
  84.                                 if i == 1:
  85.                                         mult = 60
  86.                                 if i == 2:
  87.                                         mult = 3600
  88.                                 result = result + (int(listin[i])*mult)            
  89.                 return result
  90.        
  91.         def sec2hms(self, seconds):
  92.                 seconds = float(seconds)
  93.                 h = int(seconds/3600)
  94.                 if (h > 0):
  95.                         seconds = seconds - (h * 3600)
  96.                 m = int(seconds / 60)
  97.                 s = int(seconds - (m * 60))
  98.                 hms = "{0:0=2d}:{1:0=2d}:{2:0=2d}".format(h,m,s)
  99.                 return hms
  100.        
  101.         def adj_change(self, adjustment, value, lower, upper , step_increment, page_increment):
  102.                 adjustment.set_value(value)
  103.                 adjustment.set_lower(lower)
  104.                 adjustment.set_upper(upper)
  105.                 adjustment.set_step_increment(step_increment)
  106.                 adjustment.set_page_increment(page_increment)
  107.                 #adjustment.set_page_size(page_size)
  108.                
  109.         def check_out_file(self):
  110.                 name = os.path.splitext(Vars.basename)[0]
  111.                 newname = Vars.outdir + '/' + name + Vars.ext
  112.                 if os.path.exists(newname):                    
  113.                         for i in range(2,20):
  114.                                 newname = Vars.outdir + '/' + name + '_' + str(i) + '_' + Vars.ext
  115.                                 if (os.path.exists(newname) == False):
  116.                                                         newname = newname
  117.                                                         break
  118.                 else:
  119.                         newname = newname
  120.                        
  121.                 Vars.newname = newname
  122.                 self.f3_run_outdir_label.set_tooltip_text(Vars.newname)
  123.                
  124.         def humansize(self, namefile):
  125.                 try:
  126.                         nbytes = os.path.getsize(namefile)
  127.                 except:
  128.                         return '0'
  129.                 suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
  130.                 if nbytes == 0: return '0 B'
  131.                 i = 0
  132.                 while nbytes >= 1024 and i < len(suffixes)-1:
  133.                         nbytes /= 1024.
  134.                         i += 1
  135.                 f = "{0:0.1f}".format(nbytes)
  136.                 return "{0:>5s} {1:2s}".format(f, suffixes[i])
  137.        
  138.  
  139. # Abstract struct class      
  140. class Struct:
  141.        
  142.         def __init__ (self, *argv, **argd):
  143.                 if len(argd):
  144.                         # Update by dictionary
  145.                         self.__dict__.update (argd)
  146.                 else:
  147.                         # Update by position
  148.                         attrs = filter (lambda x: x[0:2] != "__", dir(self))
  149.                         for n in range(len(argv)):
  150.                                 setattr(self, attrs[n], argv[n])
  151.                
  152. class Tips(Struct):
  153.        
  154.         map_tooltip_str = ' use 0:0  or  0:0,0:1,0:2 '
  155.         time_tooltip_str = ' use: 90 or 00:01:30 '
  156.        
  157.         black_dt_init_str = 'Detect black frames can take some time,\ndepending on the length of the video.'
  158.         compad_str = ' attacks attacks:decays decays: points dbin/dbout dbin/dbout:soft-knee:gain:initial volume:delay  '
  159.         drc_str = '   -drc_scale percentage of dynamic range compression to apply (from 0 to 6) (default 1)   '
  160.        
  161.         faac_q_str = ' faac vbr: q 80 ~96k, 90 ~100k, 100 ~118k, 120 ~128k, 160 ~156k, def:100 '
  162.         lamecbr_str = " lame mp3: 32-320 Kb/s def:128 "
  163.         lamevbr_str = " lame mp3 vbr: q 0 ~245Kb/s, 5 ~130Kb/s, 6 ~115Kb/s, 9 ~65Kb/s, def:6 "
  164.         aac_cbr_str = " aac cbr: 32-320 Kb/s def:128 "
  165.         aak_cbr_str = " aac_fdk cbr: 64-320 Kb/s def:128 "
  166.         audio_samp_str = ' audio samplerate '
  167.         audio_channels_str = ' audio channels '
  168.         f3v_label_out_start = "-crf 21.3"
  169.         subcopy_tooltip_srt = ' false= srt->ass '
  170.         cpu_tooltip_srt = ' false= -thread 0 '
  171.         nometa_tooltip_srt = ' true= --map_metadata -1 '
  172.         debug_tooltip_srt = ' only print command in terminal '
  173.         preset_tooltip_str = ' x264 preset '
  174.         tune_tooltip_str = ' x264 tune '
  175.        
  176.  
  177.  
  178. class Vars(Struct):
  179.        
  180.         def version_from_filename():
  181.                 '''
  182.                filename must be:
  183.                4FFmpeg-n.nnn.py
  184.                '''
  185.                 try:
  186.                         version = str(sys.argv[0])
  187.                 except:
  188.                         version = 'N/A'
  189.                         return version
  190.                 try:
  191.                         version = version.split('-')[1]
  192.                 except:
  193.                         version = 'N/A'
  194.                         return version
  195.                 try:
  196.                         version = version[:-3]
  197.                 except:
  198.                         version = 'N/A'
  199.                         return version          
  200.                 return version
  201.        
  202.         ffmpeg_ex = 'ffmpeg'
  203.         ffplay_ex = 'ffplay'
  204.         ffprobe_ex = 'ffprobe'
  205.         final_vf_str = ""
  206.         final_af_str = ""
  207.         deint_str = ""
  208.         crop_str = ""
  209.         scalestr = ""
  210.         dn_str = ""
  211.         uns_str = ""
  212.         fr_str = ""
  213.         filter_test_str = ""
  214.         video_width = "0"
  215.         video_height = "0"
  216.         add_1_1_dar = True
  217.         maps_str = ""
  218.         time_final_str = ""
  219.         final_codec_str = "-c:a libfaac -q:a 100 -ar 48k -ac 2 -c:v libx264 -crf 21.3 -preset faster -tune film -x264opts ref=4:bframes=4:direct=auto:aq-strength=1.3:ssim"
  220.         final_other_str = ""
  221.         acodec_is = "faaq"
  222.         audio_channels = 0
  223.         audio_codec_str = "-c:a libfaac -q:a 100 -ar 48k -ac 2"
  224.         acodec_list = "full"
  225.         vcodec_is = "x264"
  226.         video_codec_str = ""
  227.         video_codec_str_more = "-preset faster -tune film -x264opts ref=4:bframes=4:direct=auto:aq-strength=1.3:ssim"
  228.         vcodec_list = "full"
  229.         container_str = "-f matroska"
  230.         info_str = ''
  231.         blackdet_is_run = False
  232.         compinit = '.3 .3:1 1:-90/-90 -60/-40 -40/-30 -20/-14 -9/-9 0/-3:6:-3:0:.5'
  233.         compand_data = ''
  234.         compand_time = 0
  235.         time_start = 0 # for cropdetect
  236.         first_run = 0
  237.         p3_command = ""
  238.         filename = ""
  239.         dirname = ""
  240.         basename = ""
  241.         in_file_size = ""
  242.         ext = ".mkv"
  243.         outdir = ""
  244.         newname = ""
  245.         duration = ""
  246.         duration_in_sec = 0
  247.         time_done = 0
  248.         time_done_1 = 0
  249.         out_file_size = ""
  250.         debug = 0
  251.         first_pass = 0
  252.         n_pass = 1
  253.         p3_comm_first_p = ""
  254.         final_command1 = ""
  255.         final_command2 = ""
  256.         eff_pass = 0
  257.         version = version_from_filename()
  258.         BLACKDT_DONE = False
  259.         VOLDT_DONE = False
  260.         ENCODING = False
  261.         ac3_drc = ""
  262.  
  263.        
  264. class ProgrammaGTK(reuse_init):
  265.        
  266.  
  267.         def __init__(self):
  268.                
  269.                
  270.                 # initialize variables
  271.                                
  272.                 self.make_ui()
  273.                
  274.                 self.make_p3_out_command()
  275.                 Vars.outdir = os.getcwd()
  276.                
  277.                 if (len(sys.argv) == 2):
  278.                         try:
  279.                                 self.filechooserbutton.set_filename(str(sys.argv[1]))
  280.                                 self.file_changed(0)
  281.                         except:
  282.                                 pass
  283.                
  284.                 # ----------------------------
  285.                
  286.                
  287.         def make_ui(self):
  288.  
  289.                 # ---------------------
  290.                 self.window =  Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
  291.                 self.window.connect("destroy", self.on_window_destroy)
  292.                 self.window.set_title("4FFmpeg")
  293.                 self.window.set_position(1) # 1 center, 0 none,
  294.                 self.window.set_border_width(3)
  295.                 self.window.set_default_size(500,-1)
  296.                 #----------------------------------
  297.                
  298.                 #page1 stuff VIDEO FILTERS------------------------------------------
  299.                                
  300.                 # page1 VBox -------------------------
  301.                 self.vbox1 = Gtk.VBox()
  302.                 self.vbox1.set_spacing(2)
  303.                
  304.                 # map --------------------------------------
  305.                 self.make_map()        
  306.                 # add map frame
  307.                 self.vbox1.pack_start(self.f_map['frame'], 1, 0, 0)
  308.                
  309.                 #time cut ------------------------------------
  310.                 self.make_time_cut()
  311.                 # add time frame
  312.                 self.vbox1.pack_start(self.f_time['frame'], 1, 0, 0)
  313.                
  314.                 # deinterlace -----------------------
  315.                 self.make_deinterlace()
  316.                 # add deinterlace frame
  317.                 self.vbox1.pack_start(self.f_deint['frame'], 1, 0, 0)
  318.                
  319.                 # crop ----------------------------------------
  320.                 self.make_crop()        
  321.                 # add crop frame -------------------
  322.                 self.vbox1.pack_start(self.frame_crop['frame'], 1, 0, 0)
  323.        
  324.                 # scale ------------------------------
  325.                 self.make_scale()
  326.                 # add scale frame------------------
  327.                 self.vbox1.pack_start(self.frame_scale['frame'], 1, 0, 0)
  328.  
  329.                 # denoise ----------------------------
  330.                 self.make_denoise()
  331.                 # add denoise frame------------------------
  332.                 self.vbox1.pack_start(self.frame_dn['frame'], 1, 0, 0)
  333.                
  334.                 #test-------------------
  335.                 #self.f_test = self.make_frame_ag(3, "TEST" , 6, 8, 8, True)
  336.                 #self.label_test = Gtk.Label("TEST")
  337.                 #self.f_test['grid'].attach(self.label_test, 0, 0, 1, 1)
  338.  
  339.                 #self.vbox1.pack_start(self.f_test['frame'], 1, 0, 0)
  340.                 #-------------------------------------
  341.                
  342.                 # page 1 output------------------------
  343.                 self.frame_out = self.make_frame_ag(3, '  FFmpeg video filter string:  ' , 12, 8, 8, True)
  344.                 self.labelout = Gtk.Label("")
  345.                 self.labelout.set_selectable(1)
  346.                 self.labelout.set_width_chars(90)
  347.                 self.labelout.set_max_width_chars(90)
  348.                 self.labelout.set_line_wrap(True)
  349.                 self.frame_out['grid'].attach(self.labelout, 0, 0, 1 ,1)
  350.                 # add output frame ---------------------
  351.                 self.vbox1.pack_start(self.frame_out['frame'], 1, 0, 0)
  352.                
  353.                 # end page1 stuff
  354.                
  355.                
  356.                 # page2 stuff  UTILITY ------------------------------------------
  357.                
  358.                 # page2 VBox -------------------------
  359.                 self.vbox_pg2 = Gtk.VBox()
  360.                 self.vbox_pg2.set_spacing(2)
  361.                
  362.                 #volumedetect ------------------------------------
  363.                 self.make_volume_det()
  364.                 # add volumedetect frame        
  365.                 self.vbox_pg2.pack_start(self.f_volume_det['frame'], 1, 0, 0)
  366.                
  367.                 #drc ------------------------------------
  368.                 self.make_volume_drc()
  369.                 # add volumedetect frame        
  370.                 self.vbox_pg2.pack_start(self.f_volume_drc['frame'], 1, 0, 0)
  371.                
  372.                 #compand ---------------------------------------
  373.                 self.make_compand()
  374.                 # add frame
  375.                 self.vbox_pg2.pack_start(self.f_compand['frame'], 1, 0, 0)
  376.                
  377.                 # black detect ----------------------------------
  378.                 self.make_black_detect()
  379.                 # add black_detect frame
  380.                 self.vbox_pg2.pack_start(self.f_blackd['frame'], 1, 0, 0)
  381.                
  382.                 # info frame----------------------
  383.                 self.make_info_frame()
  384.                 # add info frame
  385.                 self.vbox_pg2.pack_start(self.f_info['frame'], 1, 0, 0)
  386.                
  387.                 # end page2 stuff
  388.                
  389.                 # page 3 stuff  ffmpeg commands -----------------------------------------
  390.                
  391.                 # page3 VBox -------------------------
  392.                 self.vbox_pg3 = Gtk.VBox()
  393.                 self.vbox_pg3.set_spacing(2)
  394.                
  395.                 # audio codec -------------------
  396.                 self.make_audio_codec()
  397.                 #add frame audio codec
  398.                 self.vbox_pg3.pack_start(self.f_3acodec['frame'], 1, 0, 0)
  399.                
  400.                 # video codec -------------------
  401.                 self.make_video_codec()
  402.                 #add frame video codec
  403.                 self.vbox_pg3.pack_start(self.f_3vcodec['frame'], 1, 0, 0)
  404.                
  405.                 # other options ----------------
  406.                 self.make_other_opts()
  407.                 #add frame other options
  408.                 self.vbox_pg3.pack_start(self.f3_oth['frame'], 1, 0, 0)
  409.                
  410.                 # page3 output ---------------------
  411.                 self.f3_out = self.make_frame_ag(3, "  FFmpeg command  " , 6, 8, 8, True)
  412.                 self.f3_out_label = Gtk.Label("")
  413.                 self.f3_out_label.set_width_chars(106)
  414.                 self.f3_out_label.set_max_width_chars(106)
  415.                 self.f3_out_label.set_line_wrap(True)
  416.                 self.f3_out['grid'].attach(self.f3_out_label, 0, 0, 1, 1)
  417.                 # add frame page3 output
  418.                 self.vbox_pg3.pack_start(self.f3_out['frame'], 1, 0, 0)
  419.                
  420.                 # run ffmpeg ---------------------------------
  421.                 self.make_run_ffmpeg()
  422.                 # add frame run ffmpeg
  423.                 self.vbox_pg3.pack_start(self.f3_run['frame'], 1, 0, 0)
  424.                
  425.                
  426.                 #---------------------------------------------------
  427.                 # main vbox
  428.                 self.main_vbox = Gtk.VBox()
  429.                
  430.                 # notebook      
  431.                 self.notebook = Gtk.Notebook()
  432.                 self.notebook.set_tab_pos(0)  #GTK_POS_LEFT
  433.                 self.notebook.set_show_border (False)
  434.                 self.main_vbox.pack_start(self.notebook, 1, 0, 0)
  435.                
  436.                 #page 1
  437.                 self.tab1label = Gtk.Label("Video filters")
  438.                 self.page1_ali = Gtk.Alignment()
  439.                 self.page1_ali.set_padding(0, 6, 6, 6)
  440.                 self.page1_ali.add(self.vbox1)
  441.                 self.notebook.append_page(self.page1_ali, self.tab1label)
  442.                
  443.                 #page 2
  444.                 self.tab2label = Gtk.Label("Utility")
  445.                 self.page2_ali = Gtk.Alignment()
  446.                 self.page2_ali.set_padding(0, 6, 6, 6)
  447.                 self.page2_ali.add(self.vbox_pg2)
  448.                 self.notebook.append_page(self.page2_ali, self.tab2label)
  449.                
  450.                 #page 3
  451.                 self.tab3label = Gtk.Label("Encode")
  452.                 self.page3_ali = Gtk.Alignment()
  453.                 self.page3_ali.set_padding(0, 6, 6, 6)
  454.                 self.page3_ali.add(self.vbox_pg3)
  455.                 self.notebook.append_page(self.page3_ali, self.tab3label)
  456.                
  457.                 #---------------------------------------------------
  458.                
  459.                 # low part BUTTONS AND TERM --------------------------
  460.                 self.make_low_part()
  461.                 # add low part-----------------
  462.                 self.main_vbox.pack_start(self.gridterm, 1, 1, 0)
  463.                
  464.                 #---------------------------------------------------------
  465.                 self.window.add (self.main_vbox)
  466.                 #---------------------------------
  467.                 self.window.show_all()          
  468.  
  469.                
  470.         def make_deinterlace(self):
  471.                 self.f_deint = self.make_frame_ag(3, "" , 6, 8, 8, True)
  472.                 self.checkdeint = Gtk.CheckButton("deinterlace")
  473.                 self.checkdeint.connect("toggled", self.on_deint_clicked)
  474.                 self.f_deint['grid'].attach(self.checkdeint, 0, 0, 1, 1)
  475.                
  476.                 self.box_deint = self.make_combobox(
  477.                   "yadif",
  478.                   "postprocessing linear blend",
  479.                   "detect (use only with Test)"
  480.                   )
  481.                 self.f_deint['grid'].attach(self.box_deint['cbox'], 1, 0, 1, 1)
  482.                 self.box_deint['cbox'].connect("changed", self.on_deint_clicked)
  483.                 #
  484.                 self.f_deint['grid'].attach(self.make_label(""), 2, 0, 1, 1)
  485.        
  486.         def make_map(self):
  487.                 #
  488.                 self.f_map = self.make_frame_ag(3, "" , 6, 8, 8, True)
  489.                 #
  490.                 self.check_map = Gtk.CheckButton("map")
  491.                 self.check_map.connect("toggled", self.on_map_clicked) # toggled or activate (enter)
  492.                 self.f_map['grid'].attach(self.check_map, 0, 0, 1, 1)
  493.                 #
  494.                 self.mapstream_label = self.make_label("streams: ")
  495.                 self.f_map['grid'].attach(self.mapstream_label, 1, 0, 1, 1)
  496.                 #
  497.                 self.entry_map = Gtk.Entry()
  498.                 self.entry_map.set_tooltip_text(Tips.map_tooltip_str)
  499.                 self.entry_map.connect("changed", self.on_map_clicked)
  500.                 self.f_map['grid'].attach(self.entry_map, 2, 0, 1, 1)
  501.                 #
  502.                 self.map_label = Gtk.Label("")
  503.                 self.f_map['grid'].attach(self.map_label, 3, 0, 1, 1)
  504.                 # placeholder
  505.                 self.f_map['grid'].attach(self.make_label("Version: " + Vars.version + "   "), 4, 0, 1, 1)
  506.                
  507.         def make_time_cut(self):
  508.                 #
  509.                 self.f_time = self.make_frame_ag(3, "" , 6, 8, 8, True)
  510.                 #
  511.                 self.check_time = Gtk.CheckButton("time")
  512.                 self.check_time.connect("toggled", self.on_time_clicked) # toggled or activate (enter)
  513.                 self.f_time['grid'].attach(self.check_time, 0, 0, 1, 1)
  514.                 #
  515.                 self.label_time_in = self.make_label("from: ")
  516.                 self.f_time['grid'].attach(self.label_time_in, 1, 0, 1, 1)
  517.                 self.entry_timein = Gtk.Entry()
  518.                 self.entry_timein.set_tooltip_text(Tips.time_tooltip_str)
  519.                 self.entry_timein.set_max_length(8)
  520.                 self.entry_timein.set_max_width_chars(8)
  521.                 self.entry_timein.set_width_chars(8)
  522.                 #self.entry_timein.set_halign(1)
  523.                 self.entry_timein.connect("changed", self.on_time_clicked)
  524.                 self.f_time['grid'].attach(self.entry_timein, 2, 0, 1, 1)
  525.                
  526.                 self.label_time_out = self.make_label("to: ")
  527.                 self.f_time['grid'].attach(self.label_time_out, 3, 0, 1, 1)
  528.                 self.entry_timeout = Gtk.Entry()
  529.                 self.entry_timeout.set_tooltip_text(Tips.time_tooltip_str)
  530.                 self.entry_timeout.set_max_length(8)
  531.                 self.entry_timeout.set_max_width_chars(8)
  532.                 self.entry_timeout.set_width_chars(8)
  533.                 self.entry_timeout.connect("changed", self.on_time_clicked)
  534.                 self.f_time['grid'].attach(self.entry_timeout, 4, 0, 1, 1)
  535.                 self.time_label = Gtk.Label('')
  536.                 self.f_time['grid'].attach(self.time_label, 5, 0, 2, 1)
  537.        
  538.         def make_scale(self):
  539.                 self.frame_scale = self.make_frame_ag(3, '  scale  ' , 6, 8, 8, True)
  540.                 # ------------------------------
  541.                 self.box1 = self.make_combobox(
  542.                   "None",
  543.                   "W",
  544.                   "H"
  545.                   )
  546.                 self.frame_scale['grid'].attach(self.box1['cbox'], 0, 0, 1, 1)
  547.                 self.box1['cbox'].connect("changed", self.on_scale_clicked)
  548.                 #------------------------------------
  549.                 self.box2 = self.make_combobox(
  550.                   "16/9",
  551.                   "4/3"
  552.                   )
  553.                 self.frame_scale['grid'].attach(self.box2['cbox'], 0, 1, 1, 1)
  554.                 self.box2['cbox'].connect("changed", self.on_scale_clicked)
  555.                 #-----------------------------------------
  556.                 self.size_spinner = self.make_slider_and_spinner(720, 200, 2000, 8, 32, 0)
  557.                 self.frame_scale['grid'].attach(self.size_spinner['slider'], 1, 0, 1, 1)
  558.                 self.frame_scale['grid'].attach(self.size_spinner['spinner'], 2, 0, 1, 1)
  559.                 #self.size_spinner['slider'].set_size_request(150,-1)
  560.                 self.size_spinner['adj'].set_value(720.001) #mettere decimali se no non si vede
  561.                 self.size_spinner['adj'].connect("value-changed", self.on_scale_clicked)
  562.                 #-------------------------------------------------------
  563.                 self.check = Gtk.CheckButton("lanczos")
  564.                 self.check.connect("toggled", self.on_scale_clicked)
  565.                 self.frame_scale['grid'].attach(self.check, 2, 1, 1, 1)
  566.                
  567.         def make_crop(self):
  568.                 self.frame_crop = self.make_frame_ag(3, '' , 6, 2, 0, True)
  569.                 # -------
  570.                 self.checkcr = Gtk.CheckButton("crop")
  571.                 self.checkcr.connect("toggled", self.on_crop_clicked)
  572.                 self.frame_crop['grid'].attach(self.checkcr, 0, 0, 1, 1)
  573.                 #----------
  574.                 self.butcrode = Gtk.Button(label="Crop detect")
  575.                 self.butcrode.connect("clicked", self.on_butcrode_clicked)
  576.                 self.butcrode.set_sensitive(False)
  577.                 self.frame_crop['grid'].attach(self.butcrode, 0, 1, 1, 1)
  578.                 #-----------
  579.                 self.labelcropinw = self.make_label("input W: ")
  580.                 self.frame_crop['grid'].attach(self.labelcropinw, 1, 0, 1, 1)
  581.                 self.labelcropinh = self.make_label("input H: ")
  582.                 self.frame_crop['grid'].attach(self.labelcropinh, 1, 1, 1, 1)
  583.                 #
  584.                 self.spincw = self.make_spinbut(640 , 100 , 1920 , 10 , 1 , 0, True )
  585.                 self.spincw["adj"].connect("value-changed", self.on_crop_clicked)
  586.                 self.frame_crop['grid'].attach(self.spincw["spinner"], 2, 0, 1, 1)
  587.                 #
  588.                 self.spinch = self.make_spinbut(480 , 100 , 1280 , 10 , 1 , 0, True )
  589.                 self.spinch["adj"].connect("value-changed", self.on_crop_clicked)
  590.                 self.frame_crop['grid'].attach(self.spinch["spinner"], 2, 1, 1, 1)
  591.                 #
  592.                
  593.                 self.labelcroptop = self.make_label("crop Top: ")
  594.                 self.frame_crop['grid'].attach(self.labelcroptop, 3, 0, 1, 1)
  595.                 self.labelcropbot = self.make_label("crop Bottom: ")
  596.                 self.frame_crop['grid'].attach(self.labelcropbot, 3, 1, 1, 1)
  597.                 #
  598.                
  599.                 self.spinct = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  600.                 self.spinct["adj"].connect("value-changed", self.on_crop_clicked)
  601.                 self.frame_crop['grid'].attach(self.spinct["spinner"], 4, 0, 1, 1)
  602.                 #
  603.                 self.spincb = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  604.                 self.spincb["adj"].connect("value-changed", self.on_crop_clicked)
  605.                 self.frame_crop['grid'].attach(self.spincb["spinner"], 4, 1, 1, 1)
  606.                 #
  607.                
  608.                 self.labelcroplef = self.make_label("crop Left: ")
  609.                 self.frame_crop['grid'].attach(self.labelcroplef, 5, 0, 1, 1)
  610.                 self.labelcroprig = self.make_label("crop Right: ")
  611.                 self.frame_crop['grid'].attach(self.labelcroprig, 5, 1, 1, 1)
  612.                 #
  613.                 self.spincl = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  614.                 self.spincl["adj"].connect("value-changed", self.on_crop_clicked)
  615.                 self.frame_crop['grid'].attach(self.spincl["spinner"], 6, 0, 1, 1)
  616.                 #
  617.                 self.spincr = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  618.                 self.spincr["adj"].connect("value-changed", self.on_crop_clicked)
  619.                 self.frame_crop['grid'].attach(self.spincr["spinner"], 6, 1, 1, 1)
  620.                
  621.                
  622.         def make_denoise(self):
  623.                 self.frame_dn = self.make_frame_ag(3, '  denoise / unsharp luma chroma / frame rate   ' , 6, 8, 8, True)
  624.                 # denoise ----------------------
  625.                 self.checkdn = Gtk.CheckButton("hqdn3d:")
  626.                 self.checkdn.set_alignment(1.0, 0.5)
  627.                 self.checkdn.set_halign(2)
  628.                 self.checkdn.connect("toggled", self.on_dn_clicked)
  629.                 self.frame_dn['grid'].attach(self.checkdn, 0, 0, 1, 1)
  630.                 #
  631.                 self.spindn = self.make_spinbut(4 , 2 , 8 , 1 , 10 , 0, True )
  632.                 self.spindn["adj"].connect("value-changed", self.on_dn_clicked)
  633.                 #self.spindn['spinner'].set_max_length(1)
  634.                 #self.spindn['spinner'].set_width_chars(1)
  635.                 self.frame_dn['grid'].attach(self.spindn["spinner"], 1, 0, 1, 1)
  636.                 # -----------------------
  637.                 # unsharp unsharp=5:5:luma:5:5:chroma, luma chroma -1.5 to 1.5
  638.                 self.checkuns = Gtk.CheckButton("unsharp l/c:")
  639.                 self.checkuns.set_alignment(1.0, 0.5)
  640.                 self.checkuns.set_halign(2)
  641.                 self.checkuns.connect("toggled", self.on_uns_clicked)
  642.                 self.frame_dn['grid'].attach(self.checkuns, 2, 0, 1, 1)
  643.                 self.spinunsl = self.make_spinbut(0.0 , -1.5 , 1.5 , .1 , .01 , 2, True )
  644.                 self.spinunsl["adj"].connect("value-changed", self.on_uns_clicked)
  645.                 self.frame_dn['grid'].attach(self.spinunsl["spinner"], 3, 0, 1, 1)
  646.                 self.spinunsc = self.make_spinbut(0.0 , -1.5 , 1.5 , .1 , .01 , 2, True )
  647.                 self.spinunsc["adj"].connect("value-changed", self.on_uns_clicked)
  648.                 self.frame_dn['grid'].attach(self.spinunsc["spinner"], 4, 0, 1, 1)
  649.                 # framerate --------------------------
  650.                 self.checkfr = Gtk.CheckButton("frame rate:")
  651.                 self.checkfr.set_alignment(1.0, 0.5)
  652.                 self.checkfr.set_halign(2)
  653.                 self.checkfr.connect("toggled", self.on_fr_clicked)
  654.                 self.frame_dn['grid'].attach(self.checkfr, 5, 0, 1, 1)
  655.                 self.spinfr = self.make_spinbut(0 , 0 , 100 , 1 , 10 , 2, True )
  656.                 self.spinfr["adj"].connect("value-changed", self.on_fr_clicked)
  657.                 self.frame_dn['grid'].attach(self.spinfr["spinner"], 6, 0, 1, 1)
  658.                
  659.         def make_low_part(self):
  660.                 # grid
  661.                 self.gridterm = Gtk.Grid()
  662.                 self.gridterm.set_row_spacing(2)
  663.                 self.gridterm.set_column_spacing(2)
  664.                 self.gridterm.set_column_homogeneous(True) # True
  665.                 # filechooserbutton
  666.                 self.filechooserbutton = Gtk.FileChooserButton(title="FileChooserButton")
  667.                 #
  668.                 #self.filechooserbutton.set_action(2) # 0 open file, 1 save file, 2 select folder, 3 create folder
  669.                 #
  670.                 self.filechooserbutton.connect("file-set", self.file_changed)  
  671.                 # filter
  672.                 self.filter = Gtk.FileFilter()
  673.                 self.filter.set_name("Video")
  674.                 self.filter.add_mime_type("video/x-matroska")
  675.                 self.filter.add_mime_type("video/mp4")
  676.                 self.filter.add_mime_type("video/x-flv")
  677.                 self.filter.add_mime_type("video/avi")
  678.                 self.filter.add_mime_type("video/mpg")
  679.                 self.filter.add_mime_type("video/mpeg")
  680.                 self.filter.add_mime_type("video/x-ms-wmv")
  681.                 self.filter.add_mime_type("video/webm")
  682.                 self.filter.add_mime_type("video/ogg")
  683.                 self.filter.add_mime_type("video/quicktime")
  684.                 self.filechooserbutton.add_filter(self.filter)
  685.                 # terminal
  686.                 self.terminal     = Vte.Terminal()
  687.                 self.terminal.fork_command_full(
  688.                         Vte.PtyFlags.DEFAULT, #default is fine
  689.                         os.getcwd(), #where to start the command?   os.environ['HOME']
  690.                         ["/bin/sh"], #where is the emulator?
  691.                         [], #it's ok to leave this list empty
  692.                         GLib.SpawnFlags.DO_NOT_REAP_CHILD,
  693.                         None, #at least None is required
  694.                         None,
  695.                         )
  696.                 self.scroller = Gtk.ScrolledWindow()
  697.                 self.scroller.set_hexpand(True)
  698.                 self.scroller.set_vexpand(True)
  699.                 self.scroller.add(self.terminal)
  700.                 self.scroller.set_min_content_height(90)
  701.                 #ff command button
  702.                 self.butplay = Gtk.Button(label="FFplay")
  703.                 self.butplay.connect("clicked", self.on_butplay_clicked)
  704.                 self.butplay.set_sensitive(False)
  705.                 self.butprobe = Gtk.Button(label="FFprobe")
  706.                 self.butprobe.connect("clicked", self.on_butprobe_clicked)
  707.                 self.butprobe.set_sensitive(False)
  708.                 self.buttest = Gtk.Button(label="Test")
  709.                 self.buttest.connect("clicked", self.on_buttest_clicked)
  710.                 self.buttest.set_sensitive(False)
  711.                 self.buttestspl = Gtk.Button(label="Test split")
  712.                 self.buttestspl.connect("clicked", self.on_buttestspl_clicked)
  713.                 self.buttestspl.set_sensitive(False)
  714.                
  715.                 self.gridterm.attach(self.filechooserbutton, 0, 0, 2, 1)
  716.                 self.gridterm.attach(self.butprobe, 2, 0, 1, 1)
  717.                 self.gridterm.attach(self.butplay, 3, 0, 1, 1)
  718.                 self.gridterm.attach(self.buttest, 4, 0, 1, 1)
  719.                 self.gridterm.attach(self.buttestspl, 5, 0, 1, 1)
  720.                
  721.                 self.gridterm.attach(self.scroller, 0, 1, 6, 1)
  722.  
  723.         def make_volume_det(self):
  724.                 self.f_volume_det = self.make_frame_ag(3, "" , 6, 8, 8, True)
  725.                 #
  726.                 self.but_volume_det = Gtk.Button(label="Volume detect")
  727.                 self.but_volume_det.connect("clicked", self.on_but_volume_det_clicked)
  728.                 self.f_volume_det['grid'].attach(self.but_volume_det, 0, 0, 1, 1)
  729.                 self.but_volume_det.set_sensitive(False)
  730.                 #
  731.                 self.voldet_spin = Gtk.Spinner()
  732.                 self.voldet_spin.set_sensitive(False)
  733.                 self.f_volume_det['grid'].attach(self.voldet_spin, 1, 0, 1, 1)
  734.                 #
  735.                 self.label_maxvol = Gtk.Label("")
  736.                 self.f_volume_det['grid'].attach(self.label_maxvol, 2, 0, 1, 1)
  737.                 self.label_meanvol = Gtk.Label("")
  738.                 self.f_volume_det['grid'].attach(self.label_meanvol, 3, 0, 1, 1)
  739.                 #
  740.                 self.check_vol = Gtk.CheckButton("volume")
  741.                 self.check_vol.connect("toggled", self.on_volume_clicked)
  742.                 self.f_volume_det['grid'].attach(self.check_vol, 0, 1, 1, 1)
  743.                 #
  744.                 self.label_db = self.make_label("dB: ")
  745.                 self.f_volume_det['grid'].attach(self.label_db, 1, 1, 1, 1)
  746.                 self.spin_db = self.make_spinbut(0 , -6 , 20 , 0.1 , 1 , 2, True )
  747.                 self.spin_db["adj"].connect("value-changed", self.on_volume_clicked)
  748.                 self.f_volume_det['grid'].attach(self.spin_db["spinner"], 2, 1, 1, 1)
  749.                 self.label_ratio = self.make_label("ratio: ")
  750.                 self.f_volume_det['grid'].attach(self.label_ratio, 3, 1, 1, 1)
  751.                 self.label_ratio_val = Gtk.Label("1")
  752.                 self.f_volume_det['grid'].attach(self.label_ratio_val, 4, 1, 1, 1)
  753.                
  754.         def make_volume_drc(self):
  755.                 self.f_volume_drc = self.make_frame_ag(3, "" , 6, 8, 8, True)
  756.                 self.check_drc = Gtk.CheckButton("ac3 input drc scale")
  757.                 self.check_drc.connect("toggled", self.on_drc_clicked)
  758.                 self.f_volume_drc['grid'].attach(self.check_drc, 0, 0, 1, 1)
  759.                 self.check_drc.set_sensitive(False)
  760.                 #
  761.                 self.spin_drc = self.make_spinbut(1 , 0 , 6 , 1 , 1 , 0, True )
  762.                 self.spin_drc["adj"].connect("value-changed", self.on_drc_clicked)
  763.                 self.spin_drc['spinner'].set_tooltip_text(Tips.drc_str)
  764.                 self.f_volume_drc['grid'].attach(self.spin_drc["spinner"], 1, 0, 1, 1)
  765.                 self.spin_drc["spinner"].set_sensitive(False)
  766.                 #
  767.                 self.drc_test = Gtk.Button(label="test drc")
  768.                 self.drc_test.set_sensitive(False)
  769.                 self.drc_test.connect("clicked", self.on_drc_test)
  770.                 self.f_volume_drc['grid'].attach(self.drc_test, 2, 0, 1, 1)
  771.                 #placeholder
  772.                 self.f_volume_drc['grid'].attach(Gtk.Label(''), 3, 0, 1, 1)
  773.                        
  774.         def make_compand(self):
  775.                 #
  776.                 self.f_compand = self.make_frame_ag(3, "" , 6, 8, 8, True)
  777.                 #
  778.                 self.check_compand = Gtk.CheckButton("compand")
  779.                 self.check_compand.connect("toggled", self.on_compand_clicked)
  780.                 self.f_compand['grid'].attach(self.check_compand, 0, 0, 1, 1)
  781.                 #
  782.                 self.entry_compand = Gtk.Entry()
  783.                 self.entry_compand.set_text(Vars.compinit)
  784.                 self.entry_compand.connect("changed", self.on_compand_clicked)
  785.                 self.entry_compand.set_tooltip_text(Tips.compad_str)
  786.                 self.f_compand['grid'].attach(self.entry_compand, 1, 0, 2, 1)
  787.                 #
  788.                 self.compand_reset = Gtk.Button(label="reset")
  789.                 self.compand_reset.connect("clicked", self.on_compand_reset)
  790.                 self.f_compand['grid'].attach(self.compand_reset, 3, 0, 1, 1)
  791.                 self.compand_test = Gtk.Button(label="test ebur128")
  792.                 self.compand_test.set_sensitive(False)
  793.                 self.compand_test.connect("clicked", self.on_compand_test)
  794.                 self.f_compand['grid'].attach(self.compand_test, 0, 1, 1, 1)
  795.                 self.label_comp_from = self.make_label("from: ")
  796.                 self.f_compand['grid'].attach(self.label_comp_from, 1, 1, 1, 1)
  797.                 #
  798.                 self.entry_timecomp = Gtk.Entry()
  799.                 self.entry_timecomp.set_tooltip_text(Tips.time_tooltip_str)
  800.                 self.entry_timecomp.set_max_length(8)
  801.                 self.entry_timecomp.set_max_width_chars(8)
  802.                 self.entry_timecomp.set_width_chars(8)
  803.                 self.entry_timecomp.connect("changed", self.on_compand_clicked)
  804.                 self.f_compand['grid'].attach(self.entry_timecomp, 2, 1, 1, 1)
  805.                 #placeholder
  806.                 self.f_compand['grid'].attach(Gtk.Label(''), 3, 1, 1, 1)
  807.  
  808.         def make_black_detect(self):
  809.                 self.f_blackd = self.make_frame_ag(3, "" , 6, 8, 8, True)
  810.                 #
  811.                 self.but_black_det = Gtk.Button(label="Black detect")
  812.                 self.but_black_det.connect("clicked", self.on_but_black_det_clicked)
  813.                 self.but_black_det.set_sensitive(False)
  814.                 self.f_blackd['grid'].attach(self.but_black_det, 0, 0, 1, 1)
  815.                 #
  816.                 self.blackdet_spin = Gtk.Spinner()
  817.                 self.blackdet_spin.set_sensitive(False)
  818.                 self.f_blackd['grid'].attach(self.blackdet_spin, 1, 0, 1, 1)
  819.                 #
  820.                 scrolledwindow = Gtk.ScrolledWindow()
  821.                 #scrolledwindow.set_hexpand(True)
  822.                 scrolledwindow.set_vexpand(True)
  823.                 self.textview = Gtk.TextView()
  824.                 self.textbuffer = self.textview.get_buffer()
  825.                 self.textview.set_editable(False)
  826.                 self.textview.set_cursor_visible(False)
  827.                 self.textview.modify_font(Pango.font_description_from_string('Monospace 9'))
  828.                 scrolledwindow.add(self.textview)
  829.                 self.textbuffer.set_text(Tips.black_dt_init_str)
  830.                 self.f_blackd['grid'].attach(scrolledwindow, 2, 0, 3, 3)
  831.                 #
  832.                 self.progressbar_black_det = Gtk.ProgressBar()
  833.                 self.f_blackd['grid'].attach(self.progressbar_black_det, 0, 1, 1, 1)
  834.                
  835.         def make_info_frame(self):
  836.                 self.f_info = self.make_frame_ag(3, "  info  " , 6, 8, 8, True)
  837.                 scrolledwindow1 = Gtk.ScrolledWindow()
  838.                 scrolledwindow1.set_hexpand(True)
  839.                 scrolledwindow1.set_vexpand(True)
  840.                 self.textview_info = Gtk.TextView()
  841.                 self.textbuffer_info = self.textview_info.get_buffer()
  842.                 self.textview_info.set_editable(False)
  843.                 self.textview_info.set_cursor_visible(False)
  844.                 self.textview_info.modify_font(Pango.font_description_from_string('Monospace 9'))
  845.                 scrolledwindow1.add(self.textview_info)
  846.                 self.f_info['grid'].attach(scrolledwindow1, 0, 0, 3, 3)
  847.        
  848.         def make_audio_codec(self):
  849.                 #
  850.                 self.f_3acodec = self.make_frame_ag(3, "  audio codec  " , 6, 8, 8, True)
  851.                 #
  852.                 self.box_ac = self.make_combobox(
  853.                   "libfaac quality (Q)",
  854.                   "aacplus (64 Kb/s)",
  855.                   "aacplus (32 Kb/s)",
  856.                   "no audio",
  857.                   "audio copy",
  858.                   "aac_fdk CBR (Kb/s)",
  859.                   "lame mp3 CBR (Kb/s)",
  860.                   "lame mp3 VBR (Q)",
  861.                   "aac native CBR (Kb/s)"
  862.                   )
  863.                 self.f_3acodec['grid'].attach(self.box_ac['cbox'], 0, 0, 1, 1)
  864.                 self.box_ac['cbox'].connect("changed", self.on_codec_audio_changed)
  865.                 #
  866.                 self.spin_ac = self.make_spinbut(100 , 80 , 160 , 10 , 1 , 0, True )
  867.                 self.spin_ac["adj"].connect("value-changed", self.on_codec_clicked)
  868.                 self.f_3acodec['grid'].attach(self.spin_ac["spinner"], 1, 0, 1, 1)
  869.                 self.spin_ac['spinner'].set_tooltip_text(Tips.faac_q_str)
  870.                 #
  871.                 self.box_audio_rate = self.make_combobox(
  872.                         "48000",
  873.                         "44100"
  874.                         )
  875.                 self.box_audio_rate['cbox'].set_tooltip_text(Tips.audio_samp_str)
  876.                 self.box_audio_rate['cbox'].connect("changed", self.on_codec_audio_changed)
  877.                 self.f_3acodec['grid'].attach(self.box_audio_rate['cbox'], 2, 0, 1, 1)
  878.                 #
  879.                 self.box_audio_ch = self.make_combobox(
  880.                         "2",
  881.                         "1"
  882.                         )
  883.                 self.box_audio_ch['cbox'].set_tooltip_text(Tips.audio_channels_str)
  884.                 self.box_audio_ch['cbox'].connect("changed", self.on_codec_audio_changed)
  885.                 self.f_3acodec['grid'].attach(self.box_audio_ch['cbox'], 3, 0, 1, 1)
  886.        
  887.         def make_video_codec(self):
  888.                 self.f_3vcodec = self.make_frame_ag(3, "  video codec  " , 6, 8, 8, True)
  889.                 self.box_vcodec = self.make_combobox(
  890.                         "libx264",
  891.                         "video copy",
  892.                         "mpeg4",
  893.                         "no video"
  894.                         )
  895.                 self.f_3vcodec['grid'].attach(self.box_vcodec['cbox'], 0, 0, 1, 1)
  896.                 self.box_vcodec['cbox'].connect("changed", self.on_codec_video_changed)
  897.                 #
  898.                 self.box_vrc = self.make_combobox(
  899.                         "crf",
  900.                         "bitrate kb/s"
  901.                         )
  902.                 self.f_3vcodec['grid'].attach(self.box_vrc['cbox'], 1, 0, 1, 1)
  903.                 self.box_vrc['cbox'].connect("changed", self.on_codec_vrc_changed)
  904.                 #
  905.                 self.spin_vc = self.make_spinbut(21.3 , 15 , 40 , 0.1 , 1 , 1, True )
  906.                 self.spin_vc["adj"].connect("value-changed", self.on_codec_vrc_value_change)
  907.                 self.f_3vcodec['grid'].attach(self.spin_vc["spinner"], 2, 0, 1, 1)
  908.                 #
  909.                 self.f3v_label_out = Gtk.Label("")
  910.                 self.f_3vcodec['grid'].attach(self.f3v_label_out, 3, 0, 2, 1)
  911.                 # x264 preset
  912.                 self.box_3v_preset = self.make_combobox(
  913.                         "superfast",
  914.                         "veryfast",
  915.                         "faster",
  916.                         "fast",
  917.                         "medium",
  918.                         "slow"
  919.                         ) #(-superfast -veryfast -fast, -medium, -slow, default: faster)
  920.                 self.box_3v_preset['cbox'].set_active(2)
  921.                 self.box_3v_preset['cbox'].set_tooltip_text(Tips.preset_tooltip_str)
  922.                 self.f_3vcodec['grid'].attach(self.box_3v_preset['cbox'], 0, 1, 1, 1)
  923.                 self.box_3v_preset['cbox'].connect("changed", self.on_preset_changed)
  924.                 # x264 tune
  925.                 self.box_3v_tune = self.make_combobox(
  926.                         "film",
  927.                         "animation",
  928.                         "grain",
  929.                         "stillimage"
  930.                         ) # film,animation,grain,stillimage
  931.                 self.box_3v_tune['cbox'].set_active(0)
  932.                 self.box_3v_tune['cbox'].set_tooltip_text(Tips.tune_tooltip_str)
  933.                 self.f_3vcodec['grid'].attach(self.box_3v_tune['cbox'], 1, 1, 1, 1)
  934.                 self.box_3v_tune['cbox'].connect("changed", self.on_preset_changed)
  935.                 # x264 opts
  936.                 self.box_3v_x264opts = self.make_combobox(
  937.                         "x264opts 1",
  938.                         "no opts (ssim)"
  939.                         )
  940.                 self.box_3v_x264opts['cbox'].set_active(0)
  941.                 self.f_3vcodec['grid'].attach(self.box_3v_x264opts['cbox'], 2, 1, 1, 1)
  942.                 self.box_3v_x264opts['cbox'].connect("changed", self.on_codec_clicked)
  943.                 # opencl
  944.                 self.check_3v_opencl = Gtk.CheckButton("opencl")
  945.                 self.check_3v_opencl.connect("toggled", self.on_codec_clicked)
  946.                 self.f_3vcodec['grid'].attach(self.check_3v_opencl, 3, 1, 1, 1)
  947.                
  948.                
  949.                
  950.         def make_other_opts(self):
  951.                 #
  952.                 self.f3_oth = self.make_frame_ag(3, "  other options  " , 6, 8, 8, True)
  953.                 #
  954.                 self.check_2pass = Gtk.CheckButton("2 pass")
  955.                 self.check_2pass.connect("toggled", self.on_f3_other_clicked)
  956.                 self.f3_oth['grid'].attach(self.check_2pass, 0, 0, 1, 1)
  957.                 self.check_2pass.set_sensitive(False)
  958.                 #
  959.                 self.check_nometa = Gtk.CheckButton("no metatag")
  960.                 self.check_nometa.connect("toggled", self.on_f3_other_clicked)
  961.                 self.check_nometa.set_tooltip_text(Tips.nometa_tooltip_srt)
  962.                 self.f3_oth['grid'].attach(self.check_nometa, 1, 0, 1, 1)
  963.                 #
  964.                 #
  965.                 self.check_scopy = Gtk.CheckButton("sub copy")
  966.                 self.check_scopy.connect("toggled", self.on_f3_other_clicked)
  967.                 self.check_scopy.set_tooltip_text(Tips.subcopy_tooltip_srt)
  968.                 self.f3_oth['grid'].attach(self.check_scopy, 2, 0, 1, 1)
  969.                 #
  970.                 self.check_cpu = Gtk.CheckButton("cpu 3")
  971.                 self.check_cpu.connect("toggled", self.on_f3_other_clicked)
  972.                 self.check_cpu.set_tooltip_text(Tips.cpu_tooltip_srt)
  973.                 self.f3_oth['grid'].attach(self.check_cpu, 3, 0, 1, 1)
  974.                 #
  975.                 self.check_debug = Gtk.CheckButton("debug")
  976.                 self.check_debug.connect("toggled", self.on_f3_other_clicked)
  977.                 self.check_debug.set_tooltip_text(Tips.debug_tooltip_srt)
  978.                 self.f3_oth['grid'].attach(self.check_debug, 4, 0, 1, 1)
  979.                 #
  980.                 self.box_oth_container = self.make_combobox(
  981.                   "MKV",
  982.                   "MP4",
  983.                   "AVI",
  984.                   "MKA"
  985.                   )
  986.                 self.f3_oth['grid'].attach(self.box_oth_container['cbox'], 5, 0, 1, 1)
  987.                 self.box_oth_container['cbox'].connect("changed", self.on_container_changed)
  988.                
  989.         def make_run_ffmpeg(self):
  990.                 self.f3_run = self.make_frame_ag(3, "  execute in terminal  " , 6, 8, 8, True)
  991.                 #
  992.                 self.f3_run_indir_label = Gtk.Label("")
  993.                 self.f3_run['grid'].attach(self.f3_run_indir_label, 0, 0, 1, 1)
  994.                 self.f3_run_file = Gtk.Label("no input file")
  995.                 self.f3_run_file.set_tooltip_text('')
  996.                 self.f3_run['grid'].attach(self.f3_run_file, 1, 0, 2, 1)
  997.                 self.f3_dur_file = Gtk.Label("")
  998.                 self.f3_run['grid'].attach(self.f3_dur_file, 3, 0, 1, 1)
  999.                 #
  1000.                 self.but_f3_run = Gtk.Button(label="RUN")
  1001.                 self.but_f3_run.connect("clicked", self.on_but_f3_run_clicked)
  1002.                 self.but_f3_run.set_sensitive(False)
  1003.                 self.f3_run['grid'].attach(self.but_f3_run, 3, 1, 1, 1)
  1004.                 #
  1005.                 #self.f3_run_outdir_label = Gtk.Label("out dir:  " + os.getcwd())
  1006.                 self.f3_run_outdir_label = Gtk.Label("")
  1007.                 self.f3_run_outdir_label.set_markup("<b>out dir:  </b>" + os.getcwd())
  1008.                 self.f3_run['grid'].attach(self.f3_run_outdir_label, 0, 1, 2, 1)
  1009.                 #
  1010.                 # filechooserbutton
  1011.                 self.out_dir_chooserbut = Gtk.FileChooserButton(title="Dir out")
  1012.                 self.out_dir_chooserbut.set_action(2)
  1013.                 #self.filechooserbutton.set_action(2) # 0 open file, 1 save file, 2 select folder, 3 create folder
  1014.                 acturi = "file://" + os.getcwd()
  1015.                 self.out_dir_chooserbut.set_uri(acturi)
  1016.                 self.f3_run['grid'].attach(self.out_dir_chooserbut, 2, 1, 1, 1)
  1017.                 self.out_dir_chooserbut.connect("selection-changed", self.dir_changed)
  1018.                 #
  1019.                 self.reportdata = Gtk.Label('')
  1020.                 self.f3_run['grid'].attach(self.reportdata, 0, 3, 4, 1)
  1021.                
  1022.                
  1023.         # event handlers -----------------------------------------------
  1024.        
  1025.         def on_window_destroy(self, *args):
  1026.                 Gtk.main_quit(*args)
  1027.        
  1028.         def on_scale_clicked(self, button):
  1029.                 if (self.box1['cbox'].get_active() != 0):
  1030.                         self.calcola_scale()
  1031.                 else:
  1032.                         Vars.scalestr = ""
  1033.                         self.outfilter()
  1034.                  
  1035.         def on_deint_clicked(self, button):
  1036.                 Vars.deint_str = ""
  1037.                 if self.checkdeint.get_active():
  1038.                         deint_val = self.box_deint['cbox'].get_active()
  1039.                         if (deint_val == 0):
  1040.                                 Vars.deint_str = "yadif"
  1041.                         elif (deint_val == 1):
  1042.                                 Vars.deint_str = "pp=lb"
  1043.                         elif (deint_val == 2):
  1044.                                 Vars.deint_str = "idet"
  1045.                 self.outfilter()
  1046.                        
  1047.         def on_dn_clicked(self, button):
  1048.                 Vars.dn_str = ""
  1049.                 if self.checkdn.get_active():
  1050.                         dn_val = int( self.spindn['adj'].get_value() )
  1051.                         Vars.dn_str = "hqdn3d=" + str(dn_val)
  1052.                 self.outfilter()
  1053.                
  1054.         def on_uns_clicked(self, button):
  1055.                 Vars.uns_str = ""
  1056.                 if self.checkuns.get_active():
  1057.                         luma = self.spinunsl['adj'].get_value()
  1058.                         chroma = self.spinunsc['adj'].get_value()
  1059.                         Vars.uns_str = "unsharp=5:5:" + "{0:0.2f}".format(luma) + ":5:5:" + "{0:0.2f}".format(chroma)
  1060.                 self.outfilter()
  1061.                        
  1062.         def on_fr_clicked(self, button):
  1063.                 Vars.fr_str = ""
  1064.                 if self.checkfr.get_active():
  1065.                         fr_val = self.spinfr['adj'].get_value()
  1066.                         Vars.fr_str = "-r " + "{0:0.2f}".format(fr_val)
  1067.                 self.outfilter()
  1068.                    
  1069.         def on_crop_clicked(self, button):
  1070.                 ok = 0
  1071.                 Vars.crop_str = ""
  1072.                 if self.checkcr.get_active():
  1073.                         ok = 1
  1074.                 if ok:
  1075.                         inW = int(self.spincw['adj'].get_value())
  1076.                         inH = int(self.spinch['adj'].get_value())
  1077.                         crT = int(self.spinct['adj'].get_value())
  1078.                         crB = int(self.spincb['adj'].get_value())
  1079.                         crL = int(self.spincl['adj'].get_value())
  1080.                         crR = int(self.spincr['adj'].get_value())      
  1081.                         finW = inW - crL - crR
  1082.                         finH = inH - crT - crB
  1083.                         if ( (finW < 100) or (finH < 100) ):
  1084.                                 Vars.crop_str = ""
  1085.                         else:
  1086.                                 Vars.crop_str = "crop=" + str(finW) + ":" \
  1087.                                  + str(finH) + ":" \
  1088.                                  + str(crL)  + ":" \
  1089.                                  + str(crT)
  1090.                 if (self.box2['cbox'].get_active() != 2):
  1091.                         self.outfilter()
  1092.                 else:
  1093.                         self.on_scale_clicked(button)
  1094.                
  1095.         def file_changed(self, filechooserbutton):
  1096.                 if Vars.ENCODING:
  1097.                         return
  1098.                 if self.filechooserbutton.get_filename():
  1099.                         self.butplay.set_sensitive(True) # low part ---------
  1100.                         self.butprobe.set_sensitive(True)
  1101.                         self.preview_logic() # test and testsplit
  1102.                         self.butcrode.set_sensitive(True) # crop ----------
  1103.                         self.spinct['adj'].set_value(0)
  1104.                         self.spincb['adj'].set_value(0)
  1105.                         self.spincl['adj'].set_value(0)
  1106.                         self.spincr['adj'].set_value(0)                
  1107.                         self.but_volume_det.set_sensitive(True) # volume detect
  1108.                         Vars.VOLDT_DONE = False
  1109.                         self.but_volume_det.set_label("Volume detect")
  1110.                         self.label_meanvol.set_label("")
  1111.                         self.label_maxvol.set_label("")
  1112.                         self.spin_db["adj"].set_value(0)
  1113.                         self.check_drc.set_active(False) #drc
  1114.                         self.drc_test.set_sensitive(False)
  1115.                         self.check_drc.set_sensitive(False)
  1116.                         self.spin_drc["adj"].set_value(1)
  1117.                         self.spin_drc["spinner"].set_sensitive(False)
  1118.                         Vars.ac3_drc = ""
  1119.                         self.compand_test.set_sensitive(True) #compand test
  1120.                         self.but_black_det.set_sensitive(True) # black  detect
  1121.                         self.but_black_det.set_label("Black detect")
  1122.                         self.textbuffer.set_text(Tips.black_dt_init_str)
  1123.                         self.progressbar_black_det.set_fraction(0.0)
  1124.                         self.but_f3_run.set_sensitive(True) # ffmpeg run
  1125.                         Vars.BLACKDT_DONE = False
  1126.                         #
  1127.                         command = "clear" + "\n"
  1128.                         length = len(command)
  1129.                         self.terminal.feed_child(command, length)
  1130.                         # need ffprobe
  1131.                         Vars.filename = self.filechooserbutton.get_filename()
  1132.                         Vars.dirname = os.path.dirname(Vars.filename)
  1133.                         Vars.basename = os.path.basename(Vars.filename)
  1134.                         self.check_out_file()
  1135.                         self.f3_run_indir_label.set_label(Vars.dirname)
  1136.                         file_4_label = (Vars.basename)
  1137.                         if ( len(file_4_label) > 50):
  1138.                                 a = file_4_label[:46]
  1139.                                 b = '  ...  '
  1140.                                 c = file_4_label[-4:]
  1141.                                 file_4_label = a + b + c
  1142.                         self.f3_run_file.set_label(file_4_label)
  1143.                         self.but_f3_run.set_tooltip_text("")
  1144.                         self.reportdata.set_text("")
  1145.                         command = [Vars.ffprobe_ex, '-show_format', '-show_streams', '-pretty', '-loglevel', 'quiet', Vars.filename]
  1146.                         p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  1147.                         out, err =  p.communicate()
  1148.                         out = out.decode() # python3
  1149.                         self.get_info(out)
  1150.                        
  1151.         def get_info(self, out):
  1152.                 def form_to_3(in_str):
  1153.                         '''
  1154.                        bitrate and size info formatting
  1155.                        '''
  1156.                         a = in_str.split(' ')[0]
  1157.                         if len(in_str.split(' ')) == 2:
  1158.                                 b = in_str.split(' ')[1]
  1159.                                 a = float(a)
  1160.                                 result = "{0:.3f}".format(a ) + " " + b
  1161.                         else:
  1162.                                 result = 'N/A'
  1163.                         return result
  1164.                
  1165.                 def set_w_h_video_scale():
  1166.                         self.spincw['adj'].set_value(float(Vars.video_width)) #mettere decimali se no non si vede
  1167.                         self.spincw['spinner'].set_sensitive(False)
  1168.                         self.spinch['adj'].set_value(float(Vars.video_height)) #mettere decimali se no non si vede
  1169.                         self.spinch['spinner'].set_sensitive(False)
  1170.                         if Vars.add_1_1_dar:
  1171.                                 self.box2['list'].append(["as input"])
  1172.                         Vars.add_1_1_dar = False                  
  1173.                                
  1174.                 #x Vars.info_str
  1175.                 Vars.info_str = ""
  1176.                 is_stream = 0
  1177.                 is_format = 0
  1178.                 for line in out.split('\n'):
  1179.                         line = line.strip()
  1180.                         if line.startswith('[STREAM]'):
  1181.                                 Vars.info_str = Vars.info_str + "STREAM "
  1182.                                 is_stream = 1
  1183.                         elif line.startswith('[/STREAM]'):
  1184.                                 Vars.info_str = Vars.info_str + "\n"
  1185.                                 is_stream = 0
  1186.                         elif (line.startswith('index=') and (is_stream == 1)):
  1187.                                 s = line
  1188.                                 info = s.split('=')[1]  
  1189.                                 Vars.info_str = Vars.info_str + info + ": "
  1190.                         elif (line.startswith('codec_name=') and (is_stream == 1)):
  1191.                                 s = line
  1192.                                 info = s.split('=')[1]
  1193.                                 if info == 'ac3':
  1194.                                         self.check_drc.set_sensitive(True)
  1195.                                         self.spin_drc["spinner"].set_sensitive(True)
  1196.                                         self.drc_test.set_sensitive(True)
  1197.                                 Vars.info_str = Vars.info_str + info + ", "
  1198.                         elif (line.startswith('profile=') and (is_stream == 1)):
  1199.                                 s = line
  1200.                                 info = s.split('=')[1]  
  1201.                                 Vars.info_str = Vars.info_str + "profile=" +info + ", "
  1202.                         elif (line.startswith('codec_type=') and (is_stream == 1)):
  1203.                                 s = line
  1204.                                 info = s.split('=')[1]
  1205.                                 Vars.info_str = Vars.info_str + info + ", "
  1206.                         elif (line.startswith('width=') and (is_stream == 1)):
  1207.                                 s = line
  1208.                                 info = s.split('=')[1]
  1209.                                 Vars.video_width = info
  1210.                                 Vars.info_str = Vars.info_str + info + "x"
  1211.                         elif (line.startswith('height=') and (is_stream == 1)):
  1212.                                 s = line
  1213.                                 info = s.split('=')[1]
  1214.                                 Vars.video_height = info
  1215.                                 Vars.info_str = Vars.info_str + info + ", "
  1216.                         elif (line.startswith('sample_aspect_ratio=') and (is_stream == 1)):
  1217.                                 s = line
  1218.                                 info = s.split('=')[1]  
  1219.                                 Vars.info_str = Vars.info_str + "SAR=" + info + ", "
  1220.                         elif (line.startswith('display_aspect_ratio=') and (is_stream == 1)):
  1221.                                 s = line
  1222.                                 info = s.split('=')[1]  
  1223.                                 Vars.info_str = Vars.info_str + "DAR=" + info + ", "
  1224.                         elif (line.startswith('pix_fmt=') and (is_stream == 1)):
  1225.                                 s = line
  1226.                                 info = s.split('=')[1]  
  1227.                                 Vars.info_str = Vars.info_str + info + ", "
  1228.                         elif (line.startswith('sample_rate=') and (is_stream == 1)):
  1229.                                 s = line
  1230.                                 info = s.split('=')[1]
  1231.                                 info = form_to_3(info)
  1232.                                 Vars.info_str = Vars.info_str + "samplerate=" + info + ", "
  1233.                         elif (line.startswith('channels=') and (is_stream == 1)):
  1234.                                 s = line
  1235.                                 info = s.split('=')[1]
  1236.                                 Vars.audio_channels = int(info)
  1237.                                 Vars.info_str = Vars.info_str + "channels=" + info + ", "
  1238.                         elif (line.startswith('r_frame_rate=') and (is_stream == 1)):
  1239.                                 s = line
  1240.                                 info = s.split('=')[1]
  1241.                                 a = info.split('/')[0]
  1242.                                 b = info.split('/')[1]
  1243.                                 a = float(a)
  1244.                                 b = float(b)
  1245.                                 if ((a > 0) and (b > 0)):
  1246.                                         c = float(a)/float(b)
  1247.                                         info = "{0:0.2f}".format(c)
  1248.                                         self.spinfr["adj"].set_value(c)
  1249.                                         Vars.info_str = Vars.info_str + info + " fps, "
  1250.                         elif (line.startswith('bit_rate=') and (is_stream == 1)):
  1251.                                 s = line
  1252.                                 info = s.split('=')[1]
  1253.                                 info = form_to_3(info)
  1254.                                 Vars.info_str = Vars.info_str + "bitrate=" + info + ", "
  1255.                         elif (line.startswith('TAG:language=') and (is_stream == 1)):
  1256.                                 s = line
  1257.                                 info = s.split('=')[1]  
  1258.                                 Vars.info_str = Vars.info_str + "lang=" + info + ", "
  1259.                         elif line.startswith('[FORMAT]'):
  1260.                                 Vars.info_str = Vars.info_str + "FORMAT "
  1261.                                 is_format = 1
  1262.                         elif line.startswith('[/FORMAT]'):
  1263.                                 #Vars.info_str = Vars.info_str + "/n"
  1264.                                 is_format = 0
  1265.                         elif (line.startswith('nb_streams=') and (is_format == 1)):
  1266.                                 s = line
  1267.                                 info = s.split('=')[1]  
  1268.                                 Vars.info_str = Vars.info_str + "streams=" + info + ", "
  1269.                         elif (line.startswith('duration=') and (is_format == 1)):
  1270.                                 s = line
  1271.                                 info = s.split('=')[1]  
  1272.                                 info = info.split('.')[0]
  1273.                                 self.entry_timein.set_text('0')
  1274.                                 self.entry_timeout.set_text(info)
  1275.                                 Vars.duration = info
  1276.                                 Vars.duration_in_sec = self.hms2sec(info)
  1277.                                 Vars.info_str = Vars.info_str + "duration=" + info + ", "
  1278.                         elif (line.startswith('size=') and (is_format == 1)):
  1279.                                 s = line
  1280.                                 info = s.split('=')[1]
  1281.                                 info = form_to_3(info)
  1282.                                 Vars.info_str = Vars.info_str + "size=" + info + ", "
  1283.                         elif (line.startswith('bit_rate=') and (is_format == 1)):
  1284.                                 s = line
  1285.                                 info = s.split('=')[1]
  1286.                                 info = form_to_3(info)
  1287.                                 Vars.info_str = Vars.info_str + "bitrate=" + info + ", "
  1288.                 set_w_h_video_scale()
  1289.                 self.f3_dur_file.set_label(Vars.duration)
  1290.                 self.textbuffer_info.set_text(Vars.info_str)
  1291.                 self.f3_run_file.set_tooltip_text(Vars.info_str)
  1292.                 self.check_map.set_tooltip_text(Vars.info_str)
  1293.                 self.check_time.set_tooltip_text(Vars.info_str)
  1294.                 Vars.in_file_size = self.humansize(Vars.filename)
  1295.        
  1296.         def on_butplay_clicked(self, button):
  1297.                 if Vars.ENCODING:
  1298.                         return
  1299.                 command = Vars.ffplay_ex + " \"" + Vars.filename + "\"" +"\n"
  1300.                 length = len(command)
  1301.                 self.terminal.feed_child(command, length)
  1302.                
  1303.         def on_butprobe_clicked(self, button):
  1304.                 if Vars.ENCODING:
  1305.                         return
  1306.                 command = Vars.ffprobe_ex + " \"" + Vars.filename + "\""  + " 2>&1 | grep 'Input\|Duration\|Stream'" + "\n"
  1307.                 length = len(command)
  1308.                 self.terminal.feed_child(command, length)        
  1309.                
  1310.         def on_butcrode_clicked(self, button):
  1311.                 # need ffmpeg
  1312.                 self.butcrode.set_sensitive(False)
  1313.                 if (Vars.time_start == 0):
  1314.                         command = Vars.ffmpeg_ex + " -i " + "\"" + Vars.filename + "\"" + " -ss 60 -t 1 -vf cropdetect -f null - 2>&1 | awk \'/crop/ { print $NF }\' | tail -1"
  1315.                 else:
  1316.                         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"
  1317.                 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
  1318.                 out, err =  p.communicate()
  1319.                 out = out.decode()
  1320.                 for line in out.split('\n'):
  1321.                         line = line.strip()
  1322.                         if "crop=" in line:  
  1323.                                 aa = line.split('crop=', 1)
  1324.                                 aaa = aa[1]
  1325.                                 listdata = aaa.split(':')
  1326.                                 w = listdata[0]
  1327.                                 h = listdata[1]
  1328.                                 offx = listdata[2]
  1329.                                 offy = listdata[3]
  1330.                                 ctop = int(offy)
  1331.                                 cbot = int(Vars.video_height) - int(offy) -int(h)
  1332.                                 cleft = int(offx)
  1333.                                 cright = int(Vars.video_width) - int(offx) -int(w)
  1334.                                 self.spinct['adj'].set_value(float(ctop))
  1335.                                 self.spincb['adj'].set_value(float(cbot))
  1336.                                 self.spincl['adj'].set_value(float(cleft))
  1337.                                 self.spincr['adj'].set_value(float(cright))  
  1338.                                 break
  1339.                 self.butcrode.set_sensitive(True)
  1340.                
  1341.         def on_buttest_clicked(self, button):
  1342.                 if Vars.ENCODING:
  1343.                         return
  1344.                 # -map preview: only with none -vf option  
  1345.                 if (Vars.maps_str == ""):
  1346.                         command = Vars.ffplay_ex + " \"" + Vars.filename + "\" " \
  1347.                          + " " + Vars.time_final_str + " " \
  1348.                          + "-vf "  + Vars.filter_test_str + "\n"
  1349.                 else:
  1350.                         command = Vars.ffmpeg_ex + " -i \"" + Vars.filename + "\" " \
  1351.                          + Vars.maps_str  + " " + Vars.time_final_str + " "
  1352.                         if (Vars.filter_test_str != ""):
  1353.                                 command = command + " -vf "  + Vars.filter_test_str
  1354.                         command = command +  " -c copy -f matroska - | ffplay -" + "\n"
  1355.                 length = len(command)
  1356.                 self.terminal.feed_child(command, length)
  1357.                
  1358.         def on_buttestspl_clicked(self, button):
  1359.                 if Vars.ENCODING:
  1360.                         return
  1361.                 command = Vars.ffplay_ex + " \"" + Vars.filename + "\" " \
  1362.                   + " " + Vars.time_final_str + " " \
  1363.                   + " -vf \"split[a][b]; [a]pad=iw:(ih*2)+4:color=888888 [src]; [b]" \
  1364.                   + Vars.filter_test_str + " [filt]; [src][filt]overlay=((main_w - w)/2):main_h/2\"" + "\n"
  1365.                 length = len(command)
  1366.                 self.terminal.feed_child(command, length)
  1367.        
  1368.         def on_but_volume_det_clicked(self, button):
  1369.                        
  1370.                 def finish_voldet(meanv, maxv):
  1371.                         self.label_meanvol.set_label(meanv)
  1372.                         self.label_maxvol.set_label(maxv)
  1373.                         self.but_volume_det.set_label("volume detected")
  1374.                         self.voldet_spin.stop()
  1375.                         self.voldet_spin.set_sensitive(False)
  1376.                
  1377.                 def my_thread():        
  1378.                         command = [Vars.ffmpeg_ex, '-i', Vars.filename, '-vn', '-af', 'volumedetect', '-f', 'null', '/dev/null']
  1379.                         p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
  1380.                         while True:
  1381.                                 line = p.stderr.read()
  1382.                                 if not line:
  1383.                                         break
  1384.                                 out = line.decode()
  1385.                                 for line in out.split('\n'):
  1386.                                         line = line.strip()
  1387.                                         if "mean_volume:" in line:  
  1388.                                                 aa = line.split('mean_volume:', 1)
  1389.                                                 mea_vol_det = aa[1]
  1390.                                                 meanv = "Mean vol: " + mea_vol_det
  1391.                                         if "max_volume:" in line:  
  1392.                                                 aa = line.split('max_volume:', 1)
  1393.                                                 max_vol_det = aa[1]
  1394.                                                 maxv = "Max vol: " + max_vol_det
  1395.                         p.communicate()
  1396.                         finish_voldet(meanv, maxv)
  1397.                
  1398.                 if Vars.VOLDT_DONE:
  1399.                         return
  1400.                 Vars.VOLDT_DONE = True
  1401.                 self.voldet_spin.set_sensitive(True)
  1402.                 self.voldet_spin.start()        
  1403.                 self.but_volume_det.set_label("Wait")  
  1404.                 threading.Thread(target=my_thread).start()
  1405.        
  1406.         def on_volume_clicked(self, button):
  1407.                 ratio = 1
  1408.                 self.label_ratio_val.set_label("1")
  1409.                 Vars.final_af_str = ""
  1410.                 db = self.spin_db["adj"].get_value()
  1411.                 if (db != 0.00):
  1412.                         ratio = pow(10, (db/20.0))
  1413.                         ratio = float("{0:.3f}".format(ratio))    
  1414.                         self.label_ratio_val.set_label(str(ratio))
  1415.                         if self.check_vol.get_active():
  1416.                                 Vars.final_af_str = "volume=" + str(ratio)
  1417.                         else:
  1418.                                 Vars.final_af_str = ""
  1419.                 self.make_p3_out_command()
  1420.                
  1421.         def on_drc_clicked(self, buttom):
  1422.                 Vars.ac3_drc = ""
  1423.                 if self.check_drc.get_active():
  1424.                         val = self.spin_drc["adj"].get_value()
  1425.                         Vars.ac3_drc = "-drc_scale " + str(int(val))
  1426.                        
  1427.         def on_drc_test(self, button):
  1428.                 command = Vars.ffplay_ex + " \"" + Vars.filename + "\" " + Vars.ac3_drc + "\n"
  1429.                 length = len(command)
  1430.                 self.terminal.feed_child(command, length)
  1431.  
  1432.         def on_compand_reset(self, button):
  1433.                 self.entry_compand.set_text(Vars.compinit)
  1434.                 self.on_compand_clicked(button)
  1435.  
  1436.         def on_compand_clicked(self, button):
  1437.                 Vars.compand_time = 0
  1438.                 Vars.compand_data = ""
  1439.                
  1440.                 timein_ent = self.entry_timecomp.get_chars(0, -1)
  1441.                 if (timein_ent != ""):
  1442.                         if timein_ent.isdigit():
  1443.                                 timein = int(timein_ent)
  1444.                                 if Vars.duration_in_sec != 0:
  1445.                                         if timein > Vars.duration_in_sec:
  1446.                                                 self.entry_entry_timecomp.set_text(str(Vars.duration_in_sec -1))
  1447.                                                 timein = Vars.duration_in_sec -1
  1448.                         else:  
  1449.                                 timein = self.hms2sec(timein_ent)
  1450.                                 if Vars.duration_in_sec != 0:
  1451.                                         if timein > Vars.duration_in_sec:
  1452.                                                 self.entry_entry_timecomp.set_text(str(self.sec2hms(Vars.duration_in_sec -1)))
  1453.                                                 timein = Vars.duration_in_sec -1
  1454.                         Vars.compand_time = timein
  1455.                 if self.check_compand.get_active():
  1456.                         compand_data = self.entry_compand.get_chars(0, -1)
  1457.                         if Vars.audio_channels == 6:
  1458.                                 Vars.compand_data = "aformat=channel_layouts=stereo,aresample=matrix_encoding=dplii,compand=" + compand_data
  1459.                         else:
  1460.                                 Vars.compand_data = "aformat=channel_layouts=stereo,compand=" + compand_data
  1461.                 self.make_p3_out_command()
  1462.  
  1463.  
  1464.         def on_compand_test(self, button):
  1465.                 if Vars.compand_data != "":
  1466.                         command = Vars.ffplay_ex + " -f lavfi \'amovie=" + Vars.filename + " :sp=" + str(Vars.compand_time) + " , " + Vars.compand_data + "  ,ebur128=video=1:meter=18:peak=true [out0][out1]\'" + "\n"
  1467.                 else:
  1468.                         command = Vars.ffplay_ex + " -f lavfi \'amovie=" + Vars.filename + " :sp=" + str(Vars.compand_time) + "  ,ebur128=video=1:meter=18:peak=true [out0][out1]\'" + "\n"
  1469.                 length = len(command)
  1470.                 self.terminal.feed_child(command, length)
  1471.  
  1472.  
  1473.         def on_map_clicked(self, button):
  1474.                 self.map_label.set_label("")
  1475.                 Vars.maps_str = ""
  1476.                 if self.check_map.get_active():
  1477.                         map_in = self.entry_map.get_chars(0, -1)
  1478.                         if (map_in != ""):
  1479.                                 map_l = map_in.split(",")
  1480.                                 for i in range(len(map_l)):
  1481.                                         if Vars.maps_str == "":
  1482.                                                 Vars.maps_str = Vars.maps_str + "-map " + map_l[i]
  1483.                                         else:
  1484.                                                 Vars.maps_str = Vars.maps_str + " -map " + map_l[i]
  1485.                                 self.map_label.set_label(Vars.maps_str)
  1486.                 self.outfilter()
  1487.                 self.make_p3_out_command()
  1488.                
  1489.         def on_time_clicked(self, button):
  1490.                 Vars.time_final_str = ""
  1491.                        
  1492.                 if self.check_time.get_active():
  1493.                         timein = 0
  1494.                         timeout = 0
  1495.                         timedur = 0
  1496.                         timein_ent = self.entry_timein.get_chars(0, -1)
  1497.                         if (timein_ent != ""):
  1498.                                 if timein_ent.isdigit():
  1499.                                         timein = int(timein_ent)
  1500.                                         if Vars.duration_in_sec != 0:
  1501.                                                 if timein > Vars.duration_in_sec:
  1502.                                                         self.entry_timein.set_text(str(Vars.duration_in_sec -1))
  1503.                                                         return
  1504.                                 else:  
  1505.                                         timein = self.hms2sec(timein_ent)
  1506.                                         if Vars.duration_in_sec != 0:
  1507.                                                 if timein > Vars.duration_in_sec:
  1508.                                                         self.entry_timein.set_text(str(self.sec2hms(Vars.duration_in_sec -1)))
  1509.                                                         return
  1510.                         timeout_ent = self.entry_timeout.get_chars(0, -1)
  1511.                         if (timeout_ent != ""):
  1512.                                 if timeout_ent.isdigit():
  1513.                                         timeout = int(timeout_ent)
  1514.                                         if Vars.duration_in_sec != 0:
  1515.                                                 if timeout > Vars.duration_in_sec:
  1516.                                                         self.entry_timeout.set_text(str(Vars.duration_in_sec))
  1517.                                                         return
  1518.                                         timedur = timeout - timein
  1519.                                 else:  
  1520.                                         timeout = self.hms2sec(timeout_ent)
  1521.                                         if Vars.duration_in_sec != 0:
  1522.                                                 if timeout > Vars.duration_in_sec:
  1523.                                                         self.entry_timeout.set_text(Vars.duration)
  1524.                                                         return
  1525.                                         timedur = timeout - timein
  1526.                         if (timein != 0):
  1527.                                 Vars.time_final_str = Vars.time_final_str + " -ss " + str(timein)
  1528.                                 Vars.time_start = timein
  1529.                         if (timedur > 0):
  1530.                                 Vars.time_final_str = Vars.time_final_str + " -t " + str(timedur)
  1531.                 self.time_label.set_text(Vars.time_final_str)
  1532.                 self.outfilter()
  1533.                 self.make_p3_out_command()
  1534.        
  1535.         def on_codec_audio_changed(self, button):
  1536.                 Vars.acodec_is = ""
  1537.                 audio_codec = self.box_ac['cbox'].get_active()
  1538.                 model = self.box_ac['cbox'].get_model()
  1539.                 item = model[audio_codec]
  1540.                 audio_codec = item[0]
  1541.                 self.spin_ac['spinner'].set_sensitive(True)
  1542.                 self.box_audio_ch['cbox'].set_sensitive(True)
  1543.                 self.box_audio_rate['cbox'].set_sensitive(True)
  1544.                 if (audio_codec == "libfaac quality (Q)"): # aaq        
  1545.                         self.adj_change(self.spin_ac['adj'], 100, 80, 160, 10, 1)
  1546.                         self.spin_ac['adj'].set_value(100.0)
  1547.                         self.spin_ac['spinner'].set_tooltip_text(Tips.faac_q_str)
  1548.                         Vars.acodec_is = "faaq"
  1549.                 elif (audio_codec == "aac_fdk CBR (Kb/s)"): # aac_fdk cbr 64-320 def 128
  1550.                         self.adj_change(self.spin_ac['adj'], 128, 64, 320, 8, 2)
  1551.                         self.spin_ac['adj'].set_value(128.0)
  1552.                         self.spin_ac['spinner'].set_tooltip_text(Tips.aak_cbr_str)
  1553.                         Vars.acodec_is = "fdkaac"
  1554.                 elif (audio_codec == "lame mp3 CBR (Kb/s)"): # lame cbr 32 - 320 def 128
  1555.                         self.adj_change(self.spin_ac['adj'], 128, 32, 320, 8, 2)
  1556.                         self.spin_ac['adj'].set_value(128.0)
  1557.                         self.spin_ac['spinner'].set_tooltip_text(Tips.lamecbr_str)
  1558.                         Vars.acodec_is = "lame"
  1559.                 elif (audio_codec == "lame mp3 VBR (Q)"): # lame vbr 0 - 9 def 6
  1560.                         self.adj_change(self.spin_ac['adj'], 6, 0, 9, 1, 1)
  1561.                         self.spin_ac['adj'].set_value(6.0)
  1562.                         self.spin_ac['spinner'].set_tooltip_text(Tips.lamevbr_str)
  1563.                         Vars.acodec_is = "lameq"
  1564.                 elif (audio_codec == "aac native CBR (Kb/s)"): # aac cbr 32 - 320 def 128
  1565.                         self.adj_change(self.spin_ac['adj'], 128, 32, 320, 8, 2)
  1566.                         self.spin_ac['adj'].set_value(128.0)
  1567.                         self.spin_ac['spinner'].set_tooltip_text(Tips.aac_cbr_str)
  1568.                         Vars.acodec_is = "aacn"
  1569.                 elif (audio_codec == "audio copy"): # copy
  1570.                         self.spin_ac['spinner'].set_sensitive(False)
  1571.                         self.spin_ac['spinner'].set_tooltip_text('')
  1572.                         self.box_audio_ch['cbox'].set_sensitive(False)
  1573.                         self.box_audio_rate['cbox'].set_sensitive(False)
  1574.                         Vars.acodec_is = "acopy"
  1575.                 elif (audio_codec == "no audio"): # none
  1576.                         self.spin_ac['spinner'].set_sensitive(False)
  1577.                         self.spin_ac['spinner'].set_tooltip_text('')
  1578.                         self.box_audio_ch['cbox'].set_sensitive(False)
  1579.                         self.box_audio_rate['cbox'].set_sensitive(False)
  1580.                         Vars.acodec_is = "anone"
  1581.                 elif (audio_codec == "aacplus (32 Kb/s)"): # aac+32
  1582.                         self.spin_ac['spinner'].set_sensitive(False)
  1583.                         self.spin_ac['spinner'].set_tooltip_text('')
  1584.                         self.box_audio_ch['cbox'].set_sensitive(False)
  1585.                         self.box_audio_ch['cbox'].set_active(0)
  1586.                         Vars.acodec_is = "aap32"
  1587.                 elif (audio_codec == "aacplus (64 Kb/s)"): # aac+64
  1588.                         self.spin_ac['spinner'].set_sensitive(False)
  1589.                         self.spin_ac['spinner'].set_tooltip_text('')
  1590.                         self.box_audio_ch['cbox'].set_sensitive(False)
  1591.                         self.box_audio_ch['cbox'].set_active(0)
  1592.                         Vars.acodec_is = "aap64"
  1593.                 self.on_codec_clicked(button)
  1594.  
  1595.         def on_codec_video_changed(self, button):
  1596.                 self.on_codec_clicked(button)
  1597.  
  1598.         def on_codec_vrc_changed(self, button):
  1599.                 video_rc = self.box_vrc['cbox'].get_active() #0 crf, 1 kb/s
  1600.                 video_codec = self.box_vcodec['cbox'].get_active() #0 x264, 1 -vcopy
  1601.                 model = self.box_vcodec['cbox'].get_model()
  1602.                 item = model[video_codec]
  1603.                 video_codec = item[0]
  1604.                 if (video_rc == 0):
  1605.                         self.adj_change(self.spin_vc['adj'], 21.3, 15, 40, 0.1, 1)
  1606.                         self.spin_vc['adj'].set_value(21.3)
  1607.                         self.check_2pass.set_active(False)
  1608.                         self.check_2pass.set_sensitive(False)
  1609.                 elif (video_rc == 1) and (video_codec == "mpeg4" ):
  1610.                         self.adj_change(self.spin_vc['adj'], 1200, 300, 5000, 100, 100)
  1611.                         self.spin_vc['adj'].set_value(1200.0)
  1612.                         self.check_2pass.set_sensitive(True)
  1613.                 elif (video_rc == 1):
  1614.                         self.adj_change(self.spin_vc['adj'], 730, 300, 4000, 10, 100)
  1615.                         self.spin_vc['adj'].set_value(730.0)
  1616.                         self.check_2pass.set_sensitive(True)    
  1617.  
  1618.         def on_codec_clicked(self, button):
  1619.                 Vars.final_codec_str = ""
  1620.                 #audio
  1621.                 Vars.audio_codec_str = self.audio_codec()
  1622.                 # video
  1623.                 Vars.vcodec_is = ""
  1624.                 video_codec = self.box_vcodec['cbox'].get_active() #0 x264, 1 -vcopy
  1625.                 model = self.box_vcodec['cbox'].get_model()
  1626.                 item = model[video_codec]
  1627.                 video_codec = item[0]
  1628.                 if (video_codec == "video copy"):
  1629.                         Vars.vcodec_is = "vcopy"
  1630.                         Vars.video_codec_str_more = self.v_codec_vcopy()
  1631.                 elif (video_codec == "mpeg4"): #mpeg4
  1632.                         Vars.video_codec_str_more = self.v_codec_mpeg4()
  1633.                         Vars.vcodec_is = "mpeg4"
  1634.                 elif (video_codec == "libx264"):
  1635.                         #libx264
  1636.                         Vars.video_codec_str_more = self.v_codec_x264()
  1637.                         Vars.vcodec_is = "x264"
  1638.                 elif (video_codec == "no video"):
  1639.                         #-vn
  1640.                         Vars.video_codec_str_more = self.v_codec_vn()
  1641.                         Vars.vcodec_is = "none"
  1642.                 #
  1643.                 self.on_codec_vrc_value_change(button)
  1644.                        
  1645.         def on_codec_vrc_value_change(self, button):
  1646.                 Vars.video_codec_str = ""
  1647.                 if (Vars.vcodec_is == "x264"): #x264
  1648.                         #rc
  1649.                         video_rc = self.box_vrc['cbox'].get_active() #0 crf, 1 kb/s
  1650.                         if (video_rc == 0):    
  1651.                                 video_codec_str = "-c:v libx264 " + "-crf " + str(self.spin_vc['adj'].get_value()) + " " + Vars.video_codec_str_more
  1652.                         elif (video_rc == 1):
  1653.                                 video_codec_str = "-c:v libx264 " + "-b:v " + str(int(self.spin_vc['adj'].get_value())) + "k " + Vars.video_codec_str_more
  1654.                 elif (Vars.vcodec_is == "mpeg4"):
  1655.                         video_codec_str = "-c:v mpeg4 -mpv_flags strict_gop " + "-b:v " + str(int(self.spin_vc['adj'].get_value())) + "k"
  1656.                 else:
  1657.                         video_codec_str = Vars.video_codec_str_more
  1658.                        
  1659.                 Vars.video_codec_str = video_codec_str
  1660.                        
  1661.                 #self.f3v_label_out.set_label(video_codec_str)
  1662.                 Vars.final_codec_str = Vars.audio_codec_str + " " + video_codec_str
  1663.                 self.make_p3_out_command()
  1664.                
  1665.         def audio_codec(self):
  1666.                 # channels
  1667.                 audio_codec_str = ""
  1668.                 channel_str = "-ac 2"
  1669.                 channel = self.box_audio_ch['cbox'].get_active()
  1670.                 if channel == 1:
  1671.                         channel_str = "-ac 1"
  1672.                 # sample rate
  1673.                 sample_str = "-ar 48k"
  1674.                 sample = self.box_audio_rate['cbox'].get_active()
  1675.                 if sample == 1:
  1676.                         sample_str = "-ar 44.1k"
  1677.                 # acodec
  1678.                 if (Vars.acodec_is == "faaq"):
  1679.                         audio_codec_str = "-c:a libfaac -q:a "
  1680.                         quality_faac = self.spin_ac['adj'].get_value()
  1681.                         audio_codec_str = audio_codec_str + str(int(quality_faac)) + " " + sample_str + " " + channel_str
  1682.                 elif (Vars.acodec_is == "aap64"):
  1683.                         audio_codec_str = "-c:a libaacplus -b:a 64k" + " " + sample_str + " " + channel_str
  1684.                 elif (Vars.acodec_is == "aap32"):
  1685.                         audio_codec_str = "-c:a libaacplus -b:a 32k" + " " + sample_str + " " + channel_str
  1686.                 elif (Vars.acodec_is == "anone"):
  1687.                         audio_codec_str = "-an"
  1688.                 elif (Vars.acodec_is == "acopy"):
  1689.                         audio_codec_str = "-c:a copy"
  1690.                 elif (Vars.acodec_is == "fdkaac"):
  1691.                         audio_codec_str = "-c:a libfdk_aac -b:a "
  1692.                         aakcbr = self.spin_ac['adj'].get_value()
  1693.                         audio_codec_str = audio_codec_str + str(int(aakcbr)) + "k " + sample_str + " " + channel_str
  1694.                 elif (Vars.acodec_is == "lame"):
  1695.                         audio_codec_str = "-c:a libmp3lame -b:a "
  1696.                         lamecbr = self.spin_ac['adj'].get_value()
  1697.                         audio_codec_str = audio_codec_str + str(int(lamecbr)) + "k " + sample_str + " " + channel_str
  1698.                 elif (Vars.acodec_is == "lameq"):
  1699.                         audio_codec_str = "-c:a libmp3lame -q:a "  
  1700.                         lamevbr = self.spin_ac['adj'].get_value()
  1701.                         audio_codec_str = audio_codec_str + str(int(lamevbr)) + " " + sample_str + " " + channel_str
  1702.                 elif (Vars.acodec_is == "aacn"):
  1703.                         audio_codec_str = "-c:a aac -strict -2 -b:a "
  1704.                         aaccbr = self.spin_ac['adj'].get_value()
  1705.                         audio_codec_str = audio_codec_str + str(int(aaccbr)) + "k " + sample_str + " " + channel_str
  1706.                 return audio_codec_str
  1707.                
  1708.         def v_codec_vcopy(self):        
  1709.                 self.box_vrc['cbox'].set_active(0)
  1710.                 self.box_vrc['cbox'].set_sensitive(False)
  1711.                 self.spin_vc['spinner'].set_sensitive(False)
  1712.                 self.box_3v_preset['cbox'].set_active(2)
  1713.                 self.box_3v_preset['cbox'].set_sensitive(False)
  1714.                 self.box_3v_tune['cbox'].set_active(0)
  1715.                 self.box_3v_tune['cbox'].set_sensitive(False)
  1716.                 self.box_3v_x264opts['cbox'].set_active(0)
  1717.                 self.box_3v_x264opts['cbox'].set_sensitive(False)
  1718.                 self.check_3v_opencl.set_active(False)
  1719.                 self.check_3v_opencl.set_sensitive(False)
  1720.                 self.check_cpu.set_active(False)
  1721.                 self.check_cpu.set_sensitive(False)
  1722.                 video_codec_str = "-c:v copy"
  1723.                 return video_codec_str
  1724.  
  1725.         def v_codec_vn(self):  
  1726.                 self.box_vrc['cbox'].set_active(0)
  1727.                 self.box_vrc['cbox'].set_sensitive(False)
  1728.                 self.spin_vc['spinner'].set_sensitive(False)
  1729.                 self.box_3v_preset['cbox'].set_active(2)
  1730.                 self.box_3v_preset['cbox'].set_sensitive(False)
  1731.                 self.box_3v_tune['cbox'].set_active(0)
  1732.                 self.box_3v_tune['cbox'].set_sensitive(False)
  1733.                 self.box_3v_x264opts['cbox'].set_active(0)
  1734.                 self.box_3v_x264opts['cbox'].set_sensitive(False)
  1735.                 self.check_3v_opencl.set_active(False)
  1736.                 self.check_3v_opencl.set_sensitive(False)
  1737.                 self.check_cpu.set_active(False)
  1738.                 self.check_cpu.set_sensitive(False)
  1739.                 video_codec_str = "-vn"
  1740.                 self.box_oth_container['cbox'].set_active(3)
  1741.                 return video_codec_str
  1742.  
  1743.         def v_codec_x264(self):
  1744.                 video_codec_str = ""
  1745.                 if "mpeg4" in Vars.p3_command:
  1746.                         self.box_vrc['cbox'].set_active(0)
  1747.                         self.box_3v_tune['cbox'].set_active(0)
  1748.                 self.box_vrc['cbox'].set_sensitive(True)
  1749.                 self.spin_vc['spinner'].set_sensitive(True)
  1750.                 self.box_3v_preset['cbox'].set_sensitive(True)
  1751.                 self.box_3v_tune['cbox'].set_sensitive(True)
  1752.                 self.box_3v_x264opts['cbox'].set_sensitive(True)
  1753.                 self.check_3v_opencl.set_sensitive(True)
  1754.                 self.check_cpu.set_sensitive(True)
  1755.                 #preset
  1756.                 preset_str = ""
  1757.                 preset = self.box_3v_preset['cbox'].get_active()
  1758.                 # 0 -superfast, 1 -veryfast, 2 -faster, 3 -fast, 4 -medium, 5 -slow, default: 2 faster
  1759.                 if (preset == 0):
  1760.                         preset_str = "-preset superfast "
  1761.                 if (preset == 1):
  1762.                         preset_str = "-preset veryfast "
  1763.                 if (preset == 2):
  1764.                         preset_str = "-preset faster "
  1765.                 if (preset == 3):
  1766.                         preset_str = "-preset fast "
  1767.                 if (preset == 4):
  1768.                         preset_str = "-preset medium "
  1769.                 if (preset == 5):
  1770.                         preset_str = "-preset slow "
  1771.                 # tune  film, animation, grain, stillimage
  1772.                 tune = self.box_3v_tune['cbox'].get_active()
  1773.                 if (tune == 0):
  1774.                         preset_str = preset_str + "-tune film"
  1775.                 if (tune == 1):
  1776.                         preset_str = preset_str + "-tune animation"
  1777.                 if (tune == 2):
  1778.                         preset_str = preset_str + "-tune grain"
  1779.                 if (tune == 3):
  1780.                         preset_str = preset_str + "-tune stillimage"
  1781.                 video_codec_str = preset_str
  1782.                 #x264opts      
  1783.                 if (self.box_3v_x264opts['cbox'].get_active() == 1):
  1784.                         video_codec_str = video_codec_str + " -x264opts ssim"
  1785.                 else:
  1786.                         video_codec_str = video_codec_str + " -x264opts ref=4:bframes=4:direct=auto:aq-strength=1.3:ssim"
  1787.                 #opencl
  1788.                 if self.check_3v_opencl.get_active():
  1789.                         video_codec_str = video_codec_str + ":opencl"
  1790.                 return video_codec_str
  1791.  
  1792.         def v_codec_mpeg4(self):
  1793.                 if not ("mpeg4" in Vars.p3_command):
  1794.                         self.box_vrc['cbox'].set_active(1)
  1795.                         self.on_codec_vrc_changed(1)
  1796.                 self.box_vrc['cbox'].set_sensitive(False)
  1797.                 self.spin_vc['spinner'].set_sensitive(True)
  1798.                 self.box_3v_preset['cbox'].set_sensitive(False)
  1799.                 self.box_3v_tune['cbox'].set_sensitive(False)
  1800.                 self.box_3v_x264opts['cbox'].set_sensitive(False)
  1801.                 self.check_3v_opencl.set_active(False)
  1802.                 self.check_3v_opencl.set_sensitive(False)
  1803.                 self.check_cpu.set_active(False)
  1804.                 self.check_cpu.set_sensitive(False)
  1805.                 video_codec_str = ""
  1806.                 return video_codec_str
  1807.  
  1808.         def on_preset_changed(self, button):
  1809.                 self.on_codec_clicked(button)
  1810.                
  1811.         def on_f3_other_clicked(self, button):
  1812.                 Vars.final_other_str = ""
  1813.                 Vars.debug = 0
  1814.                 Vars.first_pass = 0
  1815.                 Vars.n_pass = 1
  1816.                 if self.check_nometa.get_active():
  1817.                         Vars.final_other_str = "-map_metadata -1"
  1818.                 if self.check_2pass.get_active():
  1819.                                 Vars.first_pass = 1
  1820.                                 Vars.n_pass = 2
  1821.                 if self.check_cpu.get_active():
  1822.                         if (Vars.final_other_str == ""):
  1823.                                 Vars.final_other_str = "-threads 3"
  1824.                         else:
  1825.                                 Vars.final_other_str = Vars.final_other_str + " " + "-threads 3"
  1826.                 if self.check_scopy.get_active():
  1827.                         if (Vars.final_other_str == ""):
  1828.                                 Vars.final_other_str = "-c:s copy"
  1829.                         else:
  1830.                                 Vars.final_other_str = Vars.final_other_str + " " + "-c:s copy"
  1831.                 if self.check_debug.get_active():
  1832.                                 Vars.debug = 1
  1833.                 self.make_p3_out_command()
  1834.                
  1835.         def on_container_changed(self,button):
  1836.                
  1837.                 def full_vcodec_list(selected):
  1838.                         self.box_vcodec['cbox'].disconnect_by_func(self.on_codec_video_changed)
  1839.                         self.box_vcodec['list'].clear()
  1840.                         self.box_vcodec['list'].append(["libx264"])
  1841.                         self.box_vcodec['list'].append(["video copy"])
  1842.                         self.box_vcodec['list'].append(["mpeg4"])
  1843.                         self.box_vcodec['list'].append(["no video"])
  1844.                         self.box_vcodec['cbox'].connect("changed", self.on_codec_video_changed)
  1845.                         self.box_vcodec['cbox'].set_active(selected)
  1846.                         Vars.vcodec_list = "full"
  1847.                
  1848.                 def avi_vcodec_list(selected):
  1849.                         self.box_vcodec['cbox'].disconnect_by_func(self.on_codec_video_changed)
  1850.                         self.box_vcodec['list'].clear()
  1851.                         self.box_vcodec['list'].append(["video copy"])
  1852.                         self.box_vcodec['list'].append(["mpeg4"])
  1853.                         self.box_vcodec['list'].append(["no video"])
  1854.                         self.box_vcodec['cbox'].connect("changed", self.on_codec_video_changed)
  1855.                         self.box_vcodec['cbox'].set_active(selected)
  1856.                         Vars.vcodec_list = "avi"
  1857.                        
  1858.                 def mka_vcodec_list(selected):
  1859.                         self.box_vcodec['cbox'].disconnect_by_func(self.on_codec_video_changed)
  1860.                         self.box_vcodec['list'].clear()
  1861.                         self.box_vcodec['list'].append(["no video"])
  1862.                         self.box_vcodec['cbox'].connect("changed", self.on_codec_video_changed)
  1863.                         self.box_vcodec['cbox'].set_active(selected)
  1864.                         Vars.vcodec_list = "mka"
  1865.                
  1866.                 def full_acodec_list(selected):
  1867.                         self.box_ac['cbox'].disconnect_by_func(self.on_codec_audio_changed)
  1868.                         self.box_ac['list'].clear()
  1869.                         self.box_ac['list'].append(["libfaac quality (Q)"])
  1870.                         self.box_ac['list'].append(["aacplus (64 Kb/s)"])
  1871.                         self.box_ac['list'].append(["aacplus (32 Kb/s)"])
  1872.                         self.box_ac['list'].append(["no audio"])
  1873.                         self.box_ac['list'].append(["audio copy"])
  1874.                         self.box_ac['list'].append(["aac_fdk CBR (Kb/s)"])
  1875.                         self.box_ac['list'].append(["lame mp3 CBR (Kb/s)"])
  1876.                         self.box_ac['list'].append(["lame mp3 VBR (Q)"])
  1877.                         self.box_ac['list'].append(["aac native CBR (Kb/s)"])
  1878.                         self.box_ac['cbox'].connect("changed", self.on_codec_audio_changed)
  1879.                         self.box_ac['cbox'].set_active(selected)
  1880.                         Vars.acodec_list = "full"
  1881.                                
  1882.                 def avi_acodec_list(selected):
  1883.                         self.box_ac['cbox'].disconnect_by_func(self.on_codec_audio_changed)
  1884.                         self.box_ac['list'].clear()
  1885.                         self.box_ac['list'].append(["no audio"])
  1886.                         self.box_ac['list'].append(["audio copy"])
  1887.                         self.box_ac['list'].append(["lame mp3 CBR (Kb/s)"])
  1888.                         self.box_ac['list'].append(["lame mp3 VBR (Q)"])
  1889.                         self.box_ac['cbox'].connect("changed", self.on_codec_audio_changed)
  1890.                         self.box_ac['cbox'].set_active(selected)
  1891.                         Vars.acodec_list = "avi"
  1892.                        
  1893.                 container = self.box_oth_container['cbox'].get_active()        
  1894.                 if (container == 0):
  1895.                         Vars.container_str = "-f matroska"
  1896.                         self.check_scopy.set_sensitive(True)
  1897.                         Vars.ext = ".mkv"
  1898.                         if Vars.acodec_list != "full":
  1899.                                 full_acodec_list(0)
  1900.                         if Vars.vcodec_list != "full":
  1901.                                 full_vcodec_list(0)            
  1902.                 elif (container == 1):
  1903.                         Vars.container_str = "-f mp4"
  1904.                         self.check_scopy.set_active(False)
  1905.                         self.check_scopy.set_sensitive(False)
  1906.                         Vars.ext = ".mp4"
  1907.                         if Vars.acodec_list != "full":
  1908.                                 full_acodec_list(0)
  1909.                         if Vars.vcodec_list != "full":
  1910.                                 full_vcodec_list(0)
  1911.                 elif (container == 2):
  1912.                         Vars.container_str = "-f avi"
  1913.                         self.check_scopy.set_active(False)
  1914.                         self.check_scopy.set_sensitive(False)
  1915.                         if Vars.acodec_list != "avi":
  1916.                                 avi_acodec_list(2)
  1917.                         if Vars.vcodec_list != "avi":
  1918.                                 avi_vcodec_list(1)
  1919.                         Vars.ext = ".avi"
  1920.                 elif (container == 3):
  1921.                         Vars.container_str = "-f matroska"
  1922.                         self.check_scopy.set_sensitive(False)
  1923.                         if Vars.acodec_list != "full":
  1924.                                 full_acodec_list(0)
  1925.                         if Vars.vcodec_list != "mka":
  1926.                                 mka_vcodec_list(0)
  1927.                         Vars.ext = ".mka"
  1928.                 self.check_out_file()
  1929.                 self.make_p3_out_command()
  1930.                
  1931.         def on_but_f3_run_clicked(self, button):
  1932.        
  1933.                 def restore_dir_button(): # if is changed during encoding
  1934.                         select = self.out_dir_chooserbut.get_uri()
  1935.                         decoded = url2pathname(select)
  1936.                         newdir = decoded.split('//')[1]
  1937.                         if (newdir != Vars.outdir):
  1938.                                 self.out_dir_chooserbut.disconnect_by_func(self.dir_changed)
  1939.                                 Vars.first_run = 0
  1940.                                 acturi = "file://" + os.getcwd()
  1941.                                 self.out_dir_chooserbut.set_uri(acturi)
  1942.                                 self.out_dir_chooserbut.connect("selection-changed", self.dir_changed)
  1943.                                
  1944.                 def restore_file_button():  # if is changed during encoding
  1945.                         select = self.filechooserbutton.get_filename()
  1946.                         if (select != Vars.filename):
  1947.                                 self.filechooserbutton.disconnect_by_func(self.file_changed)
  1948.                                 self.filechooserbutton.set_filename(Vars.filename)
  1949.                                 self.filechooserbutton.connect("file-set", self.file_changed)
  1950.                                
  1951.                 def clear_ff_file():
  1952.                         if os.path.exists(Vars.outdir + '/' + 'ffmpeg2pass-0.log'):
  1953.                                 os.remove(Vars.outdir + '/' + 'ffmpeg2pass-0.log')
  1954.                         if os.path.exists(Vars.outdir + '/' + 'ffmpeg2pass-0.log.mbtree'):
  1955.                                 os.remove(Vars.outdir + '/' + 'ffmpeg2pass-0.log.mbtree')
  1956.                         if os.path.exists(Vars.outdir + '/' + 'x264_lookahead.clbin'):
  1957.                                 os.remove(Vars.outdir + '/' + 'x264_lookahead.clbin')
  1958.                
  1959.                 def end_run():
  1960.                         if (Vars.eff_pass == 0) and (Vars.final_command1 == ""):
  1961.                                 Vars.out_file_size = self.humansize(Vars.newname)
  1962.                                 stri = " Done in: " + self.sec2hms(Vars.time_done) + " " + "\n"\
  1963.                                         + " in:  " + Vars.in_file_size + "\n"\
  1964.                                         + " out: " + Vars.out_file_size
  1965.                                 self.but_f3_run.set_tooltip_text(stri)
  1966.                                 stri2 = " Done in: " + self.sec2hms(Vars.time_done) + " "\
  1967.                                         + " input size:  " + Vars.in_file_size + " "\
  1968.                                         + " output size: " + Vars.out_file_size
  1969.                                 self.reportdata.set_text(stri2)
  1970.                                 clear_ff_file()
  1971.                                 self.but_f3_run.set_label('RUN')
  1972.                                 Vars.ENCODING = False
  1973.                                 restore_dir_button()
  1974.                                 restore_file_button()
  1975.                         elif (Vars.eff_pass == 0) and (Vars.final_command1 != ""):
  1976.                                 Vars.eff_pass = 1
  1977.                                 Vars.ENCODING = False
  1978.                                 self.on_but_f3_run_clicked(1)
  1979.                         elif (Vars.eff_pass == 1):
  1980.                                 Vars.out_file_size = self.humansize(Vars.newname)
  1981.                                 stri = " Done in: " + self.sec2hms(Vars.time_done + Vars.time_done_1) + " " + "\n"\
  1982.                                         + " pass 1: " + self.sec2hms(Vars.time_done) + " " + "\n"\
  1983.                                         + " pass 2: " + self.sec2hms(Vars.time_done_1) + " " + "\n"\
  1984.                                         + " in:  " + Vars.in_file_size + "\n"\
  1985.                                         + " out: " + Vars.out_file_size
  1986.                                 self.but_f3_run.set_tooltip_text(stri)
  1987.                                 stri2 = " Done in: " + self.sec2hms(Vars.time_done + Vars.time_done_1) + " "\
  1988.                                         + " pass 1: " + self.sec2hms(Vars.time_done) + " "\
  1989.                                         + " pass 2: " + self.sec2hms(Vars.time_done_1) + " "\
  1990.                                         + " input size:  " + Vars.in_file_size + " "\
  1991.                                         + " output size: " + Vars.out_file_size
  1992.                                 self.reportdata.set_text(stri2)
  1993.                                 clear_ff_file()
  1994.                                 Vars.eff_pass = 0
  1995.                                 self.but_f3_run.set_label('RUN')
  1996.                                 Vars.ENCODING = False
  1997.                                 restore_dir_button()
  1998.                                 restore_file_button()
  1999.                
  2000.                 def check_run(name):
  2001.                         t0 = time.time()
  2002.                         processname = name
  2003.                         for line in subprocess.Popen(["ps", "xa"], shell=False, stdout=subprocess.PIPE).stdout:
  2004.                                 line = line.decode()
  2005.                                 fields = line.split()
  2006.                                 pid = fields[0]
  2007.                                 process = fields[4]
  2008.                                 if process.find(processname) >= 0:              
  2009.                                         if line.find(Vars.filename) >= 0:
  2010.                                                 mypid = pid
  2011.                                                 break
  2012.                         finn = True
  2013.                         while finn == True:
  2014.                                 time.sleep(1)
  2015.                                 try:
  2016.                                         finn = os.path.exists("/proc/" + mypid)
  2017.                                 except:
  2018.                                         Vars.eff_pass = 0
  2019.                                         self.but_f3_run.set_label('RUN')
  2020.                                         Vars.ENCODING = False
  2021.                                         restore_dir_button()
  2022.                                         restore_file_button()
  2023.                                         return
  2024.                         if Vars.eff_pass == 0:  
  2025.                                 tfin = time.time() - t0
  2026.                                 Vars.time_done = int(tfin)
  2027.                         else:
  2028.                                 tfin = time.time() - t0
  2029.                                 Vars.time_done_1 = int(tfin)
  2030.                         end_run()
  2031.                        
  2032.                 if Vars.ENCODING:
  2033.                         return
  2034.                
  2035.                 if Vars.eff_pass == 0:
  2036.                         self.check_out_file()
  2037.                         Vars.time_done = 0
  2038.                         Vars.time_done_1 = 0
  2039.                         if Vars.n_pass == 1:
  2040.                                 Vars.final_command1 = ""
  2041.                                 Vars.final_command2 = Vars.ffmpeg_ex
  2042.                                 if Vars.ac3_drc != "":
  2043.                                         Vars.final_command2 = Vars.final_command2 + " " + Vars.ac3_drc
  2044.                                 Vars.final_command2 = Vars.final_command2 + " -i \"" \
  2045.                                         + Vars.filename + "\" " \
  2046.                                         + Vars.p3_command \
  2047.                                         +  " \"" + Vars.newname + "\"" \
  2048.                                         + "\n"
  2049.                                 command = Vars.final_command2
  2050.                        
  2051.                         if Vars.n_pass == 2:
  2052.                                 Vars.final_command1 = Vars.ffmpeg_ex + " -i \"" \
  2053.                                         + Vars.filename + "\" " \
  2054.                                         + Vars.p3_comm_first_p \
  2055.                                         + "\n"
  2056.                                 Vars.final_command2 = Vars.ffmpeg_ex
  2057.                                 if Vars.ac3_drc != "":
  2058.                                         Vars.final_command2 = Vars.final_command2 + " " + Vars.ac3_drc
  2059.                                 Vars.final_command2 = Vars.final_command2 + " -i \"" \
  2060.                                         + Vars.filename + "\" " \
  2061.                                         + Vars.p3_command \
  2062.                                         +  " \"" + Vars.newname + "\"" \
  2063.                                         + "\n"
  2064.                                 command = Vars.final_command1
  2065.                 else:
  2066.                         command = Vars.final_command2
  2067.                        
  2068.                 if Vars.debug == 1:
  2069.                         if Vars.n_pass == 1:
  2070.                                 command = "echo $\'\n\n\n" + Vars.final_command2  + "\' \n"
  2071.                         if Vars.n_pass == 2:
  2072.                                 command = "echo $\'\n\n\n" + Vars.final_command1 + "\n" + Vars.final_command2 + "\' \n"
  2073.                 length = len(command)
  2074.                
  2075.                 self.terminal.feed_child(command, length)
  2076.                 #
  2077.                 if Vars.debug == 0:
  2078.                         self.but_f3_run.set_label('ENCODING ...')
  2079.                         self.but_f3_run.set_tooltip_text('')
  2080.                         self.reportdata.set_text('')
  2081.                         Vars.ENCODING = True
  2082.                         t = threading.Thread(name='child procs', target=check_run, args=(Vars.ffmpeg_ex,))
  2083.                         t.start()
  2084.              
  2085.         def dir_changed(self, button):
  2086.                 if Vars.ENCODING:
  2087.                         return
  2088.                 if Vars.first_run:
  2089.                         select = self.out_dir_chooserbut.get_uri()
  2090.                         decoded = url2pathname(select)
  2091.                         newdir = decoded.split('//')[1]
  2092.                         command = "cd " + "\"" + newdir + "\"" + "\n"
  2093.                         length = len(command)
  2094.                         self.terminal.feed_child(command, length)
  2095.                         self.f3_run_outdir_label.set_markup("<b>out dir:  </b>" + newdir)
  2096.                         Vars.outdir = newdir
  2097.                         self.check_out_file()
  2098.                 else:
  2099.                         Vars.first_run = 1
  2100.                        
  2101.                
  2102.         def on_but_black_det_clicked(self, button):
  2103.        
  2104.                 def update_progress(pprog):
  2105.                         self.progressbar_black_det.set_fraction(pprog)
  2106.                         return False
  2107.                
  2108.                 def update_textv(stri):
  2109.                         self.textbuffer.insert_at_cursor(stri, -1)
  2110.                         i = self.textbuffer.get_end_iter()
  2111.                         self.textview.scroll_to_iter(i, 0.0, True, 0.0, 1.0)
  2112.                         return False
  2113.  
  2114.                 def stopped():
  2115.                         stri = "Stopped by user.\n"
  2116.                         self.textbuffer.insert_at_cursor(stri, -1)
  2117.                         i = self.textbuffer.get_end_iter()
  2118.                         self.textview.scroll_to_iter(i, 0.0, True, 0.0, 1.0)
  2119.                         self.but_black_det.set_label("Black detect")
  2120.                         self.blackdet_spin.stop()
  2121.                         self.blackdet_spin.set_sensitive(False)
  2122.                         self.progressbar_black_det.set_fraction(0.0)
  2123.                         Vars.blackdet_is_run = False
  2124.                        
  2125.                 def bd_finish(detected):
  2126.                         if detected == 0:
  2127.                                 stri = "none black gap found"
  2128.                                 self.textbuffer.insert_at_cursor(stri, -1)
  2129.                         self.blackdet_spin.stop()
  2130.                         self.blackdet_spin.set_sensitive(False)
  2131.                         self.but_black_det.set_label("black detectet")
  2132.                         self.progressbar_black_det.set_fraction(1.0)
  2133.                         Vars.blackdet_is_run = False
  2134.                         Vars.BLACKDT_DONE = True
  2135.                
  2136.                 def my_thread():
  2137.                         Vars.blackdet_is_run = True
  2138.                         command = [Vars.ffmpeg_ex, '-i', Vars.filename, '-y', '-an', '-vf', 'blackdetect=d=.5', '-f', 'null', '/dev/null']
  2139.                         p = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, universal_newlines=True)
  2140.                         self.bd_th = False
  2141.                         detected = 0
  2142.                         time_step = 0
  2143.                         pprog = 0.0
  2144.                         stri = ""
  2145.                        
  2146.                         while True:
  2147.                                 line = p.stderr.readline()
  2148.                                
  2149.                                 if 'time=' in line:
  2150.                                         if time_step == 9:
  2151.                                                 tml = line.split('time=')[1]
  2152.                                                 tml2 = tml.split(' ')[0]
  2153.                                                 time_n = tml2.split('.')[0]
  2154.                                                 time_n = self.hms2sec(time_n)
  2155.                                                 time_step = 0
  2156.                                                 pprog = float(time_n)/Vars.duration_in_sec
  2157.                                                 GLib.idle_add(update_progress, pprog)
  2158.                                                 time.sleep(0.002)
  2159.                                         else:
  2160.                                                 time_step = time_step + 1
  2161.                                                
  2162.                                 if 'blackdetect ' in line:
  2163.                                                 a = line
  2164.                                                 b = a.split('black_start:')[1]
  2165.                                                 start = b.split(' ')[0]
  2166.                                                 st_in_s = float(start)
  2167.                                                 st_in_s = int(st_in_s)
  2168.                                                 start_in_s = ("%4.1i"% (st_in_s))  
  2169.                                                 start = self.sec2hms(start)
  2170.                                                 stri = "black start at: " + start_in_s + " s, " + start + " "
  2171.                                                 c = b.split('black_duration:')[1]
  2172.                                                 durat = c.split(' ')[0]
  2173.                                                 dur_s = float(durat)
  2174.                                                 dur_s = "{0:0=3.1f}".format(dur_s)
  2175.                                                 stri = stri + "duration: " + dur_s + "s\n"
  2176.                                                 detected = 1
  2177.                                                 GLib.idle_add(update_textv, stri)
  2178.                                                 time.sleep(0.002)
  2179.                                 if line == '' and p.poll() != None:
  2180.                                         break
  2181.                                 if self.bd_th:
  2182.                                         p.communicate("q")
  2183.                                         break
  2184.                         try:
  2185.                                 p.communicate()
  2186.                         except:
  2187.                                 stopped()
  2188.                                 return
  2189.                         bd_finish(detected)    
  2190.                        
  2191.                 if Vars.BLACKDT_DONE:
  2192.                         return          
  2193.                        
  2194.                 if Vars.blackdet_is_run == False:
  2195.                         self.but_black_det.set_label("Stop")
  2196.                         self.textbuffer.set_text('') # clear for insert from start
  2197.                         stri = "Detected:\n\n"
  2198.                         start = self.textbuffer.get_start_iter()
  2199.                         self.textbuffer.insert(start, stri, -1)
  2200.                         self.blackdet_spin.set_sensitive(True)
  2201.                         self.blackdet_spin.start()                              
  2202.                         thread = threading.Thread(target=my_thread)
  2203.                         thread.daemon = True
  2204.                         thread.start()
  2205.                        
  2206.                 elif Vars.blackdet_is_run == True:
  2207.                         self.bd_th = True
  2208.        
  2209.                
  2210.         # -------------------------------------  
  2211.        
  2212.         def preview_logic(self):
  2213.                 if ( not(('-map ' in Vars.p3_command ) or ('-vf ' in Vars.p3_command )) ):
  2214.                         self.buttest.set_sensitive(False)
  2215.                         self.buttestspl.set_sensitive(False)
  2216.                 elif ('-map ' in Vars.p3_command) and ('-vf ' in Vars.p3_command):
  2217.                         self.buttest.set_sensitive(False)
  2218.                         self.buttestspl.set_sensitive(False)
  2219.                 elif '-map ' in Vars.p3_command:
  2220.                         self.buttest.set_sensitive(True)
  2221.                         self.buttestspl.set_sensitive(False)
  2222.                 elif '-vf ' in Vars.p3_command:
  2223.                         self.buttest.set_sensitive(True)
  2224.                         self.buttestspl.set_sensitive(True)
  2225.        
  2226.         def calcola_scale(self):
  2227.                 Vars.scalestr = ""
  2228.                 numero = self.size_spinner['adj'].get_value()
  2229.                 numero = int(numero/4)*4
  2230.                 dar = self.box2['cbox'].get_active()
  2231.                 lato = self.box1['cbox'].get_active()          
  2232.                 if (dar == 1): # 4/3
  2233.                         if (lato == 1):
  2234.                                 n2 = numero/4*3
  2235.                         else:
  2236.                                 n2 = numero/3*4
  2237.                         setdar = ",setdar=4/3,setsar=1/1"
  2238.                 elif (dar == 0): # 16/9
  2239.                         if (lato == 1):
  2240.                                 n2 = numero/16*9
  2241.                         else:
  2242.                                 n2 = numero/9*16
  2243.                         setdar = ",setdar=16/9,setsar=1/1"      
  2244.                 elif (dar == 2): #1/1 same as input  
  2245.                         w = int(Vars.video_width)
  2246.                         h = int(Vars.video_height)
  2247.                         if self.checkcr.get_active():
  2248.                                 crT = int(self.spinct['adj'].get_value())
  2249.                                 crB = int(self.spincb['adj'].get_value())
  2250.                                 crL = int(self.spincl['adj'].get_value())
  2251.                                 crR = int(self.spincr['adj'].get_value())
  2252.                                 h = h - crT - crB
  2253.                                 w = w - crL - crR
  2254.                         if (lato == 1): # h                
  2255.                                 n2 = (float(h)/(w/float(numero)))  
  2256.                         else:
  2257.                                 n2 = (float(w)/(h/float(numero)))
  2258.                         setdar = ""
  2259.                 n2 = int(n2/4)*4                    
  2260.                 Vars.scalestr = "scale="
  2261.                 if (lato == 1):
  2262.                         Vars.scalestr = Vars.scalestr + str(numero) + ":" + str(n2)
  2263.                 else:
  2264.                         Vars.scalestr = Vars.scalestr + str(n2) + ":" + str(numero)                  
  2265.                 lanc = self.check.get_active()  
  2266.                 if lanc:
  2267.                         Vars.scalestr = Vars.scalestr + ":flags=lanczos" + setdar  
  2268.                 else:
  2269.                         Vars.scalestr = Vars.scalestr + setdar
  2270.                 self.outfilter()
  2271.                      
  2272.         def outfilter(self):
  2273.                 final_str = ""
  2274.                 if (Vars.deint_str != ""):
  2275.                         final_str = final_str + Vars.deint_str
  2276.                 if (Vars.crop_str != ""):
  2277.                         if (final_str == ""):
  2278.                                 final_str = final_str + Vars.crop_str
  2279.                         else:
  2280.                                         final_str = final_str + "," + Vars.crop_str
  2281.                 if (Vars.scalestr != ""):
  2282.                         if (final_str == ""):
  2283.                                 final_str = final_str + Vars.scalestr
  2284.                         else:
  2285.                                 final_str = final_str + "," + Vars.scalestr
  2286.                 if (Vars.dn_str != ""):
  2287.                         if (final_str == ""):
  2288.                                 final_str = final_str + Vars.dn_str
  2289.                         else:
  2290.                                 final_str = final_str + "," + Vars.dn_str
  2291.                 if (Vars.uns_str != ""):
  2292.                         if (final_str == ""):
  2293.                                 final_str = final_str + Vars.uns_str
  2294.                         else:
  2295.                                 final_str = final_str + "," + Vars.uns_str
  2296.                 Vars.filter_test_str = final_str
  2297.                
  2298.                 if (final_str != ""):
  2299.                         Vars.final_vf_str = "-vf " + final_str
  2300.                 else:
  2301.                         Vars.final_vf_str = ""
  2302.                
  2303.                 label_str = ""          
  2304.                 if (Vars.maps_str != ""):
  2305.                         label_str = label_str + Vars.maps_str + " "  
  2306.                 if (Vars.time_final_str != ""):
  2307.                         label_str = label_str + Vars.time_final_str + " "                      
  2308.                 if (Vars.fr_str != ""):
  2309.                         label_str = label_str + Vars.fr_str + " "                      
  2310.                 if (Vars.final_vf_str != ""):
  2311.                         label_str = label_str + Vars.final_vf_str
  2312.                    
  2313.                 self.labelout.set_text(label_str)      
  2314.                 self.make_p3_out_command()
  2315.                 if (Vars.info_str != ""):
  2316.                         self.preview_logic()    
  2317.        
  2318.         def make_p3_out_command(self):
  2319.                 Vars.p3_command = ""
  2320.                 Vars.p3_comm_first_p = ""
  2321.                 self.f3_out_label.set_label("")
  2322.                
  2323.                 if (Vars.maps_str != ""):
  2324.                         Vars.p3_command = Vars.maps_str + " "  
  2325.                 if (Vars.time_final_str != ""):
  2326.                         Vars.p3_command = Vars.p3_command + Vars.time_final_str + " "
  2327.                 if ( (Vars.fr_str != "") and (Vars.vcodec_is != "vcopy") and (Vars.vcodec_is != "none") ): # check -vcopy
  2328.                         Vars.p3_command = Vars.p3_command + Vars.fr_str + " "          
  2329.                 if ( (Vars.final_vf_str != "") and (Vars.vcodec_is != "vcopy") and (Vars.vcodec_is != "none") ): # check -vcopy
  2330.                         Vars.p3_command = Vars.p3_command + Vars.final_vf_str + " "
  2331.                        
  2332.                 # first pass    
  2333.                 if Vars.first_pass:
  2334.                         Vars.p3_comm_first_p = Vars.p3_command + Vars.video_codec_str + " "
  2335.                         if self.check_cpu.get_active():
  2336.                                 Vars.p3_comm_first_p = Vars.p3_comm_first_p + "-threads 3 "
  2337.                         if "libx264" in Vars.p3_comm_first_p:
  2338.                                 Vars.p3_comm_first_p = Vars.p3_comm_first_p + "-pass 1 -fastfirstpass 1 "
  2339.                         else:
  2340.                                 Vars.p3_comm_first_p = Vars.p3_comm_first_p + "-pass 1 "
  2341.                         Vars.p3_comm_first_p = Vars.p3_comm_first_p + "-an -f null /dev/null"
  2342.                 else:
  2343.                         Vars.p3_comm_first_p = ""
  2344.                 # -af
  2345.                 audiof = ""
  2346.                 if ( (Vars.final_af_str != "") and (Vars.acodec_is != "acopy") and (Vars.acodec_is != "anone") ):  # check -acopy -an
  2347.                         audiof_1 = Vars.final_af_str
  2348.                 else:
  2349.                         audiof_1 = ""
  2350.                 if ( (Vars.compand_data != "") and (Vars.acodec_is != "acopy") and (Vars.acodec_is != "anone") ):  # check -acopy -an
  2351.                         audiof_2 = Vars.compand_data
  2352.                 else:
  2353.                         audiof_2 = ""
  2354.                
  2355.                 if (audiof_1 != "") and (audiof_2 != ""):
  2356.                         audiof = audiof_1 + "," + audiof_2
  2357.                 elif (audiof_1 != "") and (audiof_2 == ""):
  2358.                         audiof = audiof_1
  2359.                 elif (audiof_1 == "") and (audiof_2 != ""):
  2360.                         audiof = audiof_2
  2361.                 if audiof != "":        
  2362.                         Vars.p3_command = Vars.p3_command + "-af \'" + audiof + "\' "
  2363.                
  2364.                
  2365.                 if (Vars.final_codec_str != ""):
  2366.                         Vars.p3_command = Vars.p3_command + Vars.final_codec_str + " "
  2367.                
  2368.                 #second pass
  2369.                 if Vars.n_pass == 2:
  2370.                         Vars.p3_command = Vars.p3_command + "-pass 2" + " "
  2371.                        
  2372.                 if (Vars.container_str != ""):
  2373.                         Vars.p3_command = Vars.p3_command + Vars.container_str + " "
  2374.                 if (Vars.final_other_str != ""):
  2375.                         Vars.p3_command = Vars.p3_command + Vars.final_other_str + " "
  2376.                 self.f3_out_label.set_label(Vars.p3_command)
  2377.                
  2378.         def main(self):
  2379.                 Gtk.main()
  2380.  
  2381.                
  2382.        
  2383.  
  2384. if __name__ == "__main__":
  2385.         GObject.threads_init()
  2386.         ProgrammaGTK()
  2387.         Gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement