Advertisement
Guest User

4ffmpeg_7.564

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