Advertisement
Guest User

4ffmpeg-8.025

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