Advertisement
Guest User

4ffmpeg-8.088

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