Advertisement
Guest User

4ffmpeg-8.019

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