Advertisement
Guest User

4ffmpeg-8.123

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