Advertisement
Guest User

4ffmpeg-8.053

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