Advertisement
Guest User

4ffmpeg_7.14

a guest
Nov 13th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 57.21 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # work in python3.4
  5.  
  6. from gi.repository import Gtk, GObject, Vte
  7. from gi.repository import GLib
  8. import os
  9. import sys, subprocess, shlex, re
  10. from subprocess import call
  11. from math import pow
  12. from urllib import url2pathname
  13.                
  14. class reuse_init(object):
  15.  
  16.  
  17.         def make_label(self, text):
  18.                 label = Gtk.Label(text)
  19.                 label.set_use_underline(True)
  20.                 label.set_alignment(1.0, 0.5)
  21.                 label.show()
  22.                 return label
  23.  
  24.         def make_slider_and_spinner(self, init, min, max, step, page, digits):
  25.                 controls = {'adj':Gtk.Adjustment(init, min, max, step, page), 'slider':Gtk.HScale(), 'spinner':Gtk.SpinButton()}
  26.                 controls['slider'].set_adjustment(controls['adj'])
  27.                 controls['slider'].set_draw_value(False)
  28.                 controls['spinner'].set_adjustment(controls['adj'])
  29.                 controls['spinner'].set_digits(digits)
  30.                 controls['slider'].show()
  31.                 controls['spinner'].show()
  32.                 return controls
  33.        
  34.         def make_frame_ag(self, f_shadow_type, f_label, alig_pad, gri_row_sp, gri_colu_sp, gri_homog):
  35.                 controls =  {'frame':Gtk.Frame(), 'ali':Gtk.Alignment(), 'grid':Gtk.Grid()}
  36.                 controls['frame'].set_shadow_type(f_shadow_type) # 3 GTK_SHADOW_ETCHED_IN , 1 GTK_SHADOW_IN
  37.                 controls['frame'].set_label(f_label)
  38.                 controls['ali'].set_padding(alig_pad, alig_pad, alig_pad, alig_pad)
  39.                 controls['frame'].add(controls['ali'])
  40.                 controls['grid'].set_row_spacing(gri_row_sp)
  41.                 controls['grid'].set_column_spacing(gri_colu_sp)
  42.                 controls['grid'].set_column_homogeneous(gri_homog) # True
  43.                 controls['ali'].add(controls['grid'])
  44.                 controls['frame'].show()
  45.                 controls['ali'].show()
  46.                 controls['grid'].show()
  47.                 return controls
  48.        
  49.         def make_spinbut(self, init, min, max, step, page, digits, numeric):
  50.                 controls = {'adj':Gtk.Adjustment(init, min, max, step, page), 'spinner':Gtk.SpinButton()}
  51.                 controls['spinner'].set_adjustment(controls['adj'])
  52.                 controls['spinner'].set_digits(digits)
  53.                 controls['spinner'].set_numeric(numeric)
  54.                 controls['spinner'].show()
  55.                 return controls
  56.        
  57.         def make_combobox(self, *vals):
  58.                 controls = {'list':Gtk.ListStore(str), 'cbox':Gtk.ComboBox(), 'cellr':Gtk.CellRendererText()}
  59.                 for i, v in enumerate(vals):
  60.                         controls['list'].append([v])
  61.                 controls['cbox'].set_model(controls['list'])      
  62.                 controls['cbox'].pack_start(controls['cellr'], True)
  63.                 controls['cbox'].add_attribute(controls['cellr'], "text", 0)
  64.                 controls['cbox'].set_active(0)
  65.                 controls['cbox'].show()
  66.                 return controls
  67.        
  68.         def hms2sec(self, hms):
  69.                 result = 0
  70.                 listin = hms.split(':')
  71.                 listin.reverse()
  72.                 for i in range(len(listin)):
  73.                         if listin[i].isdigit():
  74.                                 if i == 0:
  75.                                         mult = 1
  76.                                 if i == 1:
  77.                                         mult = 60
  78.                                 if i == 2:
  79.                                         mult = 3600
  80.                                 result = result + (int(listin[i])*mult)            
  81.                 return result
  82.              
  83.         def adj_change(self, adjustment, value, lower, upper , step_increment, page_increment):
  84.                 adjustment.set_value(value)
  85.                 adjustment.set_lower(lower)
  86.                 adjustment.set_upper(upper)
  87.                 adjustment.set_step_increment(step_increment)
  88.                 adjustment.set_page_increment(page_increment)
  89.                 #adjustment.set_page_size(page_size)
  90.        
  91.        
  92.        
  93. class ProgrammaGTK(reuse_init):
  94.        
  95.  
  96.         def __init__(self):
  97.                
  98.                 self.window =  Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
  99.                 self.window.connect("destroy", self.on_window_destroy)
  100.                 self.window.set_title("4FFmpeg")
  101.                 self.window.set_position(1) # 1 center, 0 none,
  102.                 self.window.set_border_width(3)
  103.                 self.window.set_default_size(500,-1)
  104.                 #----------------------------------
  105.                
  106.                 #page1 stuff ------------------------------------------
  107.                                
  108.                 # page1 VBox -------------------------
  109.                 self.vbox1 = Gtk.VBox()
  110.                 self.vbox1.set_spacing(2)
  111.                
  112.                 # map --------------------------------------
  113.                 self.make_map()        
  114.                 # add map frame
  115.                 self.vbox1.pack_start(self.f_map['frame'], 1, 0, 0)
  116.                
  117.                 #time cut ------------------------------------
  118.                 self.make_time_cut()
  119.                 # add time frame
  120.                 self.vbox1.pack_start(self.f_time['frame'], 1, 0, 0)
  121.                
  122.                 # deinterlace -----------------------
  123.                 self.make_deinterlace()
  124.                 # add deinterlace frame
  125.                 self.vbox1.pack_start(self.f_deint['frame'], 1, 0, 0)
  126.                
  127.                 # crop ----------------------------------------
  128.                 self.make_crop()        
  129.                 # add crop frame -------------------
  130.                 self.vbox1.pack_start(self.frame_crop['frame'], 1, 0, 0)
  131.        
  132.                 # scale ------------------------------
  133.                 self.make_scale()
  134.                 # add scale frame------------------
  135.                 self.vbox1.pack_start(self.frame_scale['frame'], 1, 0, 0)
  136.  
  137.                 # denoise ----------------------------
  138.                 self.make_denoise()
  139.                 # add denoise frame------------------------
  140.                 self.vbox1.pack_start(self.frame_dn['frame'], 1, 0, 0)
  141.                
  142.                 #test-------------------
  143.                 #self.f_test = self.make_frame_ag(3, "TEST" , 6, 8, 8, True)
  144.                 #self.label_test = Gtk.Label("TEST")
  145.                 #self.f_test['grid'].attach(self.label_test, 0, 0, 1, 1)
  146.  
  147.                 #self.vbox1.pack_start(self.f_test['frame'], 1, 0, 0)
  148.                 #-------------------------------------
  149.                
  150.                 # page 1 output------------------------
  151.                 self.frame_out = self.make_frame_ag(3, '  FFmpeg video filter string (select and copy):  ' , 12, 8, 8, True)
  152.                 self.labelout = Gtk.Label("")
  153.                 self.labelout.set_selectable(1)
  154.                 self.frame_out['grid'].attach(self.labelout, 0, 0, 1 ,1)
  155.                 # add output frame ---------------------
  156.                 self.vbox1.pack_start(self.frame_out['frame'], 1, 0, 0)
  157.                
  158.                 # end page1 stuff
  159.                
  160.                
  161.                 # page2 stuff ------------------------------------------
  162.                
  163.                 # page2 VBox -------------------------
  164.                 self.vbox_pg2 = Gtk.VBox()
  165.                 self.vbox_pg2.set_spacing(2)
  166.                
  167.                 #volumedetect ------------------------------------
  168.                 self.make_volume_det()
  169.                 # add volumedetect frame        
  170.                 self.vbox_pg2.pack_start(self.f_volume_det['frame'], 1, 0, 0)
  171.                
  172.                
  173.                 # end page2 stuff
  174.                
  175.                 # page 3 stuff -----------------------------------------
  176.                
  177.                 # page3 VBox -------------------------
  178.                 self.vbox_pg3 = Gtk.VBox()
  179.                 self.vbox_pg3.set_spacing(2)
  180.                
  181.                 # audio codec -------------------
  182.                 self.make_audio_codec()
  183.                 #add frame audio codec
  184.                 self.vbox_pg3.pack_start(self.f_3acodec['frame'], 1, 0, 0)
  185.                
  186.                 # video codec -------------------
  187.                 self.make_video_codec()
  188.                 #add frame video codec
  189.                 self.vbox_pg3.pack_start(self.f_3vcodec['frame'], 1, 0, 0)
  190.                
  191.                 # other options ----------------
  192.                 self.make_other_opts()
  193.                 #add frame other options
  194.                 self.vbox_pg3.pack_start(self.f3_oth['frame'], 1, 0, 0)
  195.                
  196.                 # page3 output ---------------------
  197.                 self.f3_out = self.make_frame_ag(3, "  730 command  " , 6, 8, 8, True)
  198.                 self.f3_out_label = Gtk.Label("")
  199.                 self.f3_out['grid'].attach(self.f3_out_label, 0, 0, 1, 1)
  200.                 # add frame page3 output
  201.                 self.vbox_pg3.pack_start(self.f3_out['frame'], 1, 0, 0)
  202.                
  203.                 # run 730 ---------------------------------
  204.                 self.make_run_730()
  205.                 # add frame run 730
  206.                 self.vbox_pg3.pack_start(self.f3_run['frame'], 1, 0, 0)
  207.                
  208.                
  209.                 #---------------------------------------------------
  210.                 # main vbox
  211.                 self.main_vbox = Gtk.VBox()
  212.                
  213.                 # notebook      
  214.                 self.notebook = Gtk.Notebook()
  215.                 self.notebook.set_tab_pos(0)  #GTK_POS_LEFT
  216.                 self.notebook.set_show_border (False)
  217.                 self.main_vbox.pack_start(self.notebook, 1, 0, 0)
  218.                
  219.                 #page 1
  220.                 self.tab1label = Gtk.Label("Video filters")
  221.                 self.page1_ali = Gtk.Alignment()
  222.                 self.page1_ali.set_padding(0, 6, 6, 6)
  223.                 self.page1_ali.add(self.vbox1)
  224.                 self.notebook.append_page(self.page1_ali, self.tab1label)
  225.                
  226.                 #page 2
  227.                 self.tab2label = Gtk.Label("Audio")
  228.                 self.page2_ali = Gtk.Alignment()
  229.                 self.page2_ali.set_padding(0, 6, 6, 6)
  230.                 self.page2_ali.add(self.vbox_pg2)
  231.                 self.notebook.append_page(self.page2_ali, self.tab2label)
  232.                
  233.                 #page 3
  234.                 self.tab3label = Gtk.Label("730")
  235.                 self.page3_ali = Gtk.Alignment()
  236.                 self.page3_ali.set_padding(0, 6, 6, 6)
  237.                 self.page3_ali.add(self.vbox_pg3)
  238.                 self.notebook.append_page(self.page3_ali, self.tab3label)
  239.                
  240.                 #---------------------------------------------------
  241.                
  242.                 # low part buttons and term --------------------------
  243.                 self.make_low_part()
  244.                 # add low part-----------------
  245.                 self.main_vbox.pack_start(self.gridterm, 1, 1, 0)
  246.                
  247.                 #---------------------------------------------------------
  248.                 self.window.add (self.main_vbox)
  249.                 #---------------------------------
  250.                 self.window.show_all()
  251.                
  252.                 # inizializza variabili
  253.                 self.final_vf_str = ""
  254.                 self.final_af_str = ""
  255.                 self.deint_str = ""
  256.                 self.crop_str = ""
  257.                 self.scalestr = ""
  258.                 self.dn_str = ""
  259.                 self.filter_test_str = ""
  260.                 self.video_width = "0"
  261.                 self.video_height = "0"
  262.                 self.add_1_1 = True
  263.                 self.maps_str = ""
  264.                 self.time_final_srt = ""
  265.                 self.final_codec_str = "-aaq -crf 21"
  266.                 self.final_other_str = ""
  267.                 self.a_copy = 0
  268.                 self.v_copy = 0
  269.                 self.container_str = "-mkv"
  270.                 self.make_p3_out_command()
  271.                 self.first_run = 0
  272.                
  273.         def make_deinterlace(self):
  274.                 self.f_deint = self.make_frame_ag(3, "" , 6, 8, 8, True)
  275.                 self.checkdeint = Gtk.CheckButton("deinterlace")
  276.                 self.checkdeint.connect("toggled", self.on_deint_clicked)
  277.                 self.f_deint['grid'].attach(self.checkdeint, 0, 0, 1, 1)
  278.                
  279.                 self.box_deint = self.make_combobox(
  280.                   "yadif",
  281.                   "postprocessing linear blend"
  282.                   )
  283.                 self.f_deint['grid'].attach(self.box_deint['cbox'], 1, 0, 1, 1)
  284.                 self.box_deint['cbox'].connect("changed", self.on_deint_clicked)
  285.                 #
  286.                 self.f_deint['grid'].attach(self.make_label(""), 2, 0, 1, 1)
  287.        
  288.         def make_map(self):
  289.                 self.f_map = self.make_frame_ag(3, "" , 6, 8, 8, True)
  290.                 #
  291.                 self.check_map = Gtk.CheckButton("map")
  292.                 self.check_map.connect("toggled", self.on_map_clicked) # toggled or activate (enter)
  293.                 self.f_map['grid'].attach(self.check_map, 0, 0, 1, 1)
  294.                 #
  295.                 self.mapstream_label = self.make_label("streams: ")
  296.                 self.f_map['grid'].attach(self.mapstream_label, 1, 0, 1, 1)
  297.                 #
  298.                 self.entry_map = Gtk.Entry()
  299.                 self.entry_map.set_tooltip_text("use 0:0  or  0:0,0:1,0:2")
  300.                 self.entry_map.connect("changed", self.on_map_clicked)
  301.                 self.f_map['grid'].attach(self.entry_map, 2, 0, 1, 1)
  302.                 #
  303.                 self.map_label = Gtk.Label("")
  304.                 self.f_map['grid'].attach(self.map_label, 3, 0, 1, 1)
  305.                 # placeholder
  306.                 self.f_map['grid'].attach(self.make_label(""), 4, 0, 1, 1)
  307.                
  308.         def make_time_cut(self):
  309.                 self.f_time = self.make_frame_ag(3, "" , 6, 8, 8, True)
  310.                 #
  311.                 self.check_time = Gtk.CheckButton("time")
  312.                 self.check_time.connect("toggled", self.on_time_clicked) # toggled or activate (enter)
  313.                 self.f_time['grid'].attach(self.check_time, 0, 0, 1, 1)
  314.                 #
  315.                 self.label_time_in = self.make_label("from: ")
  316.                 self.f_time['grid'].attach(self.label_time_in, 1, 0, 1, 1)
  317.                 self.entry_timein = Gtk.Entry()
  318.                 self.entry_timein.set_tooltip_text("use: 30 or 00:00:30")
  319.                 self.entry_timein.connect("changed", self.on_time_clicked)
  320.                 self.f_time['grid'].attach(self.entry_timein, 2, 0, 1, 1)
  321.                
  322.                 self.label_time_out = self.make_label("to: ")
  323.                 self.f_time['grid'].attach(self.label_time_out, 3, 0, 1, 1)
  324.                 self.entry_timeout = Gtk.Entry()
  325.                 self.entry_timeout.set_tooltip_text("use: 30 or 00:00:30")
  326.                 self.entry_timeout.connect("changed", self.on_time_clicked)
  327.                 self.f_time['grid'].attach(self.entry_timeout, 4, 0, 1, 1)
  328.        
  329.         def make_scale(self):
  330.                 self.frame_scale = self.make_frame_ag(3, '  scale  ' , 6, 8, 8, True)
  331.                 # ------------------------------
  332.                 self.box1 = self.make_combobox(
  333.                   "None",
  334.                   "W",
  335.                   "H"
  336.                   )
  337.                 self.frame_scale['grid'].attach(self.box1['cbox'], 0, 0, 1, 1)
  338.                 self.box1['cbox'].connect("changed", self.on_scale_clicked)
  339.                 #------------------------------------
  340.                 self.box2 = self.make_combobox(
  341.                   "16/9",
  342.                   "4/3"
  343.                   )
  344.                 self.frame_scale['grid'].attach(self.box2['cbox'], 0, 1, 1, 1)
  345.                 self.box2['cbox'].connect("changed", self.on_scale_clicked)
  346.                 #-----------------------------------------
  347.                 self.size_spinner = self.make_slider_and_spinner(720, 200, 2000, 1, 10, 0)
  348.                 self.frame_scale['grid'].attach(self.size_spinner['slider'], 1, 0, 1, 1)
  349.                 self.frame_scale['grid'].attach(self.size_spinner['spinner'], 2, 0, 1, 1)
  350.                 #self.size_spinner['slider'].set_size_request(150,-1)
  351.                 self.size_spinner['adj'].set_value(720.001) #mettere decimali se no non si vede
  352.                 self.size_spinner['adj'].connect("value-changed", self.on_scale_clicked)
  353.                 #-------------------------------------------------------
  354.                 self.check = Gtk.CheckButton("lanczos")
  355.                 self.check.connect("toggled", self.on_scale_clicked)
  356.                 self.frame_scale['grid'].attach(self.check, 2, 1, 1, 1)
  357.                
  358.         def make_crop(self):
  359.                 self.frame_crop = self.make_frame_ag(3, '' , 6, 2, 0, True)
  360.                 # -------
  361.                 self.checkcr = Gtk.CheckButton("crop")
  362.                 self.checkcr.connect("toggled", self.on_crop_clicked)
  363.                 self.frame_crop['grid'].attach(self.checkcr, 0, 0, 1, 1)
  364.                 #----------
  365.                 self.butcrode = Gtk.Button(label="Crop detect")
  366.                 self.butcrode.connect("clicked", self.on_butcrode_clicked)
  367.                 self.frame_crop['grid'].attach(self.butcrode, 0, 1, 1, 1)
  368.                 #-----------
  369.                 self.labelcropinw = self.make_label("input W: ")
  370.                 self.frame_crop['grid'].attach(self.labelcropinw, 1, 0, 1, 1)
  371.                 self.labelcropinh = self.make_label("input H: ")
  372.                 self.frame_crop['grid'].attach(self.labelcropinh, 1, 1, 1, 1)
  373.                 #
  374.                 self.spincw = self.make_spinbut(640 , 100 , 1920 , 10 , 1 , 0, True )
  375.                 self.spincw["adj"].connect("value-changed", self.on_crop_clicked)
  376.                 self.frame_crop['grid'].attach(self.spincw["spinner"], 2, 0, 1, 1)
  377.                 #
  378.                 self.spinch = self.make_spinbut(480 , 100 , 1280 , 10 , 1 , 0, True )
  379.                 self.spinch["adj"].connect("value-changed", self.on_crop_clicked)
  380.                 self.frame_crop['grid'].attach(self.spinch["spinner"], 2, 1, 1, 1)
  381.                 #
  382.                
  383.                 self.labelcroptop = self.make_label("crop Top: ")
  384.                 self.frame_crop['grid'].attach(self.labelcroptop, 3, 0, 1, 1)
  385.                 self.labelcropbot = self.make_label("crop Bottom: ")
  386.                 self.frame_crop['grid'].attach(self.labelcropbot, 3, 1, 1, 1)
  387.                 #
  388.                
  389.                 self.spinct = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  390.                 self.spinct["adj"].connect("value-changed", self.on_crop_clicked)
  391.                 self.frame_crop['grid'].attach(self.spinct["spinner"], 4, 0, 1, 1)
  392.                 #
  393.                 self.spincb = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  394.                 self.spincb["adj"].connect("value-changed", self.on_crop_clicked)
  395.                 self.frame_crop['grid'].attach(self.spincb["spinner"], 4, 1, 1, 1)
  396.                 #
  397.                
  398.                 self.labelcroplef = self.make_label("crop Left: ")
  399.                 self.frame_crop['grid'].attach(self.labelcroplef, 5, 0, 1, 1)
  400.                 self.labelcroprig = self.make_label("crop Right: ")
  401.                 self.frame_crop['grid'].attach(self.labelcroprig, 5, 1, 1, 1)
  402.                 #
  403.                 self.spincl = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  404.                 self.spincl["adj"].connect("value-changed", self.on_crop_clicked)
  405.                 self.frame_crop['grid'].attach(self.spincl["spinner"], 6, 0, 1, 1)
  406.                 #
  407.                 self.spincr = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
  408.                 self.spincr["adj"].connect("value-changed", self.on_crop_clicked)
  409.                 self.frame_crop['grid'].attach(self.spincr["spinner"], 6, 1, 1, 1)
  410.                
  411.                
  412.         def make_denoise(self):
  413.                 self.frame_dn = self.make_frame_ag(3, '' , 6, 8, 8, True)
  414.                 # ----------------------
  415.                 self.checkdn = Gtk.CheckButton("denoise")
  416.                 self.checkdn.connect("toggled", self.on_dn_clicked)
  417.                 self.frame_dn['grid'].attach(self.checkdn, 0, 0, 1, 1)
  418.                 # -------------------------
  419.                 self.labeldn = Gtk.Label("hqdn3d:")
  420.                 self.labeldn.set_alignment(1.0, 0.5)
  421.                 self.frame_dn['grid'].attach(self.labeldn, 1, 0, 1, 1)
  422.                 #----------------------------------------
  423.                 self.spindn = self.make_spinbut(4 , 2 , 8 , 1 , 10 , 0, True )
  424.                 self.spindn["adj"].connect("value-changed", self.on_dn_clicked)
  425.                 self.frame_dn['grid'].attach(self.spindn["spinner"], 2, 0, 1, 1)
  426.                
  427.         def make_low_part(self):
  428.                 # grid
  429.                 self.gridterm = Gtk.Grid()
  430.                 self.gridterm.set_row_spacing(2)
  431.                 self.gridterm.set_column_spacing(2)
  432.                 self.gridterm.set_column_homogeneous(True) # True
  433.                 # filechooserbutton
  434.                 self.filechooserbutton = Gtk.FileChooserButton(title="FileChooserButton")
  435.                 #
  436.                 #self.filechooserbutton.set_action(2) # 0 open file, 1 save file, 2 select folder, 3 create folder
  437.                 #
  438.                 self.filechooserbutton.connect("file-set", self.file_changed)  
  439.                 # filter
  440.                 self.filter = Gtk.FileFilter()
  441.                 self.filter.set_name("Video")
  442.                 self.filter.add_mime_type("video/x-matroska")
  443.                 self.filter.add_mime_type("video/mp4")
  444.                 self.filter.add_mime_type("video/x-flv")
  445.                 self.filter.add_mime_type("video/avi")
  446.                 self.filter.add_mime_type("video/mpg")
  447.                 self.filter.add_mime_type("video/mpeg")
  448.                 self.filter.add_mime_type("video/x-ms-wmv")
  449.                 self.filter.add_mime_type("video/webm")
  450.                 self.filter.add_mime_type("video/ogg")
  451.                 self.filter.add_mime_type("video/quicktime")
  452.                 self.filechooserbutton.add_filter(self.filter)
  453.                 # terminal
  454.                 self.terminal     = Vte.Terminal()
  455.                 self.terminal.fork_command_full(
  456.                         Vte.PtyFlags.DEFAULT, #default is fine
  457.                         os.getcwd(), #where to start the command?   os.environ['HOME']
  458.                         ["/bin/sh"], #where is the emulator?
  459.                         [], #it's ok to leave this list empty
  460.                         GLib.SpawnFlags.DO_NOT_REAP_CHILD,
  461.                         None, #at least None is required
  462.                         None,
  463.                         )
  464.                 self.scroller = Gtk.ScrolledWindow()
  465.                 self.scroller.set_hexpand(True)
  466.                 self.scroller.set_vexpand(True)
  467.                 self.scroller.add(self.terminal)
  468.                 self.scroller.set_min_content_height(90)
  469.                 #self.gridterm.attach(self.scroller, 0, 1, 6, 1)
  470.                 #ff command button
  471.                 self.butplay = Gtk.Button(label="FFplay")
  472.                 self.butplay.connect("clicked", self.on_butplay_clicked)
  473.                 self.butplay.set_sensitive(False)
  474.                 self.butprobe = Gtk.Button(label="FFprobe")
  475.                 self.butprobe.connect("clicked", self.on_butprobe_clicked)
  476.                 self.butprobe.set_sensitive(False)
  477.                 #self.butcrode = Gtk.Button(label="Crop detect")
  478.                 #self.butcrode.connect("clicked", self.on_butcrode_clicked)
  479.                 self.butcrode.set_sensitive(False)
  480.                 self.buttest = Gtk.Button(label="Test")
  481.                 self.buttest.connect("clicked", self.on_buttest_clicked)
  482.                 self.buttest.set_sensitive(False)
  483.                 self.buttestspl = Gtk.Button(label="Test split")
  484.                 self.buttestspl.connect("clicked", self.on_buttestspl_clicked)
  485.                 self.buttestspl.set_sensitive(False)
  486.                
  487.                 self.gridterm.attach(self.filechooserbutton, 0, 0, 1, 1)
  488.                 self.gridterm.attach(self.butprobe, 1, 0, 1, 1)
  489.                 self.gridterm.attach(self.butplay, 2, 0, 1, 1)
  490.                 #self.gridterm.attach(self.butcrode, 3, 0, 1, 1)
  491.                 self.gridterm.attach(self.buttest, 3, 0, 1, 1)
  492.                 self.gridterm.attach(self.buttestspl, 4, 0, 1, 1)
  493.                
  494.                 self.gridterm.attach(self.scroller, 0, 1, 5, 1)
  495.  
  496.         def make_volume_det(self):
  497.                 self.f_volume_det = self.make_frame_ag(3, "" , 6, 8, 8, True)
  498.                 #
  499.                 self.but_volume_det = Gtk.Button(label="Volume detect")
  500.                 self.but_volume_det.connect("clicked", self.on_but_volume_det_clicked)
  501.                 self.but_volume_det.set_sensitive(False)
  502.                 self.f_volume_det['grid'].attach(self.but_volume_det, 0, 0, 1, 1)
  503.                 #
  504.                 self.label_maxvol = Gtk.Label("")
  505.                 self.f_volume_det['grid'].attach(self.label_maxvol, 2, 0, 1, 1)
  506.                 self.label_meanvol = Gtk.Label("")
  507.                 self.f_volume_det['grid'].attach(self.label_meanvol, 3, 0, 1, 1)
  508.                 #
  509.                 self.check_vol = Gtk.CheckButton("volume")
  510.                 self.check_vol.connect("toggled", self.on_volume_clicked)
  511.                 self.f_volume_det['grid'].attach(self.check_vol, 0, 1, 1, 1)
  512.                 #
  513.                 self.label_db = self.make_label("dB: ")
  514.                 self.f_volume_det['grid'].attach(self.label_db, 1, 1, 1, 1)
  515.                 self.spin_db = self.make_spinbut(0 , -6 , 20 , 0.1 , 1 , 2, True )
  516.                 self.spin_db["adj"].connect("value-changed", self.on_volume_clicked)
  517.                 self.f_volume_det['grid'].attach(self.spin_db["spinner"], 2, 1, 1, 1)
  518.                 self.label_ratio = self.make_label("ratio: ")
  519.                 self.f_volume_det['grid'].attach(self.label_ratio, 3, 1, 1, 1)
  520.                 self.label_ratio_val = Gtk.Label("")
  521.                 self.f_volume_det['grid'].attach(self.label_ratio_val, 4, 1, 1, 1)
  522.  
  523.        
  524.         def make_audio_codec(self):
  525.                 self.f_3acodec = self.make_frame_ag(3, "  audio codec  " , 6, 8, 8, True)
  526.                 #
  527.                 self.box_ac = self.make_combobox(
  528.                   "libfaac quality (def. 100)",
  529.                   "aacplus (64 Kb/s)",
  530.                   "aacplus (32 Kb/s)",
  531.                   "no audio",
  532.                   "audio copy"
  533.                   )
  534.                 self.f_3acodec['grid'].attach(self.box_ac['cbox'], 0, 0, 1, 1)
  535.                 self.box_ac['cbox'].connect("changed", self.on_codec_audio_changed)
  536.                 #
  537.                 self.spin_ac = self.make_spinbut(100 , 80 , 160 , 10 , 1 , 0, True )
  538.                 self.spin_ac["adj"].connect("value-changed", self.on_codec_clicked)
  539.                 self.f_3acodec['grid'].attach(self.spin_ac["spinner"], 1, 0, 1, 1)
  540.                 # placeholder
  541.                 self.f_3acodec['grid'].attach(self.make_label(""), 2, 0, 1, 1)
  542.                 #
  543.                 self.f3ac_label_out = Gtk.Label("-aaq")
  544.                 self.f_3acodec['grid'].attach(self.f3ac_label_out, 3, 0, 1, 1)
  545.        
  546.         def make_video_codec(self):
  547.                 self.f_3vcodec = self.make_frame_ag(3, "  video codec  " , 6, 8, 8, True)
  548.                 self.box_vcodec = self.make_combobox(
  549.                   "libx264",
  550.                   "video copy"
  551.                   )
  552.                 self.f_3vcodec['grid'].attach(self.box_vcodec['cbox'], 0, 0, 1, 1)
  553.                 self.box_vcodec['cbox'].connect("changed", self.on_codec_video_changed)
  554.                 #
  555.                 self.box_vrc = self.make_combobox(
  556.                   "crf",
  557.                   "bitrate kb/s"
  558.                   )
  559.                 self.f_3vcodec['grid'].attach(self.box_vrc['cbox'], 1, 0, 1, 1)
  560.                 self.box_vrc['cbox'].connect("changed", self.on_codec_vrc_changed)
  561.                 #
  562.                 self.spin_vc = self.make_spinbut(21.3 , 15 , 40 , 0.1 , 1 , 1, True )
  563.                 self.spin_vc["adj"].connect("value-changed", self.on_codec_clicked)
  564.                 self.f_3vcodec['grid'].attach(self.spin_vc["spinner"], 2, 0, 1, 1)
  565.                 #
  566.                 self.f3v_label_out = Gtk.Label("-crf 21.3")
  567.                 self.f_3vcodec['grid'].attach(self.f3v_label_out, 3, 0, 1, 1)
  568.        
  569.         def make_other_opts(self):
  570.                 self.f3_oth = self.make_frame_ag(3, "  other options  " , 6, 8, 8, True)
  571.                 #
  572.                 self.check_2pass = Gtk.CheckButton("2 pass")
  573.                 self.check_2pass.connect("toggled", self.on_f3_other_clicked)
  574.                 self.f3_oth['grid'].attach(self.check_2pass, 0, 0, 1, 1)
  575.                 self.check_2pass.set_sensitive(False)
  576.                 #
  577.                 self.check_nometa = Gtk.CheckButton("no metatag")
  578.                 self.check_nometa.connect("toggled", self.on_f3_other_clicked)
  579.                 self.f3_oth['grid'].attach(self.check_nometa, 1, 0, 1, 1)
  580.                 #
  581.                 self.check_cpu = Gtk.CheckButton("cpu 3")
  582.                 self.check_cpu.connect("toggled", self.on_f3_other_clicked)
  583.                 self.f3_oth['grid'].attach(self.check_cpu, 2, 0, 1, 1)
  584.                 #
  585.                 self.check_debug = Gtk.CheckButton("debug")
  586.                 self.check_debug.connect("toggled", self.on_f3_other_clicked)
  587.                 self.f3_oth['grid'].attach(self.check_debug, 3, 0, 1, 1)
  588.                 #
  589.                 self.box_oth_container = self.make_combobox(
  590.                   "MKV",
  591.                   "MP4"
  592.                   )
  593.                 self.f3_oth['grid'].attach(self.box_oth_container['cbox'], 4, 0, 1, 1)
  594.                 self.box_oth_container['cbox'].connect("changed", self.on_container_changed)
  595.                
  596.         def make_run_730(self):
  597.                 self.f3_run = self.make_frame_ag(3, "  execute in terminal  " , 6, 8, 8, True)
  598.                 #
  599.                 self.f3_run_indir_label = Gtk.Label("")
  600.                 self.f3_run['grid'].attach(self.f3_run_indir_label, 0, 0, 1, 1)
  601.                 self.f3_run_file = Gtk.Label("no input file")
  602.                 self.f3_run['grid'].attach(self.f3_run_file, 1, 0, 2, 1)
  603.                 self.f3_dur_file = Gtk.Label("")
  604.                 self.f3_run['grid'].attach(self.f3_dur_file, 3, 0, 1, 1)
  605.                 #
  606.                 self.but_f3_run = Gtk.Button(label="RUN")
  607.                 self.but_f3_run.connect("clicked", self.on_but_f3_run_clicked)
  608.                 self.but_f3_run.set_sensitive(False)
  609.                 self.f3_run['grid'].attach(self.but_f3_run, 3, 1, 1, 1)
  610.                 #
  611.                 #self.f3_run_outdir_label = Gtk.Label("out dir:  " + os.getcwd())
  612.                 self.f3_run_outdir_label = Gtk.Label("")
  613.                 self.f3_run_outdir_label.set_markup("<b>out dir:  </b>" + os.getcwd())
  614.                 self.f3_run['grid'].attach(self.f3_run_outdir_label, 0, 1, 2, 1)
  615.                 #
  616.                 # filechooserbutton
  617.                 self.out_dir_chooserbut = Gtk.FileChooserButton(title="Dir out")
  618.                 self.out_dir_chooserbut.set_action(2)
  619.                 #self.filechooserbutton.set_action(2) # 0 open file, 1 save file, 2 select folder, 3 create folder
  620.                 acturi = "file://" + os.getcwd()
  621.                 self.out_dir_chooserbut.set_uri(acturi)
  622.                 self.f3_run['grid'].attach(self.out_dir_chooserbut, 2, 1, 1, 1)
  623.                 self.out_dir_chooserbut.connect("selection-changed", self.dir_changed)
  624.                
  625.                
  626.         # signal handlers -----------------------------------------------
  627.         def on_window_destroy(self, *args):
  628.                 Gtk.main_quit(*args)
  629.        
  630.         def on_scale_clicked(self, button):
  631.                 if (self.box1['cbox'].get_active() != 0):
  632.                         self.calcola_scale()
  633.                 else:
  634.                         self.scalestr = ""
  635.                         self.outfilter()
  636.                  
  637.         def on_deint_clicked(self, button):
  638.                 self.deint_str = ""
  639.                 if self.checkdeint.get_active():
  640.                         deint_val = self.box_deint['cbox'].get_active()
  641.                         if (deint_val == 0):
  642.                                 self.deint_str = "yadif"
  643.                         elif (deint_val == 1):
  644.                                 self.deint_str = "pp=lb"
  645.                 self.outfilter()
  646.                        
  647.         def on_dn_clicked(self, button):
  648.                 self.dn_str = ""
  649.                 if self.checkdn.get_active():
  650.                         dn_val = int( self.spindn['adj'].get_value() )
  651.                         self.dn_str = "hqdn3d=" + str(dn_val)
  652.                 self.outfilter()
  653.                    
  654.         def on_crop_clicked(self, button):
  655.                 ok = 0
  656.                 self.crop_str = ""
  657.                 if self.checkcr.get_active():
  658.                         ok = 1
  659.                 if ok:
  660.                         inW = int(self.spincw['adj'].get_value())
  661.                         inH = int(self.spinch['adj'].get_value())
  662.                         crT = int(self.spinct['adj'].get_value())
  663.                         crB = int(self.spincb['adj'].get_value())
  664.                         crL = int(self.spincl['adj'].get_value())
  665.                         crR = int(self.spincr['adj'].get_value())      
  666.                         finW = inW - crL - crR
  667.                         finH = inH - crT - crB
  668.                         if ( (finW < 100) or (finH < 100) ):
  669.                                 self.crop_str = (" ** invalid crop ** ")
  670.                         else:
  671.                                 self.crop_str = "crop=" + str(finW) + ":" \
  672.                                  + str(finH) + ":" \
  673.                                  + str(crL)  + ":" \
  674.                                  + str(crT)
  675.                 if (self.box2['cbox'].get_active() != 2):
  676.                         self.outfilter()
  677.                 else:
  678.                         self.on_scale_clicked(button)
  679.                
  680.         def file_changed(self, filechooserbutton):              
  681.                 if self.filechooserbutton.get_filename():
  682.                         self.butplay.set_sensitive(True)
  683.                         self.butprobe.set_sensitive(True)
  684.                         self.butcrode.set_sensitive(True)
  685.                         self.spinct['adj'].set_value(0)
  686.                         self.spincb['adj'].set_value(0)
  687.                         self.spincl['adj'].set_value(0)
  688.                         self.spincr['adj'].set_value(0)
  689.                         self.buttest.set_sensitive(True)
  690.                         self.buttestspl.set_sensitive(True)
  691.                         self.but_volume_det.set_sensitive(True)
  692.                         self.but_volume_det.set_label("Volume detect")
  693.                         self.label_meanvol.set_label("")
  694.                         self.label_maxvol.set_label("")
  695.                         self.spin_db["adj"].set_value(0)
  696.                         self.but_f3_run.set_sensitive(True)
  697.                         #
  698.                         self.command = "clear" + "\n"
  699.                         length = len(self.command)
  700.                         self.terminal.feed_child(self.command, length)
  701.                         # need ffprobe
  702.                         filename = self.filechooserbutton.get_filename()
  703.                         self.f3_run_indir_label.set_label(os.path.dirname(filename))
  704.                         #
  705.                         file_4_label = os.path.basename(filename)
  706.                         if ( len(file_4_label) > 50):
  707.                                 a = file_4_label[:46]
  708.                                 b = '  ...  '
  709.                                 c = file_4_label[-4:]
  710.                                 file_4_label = a + b + c
  711.                         self.f3_run_file.set_label(file_4_label)
  712.                         cmnd = ['ffprobe', '-show_format', '-show_streams', '-pretty', '-loglevel', 'quiet', filename]
  713.                         p = subprocess.Popen(cmnd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  714.                         out, err =  p.communicate()
  715.                         out = out.decode() # python3
  716.                         for line in out.split('\n'):
  717.                                 line = line.strip()
  718.                                 if line.startswith('width='):
  719.                                         s = line
  720.                                         width = s.split('width=', 1)
  721.                                         #print "Video pixel width is: %s" % width[1]
  722.                                         self.video_width = width[1]
  723.                                         self.spincw['adj'].set_value(float(self.video_width)) #mettere decimali se no non si vede
  724.                                         self.spincw['spinner'].set_sensitive(False)
  725.                                 elif line.startswith('height='):
  726.                                         s = line
  727.                                         height = s.split('height=', 1)
  728.                                         #print "Video pixel height is: %s" % height[1]
  729.                                         self.video_height = height[1]    
  730.                                         self.spinch['adj'].set_value(float(self.video_height)) #mettere decimali se no non si vede
  731.                                         self.spinch['spinner'].set_sensitive(False)
  732.                                         if self.add_1_1:
  733.                                                 self.box2['list'].append(["as input"])
  734.                                         self.add_1_1 = False
  735.                                 elif line.startswith('duration='):
  736.                                         s = line
  737.                                         duration = s.split('duration=', 1)
  738.                                         dur = duration[1].split('.')
  739.                                         self.f3_dur_file.set_label(dur[0])
  740.              
  741.         def on_butplay_clicked(self, button):
  742.                 self.command = "ffplay \"" + self.filechooserbutton.get_filename() + "\"" +"\n"
  743.                 length = len(self.command)
  744.                 self.terminal.feed_child(self.command, length)
  745.                
  746.         def on_butprobe_clicked(self, button):
  747.                 self.command = "ffprobe \"" + self.filechooserbutton.get_filename() + "\""  + " 2>&1 | grep 'Input\|Duration\|Stream'" + "\n"
  748.                 length = len(self.command)
  749.                 self.terminal.feed_child(self.command, length)    
  750.                
  751.         def on_butcrode_clicked(self, button):
  752.                 # need ffmpeg
  753.                 self.butcrode.set_sensitive(False)
  754.                 filename = self.filechooserbutton.get_filename()
  755.                 #cmnd = ['ffplay' , '-vf', 'cropdetect', '-autoexit' ,'-ss', '60' , '-t' , '1',  filename]
  756.                 cmnd = "ffmpeg -i " + "\"" + filename + "\"" + " -ss 60 -t 1 -vf cropdetect -f null - 2>&1 | awk \'/crop/ { print $NF }\' | tail -1"
  757.                 p = subprocess.Popen(cmnd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
  758.                 out, err =  p.communicate()
  759.                 out = out.decode()
  760.                 for line in out.split('\n'):
  761.                         line = line.strip()
  762.                         if "crop=" in line:  
  763.                                 aa = line.split('crop=', 1)
  764.                                 aaa = aa[1]
  765.                                 listdata = aaa.split(':')
  766.                                 w = listdata[0]
  767.                                 h = listdata[1]
  768.                                 offx = listdata[2]
  769.                                 offy = listdata[3]
  770.                                 ctop = int(offy)
  771.                                 cbot = int(self.video_height) - int(offy) -int(h)
  772.                                 cleft = int(offx)
  773.                                 cright = int(self.video_width) - int(offx) -int(w)
  774.                                 self.spinct['adj'].set_value(float(ctop))
  775.                                 self.spincb['adj'].set_value(float(cbot))
  776.                                 self.spincl['adj'].set_value(float(cleft))
  777.                                 self.spincr['adj'].set_value(float(cright))  
  778.                                 break
  779.                 self.butcrode.set_sensitive(True)
  780.                
  781.         def on_buttest_clicked(self, button):
  782.                 # -map preview: only with none -vf option  
  783.                 if (self.maps_str == ""):
  784.                         self.command = "ffplay \"" + self.filechooserbutton.get_filename() + "\" " \
  785.                          + " " + self.time_final_srt + " " \
  786.                          + "-vf "  + self.filter_test_str + "\n"
  787.                 else:
  788.                         self.command = "ffmpeg -i \"" + self.filechooserbutton.get_filename() + "\" " \
  789.                          + self.maps_str  + " " + self.time_final_srt + " "
  790.                         if (self.filter_test_str != ""):
  791.                                 self.command = self.command + " -vf "  + self.filter_test_str
  792.                         self.command = self.command +  " -c copy -f matroska - | ffplay -" + "\n"
  793.                 length = len(self.command)
  794.                 self.terminal.feed_child(self.command, length)
  795.                
  796.         def on_buttestspl_clicked(self, button):
  797.                 self.command = "ffplay \"" + self.filechooserbutton.get_filename() + "\" " \
  798.                   + " " + self.time_final_srt + " " \
  799.                   + " -vf \"split[a][b]; [a]pad=iw:(ih*2)+4:color=888888 [src]; [b]" \
  800.                   + self.filter_test_str + " [filt]; [src][filt]overlay=((main_w - w)/2):main_h/2\"" + "\n"
  801.                 length = len(self.command)
  802.                 self.terminal.feed_child(self.command, length)
  803.        
  804.         def on_but_volume_det_clicked(self, button):
  805.                 #self.but_volume_det.set_label("Wait")
  806.                 self.but_volume_det.set_sensitive(False)        
  807.                 filename = self.filechooserbutton.get_filename()        
  808.                 cmnd = "ffmpeg -i " + "\"" + filename + "\" " + " -vn -af volumedetect -f null /dev/null 2>&1 | grep \'mean_volume\\|max_volume\'"              
  809.                 p = subprocess.Popen(cmnd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
  810.                 out, err =  p.communicate()
  811.                 out = out.decode()
  812.                 for line in out.split('\n'):
  813.                         line = line.strip()
  814.                         if "mean_volume:" in line:  
  815.                                 aa = line.split('mean_volume:', 1)
  816.                                 mea_vol_det = aa[1]
  817.                                 self.label_meanvol.set_label("Mean vol: " + mea_vol_det)
  818.                         if "max_volume:" in line:  
  819.                                 aa = line.split('max_volume:', 1)
  820.                                 max_vol_det = aa[1]
  821.                                 self.label_maxvol.set_label("Max vol: " + max_vol_det)
  822.                 self.but_volume_det.set_label("volume detected")
  823.        
  824.         def on_volume_clicked(self, button):
  825.                 self.label_ratio_val.set_label("")
  826.                 self.final_af_str = ""
  827.                 db = self.spin_db["adj"].get_value()
  828.                 if (db != 0.00):
  829.                         ratio = pow(10, (db/20.0))
  830.                         ratio = float("{0:.3f}".format(ratio))    
  831.                         self.label_ratio_val.set_label(str(ratio))
  832.                         self.final_af_str = "-af volume=" + str(ratio)
  833.                 self.make_p3_out_command()
  834.        
  835.         def on_map_clicked(self, button):
  836.                 self.map_label.set_label("")
  837.                 self.maps_str = ""
  838.                 if self.check_map.get_active():
  839.                         map_in = self.entry_map.get_chars(0, -1)
  840.                         if (map_in != ""):
  841.                                 map_l = map_in.split(",")
  842.                                 for i in range(len(map_l)):
  843.                                         if self.maps_str == "":
  844.                                                 self.maps_str = self.maps_str + "-map " + map_l[i]
  845.                                         else:
  846.                                                 self.maps_str = self.maps_str + " -map " + map_l[i]
  847.                                 self.map_label.set_label(self.maps_str)
  848.                 self.outfilter()
  849.                 self.make_p3_out_command()
  850.                
  851.         def on_time_clicked(self, button):
  852.                 self.time_final_srt = ""
  853.                        
  854.                 if self.check_time.get_active():
  855.                         timein = 0
  856.                         timeout = 0
  857.                         timedur = 0
  858.                         timein_ent = self.entry_timein.get_chars(0, -1)
  859.                         if (timein_ent != ""):
  860.                                 if timein_ent.isdigit():
  861.                                         timein = int(timein_ent)        
  862.                                 else:  
  863.                                         timein = self.hms2sec(timein_ent)
  864.                         timeout_ent = self.entry_timeout.get_chars(0, -1)
  865.                         if (timeout_ent != ""):
  866.                                 if timeout_ent.isdigit():
  867.                                         timeout = int(timeout_ent)
  868.                                         timedur = timeout - timein
  869.                                 else:  
  870.                                         timeout = self.hms2sec(timeout_ent)
  871.                                         timedur = timeout - timein
  872.                         if (timein != 0):
  873.                                 self.time_final_srt = self.time_final_srt + " -ss " + str(timein)  
  874.                         if (timedur != 0):
  875.                                 self.time_final_srt = self.time_final_srt + " -t " + str(timedur)    
  876.                 self.outfilter()
  877.                 self.make_p3_out_command()
  878.        
  879.         def on_codec_audio_changed(self, button):
  880.                 a_cod = self.box_ac['cbox'].get_active()
  881.                 if (a_cod == 0): # aaq
  882.                         self.spin_ac['spinner'].set_sensitive(True)
  883.                         self.spin_ac['adj'].set_value(100.0)
  884.                 else:
  885.                         self.spin_ac['spinner'].set_sensitive(False)
  886.                 self.on_codec_clicked(button)
  887.        
  888.         def on_codec_video_changed(self, button):
  889.                 self.on_codec_clicked(button)
  890.        
  891.         def on_codec_vrc_changed(self, button):
  892.                 self.video_rc = self.box_vrc['cbox'].get_active() #0 crf, 1 kb/s
  893.                 if (self.video_rc == 0):
  894.                         self.adj_change(self.spin_vc['adj'], 21.3, 15, 40, 0.1, 1)
  895.                         self.spin_vc['adj'].set_value(21.3)
  896.                         self.check_2pass.set_active(False)
  897.                         self.check_2pass.set_sensitive(False)
  898.                 elif (self.video_rc == 1):
  899.                         self.adj_change(self.spin_vc['adj'], 730, 300, 4000, 10, 100)
  900.                         self.spin_vc['adj'].set_value(730.0)
  901.                         self.check_2pass.set_sensitive(True)
  902.        
  903.         def on_codec_clicked(self, button):
  904.                 self.a_copy = 0
  905.                 self.v_copy = 0
  906.                 self.final_codec_str = ""
  907.                 audio_codec = self.box_ac['cbox'].get_active() # 0 aaq. 1 a64 , 2 a32 , 3 audio none
  908.                 if (audio_codec == 0):
  909.                         audio_codec_str = "-aaq"
  910.                         quality_faac = self.spin_ac['adj'].get_value()
  911.                         if (quality_faac != 100):
  912.                                 audio_codec_str = audio_codec_str + " " + str(int(quality_faac))
  913.                 elif (audio_codec == 1):
  914.                         audio_codec_str = "-a64"
  915.                 elif (audio_codec == 2):
  916.                         audio_codec_str = "-a32"
  917.                 elif (audio_codec == 3):
  918.                         audio_codec_str = "-an"
  919.                 elif (audio_codec == 4):
  920.                         audio_codec_str = "-acopy"
  921.                         self.a_copy = 1
  922.                 self.f3ac_label_out.set_label(audio_codec_str)
  923.                 #
  924.                 self.pg2_str = audio_codec_str
  925.                 # video
  926.                 video_codec = self.box_vcodec['cbox'].get_active() #0 x264, 1 -vcopy
  927.                 if (video_codec == 1):
  928.                         video_codec_str = "-vcopy"
  929.                         self.v_copy = 1
  930.                         self.box_vrc['cbox'].set_sensitive(False)
  931.                         self.spin_vc['spinner'].set_sensitive(False)
  932.                 else:
  933.                         self.box_vrc['cbox'].set_sensitive(True)
  934.                         self.spin_vc['spinner'].set_sensitive(True)
  935.                         self.video_rc = self.box_vrc['cbox'].get_active() #0 crf, 1 kb/s
  936.                         if (self.video_rc == 0):        
  937.                                 video_codec_str = "-crf " + str(self.spin_vc['adj'].get_value())
  938.                         elif (self.video_rc == 1):
  939.                                 video_codec_str = "-b " + str(int(self.spin_vc['adj'].get_value()))
  940.                
  941.                 self.f3v_label_out.set_label(video_codec_str)    
  942.                 self.final_codec_str = audio_codec_str + " " + video_codec_str
  943.                 self.make_p3_out_command()
  944.        
  945.         def on_f3_other_clicked(self, button):
  946.                 self.final_other_str = ""
  947.                 if self.check_nometa.get_active():
  948.                         self.final_other_str = "-nometa"
  949.                 if self.check_2pass.get_active():
  950.                         if (self.final_other_str == ""):
  951.                                 self.final_other_str = "" + "-pass 2"
  952.                         else:
  953.                                 self.final_other_str = self.final_other_str + " " + "-pass 2"
  954.                 if self.check_cpu.get_active():
  955.                         if (self.final_other_str == ""):
  956.                                 self.final_other_str = "-cpu 3"
  957.                         else:
  958.                                 self.final_other_str = self.final_other_str + " " + "-cpu 3"
  959.                 if self.check_debug.get_active():
  960.                         if (self.final_other_str == ""):
  961.                                 self.final_other_str = "debug"
  962.                         else:
  963.                                 self.final_other_str = self.final_other_str + " " + "debug"
  964.                 self.make_p3_out_command()
  965.                
  966.         def on_container_changed(self,button):
  967.                 container = self.box_oth_container['cbox'].get_active() #0 mkv, 1 mp4
  968.                 if (container == 1):
  969.                         self.container_str = "-mp4"
  970.                 else:
  971.                         self.container_str = "-mkv"
  972.                 self.make_p3_out_command()
  973.                
  974.         def on_but_f3_run_clicked(self, button):
  975.                 self.command = "/home/mc/730-ffmpeg-tool-2 \"" \
  976.                   + self.filechooserbutton.get_filename() + "\" " \
  977.                   + self.p3_command + "\n"
  978.                 length = len(self.command)
  979.                 self.terminal.feed_child(self.command, length)
  980.              
  981.         def dir_changed(self, button):
  982.                 if self.first_run:
  983.                         select = self.out_dir_chooserbut.get_uri()
  984.                         decoded = url2pathname(select)
  985.                         newdir = decoded.split('//')[1]
  986.                         self.command = "cd " + "\"" + newdir + "\"" + "\n"
  987.                         length = len(self.command)
  988.                         self.terminal.feed_child(self.command, length)
  989.                         self.f3_run_outdir_label.set_markup("<b>out dir:  </b>" + newdir)
  990.                 else:
  991.                         self.first_run = 1
  992.                
  993.         # -------------------------------------  
  994.        
  995.         def calcola_scale(self):
  996.                 self.scalestr = ""
  997.                 numero = self.size_spinner['adj'].get_value()
  998.                 numero = int(numero/4)*4
  999.                 dar = self.box2['cbox'].get_active()
  1000.                 lato = self.box1['cbox'].get_active()          
  1001.                 if (dar == 1): # 4/3
  1002.                         if (lato == 1):
  1003.                                 n2 = numero/4*3
  1004.                         else:
  1005.                                 n2 = numero/3*4
  1006.                         setdar = ",setdar=4/3,setsar=1/1"
  1007.                 elif (dar == 0): # 16/9
  1008.                         if (lato == 1):
  1009.                                 n2 = numero/16*9
  1010.                         else:
  1011.                                 n2 = numero/9*16
  1012.                         setdar = ",setdar=16/9,setsar=1/1"      
  1013.                 elif (dar == 2): #1/1 same as input  
  1014.                         w = int(self.video_width)
  1015.                         h = int(self.video_height)
  1016.                         if self.checkcr.get_active():
  1017.                                 crT = int(self.spinct['adj'].get_value())
  1018.                                 crB = int(self.spincb['adj'].get_value())
  1019.                                 crL = int(self.spincl['adj'].get_value())
  1020.                                 crR = int(self.spincr['adj'].get_value())
  1021.                                 h = h - crT - crB
  1022.                                 w = w - crL - crR
  1023.                         if (lato == 1): # h                
  1024.                                 n2 = (float(h)/(w/float(numero)))  
  1025.                         else:
  1026.                                 n2 = (float(w)/(h/float(numero)))
  1027.                         setdar = ""
  1028.                 n2 = int(n2/4)*4                    
  1029.                 self.scalestr = "scale="
  1030.                 if (lato == 1):
  1031.                         self.scalestr = self.scalestr + str(numero) + ":" + str(n2)
  1032.                 else:
  1033.                         self.scalestr = self.scalestr + str(n2) + ":" + str(numero)                  
  1034.                 lanc = self.check.get_active()  
  1035.                 if lanc:
  1036.                         self.scalestr = self.scalestr + ":flags=lanczos" + setdar  
  1037.                 else:
  1038.                         self.scalestr = self.scalestr + setdar
  1039.                 self.outfilter()
  1040.                      
  1041.         def outfilter(self):
  1042.                 final_str = ""
  1043.                 if (self.deint_str != ""):
  1044.                         final_str = final_str + self.deint_str    
  1045.                 if (self.crop_str != ""):
  1046.                         if (final_str == ""):
  1047.                                 final_str = final_str + self.crop_str
  1048.                         else:
  1049.                                         final_str = final_str + "," + self.crop_str
  1050.                 if (self.scalestr != ""):
  1051.                         if (final_str == ""):
  1052.                                 final_str = final_str + self.scalestr
  1053.                         else:
  1054.                                 final_str = final_str + "," + self.scalestr
  1055.                 if (self.dn_str != ""):
  1056.                         if (final_str == ""):
  1057.                                 final_str = final_str + self.dn_str
  1058.                         else:
  1059.                                 final_str = final_str + "," + self.dn_str              
  1060.                 self.filter_test_str = final_str
  1061.                
  1062.                 if (final_str != ""):
  1063.                         self.final_vf_str = "-vf " + final_str
  1064.                 else:
  1065.                         self.final_vf_str = ""
  1066.                
  1067.                 label_str = ""          
  1068.                 if (self.maps_str != ""):
  1069.                         label_str = label_str + self.maps_str + " "  
  1070.                 if (self.time_final_srt != ""):
  1071.                         label_str = label_str + self.time_final_srt + " "
  1072.                 if (self.final_vf_str != ""):
  1073.                         label_str = label_str + self.final_vf_str
  1074.                    
  1075.                 self.labelout.set_text(label_str)
  1076.                 self.make_p3_out_command()
  1077.        
  1078.         def make_p3_out_command(self):
  1079.                 pass
  1080.                 self.p3_command = ""
  1081.                 self.f3_out_label.set_label("")
  1082.                 if (self.maps_str != ""):
  1083.                         self.p3_command = self.maps_str + " "  
  1084.                 if (self.time_final_srt != ""):
  1085.                         self.p3_command = self.p3_command + self.time_final_srt + " "
  1086.                 if ( (self.final_vf_str != "") and (self.v_copy == 0) ): # check -vcopy
  1087.                         self.p3_command = self.p3_command + self.final_vf_str + " "
  1088.                 if ( (self.final_af_str != "") and (self.a_copy == 0) ):  # check -acopy
  1089.                         self.p3_command = self.p3_command + self.final_af_str + " "
  1090.                 if (self.final_codec_str != ""):
  1091.                         self.p3_command = self.p3_command + self.final_codec_str + " "
  1092.                 if (self.container_str != "-mkv"):
  1093.                         self.p3_command = self.p3_command + self.container_str + " "
  1094.                 if (self.final_other_str != ""):
  1095.                         self.p3_command = self.p3_command + self.final_other_str + " "
  1096.                 self.f3_out_label.set_label(self.p3_command)
  1097.                
  1098.         def main(self):
  1099.                 Gtk.main()
  1100.  
  1101.                
  1102.        
  1103.  
  1104. if __name__ == "__main__":
  1105.         hwg = ProgrammaGTK()
  1106.         Gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement