Advertisement
Guest User

4ffmpeg-8.128

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