Advertisement
Guest User

4ffmpeg-8.071

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