Advertisement
Guest User

4ffmpeg-8.081

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