Advertisement
Guest User

4ffmpeg-8.106

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