Advertisement
Guest User

4ffmpeg_7.52

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