Guest User

4ffmpeg-8.222

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