Advertisement
Guest User

4ffmpeg-8.045

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