Advertisement
Guest User

4ffmpeg-8.012.py

a guest
Dec 2nd, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 101.38 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.                 nbytes = os.path.getsize(namefile)
  126.                 suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
  127.                 if nbytes == 0: return '0 B'
  128.                 i = 0
  129.                 while nbytes >= 1024 and i < len(suffixes)-1:
  130.                         nbytes /= 1024.
  131.                         i += 1
  132.                 f = "{0:0.1f}".format(nbytes)
  133.                 return "{0:>5s} {1:2s}".format(f, suffixes[i])
  134.        
  135.  
  136. # Abstract struct class      
  137. class Struct:
  138.        
  139.         def __init__ (self, *argv, **argd):
  140.                 if len(argd):
  141.                         # Update by dictionary
  142.                         self.__dict__.update (argd)
  143.                 else:
  144.                         # Update by position
  145.                         attrs = filter (lambda x: x[0:2] != "__", dir(self))
  146.                         for n in range(len(argv)):
  147.                                 setattr(self, attrs[n], argv[n])
  148.                
  149. class Tips(Struct):
  150.        
  151.         map_tooltip_str = ' use 0:0  or  0:0,0:1,0:2 '
  152.         time_tooltip_str = ' use: 90 or 00:01:30 '
  153.        
  154.         black_dt_init_str = 'Detect black frames can take some time,\ndepending on the length of the video.'
  155.        
  156.         faac_q_str = ' faac vbr: q 80 ~96k, 90 ~100k, 100 ~118k, 120 ~128k, 160 ~156k, def:100 '
  157.         lamecbr_str = " lame mp3: 32-320 Kb/s def:128 "
  158.         lamevbr_str = " lame mp3 vbr: q 0 ~245Kb/s, 5 ~130Kb/s, 6 ~115Kb/s, 9 ~65Kb/s, def:6 "
  159.         aac_cbr_str = " aac cbr: 32-320 Kb/s def:128 "
  160.         aak_cbr_str = " aac_fdk cbr: 64-320 Kb/s def:128 "
  161.         f3v_label_out_start = "-crf 21.3"
  162.         subcopy_tooltip_srt = ' false= srt->ass '
  163.         cpu_tooltip_srt = ' false= -thread 0 '
  164.         nometa_tooltip_srt = ' true= --map_metadata -1 '
  165.         debug_tooltip_srt = ' only print command in terminal '
  166.  
  167.        
  168. class Vars(Struct):
  169.        
  170.         ffmpeg_ex = 'ffmpeg'
  171.         ffplay_ex = 'ffplay'
  172.         ffprobe_ex = 'ffprobe'
  173.         final_vf_str = ""
  174.         final_af_str = ""
  175.         deint_str = ""
  176.         crop_str = ""
  177.         scalestr = ""
  178.         dn_str = ""
  179.         uns_str = ""
  180.         fr_str = ""
  181.         filter_test_str = ""
  182.         video_width = "0"
  183.         video_height = "0"
  184.         add_1_1_dar = True
  185.         maps_str = ""
  186.         time_final_str = ""
  187.         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"
  188.         final_other_str = ""
  189.         a_copy = 0
  190.         audionone = 0
  191.         v_copy = 0
  192.         audio_codec_str = "-c:a libfaac -q:a 100 -ar 48k -ac 2"
  193.         vcodec_is = ""
  194.         video_codec_str = ""
  195.         video_codec_str_more = "-preset faster -tune film -x264opts ref=4:bframes=4:direct=auto:aq-strength=1.3:ssim"
  196.         container_str = "-f matroska"
  197.         is_avi = 0
  198.         info_str = ''
  199.         blackdet_is_run = False
  200.         time_start = 0 # for cropdetect
  201.         first_run = 0
  202.         p3_command = ""
  203.         filename = ""
  204.         dirname = ""
  205.         basename = ""
  206.         in_file_size = ""
  207.         ext = ".mkv"
  208.         outdir = ""
  209.         newname = ""
  210.         duration = ""
  211.         duration_in_sec = 0
  212.         time_done = 0
  213.         time_done_1 = 0
  214.         out_file_size = ""
  215.         debug = 0
  216.         first_pass = 0
  217.         n_pass = 1
  218.         p3_comm_first_p = ""
  219.         final_command1 = ""
  220.         final_command2 = ""
  221.         eff_pass = 0
  222.         version = str(sys.argv[0])
  223.         version = version.split('-')[1]
  224.         version = version[:-3]
  225.        
  226. class ProgrammaGTK(reuse_init):
  227.        
  228.  
  229.         def __init__(self):
  230.                
  231.                
  232.                 # initialize variables
  233.                                
  234.                 # ---------------------
  235.                
  236.                 self.window =  Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
  237.                 self.window.connect("destroy", self.on_window_destroy)
  238.                 self.window.set_title("4FFmpeg")
  239.                 self.window.set_position(1) # 1 center, 0 none,
  240.                 self.window.set_border_width(3)
  241.                 self.window.set_default_size(500,-1)
  242.                 #----------------------------------
  243.                
  244.                 #page1 stuff VIDEO FILTERS------------------------------------------
  245.                                
  246.                 # page1 VBox -------------------------
  247.                 self.vbox1 = Gtk.VBox()
  248.                 self.vbox1.set_spacing(2)
  249.                
  250.                 # map --------------------------------------
  251.                 self.make_map()        
  252.                 # add map frame
  253.                 self.vbox1.pack_start(self.f_map['frame'], 1, 0, 0)
  254.                
  255.                 #time cut ------------------------------------
  256.                 self.make_time_cut()
  257.                 # add time frame
  258.                 self.vbox1.pack_start(self.f_time['frame'], 1, 0, 0)
  259.                
  260.                 # deinterlace -----------------------
  261.                 self.make_deinterlace()
  262.                 # add deinterlace frame
  263.                 self.vbox1.pack_start(self.f_deint['frame'], 1, 0, 0)
  264.                
  265.                 # crop ----------------------------------------
  266.                 self.make_crop()        
  267.                 # add crop frame -------------------
  268.                 self.vbox1.pack_start(self.frame_crop['frame'], 1, 0, 0)
  269.        
  270.                 # scale ------------------------------
  271.                 self.make_scale()
  272.                 # add scale frame------------------
  273.                 self.vbox1.pack_start(self.frame_scale['frame'], 1, 0, 0)
  274.  
  275.                 # denoise ----------------------------
  276.                 self.make_denoise()
  277.                 # add denoise frame------------------------
  278.                 self.vbox1.pack_start(self.frame_dn['frame'], 1, 0, 0)
  279.                
  280.                 #test-------------------
  281.                 #self.f_test = self.make_frame_ag(3, "TEST" , 6, 8, 8, True)
  282.                 #self.label_test = Gtk.Label("TEST")
  283.                 #self.f_test['grid'].attach(self.label_test, 0, 0, 1, 1)
  284.  
  285.                 #self.vbox1.pack_start(self.f_test['frame'], 1, 0, 0)
  286.                 #-------------------------------------
  287.                
  288.                 # page 1 output------------------------
  289.                 self.frame_out = self.make_frame_ag(3, '  FFmpeg video filter string (select and copy):  ' , 12, 8, 8, True)
  290.                 self.labelout = Gtk.Label("")
  291.                 self.labelout.set_selectable(1)
  292.                 self.labelout.set_width_chars(90)
  293.                 self.labelout.set_max_width_chars(90)
  294.                 self.labelout.set_line_wrap(True)
  295.                 self.frame_out['grid'].attach(self.labelout, 0, 0, 1 ,1)
  296.                 # add output frame ---------------------
  297.                 self.vbox1.pack_start(self.frame_out['frame'], 1, 0, 0)
  298.                
  299.                 # end page1 stuff
  300.                
  301.                
  302.                 # page2 stuff  UTILITY ------------------------------------------
  303.                
  304.                 # page2 VBox -------------------------
  305.                 self.vbox_pg2 = Gtk.VBox()
  306.                 self.vbox_pg2.set_spacing(2)
  307.                
  308.                 #volumedetect ------------------------------------
  309.                 self.make_volume_det()
  310.                 # add volumedetect frame        
  311.                 self.vbox_pg2.pack_start(self.f_volume_det['frame'], 1, 0, 0)
  312.                
  313.                 # black detect ----------------------------------
  314.                 self.make_black_detect()
  315.                 # add black_detect frame
  316.                 self.vbox_pg2.pack_start(self.f_blackd['frame'], 1, 0, 0)
  317.                
  318.                 # info frame----------------------
  319.                 self.make_info_frame()
  320.                 # add info frame
  321.                 self.vbox_pg2.pack_start(self.f_info['frame'], 1, 0, 0)
  322.                
  323.                 # end page2 stuff
  324.                
  325.                 # page 3 stuff  730 cuatom commands -----------------------------------------
  326.                
  327.                 # page3 VBox -------------------------
  328.                 self.vbox_pg3 = Gtk.VBox()
  329.                 self.vbox_pg3.set_spacing(2)
  330.                
  331.                 # audio codec -------------------
  332.                 self.make_audio_codec()
  333.                 #add frame audio codec
  334.                 self.vbox_pg3.pack_start(self.f_3acodec['frame'], 1, 0, 0)
  335.                
  336.                 # video codec -------------------
  337.                 self.make_video_codec()
  338.                 #add frame video codec
  339.                 self.vbox_pg3.pack_start(self.f_3vcodec['frame'], 1, 0, 0)
  340.                
  341.                 # other options ----------------
  342.                 self.make_other_opts()
  343.                 #add frame other options
  344.                 self.vbox_pg3.pack_start(self.f3_oth['frame'], 1, 0, 0)
  345.                
  346.                 # page3 output ---------------------
  347.                 self.f3_out = self.make_frame_ag(3, "  FFmpeg command  " , 6, 8, 8, True)
  348.                 self.f3_out_label = Gtk.Label("")
  349.                 self.f3_out_label.set_width_chars(106)
  350.                 self.f3_out_label.set_max_width_chars(106)
  351.                 self.f3_out_label.set_line_wrap(True)
  352.                 self.f3_out['grid'].attach(self.f3_out_label, 0, 0, 1, 1)
  353.                 # add frame page3 output
  354.                 self.vbox_pg3.pack_start(self.f3_out['frame'], 1, 0, 0)
  355.                
  356.                 # run 730 ---------------------------------
  357.                 self.make_run_730()
  358.                 # add frame run 730
  359.                 self.vbox_pg3.pack_start(self.f3_run['frame'], 1, 0, 0)
  360.                
  361.                
  362.                 #---------------------------------------------------
  363.                 # main vbox
  364.                 self.main_vbox = Gtk.VBox()
  365.                
  366.                 # notebook      
  367.                 self.notebook = Gtk.Notebook()
  368.                 self.notebook.set_tab_pos(0)  #GTK_POS_LEFT
  369.                 self.notebook.set_show_border (False)
  370.                 self.main_vbox.pack_start(self.notebook, 1, 0, 0)
  371.                
  372.                 #page 1
  373.                 self.tab1label = Gtk.Label("Video filters")
  374.                 self.page1_ali = Gtk.Alignment()
  375.                 self.page1_ali.set_padding(0, 6, 6, 6)
  376.                 self.page1_ali.add(self.vbox1)
  377.                 self.notebook.append_page(self.page1_ali, self.tab1label)
  378.                
  379.                 #page 2
  380.                 self.tab2label = Gtk.Label("Utility")
  381.                 self.page2_ali = Gtk.Alignment()
  382.                 self.page2_ali.set_padding(0, 6, 6, 6)
  383.                 self.page2_ali.add(self.vbox_pg2)
  384.                 self.notebook.append_page(self.page2_ali, self.tab2label)
  385.                
  386.                 #page 3
  387.                 self.tab3label = Gtk.Label("730")
  388.                 self.page3_ali = Gtk.Alignment()
  389.                 self.page3_ali.set_padding(0, 6, 6, 6)
  390.                 self.page3_ali.add(self.vbox_pg3)
  391.                 self.notebook.append_page(self.page3_ali, self.tab3label)
  392.                
  393.                 #---------------------------------------------------
  394.                
  395.                 # low part BUTTONS AND TERM --------------------------
  396.                 self.make_low_part()
  397.                 # add low part-----------------
  398.                 self.main_vbox.pack_start(self.gridterm, 1, 1, 0)
  399.                
  400.                 #---------------------------------------------------------
  401.                 self.window.add (self.main_vbox)
  402.                 #---------------------------------
  403.                 self.window.show_all()
  404.                
  405.                 #
  406.                 self.make_p3_out_command()
  407.                 Vars.outdir = os.getcwd()
  408.                
  409.                 # ----------------------------
  410.                
  411.         def make_deinterlace(self):
  412.                 self.f_deint = self.make_frame_ag(3, "" , 6, 8, 8, True)
  413.                 self.checkdeint = Gtk.CheckButton("deinterlace")
  414.                 self.checkdeint.connect("toggled", self.on_deint_clicked)
  415.                 self.f_deint['grid'].attach(self.checkdeint, 0, 0, 1, 1)
  416.                
  417.                 self.box_deint = self.make_combobox(
  418.                   "yadif",
  419.                   "postprocessing linear blend"
  420.                   )
  421.                 self.f_deint['grid'].attach(self.box_deint['cbox'], 1, 0, 1, 1)
  422.                 self.box_deint['cbox'].connect("changed", self.on_deint_clicked)
  423.                 #
  424.                 self.f_deint['grid'].attach(self.make_label(""), 2, 0, 1, 1)
  425.        
  426.         def make_map(self):
  427.                 #
  428.                 self.f_map = self.make_frame_ag(3, "" , 6, 8, 8, True)
  429.                 #
  430.                 self.check_map = Gtk.CheckButton("map")
  431.                 self.check_map.connect("toggled", self.on_map_clicked) # toggled or activate (enter)
  432.                 self.f_map['grid'].attach(self.check_map, 0, 0, 1, 1)
  433.                 #
  434.                 self.mapstream_label = self.make_label("streams: ")
  435.                 self.f_map['grid'].attach(self.mapstream_label, 1, 0, 1, 1)
  436.                 #
  437.                 self.entry_map = Gtk.Entry()
  438.                 self.entry_map.set_tooltip_text(Tips.map_tooltip_str)
  439.                 self.entry_map.connect("changed", self.on_map_clicked)
  440.                 self.f_map['grid'].attach(self.entry_map, 2, 0, 1, 1)
  441.                 #
  442.                 self.map_label = Gtk.Label("")
  443.                 self.f_map['grid'].attach(self.map_label, 3, 0, 1, 1)
  444.                 # placeholder
  445.                 self.f_map['grid'].attach(self.make_label("Version: " + Vars.version + "   "), 4, 0, 1, 1)
  446.                
  447.         def make_time_cut(self):
  448.                 #
  449.                 self.f_time = self.make_frame_ag(3, "" , 6, 8, 8, True)
  450.                 #
  451.                 self.check_time = Gtk.CheckButton("time")
  452.                 self.check_time.connect("toggled", self.on_time_clicked) # toggled or activate (enter)
  453.                 self.f_time['grid'].attach(self.check_time, 0, 0, 1, 1)
  454.                 #
  455.                 self.label_time_in = self.make_label("from: ")
  456.                 self.f_time['grid'].attach(self.label_time_in, 1, 0, 1, 1)
  457.                 self.entry_timein = Gtk.Entry()
  458.                 self.entry_timein.set_tooltip_text(Tips.time_tooltip_str)
  459.                 self.entry_timein.connect("changed", self.on_time_clicked)
  460.                 self.f_time['grid'].attach(self.entry_timein, 2, 0, 1, 1)
  461.                
  462.                 self.label_time_out = self.make_label("to: ")
  463.                 self.f_time['grid'].attach(self.label_time_out, 3, 0, 1, 1)
  464.                 self.entry_timeout = Gtk.Entry()
  465.                 self.entry_timeout.set_tooltip_text(Tips.time_tooltip_str)
  466.                 self.entry_timeout.connect("changed", self.on_time_clicked)
  467.                 self.f_time['grid'].attach(self.entry_timeout, 4, 0, 1, 1)
  468.        
  469.         def make_scale(self):
  470.                 self.frame_scale = self.make_frame_ag(3, '  scale  ' , 6, 8, 8, True)
  471.                 # ------------------------------
  472.                 self.box1 = self.make_combobox(
  473.                   "None",
  474.                   "W",
  475.                   "H"
  476.                   )
  477.                 self.frame_scale['grid'].attach(self.box1['cbox'], 0, 0, 1, 1)
  478.                 self.box1['cbox'].connect("changed", self.on_scale_clicked)
  479.                 #------------------------------------
  480.                 self.box2 = self.make_combobox(
  481.                   "16/9",
  482.                   "4/3"
  483.                   )
  484.                 self.frame_scale['grid'].attach(self.box2['cbox'], 0, 1, 1, 1)
  485.                 self.box2['cbox'].connect("changed", self.on_scale_clicked)
  486.                 #-----------------------------------------
  487.                 self.size_spinner = self.make_slider_and_spinner(720, 200, 2000, 8, 32, 0)
  488.                 self.frame_scale['grid'].attach(self.size_spinner['slider'], 1, 0, 1, 1)
  489.                 self.frame_scale['grid'].attach(self.size_spinner['spinner'], 2, 0, 1, 1)
  490.                 #self.size_spinner['slider'].set_size_request(150,-1)
  491.                 self.size_spinner['adj'].set_value(720.001) #mettere decimali se no non si vede
  492.                 self.size_spinner['adj'].connect("value-changed", self.on_scale_clicked)
  493.                 #-------------------------------------------------------
  494.                 self.check = Gtk.CheckButton("lanczos")
  495.                 self.check.connect("toggled", self.on_scale_clicked)
  496.                 self.frame_scale['grid'].attach(self.check, 2, 1, 1, 1)
  497.                
  498.         def make_crop(self):
  499.                 self.frame_crop = self.make_frame_ag(3, '' , 6, 2, 0, True)
  500.                 # -------
  501.                 self.checkcr = Gtk.CheckButton("crop")
  502.                 self.checkcr.connect("toggled", self.on_crop_clicked)
  503.                 self.frame_crop['grid'].attach(self.checkcr, 0, 0, 1, 1)
  504.                 #----------
  505.                 self.butcrode = Gtk.Button(label="Crop detect")
  506.                 self.butcrode.connect("clicked", self.on_butcrode_clicked)
  507.                 self.butcrode.set_sensitive(False)
  508.                 self.frame_crop['grid'].attach(self.butcrode, 0, 1, 1, 1)
  509.                 #-----------
  510.                 self.labelcropinw = self.make_label("input W: ")
  511.                 self.frame_crop['grid'].attach(self.labelcropinw, 1, 0, 1, 1)
  512.                 self.labelcropinh = self.make_label("input H: ")
  513.                 self.frame_crop['grid'].attach(self.labelcropinh, 1, 1, 1, 1)
  514.                 #
  515.                 self.spincw = self.make_spinbut(640 , 100 , 1920 , 10 , 1 , 0, True )
  516.                 self.spincw["adj"].connect("value-changed", self.on_crop_clicked)
  517.                 self.frame_crop['grid'].attach(self.spincw["spinner"], 2, 0, 1, 1)
  518.                 #
  519.                 self.spinch = self.make_spinbut(480 , 100 , 1280 , 10 , 1 , 0, True )
  520.                 self.spinch["adj"].connect("value-changed", self.on_crop_clicked)
  521.                 self.frame_crop['grid'].attach(self.spinch["spinner"], 2, 1, 1, 1)
  522.                 #
  523.                
  524.                 self.labelcroptop = self.make_label("crop Top: ")
  525.                 self.frame_crop['grid'].attach(self.labelcroptop, 3, 0, 1, 1)
  526.                 self.labelcropbot = self.make_label("crop Bottom: ")
  527.                 self.frame_crop['grid'].attach(self.labelcropbot, 3, 1, 1, 1)
  528.                 #
  529.                
  530.                 self.spinct = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  531.                 self.spinct["adj"].connect("value-changed", self.on_crop_clicked)
  532.                 self.frame_crop['grid'].attach(self.spinct["spinner"], 4, 0, 1, 1)
  533.                 #
  534.                 self.spincb = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  535.                 self.spincb["adj"].connect("value-changed", self.on_crop_clicked)
  536.                 self.frame_crop['grid'].attach(self.spincb["spinner"], 4, 1, 1, 1)
  537.                 #
  538.                
  539.                 self.labelcroplef = self.make_label("crop Left: ")
  540.                 self.frame_crop['grid'].attach(self.labelcroplef, 5, 0, 1, 1)
  541.                 self.labelcroprig = self.make_label("crop Right: ")
  542.                 self.frame_crop['grid'].attach(self.labelcroprig, 5, 1, 1, 1)
  543.                 #
  544.                 self.spincl = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  545.                 self.spincl["adj"].connect("value-changed", self.on_crop_clicked)
  546.                 self.frame_crop['grid'].attach(self.spincl["spinner"], 6, 0, 1, 1)
  547.                 #
  548.                 self.spincr = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  549.                 self.spincr["adj"].connect("value-changed", self.on_crop_clicked)
  550.                 self.frame_crop['grid'].attach(self.spincr["spinner"], 6, 1, 1, 1)
  551.                
  552.                
  553.         def make_denoise(self):
  554.                 self.frame_dn = self.make_frame_ag(3, '  denoise / unsharp luma chroma / frame rate   ' , 6, 8, 8, True)
  555.                 # denoise ----------------------
  556.                 self.checkdn = Gtk.CheckButton("hqdn3d:")
  557.                 self.checkdn.set_alignment(1.0, 0.5)
  558.                 self.checkdn.set_halign(2)
  559.                 self.checkdn.connect("toggled", self.on_dn_clicked)
  560.                 self.frame_dn['grid'].attach(self.checkdn, 0, 0, 1, 1)
  561.                 #
  562.                 self.spindn = self.make_spinbut(4 , 2 , 8 , 1 , 10 , 0, True )
  563.                 self.spindn["adj"].connect("value-changed", self.on_dn_clicked)
  564.                 #self.spindn['spinner'].set_max_length(1)
  565.                 #self.spindn['spinner'].set_width_chars(1)
  566.                 self.frame_dn['grid'].attach(self.spindn["spinner"], 1, 0, 1, 1)
  567.                 # -----------------------
  568.                 # unsharp unsharp=5:5:luma:5:5:chroma, luma chroma -1.5 to 1.5
  569.                 self.checkuns = Gtk.CheckButton("unsharp l/c:")
  570.                 self.checkuns.set_alignment(1.0, 0.5)
  571.                 self.checkuns.set_halign(2)
  572.                 self.checkuns.connect("toggled", self.on_uns_clicked)
  573.                 self.frame_dn['grid'].attach(self.checkuns, 2, 0, 1, 1)
  574.                 self.spinunsl = self.make_spinbut(0.0 , -1.5 , 1.5 , .1 , .01 , 2, True )
  575.                 self.spinunsl["adj"].connect("value-changed", self.on_uns_clicked)
  576.                 self.frame_dn['grid'].attach(self.spinunsl["spinner"], 3, 0, 1, 1)
  577.                 self.spinunsc = self.make_spinbut(0.0 , -1.5 , 1.5 , .1 , .01 , 2, True )
  578.                 self.spinunsc["adj"].connect("value-changed", self.on_uns_clicked)
  579.                 self.frame_dn['grid'].attach(self.spinunsc["spinner"], 4, 0, 1, 1)
  580.                 # framerate --------------------------
  581.                 self.checkfr = Gtk.CheckButton("frame rate:")
  582.                 self.checkfr.set_alignment(1.0, 0.5)
  583.                 self.checkfr.set_halign(2)
  584.                 self.checkfr.connect("toggled", self.on_fr_clicked)
  585.                 self.frame_dn['grid'].attach(self.checkfr, 5, 0, 1, 1)
  586.                 self.spinfr = self.make_spinbut(0 , 0 , 100 , 1 , 10 , 2, True )
  587.                 self.spinfr["adj"].connect("value-changed", self.on_fr_clicked)
  588.                 self.frame_dn['grid'].attach(self.spinfr["spinner"], 6, 0, 1, 1)
  589.                
  590.         def make_low_part(self):
  591.                 # grid
  592.                 self.gridterm = Gtk.Grid()
  593.                 self.gridterm.set_row_spacing(2)
  594.                 self.gridterm.set_column_spacing(2)
  595.                 self.gridterm.set_column_homogeneous(True) # True
  596.                 # filechooserbutton
  597.                 self.filechooserbutton = Gtk.FileChooserButton(title="FileChooserButton")
  598.                 #
  599.                 #self.filechooserbutton.set_action(2) # 0 open file, 1 save file, 2 select folder, 3 create folder
  600.                 #
  601.                 self.filechooserbutton.connect("file-set", self.file_changed)  
  602.                 # filter
  603.                 self.filter = Gtk.FileFilter()
  604.                 self.filter.set_name("Video")
  605.                 self.filter.add_mime_type("video/x-matroska")
  606.                 self.filter.add_mime_type("video/mp4")
  607.                 self.filter.add_mime_type("video/x-flv")
  608.                 self.filter.add_mime_type("video/avi")
  609.                 self.filter.add_mime_type("video/mpg")
  610.                 self.filter.add_mime_type("video/mpeg")
  611.                 self.filter.add_mime_type("video/x-ms-wmv")
  612.                 self.filter.add_mime_type("video/webm")
  613.                 self.filter.add_mime_type("video/ogg")
  614.                 self.filter.add_mime_type("video/quicktime")
  615.                 self.filechooserbutton.add_filter(self.filter)
  616.                 # terminal
  617.                 self.terminal     = Vte.Terminal()
  618.                 self.terminal.fork_command_full(
  619.                         Vte.PtyFlags.DEFAULT, #default is fine
  620.                         os.getcwd(), #where to start the command?   os.environ['HOME']
  621.                         ["/bin/sh"], #where is the emulator?
  622.                         [], #it's ok to leave this list empty
  623.                         GLib.SpawnFlags.DO_NOT_REAP_CHILD,
  624.                         None, #at least None is required
  625.                         None,
  626.                         )
  627.                 self.scroller = Gtk.ScrolledWindow()
  628.                 self.scroller.set_hexpand(True)
  629.                 self.scroller.set_vexpand(True)
  630.                 self.scroller.add(self.terminal)
  631.                 self.scroller.set_min_content_height(90)
  632.                 #ff command button
  633.                 self.butplay = Gtk.Button(label="FFplay")
  634.                 self.butplay.connect("clicked", self.on_butplay_clicked)
  635.                 self.butplay.set_sensitive(False)
  636.                 self.butprobe = Gtk.Button(label="FFprobe")
  637.                 self.butprobe.connect("clicked", self.on_butprobe_clicked)
  638.                 self.butprobe.set_sensitive(False)
  639.                 self.buttest = Gtk.Button(label="Test")
  640.                 self.buttest.connect("clicked", self.on_buttest_clicked)
  641.                 self.buttest.set_sensitive(False)
  642.                 self.buttestspl = Gtk.Button(label="Test split")
  643.                 self.buttestspl.connect("clicked", self.on_buttestspl_clicked)
  644.                 self.buttestspl.set_sensitive(False)
  645.                
  646.                 self.gridterm.attach(self.filechooserbutton, 0, 0, 1, 1)
  647.                 self.gridterm.attach(self.butprobe, 1, 0, 1, 1)
  648.                 self.gridterm.attach(self.butplay, 2, 0, 1, 1)
  649.                 self.gridterm.attach(self.buttest, 3, 0, 1, 1)
  650.                 self.gridterm.attach(self.buttestspl, 4, 0, 1, 1)
  651.                
  652.                 self.gridterm.attach(self.scroller, 0, 1, 5, 1)
  653.  
  654.         def make_volume_det(self):
  655.                 self.f_volume_det = self.make_frame_ag(3, "" , 6, 8, 8, True)
  656.                 #
  657.                 self.but_volume_det = Gtk.Button(label="Volume detect")
  658.                 self.but_volume_det.connect("clicked", self.on_but_volume_det_clicked)
  659.                 self.but_volume_det.set_sensitive(False)
  660.                 self.f_volume_det['grid'].attach(self.but_volume_det, 0, 0, 1, 1)
  661.                 #
  662.                 self.voldet_spin = Gtk.Spinner()
  663.                 self.voldet_spin.set_sensitive(False)
  664.                 self.f_volume_det['grid'].attach(self.voldet_spin, 1, 0, 1, 1)
  665.                 #
  666.                 self.label_maxvol = Gtk.Label("")
  667.                 self.f_volume_det['grid'].attach(self.label_maxvol, 2, 0, 1, 1)
  668.                 self.label_meanvol = Gtk.Label("")
  669.                 self.f_volume_det['grid'].attach(self.label_meanvol, 3, 0, 1, 1)
  670.                 #
  671.                 self.check_vol = Gtk.CheckButton("volume")
  672.                 self.check_vol.connect("toggled", self.on_volume_clicked)
  673.                 self.f_volume_det['grid'].attach(self.check_vol, 0, 1, 1, 1)
  674.                 #
  675.                 self.label_db = self.make_label("dB: ")
  676.                 self.f_volume_det['grid'].attach(self.label_db, 1, 1, 1, 1)
  677.                 self.spin_db = self.make_spinbut(0 , -6 , 20 , 0.1 , 1 , 2, True )
  678.                 self.spin_db["adj"].connect("value-changed", self.on_volume_clicked)
  679.                 self.f_volume_det['grid'].attach(self.spin_db["spinner"], 2, 1, 1, 1)
  680.                 self.label_ratio = self.make_label("ratio: ")
  681.                 self.f_volume_det['grid'].attach(self.label_ratio, 3, 1, 1, 1)
  682.                 self.label_ratio_val = Gtk.Label("")
  683.                 self.f_volume_det['grid'].attach(self.label_ratio_val, 4, 1, 1, 1)
  684.  
  685.         def make_black_detect(self):
  686.                 self.f_blackd = self.make_frame_ag(3, "" , 6, 8, 8, True)
  687.                 #
  688.                 self.but_black_det = Gtk.Button(label="Black detect")
  689.                 self.but_black_det.connect("clicked", self.on_but_black_det_clicked)
  690.                 self.but_black_det.set_sensitive(False)
  691.                 self.f_blackd['grid'].attach(self.but_black_det, 0, 0, 1, 1)
  692.                 #
  693.                 self.blackdet_spin = Gtk.Spinner()
  694.                 self.blackdet_spin.set_sensitive(False)
  695.                 self.f_blackd['grid'].attach(self.blackdet_spin, 1, 0, 1, 1)
  696.                 #
  697.                 scrolledwindow = Gtk.ScrolledWindow()
  698.                 #scrolledwindow.set_hexpand(True)
  699.                 scrolledwindow.set_vexpand(True)
  700.                 self.textview = Gtk.TextView()
  701.                 self.textbuffer = self.textview.get_buffer()
  702.                 self.textview.set_editable(False)
  703.                 self.textview.set_cursor_visible(False)
  704.                 self.textview.modify_font(Pango.font_description_from_string('Monospace 9'))
  705.                 scrolledwindow.add(self.textview)
  706.                 self.textbuffer.set_text(Tips.black_dt_init_str)
  707.                 self.f_blackd['grid'].attach(scrolledwindow, 2, 0, 3, 3)
  708.                 #
  709.                 self.progressbar_black_det = Gtk.ProgressBar()
  710.                 self.f_blackd['grid'].attach(self.progressbar_black_det, 0, 1, 1, 1)
  711.                
  712.         def make_info_frame(self):
  713.                 self.f_info = self.make_frame_ag(3, "  info  " , 6, 8, 8, True)
  714.                 scrolledwindow1 = Gtk.ScrolledWindow()
  715.                 scrolledwindow1.set_hexpand(True)
  716.                 scrolledwindow1.set_vexpand(True)
  717.                 self.textview_info = Gtk.TextView()
  718.                 self.textbuffer_info = self.textview_info.get_buffer()
  719.                 self.textview_info.set_editable(False)
  720.                 self.textview_info.set_cursor_visible(False)
  721.                 self.textview_info.modify_font(Pango.font_description_from_string('Monospace 9'))
  722.                 scrolledwindow1.add(self.textview_info)
  723.                 self.f_info['grid'].attach(scrolledwindow1, 0, 0, 3, 3)
  724.        
  725.         def make_audio_codec(self):
  726.                 #
  727.                 self.f_3acodec = self.make_frame_ag(3, "  audio codec  " , 6, 8, 8, True)
  728.                 #
  729.                 self.box_ac = self.make_combobox(
  730.                   "libfaac quality (Q)",
  731.                   "aacplus (64 Kb/s)",
  732.                   "aacplus (32 Kb/s)",
  733.                   "no audio",
  734.                   "audio copy",
  735.                   "aac_fdk CBR (Kb/s)",
  736.                   "lame mp3 CBR (Kb/s)",
  737.                   "lame mp3 VBR (Q)",
  738.                   "aac native CBR (Kb/s)"
  739.                   )
  740.                 self.f_3acodec['grid'].attach(self.box_ac['cbox'], 0, 0, 1, 1)
  741.                 self.box_ac['cbox'].connect("changed", self.on_codec_audio_changed)
  742.                 #
  743.                 self.spin_ac = self.make_spinbut(100 , 80 , 160 , 10 , 1 , 0, True )
  744.                 self.spin_ac["adj"].connect("value-changed", self.on_codec_clicked)
  745.                 self.f_3acodec['grid'].attach(self.spin_ac["spinner"], 1, 0, 1, 1)
  746.                 self.spin_ac['spinner'].set_tooltip_text(Tips.faac_q_str)
  747.                 # placeholder
  748.                 self.f_3acodec['grid'].attach(self.make_label(""), 2, 0, 1, 1)
  749.                 #
  750.                 self.f3ac_label_out = Gtk.Label("")
  751.                 self.f_3acodec['grid'].attach(self.f3ac_label_out, 3, 0, 1, 1)
  752.        
  753.         def make_video_codec(self):
  754.                 self.f_3vcodec = self.make_frame_ag(3, "  video codec  " , 6, 8, 8, True)
  755.                 self.box_vcodec = self.make_combobox(
  756.                   "libx264",
  757.                   "video copy",
  758.                   "mpeg4"
  759.                   )
  760.                 self.f_3vcodec['grid'].attach(self.box_vcodec['cbox'], 0, 0, 1, 1)
  761.                 self.box_vcodec['cbox'].connect("changed", self.on_codec_video_changed)
  762.                 #
  763.                 self.box_vrc = self.make_combobox(
  764.                   "crf",
  765.                   "bitrate kb/s"
  766.                   )
  767.                 self.f_3vcodec['grid'].attach(self.box_vrc['cbox'], 1, 0, 1, 1)
  768.                 self.box_vrc['cbox'].connect("changed", self.on_codec_vrc_changed)
  769.                 #
  770.                 self.spin_vc = self.make_spinbut(21.3 , 15 , 40 , 0.1 , 1 , 1, True )
  771.                 self.spin_vc["adj"].connect("value-changed", self.on_codec_vrc_value_change)
  772.                 self.f_3vcodec['grid'].attach(self.spin_vc["spinner"], 2, 0, 1, 1)
  773.                 #
  774.                 self.f3v_label_out = Gtk.Label("")
  775.                 self.f_3vcodec['grid'].attach(self.f3v_label_out, 3, 0, 2, 1)
  776.                 # x264 preset
  777.                 self.box_3v_preset = self.make_combobox(
  778.                   "superfast",
  779.                   "veryfast",
  780.                   "faster",
  781.                   "fast",
  782.                   "medium",
  783.                   "slow"
  784.                   ) #(-superfast -veryfast -fast, -medium, -slow, default: faster)
  785.                 self.box_3v_preset['cbox'].set_active(2)
  786.                 self.f_3vcodec['grid'].attach(self.box_3v_preset['cbox'], 0, 1, 1, 1)
  787.                 self.box_3v_preset['cbox'].connect("changed", self.on_preset_changed)
  788.                 # x264 opts
  789.                 self.box_3v_x264opts = self.make_combobox(
  790.                   "x264opts 1",
  791.                   "no opts (ssim)"
  792.                   )
  793.                 self.box_3v_x264opts['cbox'].set_active(0)
  794.                 self.f_3vcodec['grid'].attach(self.box_3v_x264opts['cbox'], 1, 1, 1, 1)
  795.                 self.box_3v_x264opts['cbox'].connect("changed", self.on_codec_clicked)
  796.                 # opencl
  797.                 self.check_3v_opencl = Gtk.CheckButton("opencl")
  798.                 self.check_3v_opencl.connect("toggled", self.on_codec_clicked)
  799.                 self.f_3vcodec['grid'].attach(self.check_3v_opencl, 2, 1, 1, 1)
  800.                
  801.                
  802.                
  803.         def make_other_opts(self):
  804.                 #
  805.                 self.f3_oth = self.make_frame_ag(3, "  other options  " , 6, 8, 8, True)
  806.                 #
  807.                 self.check_2pass = Gtk.CheckButton("2 pass")
  808.                 self.check_2pass.connect("toggled", self.on_f3_other_clicked)
  809.                 self.f3_oth['grid'].attach(self.check_2pass, 0, 0, 1, 1)
  810.                 self.check_2pass.set_sensitive(False)
  811.                 #
  812.                 self.check_nometa = Gtk.CheckButton("no metatag")
  813.                 self.check_nometa.connect("toggled", self.on_f3_other_clicked)
  814.                 self.check_nometa.set_tooltip_text(Tips.nometa_tooltip_srt)
  815.                 self.f3_oth['grid'].attach(self.check_nometa, 1, 0, 1, 1)
  816.                 #
  817.                 #
  818.                 self.check_scopy = Gtk.CheckButton("sub copy")
  819.                 self.check_scopy.connect("toggled", self.on_f3_other_clicked)
  820.                 self.check_scopy.set_tooltip_text(Tips.subcopy_tooltip_srt)
  821.                 self.f3_oth['grid'].attach(self.check_scopy, 2, 0, 1, 1)
  822.                 #
  823.                 self.check_cpu = Gtk.CheckButton("cpu 3")
  824.                 self.check_cpu.connect("toggled", self.on_f3_other_clicked)
  825.                 self.check_cpu.set_tooltip_text(Tips.cpu_tooltip_srt)
  826.                 self.f3_oth['grid'].attach(self.check_cpu, 3, 0, 1, 1)
  827.                 #
  828.                 self.check_debug = Gtk.CheckButton("debug")
  829.                 self.check_debug.connect("toggled", self.on_f3_other_clicked)
  830.                 self.check_debug.set_tooltip_text(Tips.debug_tooltip_srt)
  831.                 self.f3_oth['grid'].attach(self.check_debug, 4, 0, 1, 1)
  832.                 #
  833.                 self.box_oth_container = self.make_combobox(
  834.                   "MKV",
  835.                   "MP4",
  836.                   "AVI"
  837.                   )
  838.                 self.f3_oth['grid'].attach(self.box_oth_container['cbox'], 5, 0, 1, 1)
  839.                 self.box_oth_container['cbox'].connect("changed", self.on_container_changed)
  840.                
  841.         def make_run_730(self):
  842.                 self.f3_run = self.make_frame_ag(3, "  execute in terminal  " , 6, 8, 8, True)
  843.                 #
  844.                 self.f3_run_indir_label = Gtk.Label("")
  845.                 self.f3_run['grid'].attach(self.f3_run_indir_label, 0, 0, 1, 1)
  846.                 self.f3_run_file = Gtk.Label("no input file")
  847.                 self.f3_run_file.set_tooltip_text('')
  848.                 self.f3_run['grid'].attach(self.f3_run_file, 1, 0, 2, 1)
  849.                 self.f3_dur_file = Gtk.Label("")
  850.                 self.f3_run['grid'].attach(self.f3_dur_file, 3, 0, 1, 1)
  851.                 #
  852.                 self.but_f3_run = Gtk.Button(label="RUN")
  853.                 self.but_f3_run.connect("clicked", self.on_but_f3_run_clicked)
  854.                 self.but_f3_run.set_sensitive(False)
  855.                 self.f3_run['grid'].attach(self.but_f3_run, 3, 1, 1, 1)
  856.                 #
  857.                 #self.f3_run_outdir_label = Gtk.Label("out dir:  " + os.getcwd())
  858.                 self.f3_run_outdir_label = Gtk.Label("")
  859.                 self.f3_run_outdir_label.set_markup("<b>out dir:  </b>" + os.getcwd())
  860.                 self.f3_run['grid'].attach(self.f3_run_outdir_label, 0, 1, 2, 1)
  861.                 #
  862.                 # filechooserbutton
  863.                 self.out_dir_chooserbut = Gtk.FileChooserButton(title="Dir out")
  864.                 self.out_dir_chooserbut.set_action(2)
  865.                 #self.filechooserbutton.set_action(2) # 0 open file, 1 save file, 2 select folder, 3 create folder
  866.                 acturi = "file://" + os.getcwd()
  867.                 self.out_dir_chooserbut.set_uri(acturi)
  868.                 self.f3_run['grid'].attach(self.out_dir_chooserbut, 2, 1, 1, 1)
  869.                 self.out_dir_chooserbut.connect("selection-changed", self.dir_changed)
  870.                
  871.                
  872.         # event handlers -----------------------------------------------
  873.        
  874.         def on_window_destroy(self, *args):
  875.                 Gtk.main_quit(*args)
  876.        
  877.         def on_scale_clicked(self, button):
  878.                 if (self.box1['cbox'].get_active() != 0):
  879.                         self.calcola_scale()
  880.                 else:
  881.                         Vars.scalestr = ""
  882.                         self.outfilter()
  883.                  
  884.         def on_deint_clicked(self, button):
  885.                 Vars.deint_str = ""
  886.                 if self.checkdeint.get_active():
  887.                         deint_val = self.box_deint['cbox'].get_active()
  888.                         if (deint_val == 0):
  889.                                 Vars.deint_str = "yadif"
  890.                         elif (deint_val == 1):
  891.                                 Vars.deint_str = "pp=lb"
  892.                 self.outfilter()
  893.                        
  894.         def on_dn_clicked(self, button):
  895.                 Vars.dn_str = ""
  896.                 if self.checkdn.get_active():
  897.                         dn_val = int( self.spindn['adj'].get_value() )
  898.                         Vars.dn_str = "hqdn3d=" + str(dn_val)
  899.                 self.outfilter()
  900.                
  901.         def on_uns_clicked(self, button):
  902.                 Vars.uns_str = ""
  903.                 if self.checkuns.get_active():
  904.                         luma = self.spinunsl['adj'].get_value()
  905.                         chroma = self.spinunsc['adj'].get_value()
  906.                         Vars.uns_str = "unsharp=5:5:" + "{0:0.2f}".format(luma) + ":5:5:" + "{0:0.2f}".format(chroma)
  907.                 self.outfilter()
  908.                        
  909.         def on_fr_clicked(self, button):
  910.                 Vars.fr_str = ""
  911.                 if self.checkfr.get_active():
  912.                         fr_val = self.spinfr['adj'].get_value()
  913.                         Vars.fr_str = "-r " + "{0:0.2f}".format(fr_val)
  914.                 self.outfilter()
  915.                    
  916.         def on_crop_clicked(self, button):
  917.                 ok = 0
  918.                 Vars.crop_str = ""
  919.                 if self.checkcr.get_active():
  920.                         ok = 1
  921.                 if ok:
  922.                         inW = int(self.spincw['adj'].get_value())
  923.                         inH = int(self.spinch['adj'].get_value())
  924.                         crT = int(self.spinct['adj'].get_value())
  925.                         crB = int(self.spincb['adj'].get_value())
  926.                         crL = int(self.spincl['adj'].get_value())
  927.                         crR = int(self.spincr['adj'].get_value())      
  928.                         finW = inW - crL - crR
  929.                         finH = inH - crT - crB
  930.                         if ( (finW < 100) or (finH < 100) ):
  931.                                 Vars.crop_str = ""
  932.                         else:
  933.                                 Vars.crop_str = "crop=" + str(finW) + ":" \
  934.                                  + str(finH) + ":" \
  935.                                  + str(crL)  + ":" \
  936.                                  + str(crT)
  937.                 if (self.box2['cbox'].get_active() != 2):
  938.                         self.outfilter()
  939.                 else:
  940.                         self.on_scale_clicked(button)
  941.                
  942.         def file_changed(self, filechooserbutton):              
  943.                 if self.filechooserbutton.get_filename():
  944.                         self.butplay.set_sensitive(True) # low part ---------
  945.                         self.butprobe.set_sensitive(True)
  946.                         self.preview_logic() # test and testsplit
  947.                         self.butcrode.set_sensitive(True) # crop ----------
  948.                         self.spinct['adj'].set_value(0)
  949.                         self.spincb['adj'].set_value(0)
  950.                         self.spincl['adj'].set_value(0)
  951.                         self.spincr['adj'].set_value(0)                
  952.                         self.but_volume_det.set_sensitive(True) # volume detect
  953.                         self.but_volume_det.set_label("Volume detect")
  954.                         self.label_meanvol.set_label("")
  955.                         self.label_maxvol.set_label("")
  956.                         self.spin_db["adj"].set_value(0)
  957.                         self.but_black_det.set_sensitive(True) # black  detect
  958.                         self.but_black_det.set_label("Black detect")
  959.                         self.textbuffer.set_text(Tips.black_dt_init_str)
  960.                         self.progressbar_black_det.set_fraction(0.0)
  961.                         self.but_f3_run.set_sensitive(True) # 730 run
  962.                         #
  963.                         command = "clear" + "\n"
  964.                         length = len(command)
  965.                         self.terminal.feed_child(command, length)
  966.                         # need ffprobe
  967.                         Vars.filename = self.filechooserbutton.get_filename()
  968.                         Vars.dirname = os.path.dirname(Vars.filename)
  969.                         Vars.basename = os.path.basename(Vars.filename)
  970.                         self.check_out_file()
  971.                         self.f3_run_indir_label.set_label(Vars.dirname)
  972.                         file_4_label = (Vars.basename)
  973.                         if ( len(file_4_label) > 50):
  974.                                 a = file_4_label[:46]
  975.                                 b = '  ...  '
  976.                                 c = file_4_label[-4:]
  977.                                 file_4_label = a + b + c
  978.                         self.f3_run_file.set_label(file_4_label)
  979.                         self.but_f3_run.set_tooltip_text("")
  980.                         command = [Vars.ffprobe_ex, '-show_format', '-show_streams', '-pretty', '-loglevel', 'quiet', Vars.filename]
  981.                         p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  982.                         out, err =  p.communicate()
  983.                         out = out.decode() # python3
  984.                         self.get_info(out)
  985.                        
  986.         def get_info(self, out):
  987.                 def form_to_3(in_str):
  988.                         '''
  989.                        bitrate and size info formatting
  990.                        '''
  991.                         a = in_str.split(' ')[0]
  992.                         if len(in_str.split(' ')) == 2:
  993.                                 b = in_str.split(' ')[1]
  994.                                 a = float(a)
  995.                                 result = "{0:.3f}".format(a ) + " " + b
  996.                         else:
  997.                                 result = 'N/A'
  998.                         return result
  999.                
  1000.                 def set_w_h_video_scale():
  1001.                         self.spincw['adj'].set_value(float(Vars.video_width)) #mettere decimali se no non si vede
  1002.                         self.spincw['spinner'].set_sensitive(False)
  1003.                         self.spinch['adj'].set_value(float(Vars.video_height)) #mettere decimali se no non si vede
  1004.                         self.spinch['spinner'].set_sensitive(False)
  1005.                         if Vars.add_1_1_dar:
  1006.                                 self.box2['list'].append(["as input"])
  1007.                         Vars.add_1_1_dar = False                  
  1008.                                
  1009.                 #x Vars.info_str
  1010.                 Vars.info_str = ""
  1011.                 is_stream = 0
  1012.                 is_format = 0
  1013.                 for line in out.split('\n'):
  1014.                         line = line.strip()
  1015.                         if line.startswith('[STREAM]'):
  1016.                                 Vars.info_str = Vars.info_str + "STREAM "
  1017.                                 is_stream = 1
  1018.                         elif line.startswith('[/STREAM]'):
  1019.                                 Vars.info_str = Vars.info_str + "\n"
  1020.                                 is_stream = 0
  1021.                         elif (line.startswith('index=') and (is_stream == 1)):
  1022.                                 s = line
  1023.                                 info = s.split('=')[1]  
  1024.                                 Vars.info_str = Vars.info_str + info + ": "
  1025.                         elif (line.startswith('codec_name=') and (is_stream == 1)):
  1026.                                 s = line
  1027.                                 info = s.split('=')[1]  
  1028.                                 Vars.info_str = Vars.info_str + info + ", "
  1029.                         elif (line.startswith('profile=') and (is_stream == 1)):
  1030.                                 s = line
  1031.                                 info = s.split('=')[1]  
  1032.                                 Vars.info_str = Vars.info_str + "profile=" +info + ", "
  1033.                         elif (line.startswith('codec_type=') and (is_stream == 1)):
  1034.                                 s = line
  1035.                                 info = s.split('=')[1]  
  1036.                                 Vars.info_str = Vars.info_str + info + ", "
  1037.                         elif (line.startswith('width=') and (is_stream == 1)):
  1038.                                 s = line
  1039.                                 info = s.split('=')[1]
  1040.                                 Vars.video_width = info
  1041.                                 Vars.info_str = Vars.info_str + info + "x"
  1042.                         elif (line.startswith('height=') and (is_stream == 1)):
  1043.                                 s = line
  1044.                                 info = s.split('=')[1]
  1045.                                 Vars.video_height = info
  1046.                                 Vars.info_str = Vars.info_str + info + ", "
  1047.                         elif (line.startswith('sample_aspect_ratio=') and (is_stream == 1)):
  1048.                                 s = line
  1049.                                 info = s.split('=')[1]  
  1050.                                 Vars.info_str = Vars.info_str + "SAR=" + info + ", "
  1051.                         elif (line.startswith('display_aspect_ratio=') and (is_stream == 1)):
  1052.                                 s = line
  1053.                                 info = s.split('=')[1]  
  1054.                                 Vars.info_str = Vars.info_str + "DAR=" + info + ", "
  1055.                         elif (line.startswith('pix_fmt=') and (is_stream == 1)):
  1056.                                 s = line
  1057.                                 info = s.split('=')[1]  
  1058.                                 Vars.info_str = Vars.info_str + info + ", "
  1059.                         elif (line.startswith('sample_rate=') and (is_stream == 1)):
  1060.                                 s = line
  1061.                                 info = s.split('=')[1]
  1062.                                 info = form_to_3(info)
  1063.                                 Vars.info_str = Vars.info_str + "samplerate=" + info + ", "
  1064.                         elif (line.startswith('channels=') and (is_stream == 1)):
  1065.                                 s = line
  1066.                                 info = s.split('=')[1]  
  1067.                                 Vars.info_str = Vars.info_str + "channels=" + info + ", "
  1068.                         elif (line.startswith('r_frame_rate=') and (is_stream == 1)):
  1069.                                 s = line
  1070.                                 info = s.split('=')[1]
  1071.                                 a = info.split('/')[0]
  1072.                                 b = info.split('/')[1]
  1073.                                 a = float(a)
  1074.                                 b = float(b)
  1075.                                 if ((a > 0) and (b > 0)):
  1076.                                         c = float(a)/float(b)
  1077.                                         info = "{0:0.2f}".format(c)
  1078.                                         self.spinfr["adj"].set_value(c)
  1079.                                         Vars.info_str = Vars.info_str + info + " fps, "
  1080.                         elif (line.startswith('bit_rate=') and (is_stream == 1)):
  1081.                                 s = line
  1082.                                 info = s.split('=')[1]
  1083.                                 info = form_to_3(info)
  1084.                                 Vars.info_str = Vars.info_str + "bitrate=" + info + ", "
  1085.                         elif (line.startswith('TAG:language=') and (is_stream == 1)):
  1086.                                 s = line
  1087.                                 info = s.split('=')[1]  
  1088.                                 Vars.info_str = Vars.info_str + "lang=" + info + ", "
  1089.                         elif line.startswith('[FORMAT]'):
  1090.                                 Vars.info_str = Vars.info_str + "FORMAT "
  1091.                                 is_format = 1
  1092.                         elif line.startswith('[/FORMAT]'):
  1093.                                 #Vars.info_str = Vars.info_str + "/n"
  1094.                                 is_format = 0
  1095.                         elif (line.startswith('nb_streams=') and (is_format == 1)):
  1096.                                 s = line
  1097.                                 info = s.split('=')[1]  
  1098.                                 Vars.info_str = Vars.info_str + "streams=" + info + ", "
  1099.                         elif (line.startswith('duration=') and (is_format == 1)):
  1100.                                 s = line
  1101.                                 info = s.split('=')[1]  
  1102.                                 info = info.split('.')[0]
  1103.                                 Vars.duration = info
  1104.                                 Vars.duration_in_sec = self.hms2sec(info)
  1105.                                 Vars.info_str = Vars.info_str + "duration=" + info + ", "
  1106.                         elif (line.startswith('size=') and (is_format == 1)):
  1107.                                 s = line
  1108.                                 info = s.split('=')[1]
  1109.                                 info = form_to_3(info)
  1110.                                 Vars.info_str = Vars.info_str + "size=" + info + ", "
  1111.                         elif (line.startswith('bit_rate=') and (is_format == 1)):
  1112.                                 s = line
  1113.                                 info = s.split('=')[1]
  1114.                                 info = form_to_3(info)
  1115.                                 Vars.info_str = Vars.info_str + "bitrate=" + info + ", "
  1116.                 set_w_h_video_scale()
  1117.                 self.f3_dur_file.set_label(Vars.duration)
  1118.                 self.textbuffer_info.set_text(Vars.info_str)
  1119.                 self.f3_run_file.set_tooltip_text(Vars.info_str)
  1120.                 self.check_map.set_tooltip_text(Vars.info_str)
  1121.                 self.check_time.set_tooltip_text(Vars.info_str)
  1122.                 Vars.in_file_size = self.humansize(Vars.filename)
  1123.        
  1124.         def on_butplay_clicked(self, button):
  1125.                 command = Vars.ffplay_ex + " \"" + Vars.filename + "\"" +"\n"
  1126.                 length = len(command)
  1127.                 self.terminal.feed_child(command, length)
  1128.                
  1129.         def on_butprobe_clicked(self, button):
  1130.                 command = Vars.ffprobe_ex + " \"" + Vars.filename + "\""  + " 2>&1 | grep 'Input\|Duration\|Stream'" + "\n"
  1131.                 length = len(command)
  1132.                 self.terminal.feed_child(command, length)        
  1133.                
  1134.         def on_butcrode_clicked(self, button):
  1135.                 # need ffmpeg
  1136.                 self.butcrode.set_sensitive(False)
  1137.                 if (Vars.time_start == 0):
  1138.                         command = Vars.ffmpeg_ex + " -i " + "\"" + Vars.filename + "\"" + " -ss 60 -t 1 -vf cropdetect -f null - 2>&1 | awk \'/crop/ { print $NF }\' | tail -1"
  1139.                 else:
  1140.                         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"
  1141.                 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
  1142.                 out, err =  p.communicate()
  1143.                 out = out.decode()
  1144.                 for line in out.split('\n'):
  1145.                         line = line.strip()
  1146.                         if "crop=" in line:  
  1147.                                 aa = line.split('crop=', 1)
  1148.                                 aaa = aa[1]
  1149.                                 listdata = aaa.split(':')
  1150.                                 w = listdata[0]
  1151.                                 h = listdata[1]
  1152.                                 offx = listdata[2]
  1153.                                 offy = listdata[3]
  1154.                                 ctop = int(offy)
  1155.                                 cbot = int(Vars.video_height) - int(offy) -int(h)
  1156.                                 cleft = int(offx)
  1157.                                 cright = int(Vars.video_width) - int(offx) -int(w)
  1158.                                 self.spinct['adj'].set_value(float(ctop))
  1159.                                 self.spincb['adj'].set_value(float(cbot))
  1160.                                 self.spincl['adj'].set_value(float(cleft))
  1161.                                 self.spincr['adj'].set_value(float(cright))  
  1162.                                 break
  1163.                 self.butcrode.set_sensitive(True)
  1164.                
  1165.         def on_buttest_clicked(self, button):
  1166.                 # -map preview: only with none -vf option  
  1167.                 if (Vars.maps_str == ""):
  1168.                         command = Vars.ffplay_ex + " \"" + Vars.filename + "\" " \
  1169.                          + " " + Vars.time_final_str + " " \
  1170.                          + "-vf "  + Vars.filter_test_str + "\n"
  1171.                 else:
  1172.                         command = Vars.ffmpeg_ex + " -i \"" + Vars.filename + "\" " \
  1173.                          + Vars.maps_str  + " " + Vars.time_final_str + " "
  1174.                         if (Vars.filter_test_str != ""):
  1175.                                 command = command + " -vf "  + Vars.filter_test_str
  1176.                         command = command +  " -c copy -f matroska - | ffplay -" + "\n"
  1177.                 length = len(command)
  1178.                 self.terminal.feed_child(command, length)
  1179.                
  1180.         def on_buttestspl_clicked(self, button):
  1181.                 command = Vars.ffplay_ex + " \"" + Vars.filename + "\" " \
  1182.                   + " " + Vars.time_final_str + " " \
  1183.                   + " -vf \"split[a][b]; [a]pad=iw:(ih*2)+4:color=888888 [src]; [b]" \
  1184.                   + Vars.filter_test_str + " [filt]; [src][filt]overlay=((main_w - w)/2):main_h/2\"" + "\n"
  1185.                 length = len(command)
  1186.                 self.terminal.feed_child(command, length)
  1187.        
  1188.         def on_but_volume_det_clicked(self, button):
  1189.                 self.but_volume_det.set_sensitive(False)
  1190.                 self.voldet_spin.set_sensitive(True)
  1191.                 self.voldet_spin.start()
  1192.                
  1193.                 def my_thread(obj):    
  1194.                         command = [Vars.ffmpeg_ex, '-i', Vars.filename, '-vn', '-af', 'volumedetect', '-f', 'null', '/dev/null']
  1195.                         p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
  1196.                         while True:
  1197.                                 line = p.stderr.read()
  1198.                                 if not line:
  1199.                                         break
  1200.                                 out = line.decode()
  1201.                                 for line in out.split('\n'):
  1202.                                         line = line.strip()
  1203.                                         if "mean_volume:" in line:  
  1204.                                                 aa = line.split('mean_volume:', 1)
  1205.                                                 mea_vol_det = aa[1]
  1206.                                                 self.label_meanvol.set_label("Mean vol: " + mea_vol_det)
  1207.                                         if "max_volume:" in line:  
  1208.                                                 aa = line.split('max_volume:', 1)
  1209.                                                 max_vol_det = aa[1]
  1210.                                                 self.label_maxvol.set_label("Max vol: " + max_vol_det)
  1211.                                 self.but_volume_det.set_label("volume detected")
  1212.                                 self.voldet_spin.stop()
  1213.                                 self.voldet_spin.set_sensitive(False)
  1214.                         p.communicate()
  1215.                        
  1216.                 self.but_volume_det.set_label("Wait")  
  1217.                 threading.Thread(target=my_thread, args=(self,)).start()
  1218.        
  1219.         def on_volume_clicked(self, button):
  1220.                 ratio = 1
  1221.                 self.label_ratio_val.set_label("")
  1222.                 Vars.final_af_str = ""
  1223.                 db = self.spin_db["adj"].get_value()
  1224.                 if (db != 0.00):
  1225.                         ratio = pow(10, (db/20.0))
  1226.                         ratio = float("{0:.3f}".format(ratio))    
  1227.                         self.label_ratio_val.set_label(str(ratio))      
  1228.                 if self.check_vol.get_active():
  1229.                         Vars.final_af_str = "-af volume=" + str(ratio)
  1230.                 else:
  1231.                         Vars.final_af_str = ""
  1232.                 self.make_p3_out_command()
  1233.        
  1234.         def on_map_clicked(self, button):
  1235.                 self.map_label.set_label("")
  1236.                 Vars.maps_str = ""
  1237.                 if self.check_map.get_active():
  1238.                         map_in = self.entry_map.get_chars(0, -1)
  1239.                         if (map_in != ""):
  1240.                                 map_l = map_in.split(",")
  1241.                                 for i in range(len(map_l)):
  1242.                                         if Vars.maps_str == "":
  1243.                                                 Vars.maps_str = Vars.maps_str + "-map " + map_l[i]
  1244.                                         else:
  1245.                                                 Vars.maps_str = Vars.maps_str + " -map " + map_l[i]
  1246.                                 self.map_label.set_label(Vars.maps_str)
  1247.                 self.outfilter()
  1248.                 self.make_p3_out_command()
  1249.                
  1250.         def on_time_clicked(self, button):
  1251.                 Vars.time_final_str = ""
  1252.                        
  1253.                 if self.check_time.get_active():
  1254.                         timein = 0
  1255.                         timeout = 0
  1256.                         timedur = 0
  1257.                         timein_ent = self.entry_timein.get_chars(0, -1)
  1258.                         if (timein_ent != ""):
  1259.                                 if timein_ent.isdigit():
  1260.                                         timein = int(timein_ent)        
  1261.                                 else:  
  1262.                                         timein = self.hms2sec(timein_ent)
  1263.                         timeout_ent = self.entry_timeout.get_chars(0, -1)
  1264.                         if (timeout_ent != ""):
  1265.                                 if timeout_ent.isdigit():
  1266.                                         timeout = int(timeout_ent)
  1267.                                         timedur = timeout - timein
  1268.                                 else:  
  1269.                                         timeout = self.hms2sec(timeout_ent)
  1270.                                         timedur = timeout - timein
  1271.                         if (timein != 0):
  1272.                                 Vars.time_final_str = Vars.time_final_str + " -ss " + str(timein)
  1273.                                 Vars.time_start = timein
  1274.                         if (timedur > 0):
  1275.                                 Vars.time_final_str = Vars.time_final_str + " -t " + str(timedur)    
  1276.                 self.outfilter()
  1277.                 self.make_p3_out_command()
  1278.        
  1279.         def on_codec_audio_changed(self, button):
  1280.                 a_cod = self.box_ac['cbox'].get_active()
  1281.                 if (a_cod == 0): # aaq
  1282.                         self.spin_ac['spinner'].set_sensitive(True)
  1283.                         self.adj_change(self.spin_ac['adj'], 100, 80, 160, 10, 1)
  1284.                         self.spin_ac['adj'].set_value(100.0)
  1285.                         self.spin_ac['spinner'].set_tooltip_text(Tips.faac_q_str)
  1286.                 elif (a_cod == 5): # aac_fdk cbr 64-320 def 128
  1287.                         self.spin_ac['spinner'].set_sensitive(True)
  1288.                         self.adj_change(self.spin_ac['adj'], 128, 64, 320, 8, 2)
  1289.                         self.spin_ac['adj'].set_value(128.0)
  1290.                         self.spin_ac['spinner'].set_tooltip_text(Tips.aak_cbr_str)
  1291.                 elif (a_cod == 6): # lame cbr 32 - 320 def 128
  1292.                         self.spin_ac['spinner'].set_sensitive(True)
  1293.                         self.adj_change(self.spin_ac['adj'], 128, 32, 320, 8, 2)
  1294.                         self.spin_ac['adj'].set_value(128.0)
  1295.                         self.spin_ac['spinner'].set_tooltip_text(Tips.lamecbr_str)
  1296.                 elif (a_cod == 7): # lame vbr 0 - 9 def 6
  1297.                         self.spin_ac['spinner'].set_sensitive(True)
  1298.                         self.adj_change(self.spin_ac['adj'], 6, 0, 9, 1, 1)
  1299.                         self.spin_ac['adj'].set_value(6.0)
  1300.                         self.spin_ac['spinner'].set_tooltip_text(Tips.lamevbr_str)
  1301.                 elif (a_cod == 8): # aac cbr 32 - 320 def 128
  1302.                         self.spin_ac['spinner'].set_sensitive(True)
  1303.                         self.adj_change(self.spin_ac['adj'], 128, 32, 320, 8, 2)
  1304.                         self.spin_ac['adj'].set_value(128.0)
  1305.                         self.spin_ac['spinner'].set_tooltip_text(Tips.aac_cbr_str)
  1306.                 else:
  1307.                         self.spin_ac['spinner'].set_sensitive(False)
  1308.                         self.spin_ac['spinner'].set_tooltip_text('')
  1309.                 self.on_codec_clicked(button)
  1310.  
  1311.         def on_codec_video_changed(self, button):
  1312.                 self.on_codec_clicked(button)
  1313.  
  1314.         def on_codec_vrc_changed(self, button):
  1315.                 video_rc = self.box_vrc['cbox'].get_active() #0 crf, 1 kb/s
  1316.                 video_codec = self.box_vcodec['cbox'].get_active() #0 x264, 1 -vcopy
  1317.                 model = self.box_vcodec['cbox'].get_model()
  1318.                 item = model[video_codec]
  1319.                 video_codec = item[0]
  1320.                 if (video_rc == 0):
  1321.                         self.adj_change(self.spin_vc['adj'], 21.3, 15, 40, 0.1, 1)
  1322.                         self.spin_vc['adj'].set_value(21.3)
  1323.                         self.check_2pass.set_active(False)
  1324.                         self.check_2pass.set_sensitive(False)
  1325.                 elif (video_rc == 1) and (video_codec == "mpeg4" ):
  1326.                         self.adj_change(self.spin_vc['adj'], 1200, 300, 5000, 100, 100)
  1327.                         self.spin_vc['adj'].set_value(1200.0)
  1328.                         self.check_2pass.set_sensitive(True)
  1329.                 elif (video_rc == 1):
  1330.                         self.adj_change(self.spin_vc['adj'], 730, 300, 4000, 10, 100)
  1331.                         self.spin_vc['adj'].set_value(730.0)
  1332.                         self.check_2pass.set_sensitive(True)    
  1333.  
  1334.         def on_codec_clicked(self, button):
  1335.                 Vars.final_codec_str = ""
  1336.                 #audio
  1337.                 Vars.audio_codec_str = self.audio_codec()
  1338.                 #self.f3ac_label_out.set_label(Vars.audio_codec_str)
  1339.                 # video
  1340.                 Vars.v_copy = 0
  1341.                 Vars.vcodec_is = ""
  1342.                 video_codec = self.box_vcodec['cbox'].get_active() #0 x264, 1 -vcopy
  1343.                 model = self.box_vcodec['cbox'].get_model()
  1344.                 item = model[video_codec]
  1345.                 video_codec = item[0]
  1346.                 if (video_codec == "video copy"):
  1347.                         Vars.v_copy = 1
  1348.                         Vars.video_codec_str_more = self.v_codec_vcopy()
  1349.                 elif (video_codec == "mpeg4"): #mpeg4
  1350.                         Vars.video_codec_str_more = self.v_codec_mpeg4()
  1351.                         Vars.vcodec_is = "mpeg4"
  1352.                 elif (video_codec == "libx264"):
  1353.                         #libx264
  1354.                         Vars.video_codec_str_more = self.v_codec_x264()
  1355.                 #
  1356.                 self.on_codec_vrc_value_change(button)
  1357.                        
  1358.         def on_codec_vrc_value_change(self, button):
  1359.                 Vars.video_codec_str = ""
  1360.                 if (Vars.vcodec_is == "") and (Vars.v_copy == 0): #x264
  1361.                         #rc
  1362.                         video_rc = self.box_vrc['cbox'].get_active() #0 crf, 1 kb/s
  1363.                         if (video_rc == 0):    
  1364.                                 video_codec_str = "-c:v libx264 " + "-crf " + str(self.spin_vc['adj'].get_value()) + " " + Vars.video_codec_str_more
  1365.                         elif (video_rc == 1):
  1366.                                 video_codec_str = "-c:v libx264 " + "-b:v " + str(int(self.spin_vc['adj'].get_value())) + "k " + Vars.video_codec_str_more
  1367.                 elif (Vars.vcodec_is == "mpeg4"):
  1368.                         video_codec_str = "-c:v mpeg4 -mpv_flags strict_gop " + "-b:v " + str(int(self.spin_vc['adj'].get_value())) + "k"
  1369.                 else:
  1370.                         video_codec_str = Vars.video_codec_str_more
  1371.                        
  1372.                 Vars.video_codec_str = video_codec_str
  1373.                        
  1374.                 #self.f3v_label_out.set_label(video_codec_str)
  1375.                 Vars.final_codec_str = Vars.audio_codec_str + " " + video_codec_str
  1376.                 self.make_p3_out_command()
  1377.                
  1378.         def audio_codec(self):
  1379.                 Vars.a_copy = 0
  1380.                 Vars.audionone = 0
  1381.                 audio_codec_str = ""
  1382.                 audio_codec = self.box_ac['cbox'].get_active()
  1383.                 if self.box_oth_container['cbox'].get_active() == 2: # avi protection
  1384.                         if (audio_codec != 3) and (audio_codec != 4) and (audio_codec != 6) and (audio_codec != 7):
  1385.                                 self.box_ac['cbox'].set_active(6)    # only lame or acopy or noaudio
  1386.                                 audio_codec = 6
  1387.                 if (audio_codec == 0):
  1388.                         audio_codec_str = "-c:a libfaac -q:a "
  1389.                         quality_faac = self.spin_ac['adj'].get_value()
  1390.                         audio_codec_str = audio_codec_str + str(int(quality_faac)) + " -ar 48k -ac 2"
  1391.                 elif (audio_codec == 1):
  1392.                         audio_codec_str = "-c:a libaacplus -b:a 64k -ar 48k -ac 2"
  1393.                 elif (audio_codec == 2):
  1394.                         audio_codec_str = "-c:a libaacplus -b:a 32k"
  1395.                 elif (audio_codec == 3):
  1396.                         audio_codec_str = "-an"
  1397.                         Vars.audionone = 1
  1398.                 elif (audio_codec == 4):
  1399.                         audio_codec_str = "-c:a copy"
  1400.                         Vars.a_copy = 1
  1401.                 elif (audio_codec == 5):
  1402.                         audio_codec_str = "-c:a libfdk_aac -b:a "
  1403.                         aakcbr = self.spin_ac['adj'].get_value()
  1404.                         audio_codec_str = audio_codec_str + str(int(aakcbr)) + "k -ar 48k -ac 2"
  1405.                 elif (audio_codec == 6):
  1406.                         audio_codec_str = "-c:a libmp3lame -b:a "
  1407.                         lamecbr = self.spin_ac['adj'].get_value()
  1408.                         audio_codec_str = audio_codec_str + str(int(lamecbr)) + "k -ar 48k -ac 2"
  1409.                 elif (audio_codec == 7):
  1410.                         audio_codec_str = "-c:a libmp3lame -q:a "  
  1411.                         lamevbr = self.spin_ac['adj'].get_value()
  1412.                         audio_codec_str = audio_codec_str + str(int(lamevbr)) + " -ar 48k -ac 2"
  1413.                 elif (audio_codec == 8):
  1414.                         audio_codec_str = "-c:a aac -strict -2 -b:a "
  1415.                         aaccbr = self.spin_ac['adj'].get_value()
  1416.                         audio_codec_str = audio_codec_str + str(int(aaccbr)) + "k -ar 48k -ac 2"
  1417.                 return audio_codec_str
  1418.                
  1419.         def v_codec_vcopy(self):        
  1420.                 self.box_vrc['cbox'].set_active(0)
  1421.                 self.box_vrc['cbox'].set_sensitive(False)
  1422.                 self.spin_vc['spinner'].set_sensitive(False)
  1423.                 self.box_3v_preset['cbox'].set_active(2)
  1424.                 self.box_3v_preset['cbox'].set_sensitive(False)
  1425.                 self.box_3v_x264opts['cbox'].set_active(0)
  1426.                 self.box_3v_x264opts['cbox'].set_sensitive(False)
  1427.                 self.check_3v_opencl.set_active(False)
  1428.                 self.check_3v_opencl.set_sensitive(False)
  1429.                 self.check_cpu.set_active(False)
  1430.                 self.check_cpu.set_sensitive(False)
  1431.                 video_codec_str = "-c:v copy"
  1432.                 return video_codec_str
  1433.  
  1434.         def v_codec_x264(self):
  1435.                 video_codec_str = ""
  1436.                 if "mpeg4" in Vars.p3_command:
  1437.                         self.box_vrc['cbox'].set_active(0)
  1438.                 self.box_vrc['cbox'].set_sensitive(True)
  1439.                 self.spin_vc['spinner'].set_sensitive(True)
  1440.                 self.box_3v_preset['cbox'].set_sensitive(True)
  1441.                 self.box_3v_x264opts['cbox'].set_sensitive(True)
  1442.                 self.check_3v_opencl.set_sensitive(True)
  1443.                 self.check_cpu.set_sensitive(True)
  1444.                 #preset
  1445.                 preset_str = ""
  1446.                 preset = self.box_3v_preset['cbox'].get_active()
  1447.                 # 0 -superfast, 1 -veryfast, 2 -faster, 3 -fast, 4 -medium, 5 -slow, default: 2 faster
  1448.                 if (preset == 0):
  1449.                         preset_str = "-preset superfast -tune film"
  1450.                 if (preset == 1):
  1451.                         preset_str = "-preset veryfast -tune film"
  1452.                 if (preset == 2):
  1453.                         preset_str = "-preset faster -tune film"
  1454.                 if (preset == 3):
  1455.                         preset_str = "-preset fast -tune film"
  1456.                 if (preset == 4):
  1457.                         preset_str = "-preset medium -tune film"
  1458.                 if (preset == 5):
  1459.                         preset_str = "-preset slow -tune film"
  1460.                 video_codec_str = preset_str
  1461.                 #x264opts      
  1462.                 if (self.box_3v_x264opts['cbox'].get_active() == 1):
  1463.                         video_codec_str = video_codec_str + " -x264opts ssim"
  1464.                 else:
  1465.                         video_codec_str = video_codec_str + " -x264opts ref=4:bframes=4:direct=auto:aq-strength=1.3:ssim"
  1466.                 #opencl
  1467.                 if self.check_3v_opencl.get_active():
  1468.                         video_codec_str = video_codec_str + ":opencl"
  1469.                 return video_codec_str
  1470.  
  1471.         def v_codec_mpeg4(self):
  1472.                 if not ("mpeg4" in Vars.p3_command):
  1473.                         self.box_vrc['cbox'].set_active(1)
  1474.                         self.on_codec_vrc_changed(1)
  1475.                 self.box_vrc['cbox'].set_sensitive(False)
  1476.                 self.spin_vc['spinner'].set_sensitive(True)
  1477.                 self.box_3v_preset['cbox'].set_sensitive(False)
  1478.                 self.box_3v_x264opts['cbox'].set_sensitive(False)
  1479.                 self.check_3v_opencl.set_active(False)
  1480.                 self.check_3v_opencl.set_sensitive(False)
  1481.                 self.check_cpu.set_active(False)
  1482.                 self.check_cpu.set_sensitive(False)
  1483.                 video_codec_str = ""
  1484.                 return video_codec_str
  1485.  
  1486.         def on_preset_changed(self, button):
  1487.                 self.on_codec_clicked(button)
  1488.                
  1489.         def on_f3_other_clicked(self, button):
  1490.                 Vars.final_other_str = ""
  1491.                 Vars.debug = 0
  1492.                 Vars.first_pass = 0
  1493.                 Vars.n_pass = 1
  1494.                 if self.check_nometa.get_active():
  1495.                         Vars.final_other_str = "-map_metadata -1"
  1496.                 if self.check_2pass.get_active():
  1497.                                 Vars.first_pass = 1
  1498.                                 Vars.n_pass = 2
  1499.                 if self.check_cpu.get_active():
  1500.                         if (Vars.final_other_str == ""):
  1501.                                 Vars.final_other_str = "-threads 3"
  1502.                         else:
  1503.                                 Vars.final_other_str = Vars.final_other_str + " " + "-threads 3"
  1504.                 if self.check_scopy.get_active():
  1505.                         if (Vars.final_other_str == ""):
  1506.                                 Vars.final_other_str = "-c:s copy"
  1507.                         else:
  1508.                                 Vars.final_other_str = Vars.final_other_str + " " + "-c:s copy"
  1509.                 if self.check_debug.get_active():
  1510.                                 Vars.debug = 1
  1511.                 self.make_p3_out_command()
  1512.                
  1513.         def on_container_changed(self,button):
  1514.                 container = self.box_oth_container['cbox'].get_active() #0 mkv, 1 mp4
  1515.                 if (container == 1):
  1516.                         Vars.container_str = "-f mp4"
  1517.                         self.check_scopy.set_active(False)
  1518.                         self.check_scopy.set_sensitive(False)
  1519.                         Vars.ext = ".mp4"
  1520.                         self.check_out_file()
  1521.                         if Vars.is_avi:
  1522.                                 it = self.box_vcodec['list'].insert(0)
  1523.                                 self.box_vcodec['list'].set(it, {0: "libx264"})
  1524.                                 self.box_vcodec['cbox'].set_active(0)
  1525.                                 Vars.is_avi = 0
  1526.                 elif (container == 2):
  1527.                         Vars.container_str = "-f avi"
  1528.                         self.check_scopy.set_active(False)
  1529.                         self.check_scopy.set_sensitive(False)
  1530.                         audio_codec = self.box_ac['cbox'].get_active()
  1531.                         if (audio_codec != 3) and (audio_codec != 4) and (audio_codec != 6) and (audio_codec != 7):
  1532.                                 self.box_ac['cbox'].set_active(6) # lame cbr
  1533.                         model = self.box_vcodec['cbox'].get_model()
  1534.                         it = Gtk.TreeModel.get_iter(model,0)
  1535.                         self.box_vcodec['list'].remove(it)
  1536.                         self.box_vcodec['cbox'].set_active(1) # mpeg4
  1537.                         Vars.is_avi = 1
  1538.                         Vars.ext = ".avi"
  1539.                         self.check_out_file()
  1540.                 else:
  1541.                         Vars.container_str = "-f matroska"
  1542.                         self.check_scopy.set_sensitive(True)
  1543.                         Vars.ext = ".mkv"
  1544.                         self.check_out_file()
  1545.                         if Vars.is_avi:
  1546.                                 it = self.box_vcodec['list'].insert(0)
  1547.                                 self.box_vcodec['list'].set(it, {0: "libx264"})
  1548.                                 self.box_vcodec['cbox'].set_active(0)
  1549.                                 Vars.is_avi = 0
  1550.                 self.make_p3_out_command()
  1551.                
  1552.         def on_but_f3_run_clicked(self, button):
  1553.                
  1554.                 def end_run():
  1555.                         if (Vars.eff_pass == 0) and (Vars.final_command1 == ""):
  1556.                                 Vars.out_file_size = self.humansize(Vars.newname)
  1557.                                 stri = " Done in: " + self.sec2hms(Vars.time_done) + " " + "\n"\
  1558.                                         + " in:  " + Vars.in_file_size + "\n"\
  1559.                                         + " out: " + Vars.out_file_size
  1560.                                 self.but_f3_run.set_tooltip_text(stri)
  1561.                                 if os.path.exists('x264_lookahead.clbin'):
  1562.                                         os.remove('x264_lookahead.clbin')
  1563.                                 self.but_f3_run.set_sensitive(True)
  1564.                                 self.filechooserbutton.set_sensitive(True)
  1565.                                 self.out_dir_chooserbut.set_sensitive(True)
  1566.                         elif (Vars.eff_pass == 0) and (Vars.final_command1 != ""):
  1567.                                 Vars.eff_pass = 1
  1568.                                 self.on_but_f3_run_clicked(1)
  1569.                         elif (Vars.eff_pass == 1):
  1570.                                 Vars.out_file_size = self.humansize(Vars.newname)
  1571.                                 stri = " Done in: " + self.sec2hms(Vars.time_done + Vars.time_done_1) + " " + "\n"\
  1572.                                         + " pass 1: " + self.sec2hms(Vars.time_done) + " " + "\n"\
  1573.                                         + " pass 2: " + self.sec2hms(Vars.time_done_1) + " " + "\n"\
  1574.                                         + " in:  " + Vars.in_file_size + "\n"\
  1575.                                         + " out: " + Vars.out_file_size
  1576.                                 self.but_f3_run.set_tooltip_text(stri)
  1577.                                 if os.path.exists('ffmpeg2pass-0.log'):
  1578.                                         os.remove('ffmpeg2pass-0.log')
  1579.                                 if os.path.exists('ffmpeg2pass-0.log.mbtree'):
  1580.                                         os.remove('ffmpeg2pass-0.log.mbtree')
  1581.                                 if os.path.exists('x264_lookahead.clbin'):
  1582.                                         os.remove('x264_lookahead.clbin')
  1583.                                 Vars.eff_pass = 0
  1584.                                 self.but_f3_run.set_sensitive(True)
  1585.                                 self.filechooserbutton.set_sensitive(True)
  1586.                                 self.check_2pass.set_sensitive(True)
  1587.                                 self.out_dir_chooserbut.set_sensitive(True)
  1588.                
  1589.                 def check_run(name):
  1590.                         t0 = time.time()
  1591.                         processname = name
  1592.                         for line in subprocess.Popen(["ps", "xa"], shell=False, stdout=subprocess.PIPE).stdout:
  1593.                                 fields = line.split()
  1594.                                 pid = fields[0]
  1595.                                 process = fields[4]
  1596.                                 if process.find(processname) >= 0:              
  1597.                                         if line.find(Vars.filename) >= 0:
  1598.                                                 mypid = pid
  1599.                                                 break
  1600.                         finn = True
  1601.                         while finn == True:
  1602.                                 time.sleep(1)
  1603.                                 finn = os.path.exists("/proc/" + mypid)
  1604.                         if Vars.eff_pass == 0:  
  1605.                                 tfin = time.time() - t0
  1606.                                 Vars.time_done = int(tfin)
  1607.                         else:
  1608.                                 tfin = time.time() - t0
  1609.                                 Vars.time_done_1 = int(tfin)
  1610.                         end_run()
  1611.                
  1612.                 if Vars.eff_pass == 0:
  1613.                         self.check_out_file()
  1614.                         Vars.time_done = 0
  1615.                         Vars.time_done_1 = 0
  1616.                         if Vars.n_pass == 1:
  1617.                                 Vars.final_command1 = ""
  1618.                                 Vars.final_command2 = Vars.ffmpeg_ex + " -i \"" \
  1619.                                         + Vars.filename + "\" " \
  1620.                                         + Vars.p3_command \
  1621.                                         +  " \"" + Vars.newname + "\"" \
  1622.                                         + "\n"
  1623.                                 command = Vars.final_command2
  1624.                        
  1625.                         if Vars.n_pass == 2:
  1626.                                 Vars.final_command1 = Vars.ffmpeg_ex + " -i \"" \
  1627.                                         + Vars.filename + "\" " \
  1628.                                         + Vars.p3_comm_first_p \
  1629.                                         + "\n"
  1630.                                 Vars.final_command2 = Vars.ffmpeg_ex + " -i \"" \
  1631.                                         + Vars.filename + "\" " \
  1632.                                         + Vars.p3_command \
  1633.                                         +  " \"" + Vars.newname + "\"" \
  1634.                                         + "\n"
  1635.                                 command = Vars.final_command1
  1636.                 else:
  1637.                         command = Vars.final_command2
  1638.                        
  1639.                 if Vars.debug == 1:
  1640.                         if Vars.n_pass == 1:
  1641.                                 command = "echo $\'\n\n\n" + Vars.final_command2  + "\' \n"
  1642.                         if Vars.n_pass == 2:
  1643.                                 command = "echo $\'\n\n\n" + Vars.final_command1 + "\n" + Vars.final_command2 + "\' \n"
  1644.                 length = len(command)
  1645.                
  1646.                 self.terminal.feed_child(command, length)
  1647.                 #
  1648.                 if Vars.debug == 0:
  1649.                         self.but_f3_run.set_sensitive(False)
  1650.                         self.filechooserbutton.set_sensitive(False)
  1651.                         if Vars.n_pass == 2:
  1652.                                 self.check_2pass.set_sensitive(False)
  1653.                         self.out_dir_chooserbut.set_sensitive(False)
  1654.                         t = threading.Thread(name='child procs', target=check_run, args=(Vars.ffmpeg_ex,))
  1655.                         t.start()
  1656.              
  1657.         def dir_changed(self, button):
  1658.                 if Vars.first_run:
  1659.                         select = self.out_dir_chooserbut.get_uri()
  1660.                         decoded = url2pathname(select)
  1661.                         newdir = decoded.split('//')[1]
  1662.                         command = "cd " + "\"" + newdir + "\"" + "\n"
  1663.                         length = len(command)
  1664.                         self.terminal.feed_child(command, length)
  1665.                         self.f3_run_outdir_label.set_markup("<b>out dir:  </b>" + newdir)
  1666.                         Vars.outdir = newdir
  1667.                         self.check_out_file()
  1668.                 else:
  1669.                         Vars.first_run = 1
  1670.                        
  1671.        
  1672.        
  1673.                        
  1674.         def on_but_black_det_clicked(self, button):
  1675.                 def update_progress(pprog):
  1676.                         self.progressbar_black_det.set_fraction(pprog)
  1677.                         return False
  1678.                
  1679.                 def update_textv(stri):
  1680.                         self.textbuffer.insert_at_cursor(stri, -1)
  1681.                         return False
  1682.                
  1683.                 if Vars.blackdet_is_run == False:
  1684.                         self.but_black_det.set_label("Stop")
  1685.                         self.textbuffer.set_text('') # clear for insert from start
  1686.                         stri = "Detected:\n\n"
  1687.                         start = self.textbuffer.get_start_iter()
  1688.                         self.textbuffer.insert(start, stri, -1)
  1689.                         self.blackdet_spin.set_sensitive(True)
  1690.                         self.blackdet_spin.start()      
  1691.                        
  1692.                         def my_thread(obj):
  1693.                                 Vars.blackdet_is_run = True
  1694.                                 command = [Vars.ffmpeg_ex, '-i', Vars.filename, '-y', '-an', '-vf', 'blackdetect=d=.5', '-f', 'null', '/dev/null']
  1695.                                 p = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, universal_newlines=True)
  1696.                                 self.bd_th = False
  1697.                                 detected = 0
  1698.                                 time_step = 0
  1699.                                 pprog = 0.0
  1700.                                 stri = ""
  1701.                                 while True:
  1702.                                         line = p.stderr.readline()
  1703.                                         if 'time=' in line:
  1704.                                                 if time_step == 9:
  1705.                                                         tml = line.split('time=')[1]
  1706.                                                         tml2 = tml.split(' ')[0]
  1707.                                                         time_n = tml2.split('.')[0]
  1708.                                                         time_n = self.hms2sec(time_n)
  1709.                                                         time_step = 0
  1710.                                                         pprog = float(time_n)/Vars.duration_in_sec
  1711.                                                         GLib.idle_add(update_progress, pprog)
  1712.                                                         time.sleep(0.002)
  1713.                                                 else:
  1714.                                                         time_step = time_step + 1
  1715.                                         if 'blackdetect ' in line:
  1716.                                                         a = line
  1717.                                                         b = a.split('black_start:')[1]
  1718.                                                         start = b.split(' ')[0]
  1719.                                                         st_in_s = float(start)
  1720.                                                         st_in_s = int(st_in_s)
  1721.                                                         start_in_s = ("%4.1i"% (st_in_s))  
  1722.                                                         start = self.sec2hms(start)
  1723.                                                         stri = "black start at: " + start_in_s + " s, " + start + " "
  1724.                                                         c = b.split('black_duration:')[1]
  1725.                                                         durat = c.split(' ')[0]
  1726.                                                         dur_s = float(durat)
  1727.                                                         dur_s = "{0:0=3.1f}".format(dur_s)
  1728.                                                         stri = stri + "duration: " + dur_s + "s\n"
  1729.                                                         detected = 1
  1730.                                                         GLib.idle_add(update_textv, stri)
  1731.                                                         time.sleep(0.002)
  1732.                                         if line == '' and p.poll() != None:
  1733.                                                 break
  1734.                                         if self.bd_th:
  1735.                                                 p.communicate("q")
  1736.                                                 break  
  1737.                                 if detected == 0:
  1738.                                         stri = "none black gap found"
  1739.                                         self.textbuffer.insert_at_cursor(stri, -1)
  1740.                                 p.communicate()                
  1741.                                 self.blackdet_spin.stop()
  1742.                                 self.blackdet_spin.set_sensitive(False)
  1743.                                 self.but_black_det.set_label("black detectet")
  1744.                                 self.progressbar_black_det.set_fraction(1.0)
  1745.                                 Vars.blackdet_is_run = False
  1746.                                 self.but_black_det.set_sensitive(False)
  1747.                                
  1748.                         thread = threading.Thread(target=my_thread, args=(self,))
  1749.                         thread.daemon = True
  1750.                         thread.start()
  1751.                 elif Vars.blackdet_is_run == True:
  1752.                         self.bd_th = True
  1753.                         stri = "Stopped by user.\n"
  1754.                         self.textbuffer.insert_at_cursor(stri, -1)
  1755.                         self.but_black_det.set_label("Black detect")
  1756.                         self.blackdet_spin.stop()
  1757.                         self.blackdet_spin.set_sensitive(False)
  1758.                         self.progressbar_black_det.set_fraction(0.0)
  1759.                         Vars.blackdet_is_run = False
  1760.        
  1761.                
  1762.         # -------------------------------------  
  1763.        
  1764.         def preview_logic(self):
  1765.                 if ( not(('-map ' in Vars.p3_command ) or ('-vf ' in Vars.p3_command )) ):
  1766.                         self.buttest.set_sensitive(False)
  1767.                         self.buttestspl.set_sensitive(False)
  1768.                 elif ('-map ' in Vars.p3_command) and ('-vf ' in Vars.p3_command):
  1769.                         self.buttest.set_sensitive(False)
  1770.                         self.buttestspl.set_sensitive(False)
  1771.                 elif '-map ' in Vars.p3_command:
  1772.                         self.buttest.set_sensitive(True)
  1773.                         self.buttestspl.set_sensitive(False)
  1774.                 elif '-vf ' in Vars.p3_command:
  1775.                         self.buttest.set_sensitive(True)
  1776.                         self.buttestspl.set_sensitive(True)
  1777.        
  1778.         def calcola_scale(self):
  1779.                 Vars.scalestr = ""
  1780.                 numero = self.size_spinner['adj'].get_value()
  1781.                 numero = int(numero/4)*4
  1782.                 dar = self.box2['cbox'].get_active()
  1783.                 lato = self.box1['cbox'].get_active()          
  1784.                 if (dar == 1): # 4/3
  1785.                         if (lato == 1):
  1786.                                 n2 = numero/4*3
  1787.                         else:
  1788.                                 n2 = numero/3*4
  1789.                         setdar = ",setdar=4/3,setsar=1/1"
  1790.                 elif (dar == 0): # 16/9
  1791.                         if (lato == 1):
  1792.                                 n2 = numero/16*9
  1793.                         else:
  1794.                                 n2 = numero/9*16
  1795.                         setdar = ",setdar=16/9,setsar=1/1"      
  1796.                 elif (dar == 2): #1/1 same as input  
  1797.                         w = int(Vars.video_width)
  1798.                         h = int(Vars.video_height)
  1799.                         if self.checkcr.get_active():
  1800.                                 crT = int(self.spinct['adj'].get_value())
  1801.                                 crB = int(self.spincb['adj'].get_value())
  1802.                                 crL = int(self.spincl['adj'].get_value())
  1803.                                 crR = int(self.spincr['adj'].get_value())
  1804.                                 h = h - crT - crB
  1805.                                 w = w - crL - crR
  1806.                         if (lato == 1): # h                
  1807.                                 n2 = (float(h)/(w/float(numero)))  
  1808.                         else:
  1809.                                 n2 = (float(w)/(h/float(numero)))
  1810.                         setdar = ""
  1811.                 n2 = int(n2/4)*4                    
  1812.                 Vars.scalestr = "scale="
  1813.                 if (lato == 1):
  1814.                         Vars.scalestr = Vars.scalestr + str(numero) + ":" + str(n2)
  1815.                 else:
  1816.                         Vars.scalestr = Vars.scalestr + str(n2) + ":" + str(numero)                  
  1817.                 lanc = self.check.get_active()  
  1818.                 if lanc:
  1819.                         Vars.scalestr = Vars.scalestr + ":flags=lanczos" + setdar  
  1820.                 else:
  1821.                         Vars.scalestr = Vars.scalestr + setdar
  1822.                 self.outfilter()
  1823.                      
  1824.         def outfilter(self):
  1825.                 final_str = ""
  1826.                 if (Vars.deint_str != ""):
  1827.                         final_str = final_str + Vars.deint_str    
  1828.                 if (Vars.crop_str != ""):
  1829.                         if (final_str == ""):
  1830.                                 final_str = final_str + Vars.crop_str
  1831.                         else:
  1832.                                         final_str = final_str + "," + Vars.crop_str
  1833.                 if (Vars.scalestr != ""):
  1834.                         if (final_str == ""):
  1835.                                 final_str = final_str + Vars.scalestr
  1836.                         else:
  1837.                                 final_str = final_str + "," + Vars.scalestr
  1838.                 if (Vars.dn_str != ""):
  1839.                         if (final_str == ""):
  1840.                                 final_str = final_str + Vars.dn_str
  1841.                         else:
  1842.                                 final_str = final_str + "," + Vars.dn_str
  1843.                 if (Vars.uns_str != ""):
  1844.                         if (final_str == ""):
  1845.                                 final_str = final_str + Vars.uns_str
  1846.                         else:
  1847.                                 final_str = final_str + "," + Vars.uns_str
  1848.                 Vars.filter_test_str = final_str
  1849.                
  1850.                 if (final_str != ""):
  1851.                         Vars.final_vf_str = "-vf " + final_str
  1852.                 else:
  1853.                         Vars.final_vf_str = ""
  1854.                
  1855.                 label_str = ""          
  1856.                 if (Vars.maps_str != ""):
  1857.                         label_str = label_str + Vars.maps_str + " "  
  1858.                 if (Vars.time_final_str != ""):
  1859.                         label_str = label_str + Vars.time_final_str + " "                      
  1860.                 if (Vars.fr_str != ""):
  1861.                         label_str = label_str + Vars.fr_str + " "                      
  1862.                 if (Vars.final_vf_str != ""):
  1863.                         label_str = label_str + Vars.final_vf_str
  1864.                    
  1865.                 self.labelout.set_text(label_str)      
  1866.                 self.make_p3_out_command()
  1867.                 if (Vars.info_str != ""):
  1868.                         self.preview_logic()    
  1869.        
  1870.         def make_p3_out_command(self):
  1871.                 Vars.p3_command = ""
  1872.                 Vars.p3_comm_first_p = ""
  1873.                 self.f3_out_label.set_label("")
  1874.                 if (Vars.maps_str != ""):
  1875.                         Vars.p3_command = Vars.maps_str + " "  
  1876.                 if (Vars.time_final_str != ""):
  1877.                         Vars.p3_command = Vars.p3_command + Vars.time_final_str + " "
  1878.                 if ( (Vars.fr_str != "") and (Vars.v_copy == 0) ): # check -vcopy
  1879.                                 Vars.p3_command = Vars.p3_command + Vars.fr_str + " "                  
  1880.                 if ( (Vars.final_vf_str != "") and (Vars.v_copy == 0) ): # check -vcopy
  1881.                         Vars.p3_command = Vars.p3_command + Vars.final_vf_str + " "
  1882.                 # first pass    
  1883.                 if Vars.first_pass:
  1884.                         Vars.p3_comm_first_p = Vars.p3_command + Vars.video_codec_str + " "
  1885.                         if self.check_cpu.get_active():
  1886.                                 Vars.p3_comm_first_p = Vars.p3_comm_first_p + "-threads 3 "
  1887.                         if "libx264" in Vars.p3_comm_first_p:
  1888.                                 Vars.p3_comm_first_p = Vars.p3_comm_first_p + "-pass 1 -fastfirstpass 1 "
  1889.                         else:
  1890.                                 Vars.p3_comm_first_p = Vars.p3_comm_first_p + "-pass 1 "
  1891.                         Vars.p3_comm_first_p = Vars.p3_comm_first_p + "-an -f null /dev/null"
  1892.                 else:
  1893.                         Vars.p3_comm_first_p = ""
  1894.                        
  1895.                 if ( (Vars.final_af_str != "") and (Vars.a_copy == 0) and (Vars.audionone == 0) ):  # check -acopy -an
  1896.                         Vars.p3_command = Vars.p3_command + Vars.final_af_str + " "
  1897.                 if (Vars.final_codec_str != ""):
  1898.                         Vars.p3_command = Vars.p3_command + Vars.final_codec_str + " "
  1899.                
  1900.                 #second pass
  1901.                 if Vars.n_pass == 2:
  1902.                         Vars.p3_command = Vars.p3_command + "-pass 2" + " "
  1903.                        
  1904.                 if (Vars.container_str != ""):
  1905.                         Vars.p3_command = Vars.p3_command + Vars.container_str + " "
  1906.                 if (Vars.final_other_str != ""):
  1907.                         Vars.p3_command = Vars.p3_command + Vars.final_other_str + " "
  1908.                 self.f3_out_label.set_label(Vars.p3_command)
  1909.                
  1910.         def main(self):
  1911.                 Gtk.main()
  1912.  
  1913.                
  1914.        
  1915.  
  1916. if __name__ == "__main__":
  1917.         GObject.threads_init()
  1918.         ProgrammaGTK()
  1919.         Gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement