Advertisement
Guest User

4ffmpeg-8.055

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