Advertisement
Guest User

4ffmpeg-8.196

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