Advertisement
Guest User

4ffmpeg_7.37

a guest
Nov 20th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 80.65 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # work in python3.4
  5.  
  6. from gi.repository import Gtk, GObject, Vte
  7. from gi.repository import GLib
  8. import os
  9. import sys, subprocess, shlex, re
  10. from subprocess import call
  11. from math import pow
  12. from urllib import url2pathname
  13. from gi.repository import Pango
  14. import threading
  15.                
  16. class reuse_init(object):
  17.  
  18.  
  19.         def make_label(self, text):
  20.                 label = Gtk.Label(text)
  21.                 label.set_use_underline(True)
  22.                 label.set_alignment(1.0, 0.5)
  23.                 label.show()
  24.                 return label
  25.  
  26.         def make_slider_and_spinner(self, init, min, max, step, page, digits):
  27.                 controls = {'adj':Gtk.Adjustment(init, min, max, step, page), 'slider':Gtk.HScale(), 'spinner':Gtk.SpinButton()}
  28.                 controls['slider'].set_adjustment(controls['adj'])
  29.                 controls['slider'].set_draw_value(False)
  30.                 controls['spinner'].set_adjustment(controls['adj'])
  31.                 controls['spinner'].set_digits(digits)
  32.                 controls['slider'].show()
  33.                 controls['spinner'].show()
  34.                 return controls
  35.        
  36.         def make_frame_ag(self, f_shadow_type, f_label, alig_pad, gri_row_sp, gri_colu_sp, gri_homog):
  37.                 controls =  {'frame':Gtk.Frame(), 'ali':Gtk.Alignment(), 'grid':Gtk.Grid()}
  38.                 controls['frame'].set_shadow_type(f_shadow_type) # 3 GTK_SHADOW_ETCHED_IN , 1 GTK_SHADOW_IN
  39.                 controls['frame'].set_label(f_label)
  40.                 controls['ali'].set_padding(alig_pad, alig_pad, alig_pad, alig_pad)
  41.                 controls['frame'].add(controls['ali'])
  42.                 controls['grid'].set_row_spacing(gri_row_sp)
  43.                 controls['grid'].set_column_spacing(gri_colu_sp)
  44.                 controls['grid'].set_column_homogeneous(gri_homog) # True
  45.                 controls['ali'].add(controls['grid'])
  46.                 controls['frame'].show()
  47.                 controls['ali'].show()
  48.                 controls['grid'].show()
  49.                 return controls
  50.        
  51.         def make_spinbut(self, init, min, max, step, page, digits, numeric):
  52.                 controls = {'adj':Gtk.Adjustment(init, min, max, step, page), 'spinner':Gtk.SpinButton()}
  53.                 controls['spinner'].set_adjustment(controls['adj'])
  54.                 controls['spinner'].set_digits(digits)
  55.                 controls['spinner'].set_numeric(numeric)
  56.                 controls['spinner'].show()
  57.                 return controls
  58.        
  59.         def make_combobox(self, *vals):
  60.                 controls = {'list':Gtk.ListStore(str), 'cbox':Gtk.ComboBox(), 'cellr':Gtk.CellRendererText()}
  61.                 for i, v in enumerate(vals):
  62.                         controls['list'].append([v])
  63.                 controls['cbox'].set_model(controls['list'])      
  64.                 controls['cbox'].pack_start(controls['cellr'], True)
  65.                 controls['cbox'].add_attribute(controls['cellr'], "text", 0)
  66.                 controls['cbox'].set_active(0)
  67.                 controls['cbox'].show()
  68.                 return controls
  69.        
  70.         def hms2sec(self, hms):
  71.                 result = 0
  72.                 listin = hms.split(':')
  73.                 listin.reverse()
  74.                 for i in range(len(listin)):
  75.                         if listin[i].isdigit():
  76.                                 if i == 0:
  77.                                         mult = 1
  78.                                 if i == 1:
  79.                                         mult = 60
  80.                                 if i == 2:
  81.                                         mult = 3600
  82.                                 result = result + (int(listin[i])*mult)            
  83.                 return result
  84.        
  85.         def sec2hms(self, seconds):
  86.                 seconds = float(seconds)
  87.                 h = int(seconds/3600)
  88.                 if (h > 0):
  89.                         seconds = seconds - (h * 3600)
  90.                 m = int(seconds / 60)
  91.                 s = int(seconds - (m * 60))
  92.                 hms = "{0:0=2d}:{1:0=2d}:{2:0=2d}".format(h,m,s)
  93.                 return hms
  94.        
  95.         def adj_change(self, adjustment, value, lower, upper , step_increment, page_increment):
  96.                 adjustment.set_value(value)
  97.                 adjustment.set_lower(lower)
  98.                 adjustment.set_upper(upper)
  99.                 adjustment.set_step_increment(step_increment)
  100.                 adjustment.set_page_increment(page_increment)
  101.                 #adjustment.set_page_size(page_size)
  102.        
  103.        
  104.        
  105. class ProgrammaGTK(reuse_init):
  106.        
  107.  
  108.         def __init__(self):
  109.                
  110.                 self.window =  Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
  111.                 self.window.connect("destroy", self.on_window_destroy)
  112.                 self.window.set_title("4FFmpeg")
  113.                 self.window.set_position(1) # 1 center, 0 none,
  114.                 self.window.set_border_width(3)
  115.                 self.window.set_default_size(500,-1)
  116.                 #----------------------------------
  117.                
  118.                 #page1 stuff VIDEO FILTERS------------------------------------------
  119.                                
  120.                 # page1 VBox -------------------------
  121.                 self.vbox1 = Gtk.VBox()
  122.                 self.vbox1.set_spacing(2)
  123.                
  124.                 # map --------------------------------------
  125.                 self.make_map()        
  126.                 # add map frame
  127.                 self.vbox1.pack_start(self.f_map['frame'], 1, 0, 0)
  128.                
  129.                 #time cut ------------------------------------
  130.                 self.make_time_cut()
  131.                 # add time frame
  132.                 self.vbox1.pack_start(self.f_time['frame'], 1, 0, 0)
  133.                
  134.                 # deinterlace -----------------------
  135.                 self.make_deinterlace()
  136.                 # add deinterlace frame
  137.                 self.vbox1.pack_start(self.f_deint['frame'], 1, 0, 0)
  138.                
  139.                 # crop ----------------------------------------
  140.                 self.make_crop()        
  141.                 # add crop frame -------------------
  142.                 self.vbox1.pack_start(self.frame_crop['frame'], 1, 0, 0)
  143.        
  144.                 # scale ------------------------------
  145.                 self.make_scale()
  146.                 # add scale frame------------------
  147.                 self.vbox1.pack_start(self.frame_scale['frame'], 1, 0, 0)
  148.  
  149.                 # denoise ----------------------------
  150.                 self.make_denoise()
  151.                 # add denoise frame------------------------
  152.                 self.vbox1.pack_start(self.frame_dn['frame'], 1, 0, 0)
  153.                
  154.                 #test-------------------
  155.                 #self.f_test = self.make_frame_ag(3, "TEST" , 6, 8, 8, True)
  156.                 #self.label_test = Gtk.Label("TEST")
  157.                 #self.f_test['grid'].attach(self.label_test, 0, 0, 1, 1)
  158.  
  159.                 #self.vbox1.pack_start(self.f_test['frame'], 1, 0, 0)
  160.                 #-------------------------------------
  161.                
  162.                 # page 1 output------------------------
  163.                 self.frame_out = self.make_frame_ag(3, '  FFmpeg video filter string (select and copy):  ' , 12, 8, 8, True)
  164.                 self.labelout = Gtk.Label("")
  165.                 self.labelout.set_selectable(1)
  166.                 self.frame_out['grid'].attach(self.labelout, 0, 0, 1 ,1)
  167.                 # add output frame ---------------------
  168.                 self.vbox1.pack_start(self.frame_out['frame'], 1, 0, 0)
  169.                
  170.                 # end page1 stuff
  171.                
  172.                
  173.                 # page2 stuff  UTILITY ------------------------------------------
  174.                
  175.                 # page2 VBox -------------------------
  176.                 self.vbox_pg2 = Gtk.VBox()
  177.                 self.vbox_pg2.set_spacing(2)
  178.                
  179.                 #volumedetect ------------------------------------
  180.                 self.make_volume_det()
  181.                 # add volumedetect frame        
  182.                 self.vbox_pg2.pack_start(self.f_volume_det['frame'], 1, 0, 0)
  183.                
  184.                 # black detect ----------------------------------
  185.                 self.make_black_detect()
  186.                 # add black_detect frame
  187.                 self.vbox_pg2.pack_start(self.f_blackd['frame'], 1, 0, 0)
  188.                
  189.                 # info frame----------------------
  190.                 self.make_info_frame()
  191.                 # add info frame
  192.                 self.vbox_pg2.pack_start(self.f_info['frame'], 1, 0, 0)
  193.                
  194.                 # end page2 stuff
  195.                
  196.                 # page 3 stuff  730 cuatom commands -----------------------------------------
  197.                
  198.                 # page3 VBox -------------------------
  199.                 self.vbox_pg3 = Gtk.VBox()
  200.                 self.vbox_pg3.set_spacing(2)
  201.                
  202.                 # audio codec -------------------
  203.                 self.make_audio_codec()
  204.                 #add frame audio codec
  205.                 self.vbox_pg3.pack_start(self.f_3acodec['frame'], 1, 0, 0)
  206.                
  207.                 # video codec -------------------
  208.                 self.make_video_codec()
  209.                 #add frame video codec
  210.                 self.vbox_pg3.pack_start(self.f_3vcodec['frame'], 1, 0, 0)
  211.                
  212.                 # other options ----------------
  213.                 self.make_other_opts()
  214.                 #add frame other options
  215.                 self.vbox_pg3.pack_start(self.f3_oth['frame'], 1, 0, 0)
  216.                
  217.                 # page3 output ---------------------
  218.                 self.f3_out = self.make_frame_ag(3, "  730 command  " , 6, 8, 8, True)
  219.                 self.f3_out_label = Gtk.Label("")
  220.                 self.f3_out['grid'].attach(self.f3_out_label, 0, 0, 1, 1)
  221.                 # add frame page3 output
  222.                 self.vbox_pg3.pack_start(self.f3_out['frame'], 1, 0, 0)
  223.                
  224.                 # run 730 ---------------------------------
  225.                 self.make_run_730()
  226.                 # add frame run 730
  227.                 self.vbox_pg3.pack_start(self.f3_run['frame'], 1, 0, 0)
  228.                
  229.                
  230.                 #---------------------------------------------------
  231.                 # main vbox
  232.                 self.main_vbox = Gtk.VBox()
  233.                
  234.                 # notebook      
  235.                 self.notebook = Gtk.Notebook()
  236.                 self.notebook.set_tab_pos(0)  #GTK_POS_LEFT
  237.                 self.notebook.set_show_border (False)
  238.                 self.main_vbox.pack_start(self.notebook, 1, 0, 0)
  239.                
  240.                 #page 1
  241.                 self.tab1label = Gtk.Label("Video filters")
  242.                 self.page1_ali = Gtk.Alignment()
  243.                 self.page1_ali.set_padding(0, 6, 6, 6)
  244.                 self.page1_ali.add(self.vbox1)
  245.                 self.notebook.append_page(self.page1_ali, self.tab1label)
  246.                
  247.                 #page 2
  248.                 self.tab2label = Gtk.Label("Utility")
  249.                 self.page2_ali = Gtk.Alignment()
  250.                 self.page2_ali.set_padding(0, 6, 6, 6)
  251.                 self.page2_ali.add(self.vbox_pg2)
  252.                 self.notebook.append_page(self.page2_ali, self.tab2label)
  253.                
  254.                 #page 3
  255.                 self.tab3label = Gtk.Label("730")
  256.                 self.page3_ali = Gtk.Alignment()
  257.                 self.page3_ali.set_padding(0, 6, 6, 6)
  258.                 self.page3_ali.add(self.vbox_pg3)
  259.                 self.notebook.append_page(self.page3_ali, self.tab3label)
  260.                
  261.                 #---------------------------------------------------
  262.                
  263.                 # low part BUTTONS AND TERM --------------------------
  264.                 self.make_low_part()
  265.                 # add low part-----------------
  266.                 self.main_vbox.pack_start(self.gridterm, 1, 1, 0)
  267.                
  268.                 #---------------------------------------------------------
  269.                 self.window.add (self.main_vbox)
  270.                 #---------------------------------
  271.                 self.window.show_all()
  272.                
  273.                 # initialize variables
  274.                 self.final_vf_str = ""
  275.                 self.final_af_str = ""
  276.                 self.deint_str = ""
  277.                 self.crop_str = ""
  278.                 self.scalestr = ""
  279.                 self.dn_str = ""
  280.                 self.filter_test_str = ""
  281.                 self.video_width = "0"
  282.                 self.video_height = "0"
  283.                 self.add_1_1 = True
  284.                 self.maps_str = ""
  285.                 self.time_final_srt = ""
  286.                 self.final_codec_str = "-aaq -crf 21"
  287.                 self.final_other_str = ""
  288.                 self.a_copy = 0
  289.                 self.v_copy = 0
  290.                 self.container_str = "-mkv"
  291.                 self.preset_str = "-faster"
  292.                 self.info_str = ''
  293.                 self.make_p3_out_command()
  294.                 self.blackdet_is_run = False
  295.                 self.first_run = 0
  296.                
  297.                 # ----------------------------
  298.                
  299.         def make_deinterlace(self):
  300.                 self.f_deint = self.make_frame_ag(3, "" , 6, 8, 8, True)
  301.                 self.checkdeint = Gtk.CheckButton("deinterlace")
  302.                 self.checkdeint.connect("toggled", self.on_deint_clicked)
  303.                 self.f_deint['grid'].attach(self.checkdeint, 0, 0, 1, 1)
  304.                
  305.                 self.box_deint = self.make_combobox(
  306.                   "yadif",
  307.                   "postprocessing linear blend"
  308.                   )
  309.                 self.f_deint['grid'].attach(self.box_deint['cbox'], 1, 0, 1, 1)
  310.                 self.box_deint['cbox'].connect("changed", self.on_deint_clicked)
  311.                 #
  312.                 self.f_deint['grid'].attach(self.make_label(""), 2, 0, 1, 1)
  313.        
  314.         def make_map(self):
  315.                 #
  316.                 self.map_tooltip_str = ' use 0:0  or  0:0,0:1,0:2 '
  317.                 #
  318.                 self.f_map = self.make_frame_ag(3, "" , 6, 8, 8, True)
  319.                 #
  320.                 self.check_map = Gtk.CheckButton("map")
  321.                 self.check_map.connect("toggled", self.on_map_clicked) # toggled or activate (enter)
  322.                 self.f_map['grid'].attach(self.check_map, 0, 0, 1, 1)
  323.                 #
  324.                 self.mapstream_label = self.make_label("streams: ")
  325.                 self.f_map['grid'].attach(self.mapstream_label, 1, 0, 1, 1)
  326.                 #
  327.                 self.entry_map = Gtk.Entry()
  328.                 self.entry_map.set_tooltip_text(self.map_tooltip_str)
  329.                 self.entry_map.connect("changed", self.on_map_clicked)
  330.                 self.f_map['grid'].attach(self.entry_map, 2, 0, 1, 1)
  331.                 #
  332.                 self.map_label = Gtk.Label("")
  333.                 self.f_map['grid'].attach(self.map_label, 3, 0, 1, 1)
  334.                 # placeholder
  335.                 self.f_map['grid'].attach(self.make_label(""), 4, 0, 1, 1)
  336.                
  337.         def make_time_cut(self):
  338.                 #
  339.                 self.time_tooltip_str = ' use: 90 or 00:01:30 '
  340.                 #
  341.                 self.f_time = self.make_frame_ag(3, "" , 6, 8, 8, True)
  342.                 #
  343.                 self.check_time = Gtk.CheckButton("time")
  344.                 self.check_time.connect("toggled", self.on_time_clicked) # toggled or activate (enter)
  345.                 self.f_time['grid'].attach(self.check_time, 0, 0, 1, 1)
  346.                 #
  347.                 self.label_time_in = self.make_label("from: ")
  348.                 self.f_time['grid'].attach(self.label_time_in, 1, 0, 1, 1)
  349.                 self.entry_timein = Gtk.Entry()
  350.                 self.entry_timein.set_tooltip_text(self.time_tooltip_str)
  351.                 self.entry_timein.connect("changed", self.on_time_clicked)
  352.                 self.f_time['grid'].attach(self.entry_timein, 2, 0, 1, 1)
  353.                
  354.                 self.label_time_out = self.make_label("to: ")
  355.                 self.f_time['grid'].attach(self.label_time_out, 3, 0, 1, 1)
  356.                 self.entry_timeout = Gtk.Entry()
  357.                 self.entry_timeout.set_tooltip_text(self.time_tooltip_str)
  358.                 self.entry_timeout.connect("changed", self.on_time_clicked)
  359.                 self.f_time['grid'].attach(self.entry_timeout, 4, 0, 1, 1)
  360.        
  361.         def make_scale(self):
  362.                 self.frame_scale = self.make_frame_ag(3, '  scale  ' , 6, 8, 8, True)
  363.                 # ------------------------------
  364.                 self.box1 = self.make_combobox(
  365.                   "None",
  366.                   "W",
  367.                   "H"
  368.                   )
  369.                 self.frame_scale['grid'].attach(self.box1['cbox'], 0, 0, 1, 1)
  370.                 self.box1['cbox'].connect("changed", self.on_scale_clicked)
  371.                 #------------------------------------
  372.                 self.box2 = self.make_combobox(
  373.                   "16/9",
  374.                   "4/3"
  375.                   )
  376.                 self.frame_scale['grid'].attach(self.box2['cbox'], 0, 1, 1, 1)
  377.                 self.box2['cbox'].connect("changed", self.on_scale_clicked)
  378.                 #-----------------------------------------
  379.                 self.size_spinner = self.make_slider_and_spinner(720, 200, 2000, 1, 10, 0)
  380.                 self.frame_scale['grid'].attach(self.size_spinner['slider'], 1, 0, 1, 1)
  381.                 self.frame_scale['grid'].attach(self.size_spinner['spinner'], 2, 0, 1, 1)
  382.                 #self.size_spinner['slider'].set_size_request(150,-1)
  383.                 self.size_spinner['adj'].set_value(720.001) #mettere decimali se no non si vede
  384.                 self.size_spinner['adj'].connect("value-changed", self.on_scale_clicked)
  385.                 #-------------------------------------------------------
  386.                 self.check = Gtk.CheckButton("lanczos")
  387.                 self.check.connect("toggled", self.on_scale_clicked)
  388.                 self.frame_scale['grid'].attach(self.check, 2, 1, 1, 1)
  389.                
  390.         def make_crop(self):
  391.                 self.frame_crop = self.make_frame_ag(3, '' , 6, 2, 0, True)
  392.                 # -------
  393.                 self.checkcr = Gtk.CheckButton("crop")
  394.                 self.checkcr.connect("toggled", self.on_crop_clicked)
  395.                 self.frame_crop['grid'].attach(self.checkcr, 0, 0, 1, 1)
  396.                 #----------
  397.                 self.butcrode = Gtk.Button(label="Crop detect")
  398.                 self.butcrode.connect("clicked", self.on_butcrode_clicked)
  399.                 self.frame_crop['grid'].attach(self.butcrode, 0, 1, 1, 1)
  400.                 #-----------
  401.                 self.labelcropinw = self.make_label("input W: ")
  402.                 self.frame_crop['grid'].attach(self.labelcropinw, 1, 0, 1, 1)
  403.                 self.labelcropinh = self.make_label("input H: ")
  404.                 self.frame_crop['grid'].attach(self.labelcropinh, 1, 1, 1, 1)
  405.                 #
  406.                 self.spincw = self.make_spinbut(640 , 100 , 1920 , 10 , 1 , 0, True )
  407.                 self.spincw["adj"].connect("value-changed", self.on_crop_clicked)
  408.                 self.frame_crop['grid'].attach(self.spincw["spinner"], 2, 0, 1, 1)
  409.                 #
  410.                 self.spinch = self.make_spinbut(480 , 100 , 1280 , 10 , 1 , 0, True )
  411.                 self.spinch["adj"].connect("value-changed", self.on_crop_clicked)
  412.                 self.frame_crop['grid'].attach(self.spinch["spinner"], 2, 1, 1, 1)
  413.                 #
  414.                
  415.                 self.labelcroptop = self.make_label("crop Top: ")
  416.                 self.frame_crop['grid'].attach(self.labelcroptop, 3, 0, 1, 1)
  417.                 self.labelcropbot = self.make_label("crop Bottom: ")
  418.                 self.frame_crop['grid'].attach(self.labelcropbot, 3, 1, 1, 1)
  419.                 #
  420.                
  421.                 self.spinct = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  422.                 self.spinct["adj"].connect("value-changed", self.on_crop_clicked)
  423.                 self.frame_crop['grid'].attach(self.spinct["spinner"], 4, 0, 1, 1)
  424.                 #
  425.                 self.spincb = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  426.                 self.spincb["adj"].connect("value-changed", self.on_crop_clicked)
  427.                 self.frame_crop['grid'].attach(self.spincb["spinner"], 4, 1, 1, 1)
  428.                 #
  429.                
  430.                 self.labelcroplef = self.make_label("crop Left: ")
  431.                 self.frame_crop['grid'].attach(self.labelcroplef, 5, 0, 1, 1)
  432.                 self.labelcroprig = self.make_label("crop Right: ")
  433.                 self.frame_crop['grid'].attach(self.labelcroprig, 5, 1, 1, 1)
  434.                 #
  435.                 self.spincl = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  436.                 self.spincl["adj"].connect("value-changed", self.on_crop_clicked)
  437.                 self.frame_crop['grid'].attach(self.spincl["spinner"], 6, 0, 1, 1)
  438.                 #
  439.                 self.spincr = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  440.                 self.spincr["adj"].connect("value-changed", self.on_crop_clicked)
  441.                 self.frame_crop['grid'].attach(self.spincr["spinner"], 6, 1, 1, 1)
  442.                
  443.                
  444.         def make_denoise(self):
  445.                 self.frame_dn = self.make_frame_ag(3, '' , 6, 8, 8, True)
  446.                 # ----------------------
  447.                 self.checkdn = Gtk.CheckButton("denoise")
  448.                 self.checkdn.connect("toggled", self.on_dn_clicked)
  449.                 self.frame_dn['grid'].attach(self.checkdn, 0, 0, 1, 1)
  450.                 # -------------------------
  451.                 self.labeldn = Gtk.Label("hqdn3d:")
  452.                 self.labeldn.set_alignment(1.0, 0.5)
  453.                 self.frame_dn['grid'].attach(self.labeldn, 1, 0, 1, 1)
  454.                 #----------------------------------------
  455.                 self.spindn = self.make_spinbut(4 , 2 , 8 , 1 , 10 , 0, True )
  456.                 self.spindn["adj"].connect("value-changed", self.on_dn_clicked)
  457.                 self.frame_dn['grid'].attach(self.spindn["spinner"], 2, 0, 1, 1)
  458.                
  459.         def make_low_part(self):
  460.                 # grid
  461.                 self.gridterm = Gtk.Grid()
  462.                 self.gridterm.set_row_spacing(2)
  463.                 self.gridterm.set_column_spacing(2)
  464.                 self.gridterm.set_column_homogeneous(True) # True
  465.                 # filechooserbutton
  466.                 self.filechooserbutton = Gtk.FileChooserButton(title="FileChooserButton")
  467.                 #
  468.                 #self.filechooserbutton.set_action(2) # 0 open file, 1 save file, 2 select folder, 3 create folder
  469.                 #
  470.                 self.filechooserbutton.connect("file-set", self.file_changed)  
  471.                 # filter
  472.                 self.filter = Gtk.FileFilter()
  473.                 self.filter.set_name("Video")
  474.                 self.filter.add_mime_type("video/x-matroska")
  475.                 self.filter.add_mime_type("video/mp4")
  476.                 self.filter.add_mime_type("video/x-flv")
  477.                 self.filter.add_mime_type("video/avi")
  478.                 self.filter.add_mime_type("video/mpg")
  479.                 self.filter.add_mime_type("video/mpeg")
  480.                 self.filter.add_mime_type("video/x-ms-wmv")
  481.                 self.filter.add_mime_type("video/webm")
  482.                 self.filter.add_mime_type("video/ogg")
  483.                 self.filter.add_mime_type("video/quicktime")
  484.                 self.filechooserbutton.add_filter(self.filter)
  485.                 # terminal
  486.                 self.terminal     = Vte.Terminal()
  487.                 self.terminal.fork_command_full(
  488.                         Vte.PtyFlags.DEFAULT, #default is fine
  489.                         os.getcwd(), #where to start the command?   os.environ['HOME']
  490.                         ["/bin/sh"], #where is the emulator?
  491.                         [], #it's ok to leave this list empty
  492.                         GLib.SpawnFlags.DO_NOT_REAP_CHILD,
  493.                         None, #at least None is required
  494.                         None,
  495.                         )
  496.                 self.scroller = Gtk.ScrolledWindow()
  497.                 self.scroller.set_hexpand(True)
  498.                 self.scroller.set_vexpand(True)
  499.                 self.scroller.add(self.terminal)
  500.                 self.scroller.set_min_content_height(90)
  501.                 #self.gridterm.attach(self.scroller, 0, 1, 6, 1)
  502.                 #ff command button
  503.                 self.butplay = Gtk.Button(label="FFplay")
  504.                 self.butplay.connect("clicked", self.on_butplay_clicked)
  505.                 self.butplay.set_sensitive(False)
  506.                 self.butprobe = Gtk.Button(label="FFprobe")
  507.                 self.butprobe.connect("clicked", self.on_butprobe_clicked)
  508.                 self.butprobe.set_sensitive(False)
  509.                 #self.butcrode = Gtk.Button(label="Crop detect")
  510.                 #self.butcrode.connect("clicked", self.on_butcrode_clicked)
  511.                 self.butcrode.set_sensitive(False)
  512.                 self.buttest = Gtk.Button(label="Test")
  513.                 self.buttest.connect("clicked", self.on_buttest_clicked)
  514.                 self.buttest.set_sensitive(False)
  515.                 self.buttestspl = Gtk.Button(label="Test split")
  516.                 self.buttestspl.connect("clicked", self.on_buttestspl_clicked)
  517.                 self.buttestspl.set_sensitive(False)
  518.                
  519.                 self.gridterm.attach(self.filechooserbutton, 0, 0, 1, 1)
  520.                 self.gridterm.attach(self.butprobe, 1, 0, 1, 1)
  521.                 self.gridterm.attach(self.butplay, 2, 0, 1, 1)
  522.                 #self.gridterm.attach(self.butcrode, 3, 0, 1, 1)
  523.                 self.gridterm.attach(self.buttest, 3, 0, 1, 1)
  524.                 self.gridterm.attach(self.buttestspl, 4, 0, 1, 1)
  525.                
  526.                 self.gridterm.attach(self.scroller, 0, 1, 5, 1)
  527.  
  528.         def make_volume_det(self):
  529.                 self.f_volume_det = self.make_frame_ag(3, "" , 6, 8, 8, True)
  530.                 #
  531.                 self.but_volume_det = Gtk.Button(label="Volume detect")
  532.                 self.but_volume_det.connect("clicked", self.on_but_volume_det_clicked)
  533.                 self.but_volume_det.set_sensitive(False)
  534.                 self.f_volume_det['grid'].attach(self.but_volume_det, 0, 0, 1, 1)
  535.                 #
  536.                 self.voldet_spin = Gtk.Spinner()
  537.                 self.voldet_spin.set_sensitive(False)
  538.                 self.f_volume_det['grid'].attach(self.voldet_spin, 1, 0, 1, 1)
  539.                 #
  540.                 self.label_maxvol = Gtk.Label("")
  541.                 self.f_volume_det['grid'].attach(self.label_maxvol, 2, 0, 1, 1)
  542.                 self.label_meanvol = Gtk.Label("")
  543.                 self.f_volume_det['grid'].attach(self.label_meanvol, 3, 0, 1, 1)
  544.                 #
  545.                 self.check_vol = Gtk.CheckButton("volume")
  546.                 self.check_vol.connect("toggled", self.on_volume_clicked)
  547.                 self.f_volume_det['grid'].attach(self.check_vol, 0, 1, 1, 1)
  548.                 #
  549.                 self.label_db = self.make_label("dB: ")
  550.                 self.f_volume_det['grid'].attach(self.label_db, 1, 1, 1, 1)
  551.                 self.spin_db = self.make_spinbut(0 , -6 , 20 , 0.1 , 1 , 2, True )
  552.                 self.spin_db["adj"].connect("value-changed", self.on_volume_clicked)
  553.                 self.f_volume_det['grid'].attach(self.spin_db["spinner"], 2, 1, 1, 1)
  554.                 self.label_ratio = self.make_label("ratio: ")
  555.                 self.f_volume_det['grid'].attach(self.label_ratio, 3, 1, 1, 1)
  556.                 self.label_ratio_val = Gtk.Label("")
  557.                 self.f_volume_det['grid'].attach(self.label_ratio_val, 4, 1, 1, 1)
  558.  
  559.         def make_black_detect(self):
  560.                 self.f_blackd = self.make_frame_ag(3, "" , 6, 8, 8, True)
  561.                 #
  562.                 self.but_black_det = Gtk.Button(label="Black detect")
  563.                 self.but_black_det.connect("clicked", self.on_but_black_det_clicked)
  564.                 self.but_black_det.set_sensitive(False)
  565.                 self.f_blackd['grid'].attach(self.but_black_det, 0, 0, 1, 1)
  566.                 #
  567.                 self.blackdet_spin = Gtk.Spinner()
  568.                 self.blackdet_spin.set_sensitive(False)
  569.                 self.f_blackd['grid'].attach(self.blackdet_spin, 1, 0, 1, 1)
  570.                 #
  571.                 scrolledwindow = Gtk.ScrolledWindow()
  572.                 #scrolledwindow.set_hexpand(True)
  573.                 scrolledwindow.set_vexpand(True)
  574.                 self.textview = Gtk.TextView()
  575.                 self.textbuffer = self.textview.get_buffer()
  576.                 self.textview.set_editable(False)
  577.                 self.textview.set_cursor_visible(False)
  578.                 self.textview.modify_font(Pango.font_description_from_string('Monospace 9'))
  579.                 scrolledwindow.add(self.textview)
  580.                 self.black_dt_init_str = 'Detect black frames can take some time,\ndepending on the length of the video.'
  581.                 self.textbuffer.set_text(self.black_dt_init_str)
  582.                 self.f_blackd['grid'].attach(scrolledwindow, 2, 0, 3, 3)
  583.                 #
  584.                 self.progressbar_black_det = Gtk.ProgressBar()
  585.                 self.f_blackd['grid'].attach(self.progressbar_black_det, 0, 1, 1, 1)
  586.                
  587.         def make_info_frame(self):
  588.                 self.f_info = self.make_frame_ag(3, "  info  " , 6, 8, 8, True)
  589.                 scrolledwindow1 = Gtk.ScrolledWindow()
  590.                 scrolledwindow1.set_hexpand(True)
  591.                 scrolledwindow1.set_vexpand(True)
  592.                 self.textview_info = Gtk.TextView()
  593.                 self.textbuffer_info = self.textview_info.get_buffer()
  594.                 self.textview_info.set_editable(False)
  595.                 self.textview_info.set_cursor_visible(False)
  596.                 self.textview_info.modify_font(Pango.font_description_from_string('Monospace 9'))
  597.                 scrolledwindow1.add(self.textview_info)
  598.                 self.f_info['grid'].attach(scrolledwindow1, 0, 0, 3, 3)
  599.        
  600.         def make_audio_codec(self):
  601.                 # tooltips
  602.                 self.faac_q_str = 'faac vbr: q 80 ~96k, 90 ~100k, 100 ~118k, 120 ~128k, 160 ~156k'
  603.                 #
  604.                 self.f_3acodec = self.make_frame_ag(3, "  audio codec  " , 6, 8, 8, True)
  605.                 #
  606.                 self.box_ac = self.make_combobox(
  607.                   "libfaac quality (def. 100)",
  608.                   "aacplus (64 Kb/s)",
  609.                   "aacplus (32 Kb/s)",
  610.                   "no audio",
  611.                   "audio copy"
  612.                   )
  613.                 self.f_3acodec['grid'].attach(self.box_ac['cbox'], 0, 0, 1, 1)
  614.                 self.box_ac['cbox'].connect("changed", self.on_codec_audio_changed)
  615.                 #
  616.                 self.spin_ac = self.make_spinbut(100 , 80 , 160 , 10 , 1 , 0, True )
  617.                 self.spin_ac["adj"].connect("value-changed", self.on_codec_clicked)
  618.                 self.f_3acodec['grid'].attach(self.spin_ac["spinner"], 1, 0, 1, 1)
  619.                 self.spin_ac['spinner'].set_tooltip_text(self.faac_q_str)
  620.                 # placeholder
  621.                 self.f_3acodec['grid'].attach(self.make_label(""), 2, 0, 1, 1)
  622.                 #
  623.                 self.f3ac_label_out = Gtk.Label("-aaq")
  624.                 self.f_3acodec['grid'].attach(self.f3ac_label_out, 3, 0, 1, 1)
  625.        
  626.         def make_video_codec(self):
  627.                 self.f_3vcodec = self.make_frame_ag(3, "  video codec  " , 6, 8, 8, True)
  628.                 self.box_vcodec = self.make_combobox(
  629.                   "libx264",
  630.                   "video copy"
  631.                   )
  632.                 self.f_3vcodec['grid'].attach(self.box_vcodec['cbox'], 0, 0, 1, 1)
  633.                 self.box_vcodec['cbox'].connect("changed", self.on_codec_video_changed)
  634.                 #
  635.                 self.box_vrc = self.make_combobox(
  636.                   "crf",
  637.                   "bitrate kb/s"
  638.                   )
  639.                 self.f_3vcodec['grid'].attach(self.box_vrc['cbox'], 1, 0, 1, 1)
  640.                 self.box_vrc['cbox'].connect("changed", self.on_codec_vrc_changed)
  641.                 #
  642.                 self.spin_vc = self.make_spinbut(21.3 , 15 , 40 , 0.1 , 1 , 1, True )
  643.                 self.spin_vc["adj"].connect("value-changed", self.on_codec_clicked)
  644.                 self.f_3vcodec['grid'].attach(self.spin_vc["spinner"], 2, 0, 1, 1)
  645.                 #
  646.                 self.f3v_label_out = Gtk.Label("-crf 21.3")
  647.                 self.f_3vcodec['grid'].attach(self.f3v_label_out, 3, 0, 1, 1)
  648.                 # x264 preset
  649.                 self.box_3v_preset = self.make_combobox(
  650.                   "superfast",
  651.                   "veryfast",
  652.                   "faster",
  653.                   "fast",
  654.                   "medium",
  655.                   "slow"
  656.                   ) #(-superfast -veryfast -fast, -medium, -slow, default: faster)
  657.                 self.box_3v_preset['cbox'].set_active(2)
  658.                 self.f_3vcodec['grid'].attach(self.box_3v_preset['cbox'], 0, 1, 1, 1)
  659.                 self.box_3v_preset['cbox'].connect("changed", self.on_preset_changed)
  660.                 # x264 opts
  661.                 self.box_3v_x264opts = self.make_combobox(
  662.                   "x264opts 1",
  663.                   "no opts (ssim)"
  664.                   )
  665.                 self.box_3v_x264opts['cbox'].set_active(0)
  666.                 self.f_3vcodec['grid'].attach(self.box_3v_x264opts['cbox'], 1, 1, 1, 1)
  667.                 self.box_3v_x264opts['cbox'].connect("changed", self.on_codec_clicked)
  668.                 # opencl
  669.                 self.check_3v_opencl = Gtk.CheckButton("opencl")
  670.                 self.check_3v_opencl.connect("toggled", self.on_codec_clicked)
  671.                 self.f_3vcodec['grid'].attach(self.check_3v_opencl, 2, 1, 1, 1)
  672.                
  673.                
  674.                
  675.         def make_other_opts(self):
  676.                 #
  677.                 subcopy_tooltip_srt = 'if false srt->ass'
  678.                 cpu_tooltip_srt = 'if false -thread 0'
  679.                 nometa_tooltip_srt = 'if true --map_metadata -1'
  680.                 #
  681.                 self.f3_oth = self.make_frame_ag(3, "  other options  " , 6, 8, 8, True)
  682.                 #
  683.                 self.check_2pass = Gtk.CheckButton("2 pass")
  684.                 self.check_2pass.connect("toggled", self.on_f3_other_clicked)
  685.                 self.f3_oth['grid'].attach(self.check_2pass, 0, 0, 1, 1)
  686.                 self.check_2pass.set_sensitive(False)
  687.                 #
  688.                 self.check_nometa = Gtk.CheckButton("no metatag")
  689.                 self.check_nometa.connect("toggled", self.on_f3_other_clicked)
  690.                 self.check_nometa.set_tooltip_text(nometa_tooltip_srt)
  691.                 self.f3_oth['grid'].attach(self.check_nometa, 1, 0, 1, 1)
  692.                 #
  693.                 #
  694.                 self.check_scopy = Gtk.CheckButton("sub copy")
  695.                 self.check_scopy.connect("toggled", self.on_f3_other_clicked)
  696.                 self.check_scopy.set_tooltip_text(subcopy_tooltip_srt)
  697.                 self.f3_oth['grid'].attach(self.check_scopy, 2, 0, 1, 1)
  698.                 #
  699.                 self.check_cpu = Gtk.CheckButton("cpu 3")
  700.                 self.check_cpu.connect("toggled", self.on_f3_other_clicked)
  701.                 self.check_cpu.set_tooltip_text(cpu_tooltip_srt)
  702.                 self.f3_oth['grid'].attach(self.check_cpu, 3, 0, 1, 1)
  703.                 #
  704.                 self.check_debug = Gtk.CheckButton("debug")
  705.                 self.check_debug.connect("toggled", self.on_f3_other_clicked)
  706.                 self.f3_oth['grid'].attach(self.check_debug, 4, 0, 1, 1)
  707.                 #
  708.                 self.box_oth_container = self.make_combobox(
  709.                   "MKV",
  710.                   "MP4"
  711.                   )
  712.                 self.f3_oth['grid'].attach(self.box_oth_container['cbox'], 5, 0, 1, 1)
  713.                 self.box_oth_container['cbox'].connect("changed", self.on_container_changed)
  714.                
  715.         def make_run_730(self):
  716.                 self.f3_run = self.make_frame_ag(3, "  execute in terminal  " , 6, 8, 8, True)
  717.                 #
  718.                 self.f3_run_indir_label = Gtk.Label("")
  719.                 self.f3_run['grid'].attach(self.f3_run_indir_label, 0, 0, 1, 1)
  720.                 self.f3_run_file = Gtk.Label("no input file")
  721.                 self.f3_run_file.set_tooltip_text('')
  722.                 self.f3_run['grid'].attach(self.f3_run_file, 1, 0, 2, 1)
  723.                 self.f3_dur_file = Gtk.Label("")
  724.                 self.f3_run['grid'].attach(self.f3_dur_file, 3, 0, 1, 1)
  725.                 #
  726.                 self.but_f3_run = Gtk.Button(label="RUN")
  727.                 self.but_f3_run.connect("clicked", self.on_but_f3_run_clicked)
  728.                 self.but_f3_run.set_sensitive(False)
  729.                 self.f3_run['grid'].attach(self.but_f3_run, 3, 1, 1, 1)
  730.                 #
  731.                 #self.f3_run_outdir_label = Gtk.Label("out dir:  " + os.getcwd())
  732.                 self.f3_run_outdir_label = Gtk.Label("")
  733.                 self.f3_run_outdir_label.set_markup("<b>out dir:  </b>" + os.getcwd())
  734.                 self.f3_run['grid'].attach(self.f3_run_outdir_label, 0, 1, 2, 1)
  735.                 #
  736.                 # filechooserbutton
  737.                 self.out_dir_chooserbut = Gtk.FileChooserButton(title="Dir out")
  738.                 self.out_dir_chooserbut.set_action(2)
  739.                 #self.filechooserbutton.set_action(2) # 0 open file, 1 save file, 2 select folder, 3 create folder
  740.                 acturi = "file://" + os.getcwd()
  741.                 self.out_dir_chooserbut.set_uri(acturi)
  742.                 self.f3_run['grid'].attach(self.out_dir_chooserbut, 2, 1, 1, 1)
  743.                 self.out_dir_chooserbut.connect("selection-changed", self.dir_changed)
  744.                
  745.                
  746.         # signal handlers -----------------------------------------------
  747.        
  748.         def on_window_destroy(self, *args):
  749.                 Gtk.main_quit(*args)
  750.        
  751.         def on_scale_clicked(self, button):
  752.                 if (self.box1['cbox'].get_active() != 0):
  753.                         self.calcola_scale()
  754.                 else:
  755.                         self.scalestr = ""
  756.                         self.outfilter()
  757.                  
  758.         def on_deint_clicked(self, button):
  759.                 self.deint_str = ""
  760.                 if self.checkdeint.get_active():
  761.                         deint_val = self.box_deint['cbox'].get_active()
  762.                         if (deint_val == 0):
  763.                                 self.deint_str = "yadif"
  764.                         elif (deint_val == 1):
  765.                                 self.deint_str = "pp=lb"
  766.                 self.outfilter()
  767.                        
  768.         def on_dn_clicked(self, button):
  769.                 self.dn_str = ""
  770.                 if self.checkdn.get_active():
  771.                         dn_val = int( self.spindn['adj'].get_value() )
  772.                         self.dn_str = "hqdn3d=" + str(dn_val)
  773.                 self.outfilter()
  774.                    
  775.         def on_crop_clicked(self, button):
  776.                 ok = 0
  777.                 self.crop_str = ""
  778.                 if self.checkcr.get_active():
  779.                         ok = 1
  780.                 if ok:
  781.                         inW = int(self.spincw['adj'].get_value())
  782.                         inH = int(self.spinch['adj'].get_value())
  783.                         crT = int(self.spinct['adj'].get_value())
  784.                         crB = int(self.spincb['adj'].get_value())
  785.                         crL = int(self.spincl['adj'].get_value())
  786.                         crR = int(self.spincr['adj'].get_value())      
  787.                         finW = inW - crL - crR
  788.                         finH = inH - crT - crB
  789.                         if ( (finW < 100) or (finH < 100) ):
  790.                                 self.crop_str = ""
  791.                         else:
  792.                                 self.crop_str = "crop=" + str(finW) + ":" \
  793.                                  + str(finH) + ":" \
  794.                                  + str(crL)  + ":" \
  795.                                  + str(crT)
  796.                 if (self.box2['cbox'].get_active() != 2):
  797.                         self.outfilter()
  798.                 else:
  799.                         self.on_scale_clicked(button)
  800.                
  801.         def file_changed(self, filechooserbutton):              
  802.                 if self.filechooserbutton.get_filename():
  803.                         self.butplay.set_sensitive(True) # low part ---------
  804.                         self.butprobe.set_sensitive(True)
  805.                         self.preview_logic() # test and testsplit
  806.                         #self.buttest.set_sensitive(True)
  807.                         #self.buttestspl.set_sensitive(True)
  808.                         self.butcrode.set_sensitive(True) # crop ----------
  809.                         self.spinct['adj'].set_value(0)
  810.                         self.spincb['adj'].set_value(0)
  811.                         self.spincl['adj'].set_value(0)
  812.                         self.spincr['adj'].set_value(0)                
  813.                         self.but_volume_det.set_sensitive(True) # volume detect
  814.                         self.but_volume_det.set_label("Volume detect")
  815.                         self.label_meanvol.set_label("")
  816.                         self.label_maxvol.set_label("")
  817.                         self.spin_db["adj"].set_value(0)
  818.                         self.but_black_det.set_sensitive(True) # black  detect
  819.                         self.textbuffer.set_text(self.black_dt_init_str)
  820.                         self.progressbar_black_det.set_fraction(0.0)
  821.                         self.but_f3_run.set_sensitive(True) # 730 run
  822.                         #
  823.                         self.command = "clear" + "\n"
  824.                         length = len(self.command)
  825.                         self.terminal.feed_child(self.command, length)
  826.                         # need ffprobe
  827.                         filename = self.filechooserbutton.get_filename()
  828.                         self.f3_run_indir_label.set_label(os.path.dirname(filename))
  829.                         #
  830.                         file_4_label = os.path.basename(filename)
  831.                         if ( len(file_4_label) > 50):
  832.                                 a = file_4_label[:46]
  833.                                 b = '  ...  '
  834.                                 c = file_4_label[-4:]
  835.                                 file_4_label = a + b + c
  836.                         self.f3_run_file.set_label(file_4_label)
  837.                         cmnd = ['ffprobe', '-show_format', '-show_streams', '-pretty', '-loglevel', 'quiet', filename]
  838.                         p = subprocess.Popen(cmnd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  839.                         out, err =  p.communicate()
  840.                         out = out.decode() # python3
  841.                         self.get_info(out)
  842.                        
  843.         def get_info(self, out):
  844.                 def form_to_3(in_str):
  845.                         '''
  846.                        bitrate and size info formatting
  847.                        '''
  848.                         a = in_str.split(' ')[0]
  849.                         if len(in_str.split(' ')) == 2:
  850.                                 b = in_str.split(' ')[1]
  851.                                 a = float(a)
  852.                                 result = "{0:.3f}".format(a ) + " " + b
  853.                         else:
  854.                                 result = 'N/A'
  855.                         return result
  856.                 # x scale w h, duration label p3
  857.                 for line in out.split('\n'):
  858.                         line = line.strip()
  859.                         if line.startswith('width='):
  860.                                 s = line
  861.                                 width = s.split('width=', 1)
  862.                                 #print "Video pixel width is: %s" % width[1]
  863.                                 self.video_width = width[1]
  864.                                 self.spincw['adj'].set_value(float(self.video_width)) #mettere decimali se no non si vede
  865.                                 self.spincw['spinner'].set_sensitive(False)
  866.                         elif line.startswith('height='):
  867.                                 s = line
  868.                                 height = s.split('height=', 1)
  869.                                 #print "Video pixel height is: %s" % height[1]
  870.                                 self.video_height = height[1]    
  871.                                 self.spinch['adj'].set_value(float(self.video_height)) #mettere decimali se no non si vede
  872.                                 self.spinch['spinner'].set_sensitive(False)
  873.                                 if self.add_1_1:
  874.                                         self.box2['list'].append(["as input"])
  875.                                 self.add_1_1 = False
  876.                         elif line.startswith('duration='):
  877.                                 s = line
  878.                                 duration = s.split('duration=', 1)
  879.                                 dur = duration[1].split('.')
  880.                                 self.f3_dur_file.set_label(dur[0])
  881.                 #x self.info_str
  882.                 self.info_str = ""
  883.                 is_stream = 0
  884.                 is_format = 0
  885.                 for line in out.split('\n'):
  886.                         line = line.strip()
  887.                         if line.startswith('[STREAM]'):
  888.                                 self.info_str = self.info_str + "STREAM "
  889.                                 is_stream = 1
  890.                         elif line.startswith('[/STREAM]'):
  891.                                 self.info_str = self.info_str + "\n"
  892.                                 is_stream = 0
  893.                         elif (line.startswith('index=') and (is_stream == 1)):
  894.                                 s = line
  895.                                 info = s.split('=')[1]  
  896.                                 self.info_str = self.info_str + info + ": "
  897.                         elif (line.startswith('codec_name=') and (is_stream == 1)):
  898.                                 s = line
  899.                                 info = s.split('=')[1]  
  900.                                 self.info_str = self.info_str + info + ", "
  901.                         elif (line.startswith('profile=') and (is_stream == 1)):
  902.                                 s = line
  903.                                 info = s.split('=')[1]  
  904.                                 self.info_str = self.info_str + "profile=" +info + ", "
  905.                         elif (line.startswith('codec_type=') and (is_stream == 1)):
  906.                                 s = line
  907.                                 info = s.split('=')[1]  
  908.                                 self.info_str = self.info_str + info + ", "
  909.                         elif (line.startswith('width=') and (is_stream == 1)):
  910.                                 s = line
  911.                                 info = s.split('=')[1]  
  912.                                 self.info_str = self.info_str + info + "x"
  913.                         elif (line.startswith('height=') and (is_stream == 1)):
  914.                                 s = line
  915.                                 info = s.split('=')[1]  
  916.                                 self.info_str = self.info_str + info + ", "
  917.                         elif (line.startswith('sample_aspect_ratio=') and (is_stream == 1)):
  918.                                 s = line
  919.                                 info = s.split('=')[1]  
  920.                                 self.info_str = self.info_str + "SAR=" + info + ", "
  921.                         elif (line.startswith('display_aspect_ratio=') and (is_stream == 1)):
  922.                                 s = line
  923.                                 info = s.split('=')[1]  
  924.                                 self.info_str = self.info_str + "DAR=" + info + ", "
  925.                         elif (line.startswith('pix_fmt=') and (is_stream == 1)):
  926.                                 s = line
  927.                                 info = s.split('=')[1]  
  928.                                 self.info_str = self.info_str + info + ", "
  929.                         elif (line.startswith('sample_rate=') and (is_stream == 1)):
  930.                                 s = line
  931.                                 info = s.split('=')[1]
  932.                                 info = form_to_3(info)
  933.                                 self.info_str = self.info_str + "samplerate=" + info + ", "
  934.                         elif (line.startswith('channels=') and (is_stream == 1)):
  935.                                 s = line
  936.                                 info = s.split('=')[1]  
  937.                                 self.info_str = self.info_str + "channels=" + info + ", "
  938.                         elif (line.startswith('r_frame_rate=') and (is_stream == 1)):
  939.                                 s = line
  940.                                 info = s.split('=')[1]
  941.                                 a = info.split('/')[0]
  942.                                 b = info.split('/')[1]
  943.                                 a = float(a)
  944.                                 b = float(b)
  945.                                 if ((a > 0) and (b > 0)):
  946.                                         c = float(a)/float(b)
  947.                                         info = "{0:0.2f}".format(c)
  948.                                         self.info_str = self.info_str + info + " fps, "
  949.                         elif (line.startswith('bit_rate=') and (is_stream == 1)):
  950.                                 s = line
  951.                                 info = s.split('=')[1]
  952.                                 info = form_to_3(info)
  953.                                 self.info_str = self.info_str + "bitrate=" + info + ", "
  954.                         elif (line.startswith('TAG:language=') and (is_stream == 1)):
  955.                                 s = line
  956.                                 info = s.split('=')[1]  
  957.                                 self.info_str = self.info_str + "lang=" + info + ", "
  958.                         elif line.startswith('[FORMAT]'):
  959.                                 self.info_str = self.info_str + "FORMAT "
  960.                                 is_format = 1
  961.                         elif line.startswith('[/FORMAT]'):
  962.                                 #self.info_str = self.info_str + "/n"
  963.                                 is_format = 0
  964.                         elif (line.startswith('nb_streams=') and (is_format == 1)):
  965.                                 s = line
  966.                                 info = s.split('=')[1]  
  967.                                 self.info_str = self.info_str + "streams=" + info + ", "
  968.                         elif (line.startswith('duration=') and (is_format == 1)):
  969.                                 s = line
  970.                                 info = s.split('=')[1]  
  971.                                 info = info.split('.')[0]
  972.                                 self.duration_in_sec = self.hms2sec(info)
  973.                                 self.info_str = self.info_str + "duration=" + info + ", "
  974.                         elif (line.startswith('size=') and (is_format == 1)):
  975.                                 s = line
  976.                                 info = s.split('=')[1]
  977.                                 info = form_to_3(info)
  978.                                 self.info_str = self.info_str + "size=" + info + ", "
  979.                         elif (line.startswith('bit_rate=') and (is_format == 1)):
  980.                                 s = line
  981.                                 info = s.split('=')[1]
  982.                                 info = form_to_3(info)
  983.                                 self.info_str = self.info_str + "bitrate=" + info + ", "
  984.                 self.textbuffer_info.set_text(self.info_str)
  985.                 self.f3_run_file.set_tooltip_text(self.info_str)
  986.                 self.check_map.set_tooltip_text(self.info_str)
  987.                 self.check_time.set_tooltip_text(self.info_str)
  988.        
  989.         def on_butplay_clicked(self, button):
  990.                 self.command = "ffplay \"" + self.filechooserbutton.get_filename() + "\"" +"\n"
  991.                 length = len(self.command)
  992.                 self.terminal.feed_child(self.command, length)
  993.                
  994.         def on_butprobe_clicked(self, button):
  995.                 self.command = "ffprobe \"" + self.filechooserbutton.get_filename() + "\""  + " 2>&1 | grep 'Input\|Duration\|Stream'" + "\n"
  996.                 length = len(self.command)
  997.                 self.terminal.feed_child(self.command, length)    
  998.                
  999.         def on_butcrode_clicked(self, button):
  1000.                 # need ffmpeg
  1001.                 self.butcrode.set_sensitive(False)
  1002.                 filename = self.filechooserbutton.get_filename()
  1003.                 #cmnd = ['ffplay' , '-vf', 'cropdetect', '-autoexit' ,'-ss', '60' , '-t' , '1',  filename]
  1004.                 cmnd = "ffmpeg -i " + "\"" + filename + "\"" + " -ss 60 -t 1 -vf cropdetect -f null - 2>&1 | awk \'/crop/ { print $NF }\' | tail -1"
  1005.                 p = subprocess.Popen(cmnd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
  1006.                 out, err =  p.communicate()
  1007.                 out = out.decode()
  1008.                 for line in out.split('\n'):
  1009.                         line = line.strip()
  1010.                         if "crop=" in line:  
  1011.                                 aa = line.split('crop=', 1)
  1012.                                 aaa = aa[1]
  1013.                                 listdata = aaa.split(':')
  1014.                                 w = listdata[0]
  1015.                                 h = listdata[1]
  1016.                                 offx = listdata[2]
  1017.                                 offy = listdata[3]
  1018.                                 ctop = int(offy)
  1019.                                 cbot = int(self.video_height) - int(offy) -int(h)
  1020.                                 cleft = int(offx)
  1021.                                 cright = int(self.video_width) - int(offx) -int(w)
  1022.                                 self.spinct['adj'].set_value(float(ctop))
  1023.                                 self.spincb['adj'].set_value(float(cbot))
  1024.                                 self.spincl['adj'].set_value(float(cleft))
  1025.                                 self.spincr['adj'].set_value(float(cright))  
  1026.                                 break
  1027.                 self.butcrode.set_sensitive(True)
  1028.                
  1029.         def on_buttest_clicked(self, button):
  1030.                 # -map preview: only with none -vf option  
  1031.                 if (self.maps_str == ""):
  1032.                         self.command = "ffplay \"" + self.filechooserbutton.get_filename() + "\" " \
  1033.                          + " " + self.time_final_srt + " " \
  1034.                          + "-vf "  + self.filter_test_str + "\n"
  1035.                 else:
  1036.                         self.command = "ffmpeg -i \"" + self.filechooserbutton.get_filename() + "\" " \
  1037.                          + self.maps_str  + " " + self.time_final_srt + " "
  1038.                         if (self.filter_test_str != ""):
  1039.                                 self.command = self.command + " -vf "  + self.filter_test_str
  1040.                         self.command = self.command +  " -c copy -f matroska - | ffplay -" + "\n"
  1041.                 length = len(self.command)
  1042.                 self.terminal.feed_child(self.command, length)
  1043.                
  1044.         def on_buttestspl_clicked(self, button):
  1045.                 self.command = "ffplay \"" + self.filechooserbutton.get_filename() + "\" " \
  1046.                   + " " + self.time_final_srt + " " \
  1047.                   + " -vf \"split[a][b]; [a]pad=iw:(ih*2)+4:color=888888 [src]; [b]" \
  1048.                   + self.filter_test_str + " [filt]; [src][filt]overlay=((main_w - w)/2):main_h/2\"" + "\n"
  1049.                 length = len(self.command)
  1050.                 self.terminal.feed_child(self.command, length)
  1051.        
  1052.         def on_but_volume_det_clicked(self, button):
  1053.                 self.but_volume_det.set_sensitive(False)
  1054.                 self.voldet_spin.set_sensitive(True)
  1055.                 self.voldet_spin.start()
  1056.                 def my_thread(obj):
  1057.                         filename = self.filechooserbutton.get_filename()        
  1058.                         #cmnd = "ffmpeg -i " + "\"" + filename + "\" " + " -vn -af volumedetect -f null /dev/null 2>&1 | grep \'mean_volume\\|max_volume\'"
  1059.                         cmnd = ['ffmpeg', '-i', filename, '-vn', '-af', 'volumedetect', '-f', 'null', '/dev/null']
  1060.                         p = subprocess.Popen(cmnd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
  1061.                         while True:
  1062.                                 line = p.stderr.read()
  1063.                                 if not line:
  1064.                                         break
  1065.                                 out = line.decode()
  1066.                                 for line in out.split('\n'):
  1067.                                         line = line.strip()
  1068.                                         if "mean_volume:" in line:  
  1069.                                                 aa = line.split('mean_volume:', 1)
  1070.                                                 mea_vol_det = aa[1]
  1071.                                                 self.label_meanvol.set_label("Mean vol: " + mea_vol_det)
  1072.                                         if "max_volume:" in line:  
  1073.                                                 aa = line.split('max_volume:', 1)
  1074.                                                 max_vol_det = aa[1]
  1075.                                                 self.label_maxvol.set_label("Max vol: " + max_vol_det)
  1076.                                 self.but_volume_det.set_label("volume detected")
  1077.                                 self.voldet_spin.stop()
  1078.                                 self.voldet_spin.set_sensitive(False)
  1079.                         p.communicate()
  1080.                 self.but_volume_det.set_label("Wait")  
  1081.                 threading.Thread(target=my_thread, args=(self,)).start()
  1082.        
  1083.         def on_volume_clicked(self, button):
  1084.                 self.label_ratio_val.set_label("")
  1085.                 self.final_af_str = ""
  1086.                 db = self.spin_db["adj"].get_value()
  1087.                 if (db != 0.00):
  1088.                         ratio = pow(10, (db/20.0))
  1089.                         ratio = float("{0:.3f}".format(ratio))    
  1090.                         self.label_ratio_val.set_label(str(ratio))
  1091.                         self.final_af_str = "-af volume=" + str(ratio)
  1092.                 self.make_p3_out_command()
  1093.        
  1094.         def on_map_clicked(self, button):
  1095.                 self.map_label.set_label("")
  1096.                 self.maps_str = ""
  1097.                 if self.check_map.get_active():
  1098.                         map_in = self.entry_map.get_chars(0, -1)
  1099.                         if (map_in != ""):
  1100.                                 map_l = map_in.split(",")
  1101.                                 for i in range(len(map_l)):
  1102.                                         if self.maps_str == "":
  1103.                                                 self.maps_str = self.maps_str + "-map " + map_l[i]
  1104.                                         else:
  1105.                                                 self.maps_str = self.maps_str + " -map " + map_l[i]
  1106.                                 self.map_label.set_label(self.maps_str)
  1107.                 self.outfilter()
  1108.                 self.make_p3_out_command()
  1109.                
  1110.         def on_time_clicked(self, button):
  1111.                 self.time_final_srt = ""
  1112.                        
  1113.                 if self.check_time.get_active():
  1114.                         timein = 0
  1115.                         timeout = 0
  1116.                         timedur = 0
  1117.                         timein_ent = self.entry_timein.get_chars(0, -1)
  1118.                         if (timein_ent != ""):
  1119.                                 if timein_ent.isdigit():
  1120.                                         timein = int(timein_ent)        
  1121.                                 else:  
  1122.                                         timein = self.hms2sec(timein_ent)
  1123.                         timeout_ent = self.entry_timeout.get_chars(0, -1)
  1124.                         if (timeout_ent != ""):
  1125.                                 if timeout_ent.isdigit():
  1126.                                         timeout = int(timeout_ent)
  1127.                                         timedur = timeout - timein
  1128.                                 else:  
  1129.                                         timeout = self.hms2sec(timeout_ent)
  1130.                                         timedur = timeout - timein
  1131.                         if (timein != 0):
  1132.                                 self.time_final_srt = self.time_final_srt + " -ss " + str(timein)  
  1133.                         if (timedur > 0):
  1134.                                 self.time_final_srt = self.time_final_srt + " -t " + str(timedur)    
  1135.                 self.outfilter()
  1136.                 self.make_p3_out_command()
  1137.        
  1138.         def on_codec_audio_changed(self, button):
  1139.                 a_cod = self.box_ac['cbox'].get_active()
  1140.                 if (a_cod == 0): # aaq
  1141.                         self.spin_ac['spinner'].set_sensitive(True)
  1142.                         self.spin_ac['adj'].set_value(100.0)
  1143.                         self.spin_ac['spinner'].set_tooltip_text(self.faac_q_str)
  1144.                 else:
  1145.                         self.spin_ac['spinner'].set_sensitive(False)
  1146.                         self.spin_ac['spinner'].set_tooltip_text('')
  1147.                 self.on_codec_clicked(button)
  1148.        
  1149.         def on_codec_video_changed(self, button):
  1150.                 self.on_codec_clicked(button)
  1151.        
  1152.         def on_codec_vrc_changed(self, button):
  1153.                 self.video_rc = self.box_vrc['cbox'].get_active() #0 crf, 1 kb/s
  1154.                 if (self.video_rc == 0):
  1155.                         self.adj_change(self.spin_vc['adj'], 21.3, 15, 40, 0.1, 1)
  1156.                         self.spin_vc['adj'].set_value(21.3)
  1157.                         self.check_2pass.set_active(False)
  1158.                         self.check_2pass.set_sensitive(False)
  1159.                 elif (self.video_rc == 1):
  1160.                         self.adj_change(self.spin_vc['adj'], 730, 300, 4000, 10, 100)
  1161.                         self.spin_vc['adj'].set_value(730.0)
  1162.                         self.check_2pass.set_sensitive(True)
  1163.        
  1164.         def on_codec_clicked(self, button):
  1165.                 self.a_copy = 0
  1166.                 self.v_copy = 0
  1167.                 self.final_codec_str = ""
  1168.                 audio_codec = self.box_ac['cbox'].get_active() # 0 aaq. 1 a64 , 2 a32 , 3 audio none
  1169.                 if (audio_codec == 0):
  1170.                         audio_codec_str = "-aaq"
  1171.                         quality_faac = self.spin_ac['adj'].get_value()
  1172.                         if (quality_faac != 100):
  1173.                                 audio_codec_str = audio_codec_str + " " + str(int(quality_faac))
  1174.                 elif (audio_codec == 1):
  1175.                         audio_codec_str = "-a64"
  1176.                 elif (audio_codec == 2):
  1177.                         audio_codec_str = "-a32"
  1178.                 elif (audio_codec == 3):
  1179.                         audio_codec_str = "-an"
  1180.                 elif (audio_codec == 4):
  1181.                         audio_codec_str = "-acopy"
  1182.                         self.a_copy = 1
  1183.                 self.f3ac_label_out.set_label(audio_codec_str)
  1184.                 #
  1185.                 self.pg2_str = audio_codec_str
  1186.                 # video
  1187.                 video_codec = self.box_vcodec['cbox'].get_active() #0 x264, 1 -vcopy
  1188.                 if (video_codec == 1):
  1189.                         video_codec_str = "-vcopy"
  1190.                         self.v_copy = 1
  1191.                         self.box_vrc['cbox'].set_active(0)
  1192.                         self.box_vrc['cbox'].set_sensitive(False)
  1193.                         self.spin_vc['spinner'].set_sensitive(False)
  1194.                         self.box_3v_preset['cbox'].set_active(2)
  1195.                         self.box_3v_preset['cbox'].set_sensitive(False)
  1196.                         self.box_3v_x264opts['cbox'].set_active(0)
  1197.                         self.box_3v_x264opts['cbox'].set_sensitive(False)
  1198.                         self.check_3v_opencl.set_active(False)
  1199.                         self.check_3v_opencl.set_sensitive(False)
  1200.                        
  1201.                 else:
  1202.                         self.box_vrc['cbox'].set_sensitive(True)
  1203.                         self.spin_vc['spinner'].set_sensitive(True)
  1204.                         self.box_3v_preset['cbox'].set_sensitive(True)
  1205.                         self.box_3v_x264opts['cbox'].set_sensitive(True)
  1206.                         self.check_3v_opencl.set_sensitive(True)
  1207.                         self.video_rc = self.box_vrc['cbox'].get_active() #0 crf, 1 kb/s
  1208.                         if (self.video_rc == 0):        
  1209.                                 video_codec_str = "-crf " + str(self.spin_vc['adj'].get_value())
  1210.                         elif (self.video_rc == 1):
  1211.                                 video_codec_str = "-b " + str(int(self.spin_vc['adj'].get_value()))
  1212.                         if (self.box_3v_x264opts['cbox'].get_active() == 1):
  1213.                                 video_codec_str = video_codec_str + " -nopts"
  1214.                         if self.check_3v_opencl.get_active():
  1215.                                 video_codec_str = video_codec_str + " -opencl"
  1216.                 self.f3v_label_out.set_label(video_codec_str)    
  1217.                 self.final_codec_str = audio_codec_str + " " + video_codec_str
  1218.                 self.make_p3_out_command()
  1219.        
  1220.         def on_preset_changed(self, button):
  1221.                 self.preset_str = "-faster"
  1222.                 preset = self.box_3v_preset['cbox'].get_active()
  1223.                 # 0 -superfast, 1 -veryfast, 2 -faster, 3 -fast, 4 -medium, 5 -slow, default: 2 faster
  1224.                 if (preset == 0):
  1225.                         self.preset_str = "-superfast"
  1226.                 if (preset == 1):
  1227.                         self.preset_str = "-veryfast"
  1228.                 if (preset == 3):
  1229.                         self.preset_str = "-fast"
  1230.                 if (preset == 4):
  1231.                         self.preset_str = "-medium"
  1232.                 if (preset == 5):
  1233.                         self.preset_str = "-slow"
  1234.                 self.make_p3_out_command()
  1235.                
  1236.         def on_f3_other_clicked(self, button):
  1237.                 self.final_other_str = ""
  1238.                 if self.check_nometa.get_active():
  1239.                         self.final_other_str = "-nometa"
  1240.                 if self.check_2pass.get_active():
  1241.                         if (self.final_other_str == ""):
  1242.                                 self.final_other_str = "" + "-pass 2"
  1243.                         else:
  1244.                                 self.final_other_str = self.final_other_str + " " + "-pass 2"
  1245.                 if self.check_cpu.get_active():
  1246.                         if (self.final_other_str == ""):
  1247.                                 self.final_other_str = "-cpu 3"
  1248.                         else:
  1249.                                 self.final_other_str = self.final_other_str + " " + "-cpu 3"
  1250.                 if self.check_scopy.get_active():
  1251.                         if (self.final_other_str == ""):
  1252.                                 self.final_other_str = "-scopy"
  1253.                         else:
  1254.                                 self.final_other_str = self.final_other_str + " " + "-scopy"    
  1255.                 if self.check_debug.get_active():
  1256.                         if (self.final_other_str == ""):
  1257.                                 self.final_other_str = "debug"
  1258.                         else:
  1259.                                 self.final_other_str = self.final_other_str + " " + "debug"
  1260.                 self.make_p3_out_command()
  1261.                
  1262.         def on_container_changed(self,button):
  1263.                 container = self.box_oth_container['cbox'].get_active() #0 mkv, 1 mp4
  1264.                 if (container == 1):
  1265.                         self.container_str = "-mp4"
  1266.                 else:
  1267.                         self.container_str = "-mkv"
  1268.                 self.make_p3_out_command()
  1269.                
  1270.         def on_but_f3_run_clicked(self, button):
  1271.                 self.command = "/home/mc/t/730-ffmpeg-tool-2 \"" \
  1272.                   + self.filechooserbutton.get_filename() + "\" " \
  1273.                   + self.p3_command + "\n"
  1274.                 length = len(self.command)
  1275.                 self.terminal.feed_child(self.command, length)
  1276.              
  1277.         def dir_changed(self, button):
  1278.                 if self.first_run:
  1279.                         select = self.out_dir_chooserbut.get_uri()
  1280.                         decoded = url2pathname(select)
  1281.                         newdir = decoded.split('//')[1]
  1282.                         self.command = "cd " + "\"" + newdir + "\"" + "\n"
  1283.                         length = len(self.command)
  1284.                         self.terminal.feed_child(self.command, length)
  1285.                         self.f3_run_outdir_label.set_markup("<b>out dir:  </b>" + newdir)
  1286.                 else:
  1287.                         self.first_run = 1
  1288.                        
  1289.         def on_but_black_det_clicked(self, button):
  1290.                 if self.blackdet_is_run == False:
  1291.                         #self.but_black_det.set_sensitive(False)
  1292.                         self.but_black_det.set_label("Stop")
  1293.                         self.textbuffer.set_text('') # clear for insert from start
  1294.                         stri = "Detected:\n\n"
  1295.                         start = self.textbuffer.get_start_iter()
  1296.                         self.textbuffer.insert(start, stri, -1)
  1297.                         self.blackdet_spin.set_sensitive(True)
  1298.                         self.blackdet_spin.start()
  1299.                         def my_thread(obj):
  1300.                                 self.blackdet_is_run = True
  1301.                                 filename = self.filechooserbutton.get_filename()
  1302.                                 #filein = os.path.basename(filename)
  1303.                                 #self.textbuffer.set_text(stri)
  1304.                                 #
  1305.                                 #ffmpeg -i "A.mp4" -y -an -vf blackdetect=d=.5 -f null - 2>&1 | grep blackdetect
  1306.                                 #cmnd = "ffmpeg -i " + "\"" + filename + "\"" + " -y -an -vf blackdetect=d=.5 -f null - 2>&1 | grep blackdetect"
  1307.                                 cmnd = ['ffmpeg', '-i', filename, '-y', '-an', '-vf', 'blackdetect=d=.5', '-f', 'null', '/dev/null']
  1308.                                 p = subprocess.Popen(cmnd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, universal_newlines=True)
  1309.                                 self.bd_th = False
  1310.                                 detected = 0
  1311.                                 time_step = 0
  1312.                                 while True:
  1313.                                         line = p.stderr.readline()
  1314.                                         if 'time=' in line:
  1315.                                                 if time_step == 9:
  1316.                                                         tml = line.split('time=')[1]
  1317.                                                         tml2 = tml.split(' ')[0]
  1318.                                                         time_n = tml2.split('.')[0]
  1319.                                                         time_n = self.hms2sec(time_n)
  1320.                                                         time_step = 0
  1321.                                                         percent = (100 * time_n)/self.duration_in_sec
  1322.                                                         pprog= float(percent)/100
  1323.                                                         self.progressbar_black_det.set_fraction(pprog)
  1324.                                                 else:
  1325.                                                         time_step = time_step + 1
  1326.                                         if 'blackdetect ' in line:
  1327.                                                         a = line
  1328.                                                         b = a.split('black_start:')[1]
  1329.                                                         start = b.split(' ')[0]
  1330.                                                         st_in_s = float(start)
  1331.                                                         st_in_s = int(st_in_s)
  1332.                                                         start_in_s = ("%4.1i"% (st_in_s))  
  1333.                                                         start = self.sec2hms(start)
  1334.                                                         stri = "black start at: " + start_in_s + " s, " + start + " "
  1335.                                                         c = b.split('black_duration:')[1]
  1336.                                                         durat = c.split(' ')[0]
  1337.                                                         dur_s = float(durat)
  1338.                                                         dur_s = "{0:0=3.1f}".format(dur_s)
  1339.                                                         stri = stri + "duration: " + dur_s + "s\n"
  1340.                                                         #self.label_test.set_text(stri)
  1341.                                                         self.textbuffer.insert_at_cursor(stri, -1)
  1342.                                                         detected = 1
  1343.                                         if line == '' and p.poll() != None:
  1344.                                                 break
  1345.                                         if self.bd_th:
  1346.                                                 p.communicate("q")
  1347.                                                 #p.terminate()
  1348.                                                 #sys.stderr.flush()
  1349.                                                 #sys.stdin.flush()
  1350.                                                 break
  1351.                                 if detected == 0:
  1352.                                         stri = "none black gap found"
  1353.                                         self.textbuffer.insert_at_cursor(stri, -1)
  1354.                                 p.communicate()                
  1355.                                 self.blackdet_spin.stop()
  1356.                                 self.blackdet_spin.set_sensitive(False)
  1357.                                 self.but_black_det.set_label("black detectet")
  1358.                                 self.progressbar_black_det.set_fraction(1.0)
  1359.                                 self.blackdet_is_run = False
  1360.                                 self.but_black_det.set_sensitive(False)
  1361.                         threading.Thread(target=my_thread, args=(self,)).start()
  1362.                 elif self.blackdet_is_run == True:
  1363.                         self.bd_th = True
  1364.                         stri = "Stopped by user.\n"
  1365.                         self.textbuffer.insert_at_cursor(stri, -1)
  1366.                         self.but_black_det.set_label("Black detect")
  1367.                         self.blackdet_spin.stop()
  1368.                         self.blackdet_spin.set_sensitive(False)
  1369.                         self.progressbar_black_det.set_fraction(0.0)
  1370.                         self.blackdet_is_run = False
  1371.        
  1372.                
  1373.         # -------------------------------------  
  1374.        
  1375.         def preview_logic(self):
  1376.                 if ( not(('-map ' in self.p3_command ) or ('-vf ' in self.p3_command )) ):
  1377.                         self.buttest.set_sensitive(False)
  1378.                         self.buttestspl.set_sensitive(False)
  1379.                 elif ('-map ' in self.p3_command) and ('-vf ' in self.p3_command):
  1380.                         self.buttest.set_sensitive(False)
  1381.                         self.buttestspl.set_sensitive(False)
  1382.                 elif '-map ' in self.p3_command:
  1383.                         self.buttest.set_sensitive(True)
  1384.                         self.buttestspl.set_sensitive(False)
  1385.                 elif '-vf ' in self.p3_command:
  1386.                         self.buttest.set_sensitive(True)
  1387.                         self.buttestspl.set_sensitive(True)
  1388.        
  1389.         def calcola_scale(self):
  1390.                 self.scalestr = ""
  1391.                 numero = self.size_spinner['adj'].get_value()
  1392.                 numero = int(numero/4)*4
  1393.                 dar = self.box2['cbox'].get_active()
  1394.                 lato = self.box1['cbox'].get_active()          
  1395.                 if (dar == 1): # 4/3
  1396.                         if (lato == 1):
  1397.                                 n2 = numero/4*3
  1398.                         else:
  1399.                                 n2 = numero/3*4
  1400.                         setdar = ",setdar=4/3,setsar=1/1"
  1401.                 elif (dar == 0): # 16/9
  1402.                         if (lato == 1):
  1403.                                 n2 = numero/16*9
  1404.                         else:
  1405.                                 n2 = numero/9*16
  1406.                         setdar = ",setdar=16/9,setsar=1/1"      
  1407.                 elif (dar == 2): #1/1 same as input  
  1408.                         w = int(self.video_width)
  1409.                         h = int(self.video_height)
  1410.                         if self.checkcr.get_active():
  1411.                                 crT = int(self.spinct['adj'].get_value())
  1412.                                 crB = int(self.spincb['adj'].get_value())
  1413.                                 crL = int(self.spincl['adj'].get_value())
  1414.                                 crR = int(self.spincr['adj'].get_value())
  1415.                                 h = h - crT - crB
  1416.                                 w = w - crL - crR
  1417.                         if (lato == 1): # h                
  1418.                                 n2 = (float(h)/(w/float(numero)))  
  1419.                         else:
  1420.                                 n2 = (float(w)/(h/float(numero)))
  1421.                         setdar = ""
  1422.                 n2 = int(n2/4)*4                    
  1423.                 self.scalestr = "scale="
  1424.                 if (lato == 1):
  1425.                         self.scalestr = self.scalestr + str(numero) + ":" + str(n2)
  1426.                 else:
  1427.                         self.scalestr = self.scalestr + str(n2) + ":" + str(numero)                  
  1428.                 lanc = self.check.get_active()  
  1429.                 if lanc:
  1430.                         self.scalestr = self.scalestr + ":flags=lanczos" + setdar  
  1431.                 else:
  1432.                         self.scalestr = self.scalestr + setdar
  1433.                 self.outfilter()
  1434.                      
  1435.         def outfilter(self):
  1436.                 final_str = ""
  1437.                 if (self.deint_str != ""):
  1438.                         final_str = final_str + self.deint_str    
  1439.                 if (self.crop_str != ""):
  1440.                         if (final_str == ""):
  1441.                                 final_str = final_str + self.crop_str
  1442.                         else:
  1443.                                         final_str = final_str + "," + self.crop_str
  1444.                 if (self.scalestr != ""):
  1445.                         if (final_str == ""):
  1446.                                 final_str = final_str + self.scalestr
  1447.                         else:
  1448.                                 final_str = final_str + "," + self.scalestr
  1449.                 if (self.dn_str != ""):
  1450.                         if (final_str == ""):
  1451.                                 final_str = final_str + self.dn_str
  1452.                         else:
  1453.                                 final_str = final_str + "," + self.dn_str              
  1454.                 self.filter_test_str = final_str
  1455.                
  1456.                 if (final_str != ""):
  1457.                         self.final_vf_str = "-vf " + final_str
  1458.                 else:
  1459.                         self.final_vf_str = ""
  1460.                
  1461.                 label_str = ""          
  1462.                 if (self.maps_str != ""):
  1463.                         label_str = label_str + self.maps_str + " "  
  1464.                 if (self.time_final_srt != ""):
  1465.                         label_str = label_str + self.time_final_srt + " "
  1466.                 if (self.final_vf_str != ""):
  1467.                         label_str = label_str + self.final_vf_str
  1468.                    
  1469.                 self.labelout.set_text(label_str)      
  1470.                 self.make_p3_out_command()
  1471.                 if (self.info_str != ""):
  1472.                         self.preview_logic()    
  1473.        
  1474.         def make_p3_out_command(self):
  1475.                 pass
  1476.                 self.p3_command = ""
  1477.                 self.f3_out_label.set_label("")
  1478.                 if (self.maps_str != ""):
  1479.                         self.p3_command = self.maps_str + " "  
  1480.                 if (self.time_final_srt != ""):
  1481.                         self.p3_command = self.p3_command + self.time_final_srt + " "
  1482.                 if ( (self.final_vf_str != "") and (self.v_copy == 0) ): # check -vcopy
  1483.                         self.p3_command = self.p3_command + self.final_vf_str + " "
  1484.                 if ( (self.final_af_str != "") and (self.a_copy == 0) ):  # check -acopy
  1485.                         self.p3_command = self.p3_command + self.final_af_str + " "
  1486.                 if (self.final_codec_str != ""):
  1487.                         self.p3_command = self.p3_command + self.final_codec_str + " "
  1488.                 if (self.preset_str != "-faster"):
  1489.                         self.p3_command = self.p3_command + self.preset_str + " "
  1490.                 if (self.container_str != "-mkv"):
  1491.                         self.p3_command = self.p3_command + self.container_str + " "
  1492.                 if (self.final_other_str != ""):
  1493.                         self.p3_command = self.p3_command + self.final_other_str + " "
  1494.                 self.f3_out_label.set_label(self.p3_command)
  1495.                
  1496.         def main(self):
  1497.                 Gtk.main()
  1498.  
  1499.                
  1500.        
  1501.  
  1502. if __name__ == "__main__":
  1503.         GObject.threads_init()
  1504.         hwg = ProgrammaGTK()
  1505.         Gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement