Advertisement
Guest User

4ffmpeg-8.036

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