Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # work in python3.4 ---
- # from urllib.request import url2pathname
- #----------------------
- from gi.repository import Gtk, GObject, Vte
- from gi.repository import GLib
- import os
- import sys, subprocess, shlex, re
- from subprocess import call
- from math import pow
- try:
- from urllib import url2pathname
- except ImportError:
- from urllib.request import url2pathname
- from gi.repository import Pango
- import threading
- import time
- class reuse_init(object):
- def make_label(self, text):
- label = Gtk.Label(text)
- label.set_use_underline(True)
- label.set_alignment(1.0, 0.5)
- label.show()
- return label
- def make_slider_and_spinner(self, init, min, max, step, page, digits):
- controls = {'adj':Gtk.Adjustment(init, min, max, step, page), 'slider':Gtk.HScale(), 'spinner':Gtk.SpinButton()}
- controls['slider'].set_adjustment(controls['adj'])
- controls['slider'].set_draw_value(False)
- controls['spinner'].set_adjustment(controls['adj'])
- controls['spinner'].set_digits(digits)
- controls['slider'].show()
- controls['spinner'].show()
- return controls
- def make_frame_ag(self, f_shadow_type, f_label, alig_pad, gri_row_sp, gri_colu_sp, gri_homog):
- controls = {'frame':Gtk.Frame(), 'ali':Gtk.Alignment(), 'grid':Gtk.Grid()}
- controls['frame'].set_shadow_type(f_shadow_type) # 3 GTK_SHADOW_ETCHED_IN , 1 GTK_SHADOW_IN
- controls['frame'].set_label(f_label)
- controls['ali'].set_padding(alig_pad, alig_pad, alig_pad, alig_pad)
- controls['frame'].add(controls['ali'])
- controls['grid'].set_row_spacing(gri_row_sp)
- controls['grid'].set_column_spacing(gri_colu_sp)
- controls['grid'].set_column_homogeneous(gri_homog) # True
- controls['ali'].add(controls['grid'])
- controls['frame'].show()
- controls['ali'].show()
- controls['grid'].show()
- return controls
- def make_spinbut(self, init, min, max, step, page, digits, numeric):
- controls = {'adj':Gtk.Adjustment(init, min, max, step, page), 'spinner':Gtk.SpinButton()}
- controls['spinner'].set_adjustment(controls['adj'])
- controls['spinner'].set_digits(digits)
- controls['spinner'].set_numeric(numeric)
- controls['spinner'].show()
- return controls
- def make_combobox(self, *vals):
- controls = {'list':Gtk.ListStore(str), 'cbox':Gtk.ComboBox(), 'cellr':Gtk.CellRendererText()}
- for i, v in enumerate(vals):
- controls['list'].append([v])
- controls['cbox'].set_model(controls['list'])
- controls['cbox'].pack_start(controls['cellr'], True)
- controls['cbox'].add_attribute(controls['cellr'], "text", 0)
- controls['cbox'].set_active(0)
- controls['cbox'].show()
- return controls
- def hms2sec(self, hms):
- result = 0
- listin = hms.split(':')
- listin.reverse()
- for i in range(len(listin)):
- if listin[i].isdigit():
- if i == 0:
- mult = 1
- if i == 1:
- mult = 60
- if i == 2:
- mult = 3600
- result = result + (int(listin[i])*mult)
- return result
- def sec2hms(self, seconds):
- seconds = float(seconds)
- h = int(seconds/3600)
- if (h > 0):
- seconds = seconds - (h * 3600)
- m = int(seconds / 60)
- s = int(seconds - (m * 60))
- hms = "{0:0=2d}:{1:0=2d}:{2:0=2d}".format(h,m,s)
- return hms
- def adj_change(self, adjustment, value, lower, upper , step_increment, page_increment):
- adjustment.set_value(value)
- adjustment.set_lower(lower)
- adjustment.set_upper(upper)
- adjustment.set_step_increment(step_increment)
- adjustment.set_page_increment(page_increment)
- #adjustment.set_page_size(page_size)
- def check_out_file(self):
- name = os.path.splitext(Vars.basename)[0]
- newname = Vars.outdir + '/' + name + Vars.ext
- if os.path.exists(newname):
- for i in range(2,20):
- newname = Vars.outdir + '/' + name + '_' + str(i) + '_' + Vars.ext
- if (os.path.exists(newname) == False):
- newname = newname
- break
- else:
- newname = newname
- Vars.newname = newname
- self.f3_run_outdir_label.set_tooltip_text(Vars.newname)
- def humansize(self, namefile):
- try:
- nbytes = os.path.getsize(namefile)
- except:
- return '0'
- suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
- if nbytes == 0: return '0 B'
- i = 0
- while nbytes >= 1024 and i < len(suffixes)-1:
- nbytes /= 1024.
- i += 1
- f = "{0:0.1f}".format(nbytes)
- return "{0:>5s} {1:2s}".format(f, suffixes[i])
- # Abstract struct class
- class Struct:
- def __init__ (self, *argv, **argd):
- if len(argd):
- # Update by dictionary
- self.__dict__.update (argd)
- else:
- # Update by position
- attrs = filter (lambda x: x[0:2] != "__", dir(self))
- for n in range(len(argv)):
- setattr(self, attrs[n], argv[n])
- class Tips(Struct):
- map_tooltip_str = ' use 0:0 or 0:0,0:1,0:2 '
- time_tooltip_str = ' use: 90 or 00:01:30 '
- black_dt_init_str = 'Detect black frames can take some time,\ndepending on the length of the video.'
- compad_str = ' attacks attacks:decays decays: points dbin/dbout dbin/dbout:soft-knee:gain:initial volume:delay '
- faac_q_str = ' faac vbr: q 80 ~96k, 90 ~100k, 100 ~118k, 120 ~128k, 160 ~156k, def:100 '
- lamecbr_str = " lame mp3: 32-320 Kb/s def:128 "
- lamevbr_str = " lame mp3 vbr: q 0 ~245Kb/s, 5 ~130Kb/s, 6 ~115Kb/s, 9 ~65Kb/s, def:6 "
- aac_cbr_str = " aac cbr: 32-320 Kb/s def:128 "
- aak_cbr_str = " aac_fdk cbr: 64-320 Kb/s def:128 "
- audio_samp_str = ' audio samplerate '
- audio_channels_str = ' audio channels '
- f3v_label_out_start = "-crf 21.3"
- subcopy_tooltip_srt = ' false= srt->ass '
- cpu_tooltip_srt = ' false= -thread 0 '
- nometa_tooltip_srt = ' true= --map_metadata -1 '
- debug_tooltip_srt = ' only print command in terminal '
- preset_tooltip_str = ' x264 preset '
- tune_tooltip_str = ' x264 tune '
- class Vars(Struct):
- def version_from_filename():
- '''
- filename must be:
- 4FFmpeg-n.nnn.py
- '''
- try:
- version = str(sys.argv[0])
- except:
- version = 'N/A'
- return version
- try:
- version = version.split('-')[1]
- except:
- version = 'N/A'
- return version
- try:
- version = version[:-3]
- except:
- version = 'N/A'
- return version
- return version
- ffmpeg_ex = 'ffmpeg'
- ffplay_ex = 'ffplay'
- ffprobe_ex = 'ffprobe'
- final_vf_str = ""
- final_af_str = ""
- deint_str = ""
- crop_str = ""
- scalestr = ""
- dn_str = ""
- uns_str = ""
- fr_str = ""
- filter_test_str = ""
- video_width = "0"
- video_height = "0"
- add_1_1_dar = True
- maps_str = ""
- time_final_str = ""
- final_codec_str = "-c:a libfaac -q:a 100 -ar 48k -ac 2 -c:v libx264 -crf 21.3 -preset faster -tune film -x264opts ref=4:bframes=4:direct=auto:aq-strength=1.3:ssim"
- final_other_str = ""
- a_copy = 0
- audionone = 0
- audio_channels = 0
- v_copy = 0
- audio_codec_str = "-c:a libfaac -q:a 100 -ar 48k -ac 2"
- vcodec_is = ""
- video_codec_str = ""
- video_codec_str_more = "-preset faster -tune film -x264opts ref=4:bframes=4:direct=auto:aq-strength=1.3:ssim"
- container_str = "-f matroska"
- is_avi = 0
- info_str = ''
- blackdet_is_run = False
- compinit = '.3 .3:1 1:-90/-90 -60/-40 -40/-30 -20/-14 -9/-9 0/-3:6:-3:0:.5'
- compand_data = ''
- compand_time = 0
- time_start = 0 # for cropdetect
- first_run = 0
- p3_command = ""
- filename = ""
- dirname = ""
- basename = ""
- in_file_size = ""
- ext = ".mkv"
- outdir = ""
- newname = ""
- duration = ""
- duration_in_sec = 0
- time_done = 0
- time_done_1 = 0
- out_file_size = ""
- debug = 0
- first_pass = 0
- n_pass = 1
- p3_comm_first_p = ""
- final_command1 = ""
- final_command2 = ""
- eff_pass = 0
- version = version_from_filename()
- BLACKDT_DONE = False
- VOLDT_DONE = False
- ENCODING = False
- class ProgrammaGTK(reuse_init):
- def __init__(self):
- # initialize variables
- self.make_ui()
- self.make_p3_out_command()
- Vars.outdir = os.getcwd()
- if (len(sys.argv) == 2):
- try:
- self.filechooserbutton.set_filename(str(sys.argv[1]))
- self.file_changed(0)
- except:
- pass
- # ----------------------------
- def make_ui(self):
- # ---------------------
- self.window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
- self.window.connect("destroy", self.on_window_destroy)
- self.window.set_title("4FFmpeg")
- self.window.set_position(1) # 1 center, 0 none,
- self.window.set_border_width(3)
- self.window.set_default_size(500,-1)
- #----------------------------------
- #page1 stuff VIDEO FILTERS------------------------------------------
- # page1 VBox -------------------------
- self.vbox1 = Gtk.VBox()
- self.vbox1.set_spacing(2)
- # map --------------------------------------
- self.make_map()
- # add map frame
- self.vbox1.pack_start(self.f_map['frame'], 1, 0, 0)
- #time cut ------------------------------------
- self.make_time_cut()
- # add time frame
- self.vbox1.pack_start(self.f_time['frame'], 1, 0, 0)
- # deinterlace -----------------------
- self.make_deinterlace()
- # add deinterlace frame
- self.vbox1.pack_start(self.f_deint['frame'], 1, 0, 0)
- # crop ----------------------------------------
- self.make_crop()
- # add crop frame -------------------
- self.vbox1.pack_start(self.frame_crop['frame'], 1, 0, 0)
- # scale ------------------------------
- self.make_scale()
- # add scale frame------------------
- self.vbox1.pack_start(self.frame_scale['frame'], 1, 0, 0)
- # denoise ----------------------------
- self.make_denoise()
- # add denoise frame------------------------
- self.vbox1.pack_start(self.frame_dn['frame'], 1, 0, 0)
- #test-------------------
- #self.f_test = self.make_frame_ag(3, "TEST" , 6, 8, 8, True)
- #self.label_test = Gtk.Label("TEST")
- #self.f_test['grid'].attach(self.label_test, 0, 0, 1, 1)
- #self.vbox1.pack_start(self.f_test['frame'], 1, 0, 0)
- #-------------------------------------
- # page 1 output------------------------
- self.frame_out = self.make_frame_ag(3, ' FFmpeg video filter string: ' , 12, 8, 8, True)
- self.labelout = Gtk.Label("")
- self.labelout.set_selectable(1)
- self.labelout.set_width_chars(90)
- self.labelout.set_max_width_chars(90)
- self.labelout.set_line_wrap(True)
- self.frame_out['grid'].attach(self.labelout, 0, 0, 1 ,1)
- # add output frame ---------------------
- self.vbox1.pack_start(self.frame_out['frame'], 1, 0, 0)
- # end page1 stuff
- # page2 stuff UTILITY ------------------------------------------
- # page2 VBox -------------------------
- self.vbox_pg2 = Gtk.VBox()
- self.vbox_pg2.set_spacing(2)
- #volumedetect ------------------------------------
- self.make_volume_det()
- # add volumedetect frame
- self.vbox_pg2.pack_start(self.f_volume_det['frame'], 1, 0, 0)
- #compand ---------------------------------------
- self.make_compand()
- # add frame
- self.vbox_pg2.pack_start(self.f_compand['frame'], 1, 0, 0)
- # black detect ----------------------------------
- self.make_black_detect()
- # add black_detect frame
- self.vbox_pg2.pack_start(self.f_blackd['frame'], 1, 0, 0)
- # info frame----------------------
- self.make_info_frame()
- # add info frame
- self.vbox_pg2.pack_start(self.f_info['frame'], 1, 0, 0)
- # end page2 stuff
- # page 3 stuff ffmpeg commands -----------------------------------------
- # page3 VBox -------------------------
- self.vbox_pg3 = Gtk.VBox()
- self.vbox_pg3.set_spacing(2)
- # audio codec -------------------
- self.make_audio_codec()
- #add frame audio codec
- self.vbox_pg3.pack_start(self.f_3acodec['frame'], 1, 0, 0)
- # video codec -------------------
- self.make_video_codec()
- #add frame video codec
- self.vbox_pg3.pack_start(self.f_3vcodec['frame'], 1, 0, 0)
- # other options ----------------
- self.make_other_opts()
- #add frame other options
- self.vbox_pg3.pack_start(self.f3_oth['frame'], 1, 0, 0)
- # page3 output ---------------------
- self.f3_out = self.make_frame_ag(3, " FFmpeg command " , 6, 8, 8, True)
- self.f3_out_label = Gtk.Label("")
- self.f3_out_label.set_width_chars(106)
- self.f3_out_label.set_max_width_chars(106)
- self.f3_out_label.set_line_wrap(True)
- self.f3_out['grid'].attach(self.f3_out_label, 0, 0, 1, 1)
- # add frame page3 output
- self.vbox_pg3.pack_start(self.f3_out['frame'], 1, 0, 0)
- # run ffmpeg ---------------------------------
- self.make_run_ffmpeg()
- # add frame run ffmpeg
- self.vbox_pg3.pack_start(self.f3_run['frame'], 1, 0, 0)
- #---------------------------------------------------
- # main vbox
- self.main_vbox = Gtk.VBox()
- # notebook
- self.notebook = Gtk.Notebook()
- self.notebook.set_tab_pos(0) #GTK_POS_LEFT
- self.notebook.set_show_border (False)
- self.main_vbox.pack_start(self.notebook, 1, 0, 0)
- #page 1
- self.tab1label = Gtk.Label("Video filters")
- self.page1_ali = Gtk.Alignment()
- self.page1_ali.set_padding(0, 6, 6, 6)
- self.page1_ali.add(self.vbox1)
- self.notebook.append_page(self.page1_ali, self.tab1label)
- #page 2
- self.tab2label = Gtk.Label("Utility")
- self.page2_ali = Gtk.Alignment()
- self.page2_ali.set_padding(0, 6, 6, 6)
- self.page2_ali.add(self.vbox_pg2)
- self.notebook.append_page(self.page2_ali, self.tab2label)
- #page 3
- self.tab3label = Gtk.Label("Encode")
- self.page3_ali = Gtk.Alignment()
- self.page3_ali.set_padding(0, 6, 6, 6)
- self.page3_ali.add(self.vbox_pg3)
- self.notebook.append_page(self.page3_ali, self.tab3label)
- #---------------------------------------------------
- # low part BUTTONS AND TERM --------------------------
- self.make_low_part()
- # add low part-----------------
- self.main_vbox.pack_start(self.gridterm, 1, 1, 0)
- #---------------------------------------------------------
- self.window.add (self.main_vbox)
- #---------------------------------
- self.window.show_all()
- def make_deinterlace(self):
- self.f_deint = self.make_frame_ag(3, "" , 6, 8, 8, True)
- self.checkdeint = Gtk.CheckButton("deinterlace")
- self.checkdeint.connect("toggled", self.on_deint_clicked)
- self.f_deint['grid'].attach(self.checkdeint, 0, 0, 1, 1)
- self.box_deint = self.make_combobox(
- "yadif",
- "postprocessing linear blend",
- "detect (use only with Test)"
- )
- self.f_deint['grid'].attach(self.box_deint['cbox'], 1, 0, 1, 1)
- self.box_deint['cbox'].connect("changed", self.on_deint_clicked)
- #
- self.f_deint['grid'].attach(self.make_label(""), 2, 0, 1, 1)
- def make_map(self):
- #
- self.f_map = self.make_frame_ag(3, "" , 6, 8, 8, True)
- #
- self.check_map = Gtk.CheckButton("map")
- self.check_map.connect("toggled", self.on_map_clicked) # toggled or activate (enter)
- self.f_map['grid'].attach(self.check_map, 0, 0, 1, 1)
- #
- self.mapstream_label = self.make_label("streams: ")
- self.f_map['grid'].attach(self.mapstream_label, 1, 0, 1, 1)
- #
- self.entry_map = Gtk.Entry()
- self.entry_map.set_tooltip_text(Tips.map_tooltip_str)
- self.entry_map.connect("changed", self.on_map_clicked)
- self.f_map['grid'].attach(self.entry_map, 2, 0, 1, 1)
- #
- self.map_label = Gtk.Label("")
- self.f_map['grid'].attach(self.map_label, 3, 0, 1, 1)
- # placeholder
- self.f_map['grid'].attach(self.make_label("Version: " + Vars.version + " "), 4, 0, 1, 1)
- def make_time_cut(self):
- #
- self.f_time = self.make_frame_ag(3, "" , 6, 8, 8, True)
- #
- self.check_time = Gtk.CheckButton("time")
- self.check_time.connect("toggled", self.on_time_clicked) # toggled or activate (enter)
- self.f_time['grid'].attach(self.check_time, 0, 0, 1, 1)
- #
- self.label_time_in = self.make_label("from: ")
- self.f_time['grid'].attach(self.label_time_in, 1, 0, 1, 1)
- self.entry_timein = Gtk.Entry()
- self.entry_timein.set_tooltip_text(Tips.time_tooltip_str)
- self.entry_timein.set_max_length(8)
- self.entry_timein.set_max_width_chars(8)
- self.entry_timein.set_width_chars(8)
- #self.entry_timein.set_halign(1)
- self.entry_timein.connect("changed", self.on_time_clicked)
- self.f_time['grid'].attach(self.entry_timein, 2, 0, 1, 1)
- self.label_time_out = self.make_label("to: ")
- self.f_time['grid'].attach(self.label_time_out, 3, 0, 1, 1)
- self.entry_timeout = Gtk.Entry()
- self.entry_timeout.set_tooltip_text(Tips.time_tooltip_str)
- self.entry_timeout.set_max_length(8)
- self.entry_timeout.set_max_width_chars(8)
- self.entry_timeout.set_width_chars(8)
- self.entry_timeout.connect("changed", self.on_time_clicked)
- self.f_time['grid'].attach(self.entry_timeout, 4, 0, 1, 1)
- self.time_label = Gtk.Label('')
- self.f_time['grid'].attach(self.time_label, 5, 0, 2, 1)
- def make_scale(self):
- self.frame_scale = self.make_frame_ag(3, ' scale ' , 6, 8, 8, True)
- # ------------------------------
- self.box1 = self.make_combobox(
- "None",
- "W",
- "H"
- )
- self.frame_scale['grid'].attach(self.box1['cbox'], 0, 0, 1, 1)
- self.box1['cbox'].connect("changed", self.on_scale_clicked)
- #------------------------------------
- self.box2 = self.make_combobox(
- "16/9",
- "4/3"
- )
- self.frame_scale['grid'].attach(self.box2['cbox'], 0, 1, 1, 1)
- self.box2['cbox'].connect("changed", self.on_scale_clicked)
- #-----------------------------------------
- self.size_spinner = self.make_slider_and_spinner(720, 200, 2000, 8, 32, 0)
- self.frame_scale['grid'].attach(self.size_spinner['slider'], 1, 0, 1, 1)
- self.frame_scale['grid'].attach(self.size_spinner['spinner'], 2, 0, 1, 1)
- #self.size_spinner['slider'].set_size_request(150,-1)
- self.size_spinner['adj'].set_value(720.001) #mettere decimali se no non si vede
- self.size_spinner['adj'].connect("value-changed", self.on_scale_clicked)
- #-------------------------------------------------------
- self.check = Gtk.CheckButton("lanczos")
- self.check.connect("toggled", self.on_scale_clicked)
- self.frame_scale['grid'].attach(self.check, 2, 1, 1, 1)
- def make_crop(self):
- self.frame_crop = self.make_frame_ag(3, '' , 6, 2, 0, True)
- # -------
- self.checkcr = Gtk.CheckButton("crop")
- self.checkcr.connect("toggled", self.on_crop_clicked)
- self.frame_crop['grid'].attach(self.checkcr, 0, 0, 1, 1)
- #----------
- self.butcrode = Gtk.Button(label="Crop detect")
- self.butcrode.connect("clicked", self.on_butcrode_clicked)
- self.butcrode.set_sensitive(False)
- self.frame_crop['grid'].attach(self.butcrode, 0, 1, 1, 1)
- #-----------
- self.labelcropinw = self.make_label("input W: ")
- self.frame_crop['grid'].attach(self.labelcropinw, 1, 0, 1, 1)
- self.labelcropinh = self.make_label("input H: ")
- self.frame_crop['grid'].attach(self.labelcropinh, 1, 1, 1, 1)
- #
- self.spincw = self.make_spinbut(640 , 100 , 1920 , 10 , 1 , 0, True )
- self.spincw["adj"].connect("value-changed", self.on_crop_clicked)
- self.frame_crop['grid'].attach(self.spincw["spinner"], 2, 0, 1, 1)
- #
- self.spinch = self.make_spinbut(480 , 100 , 1280 , 10 , 1 , 0, True )
- self.spinch["adj"].connect("value-changed", self.on_crop_clicked)
- self.frame_crop['grid'].attach(self.spinch["spinner"], 2, 1, 1, 1)
- #
- self.labelcroptop = self.make_label("crop Top: ")
- self.frame_crop['grid'].attach(self.labelcroptop, 3, 0, 1, 1)
- self.labelcropbot = self.make_label("crop Bottom: ")
- self.frame_crop['grid'].attach(self.labelcropbot, 3, 1, 1, 1)
- #
- self.spinct = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
- self.spinct["adj"].connect("value-changed", self.on_crop_clicked)
- self.frame_crop['grid'].attach(self.spinct["spinner"], 4, 0, 1, 1)
- #
- self.spincb = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
- self.spincb["adj"].connect("value-changed", self.on_crop_clicked)
- self.frame_crop['grid'].attach(self.spincb["spinner"], 4, 1, 1, 1)
- #
- self.labelcroplef = self.make_label("crop Left: ")
- self.frame_crop['grid'].attach(self.labelcroplef, 5, 0, 1, 1)
- self.labelcroprig = self.make_label("crop Right: ")
- self.frame_crop['grid'].attach(self.labelcroprig, 5, 1, 1, 1)
- #
- self.spincl = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
- self.spincl["adj"].connect("value-changed", self.on_crop_clicked)
- self.frame_crop['grid'].attach(self.spincl["spinner"], 6, 0, 1, 1)
- #
- self.spincr = self.make_spinbut(0 , 0 , 600 , 1 , 10 , 0, True )
- self.spincr["adj"].connect("value-changed", self.on_crop_clicked)
- self.frame_crop['grid'].attach(self.spincr["spinner"], 6, 1, 1, 1)
- def make_denoise(self):
- self.frame_dn = self.make_frame_ag(3, ' denoise / unsharp luma chroma / frame rate ' , 6, 8, 8, True)
- # denoise ----------------------
- self.checkdn = Gtk.CheckButton("hqdn3d:")
- self.checkdn.set_alignment(1.0, 0.5)
- self.checkdn.set_halign(2)
- self.checkdn.connect("toggled", self.on_dn_clicked)
- self.frame_dn['grid'].attach(self.checkdn, 0, 0, 1, 1)
- #
- self.spindn = self.make_spinbut(4 , 2 , 8 , 1 , 10 , 0, True )
- self.spindn["adj"].connect("value-changed", self.on_dn_clicked)
- #self.spindn['spinner'].set_max_length(1)
- #self.spindn['spinner'].set_width_chars(1)
- self.frame_dn['grid'].attach(self.spindn["spinner"], 1, 0, 1, 1)
- # -----------------------
- # unsharp unsharp=5:5:luma:5:5:chroma, luma chroma -1.5 to 1.5
- self.checkuns = Gtk.CheckButton("unsharp l/c:")
- self.checkuns.set_alignment(1.0, 0.5)
- self.checkuns.set_halign(2)
- self.checkuns.connect("toggled", self.on_uns_clicked)
- self.frame_dn['grid'].attach(self.checkuns, 2, 0, 1, 1)
- self.spinunsl = self.make_spinbut(0.0 , -1.5 , 1.5 , .1 , .01 , 2, True )
- self.spinunsl["adj"].connect("value-changed", self.on_uns_clicked)
- self.frame_dn['grid'].attach(self.spinunsl["spinner"], 3, 0, 1, 1)
- self.spinunsc = self.make_spinbut(0.0 , -1.5 , 1.5 , .1 , .01 , 2, True )
- self.spinunsc["adj"].connect("value-changed", self.on_uns_clicked)
- self.frame_dn['grid'].attach(self.spinunsc["spinner"], 4, 0, 1, 1)
- # framerate --------------------------
- self.checkfr = Gtk.CheckButton("frame rate:")
- self.checkfr.set_alignment(1.0, 0.5)
- self.checkfr.set_halign(2)
- self.checkfr.connect("toggled", self.on_fr_clicked)
- self.frame_dn['grid'].attach(self.checkfr, 5, 0, 1, 1)
- self.spinfr = self.make_spinbut(0 , 0 , 100 , 1 , 10 , 2, True )
- self.spinfr["adj"].connect("value-changed", self.on_fr_clicked)
- self.frame_dn['grid'].attach(self.spinfr["spinner"], 6, 0, 1, 1)
- def make_low_part(self):
- # grid
- self.gridterm = Gtk.Grid()
- self.gridterm.set_row_spacing(2)
- self.gridterm.set_column_spacing(2)
- self.gridterm.set_column_homogeneous(True) # True
- # filechooserbutton
- self.filechooserbutton = Gtk.FileChooserButton(title="FileChooserButton")
- #
- #self.filechooserbutton.set_action(2) # 0 open file, 1 save file, 2 select folder, 3 create folder
- #
- self.filechooserbutton.connect("file-set", self.file_changed)
- # filter
- self.filter = Gtk.FileFilter()
- self.filter.set_name("Video")
- self.filter.add_mime_type("video/x-matroska")
- self.filter.add_mime_type("video/mp4")
- self.filter.add_mime_type("video/x-flv")
- self.filter.add_mime_type("video/avi")
- self.filter.add_mime_type("video/mpg")
- self.filter.add_mime_type("video/mpeg")
- self.filter.add_mime_type("video/x-ms-wmv")
- self.filter.add_mime_type("video/webm")
- self.filter.add_mime_type("video/ogg")
- self.filter.add_mime_type("video/quicktime")
- self.filechooserbutton.add_filter(self.filter)
- # terminal
- self.terminal = Vte.Terminal()
- self.terminal.fork_command_full(
- Vte.PtyFlags.DEFAULT, #default is fine
- os.getcwd(), #where to start the command? os.environ['HOME']
- ["/bin/sh"], #where is the emulator?
- [], #it's ok to leave this list empty
- GLib.SpawnFlags.DO_NOT_REAP_CHILD,
- None, #at least None is required
- None,
- )
- self.scroller = Gtk.ScrolledWindow()
- self.scroller.set_hexpand(True)
- self.scroller.set_vexpand(True)
- self.scroller.add(self.terminal)
- self.scroller.set_min_content_height(90)
- #ff command button
- self.butplay = Gtk.Button(label="FFplay")
- self.butplay.connect("clicked", self.on_butplay_clicked)
- self.butplay.set_sensitive(False)
- self.butprobe = Gtk.Button(label="FFprobe")
- self.butprobe.connect("clicked", self.on_butprobe_clicked)
- self.butprobe.set_sensitive(False)
- self.buttest = Gtk.Button(label="Test")
- self.buttest.connect("clicked", self.on_buttest_clicked)
- self.buttest.set_sensitive(False)
- self.buttestspl = Gtk.Button(label="Test split")
- self.buttestspl.connect("clicked", self.on_buttestspl_clicked)
- self.buttestspl.set_sensitive(False)
- self.gridterm.attach(self.filechooserbutton, 0, 0, 2, 1)
- self.gridterm.attach(self.butprobe, 2, 0, 1, 1)
- self.gridterm.attach(self.butplay, 3, 0, 1, 1)
- self.gridterm.attach(self.buttest, 4, 0, 1, 1)
- self.gridterm.attach(self.buttestspl, 5, 0, 1, 1)
- self.gridterm.attach(self.scroller, 0, 1, 6, 1)
- def make_volume_det(self):
- self.f_volume_det = self.make_frame_ag(3, "" , 6, 8, 8, True)
- #
- self.but_volume_det = Gtk.Button(label="Volume detect")
- self.but_volume_det.connect("clicked", self.on_but_volume_det_clicked)
- self.f_volume_det['grid'].attach(self.but_volume_det, 0, 0, 1, 1)
- self.but_volume_det.set_sensitive(False)
- #
- self.voldet_spin = Gtk.Spinner()
- self.voldet_spin.set_sensitive(False)
- self.f_volume_det['grid'].attach(self.voldet_spin, 1, 0, 1, 1)
- #
- self.label_maxvol = Gtk.Label("")
- self.f_volume_det['grid'].attach(self.label_maxvol, 2, 0, 1, 1)
- self.label_meanvol = Gtk.Label("")
- self.f_volume_det['grid'].attach(self.label_meanvol, 3, 0, 1, 1)
- #
- self.check_vol = Gtk.CheckButton("volume")
- self.check_vol.connect("toggled", self.on_volume_clicked)
- self.f_volume_det['grid'].attach(self.check_vol, 0, 1, 1, 1)
- #
- self.label_db = self.make_label("dB: ")
- self.f_volume_det['grid'].attach(self.label_db, 1, 1, 1, 1)
- self.spin_db = self.make_spinbut(0 , -6 , 20 , 0.1 , 1 , 2, True )
- self.spin_db["adj"].connect("value-changed", self.on_volume_clicked)
- self.f_volume_det['grid'].attach(self.spin_db["spinner"], 2, 1, 1, 1)
- self.label_ratio = self.make_label("ratio: ")
- self.f_volume_det['grid'].attach(self.label_ratio, 3, 1, 1, 1)
- self.label_ratio_val = Gtk.Label("1")
- self.f_volume_det['grid'].attach(self.label_ratio_val, 4, 1, 1, 1)
- def make_compand(self):
- #
- self.f_compand = self.make_frame_ag(3, "" , 6, 8, 8, True)
- #
- self.check_compand = Gtk.CheckButton("compand")
- self.check_compand.connect("toggled", self.on_compand_clicked)
- self.f_compand['grid'].attach(self.check_compand, 0, 0, 1, 1)
- #
- self.entry_compand = Gtk.Entry()
- self.entry_compand.set_text(Vars.compinit)
- self.entry_compand.connect("changed", self.on_compand_clicked)
- self.entry_compand.set_tooltip_text(Tips.compad_str)
- self.f_compand['grid'].attach(self.entry_compand, 1, 0, 2, 1)
- #
- self.compand_reset = Gtk.Button(label="reset")
- self.compand_reset.connect("clicked", self.on_compand_reset)
- self.f_compand['grid'].attach(self.compand_reset, 3, 0, 1, 1)
- self.compand_test = Gtk.Button(label="test ebur128")
- self.compand_test.set_sensitive(False)
- self.compand_test.connect("clicked", self.on_compand_test)
- self.f_compand['grid'].attach(self.compand_test, 0, 1, 1, 1)
- self.label_comp_from = self.make_label("from: ")
- self.f_compand['grid'].attach(self.label_comp_from, 1, 1, 1, 1)
- #
- self.entry_timecomp = Gtk.Entry()
- self.entry_timecomp.set_tooltip_text(Tips.time_tooltip_str)
- self.entry_timecomp.set_max_length(8)
- self.entry_timecomp.set_max_width_chars(8)
- self.entry_timecomp.set_width_chars(8)
- self.entry_timecomp.connect("changed", self.on_compand_clicked)
- self.f_compand['grid'].attach(self.entry_timecomp, 2, 1, 1, 1)
- #placeholder
- self.f_compand['grid'].attach(Gtk.Label(''), 3, 1, 1, 1)
- def make_black_detect(self):
- self.f_blackd = self.make_frame_ag(3, "" , 6, 8, 8, True)
- #
- self.but_black_det = Gtk.Button(label="Black detect")
- self.but_black_det.connect("clicked", self.on_but_black_det_clicked)
- self.but_black_det.set_sensitive(False)
- self.f_blackd['grid'].attach(self.but_black_det, 0, 0, 1, 1)
- #
- self.blackdet_spin = Gtk.Spinner()
- self.blackdet_spin.set_sensitive(False)
- self.f_blackd['grid'].attach(self.blackdet_spin, 1, 0, 1, 1)
- #
- scrolledwindow = Gtk.ScrolledWindow()
- #scrolledwindow.set_hexpand(True)
- scrolledwindow.set_vexpand(True)
- self.textview = Gtk.TextView()
- self.textbuffer = self.textview.get_buffer()
- self.textview.set_editable(False)
- self.textview.set_cursor_visible(False)
- self.textview.modify_font(Pango.font_description_from_string('Monospace 9'))
- scrolledwindow.add(self.textview)
- self.textbuffer.set_text(Tips.black_dt_init_str)
- self.f_blackd['grid'].attach(scrolledwindow, 2, 0, 3, 3)
- #
- self.progressbar_black_det = Gtk.ProgressBar()
- self.f_blackd['grid'].attach(self.progressbar_black_det, 0, 1, 1, 1)
- def make_info_frame(self):
- self.f_info = self.make_frame_ag(3, " info " , 6, 8, 8, True)
- scrolledwindow1 = Gtk.ScrolledWindow()
- scrolledwindow1.set_hexpand(True)
- scrolledwindow1.set_vexpand(True)
- self.textview_info = Gtk.TextView()
- self.textbuffer_info = self.textview_info.get_buffer()
- self.textview_info.set_editable(False)
- self.textview_info.set_cursor_visible(False)
- self.textview_info.modify_font(Pango.font_description_from_string('Monospace 9'))
- scrolledwindow1.add(self.textview_info)
- self.f_info['grid'].attach(scrolledwindow1, 0, 0, 3, 3)
- def make_audio_codec(self):
- #
- self.f_3acodec = self.make_frame_ag(3, " audio codec " , 6, 8, 8, True)
- #
- self.box_ac = self.make_combobox(
- "libfaac quality (Q)",
- "aacplus (64 Kb/s)",
- "aacplus (32 Kb/s)",
- "no audio",
- "audio copy",
- "aac_fdk CBR (Kb/s)",
- "lame mp3 CBR (Kb/s)",
- "lame mp3 VBR (Q)",
- "aac native CBR (Kb/s)"
- )
- self.f_3acodec['grid'].attach(self.box_ac['cbox'], 0, 0, 1, 1)
- self.box_ac['cbox'].connect("changed", self.on_codec_audio_changed)
- #
- self.spin_ac = self.make_spinbut(100 , 80 , 160 , 10 , 1 , 0, True )
- self.spin_ac["adj"].connect("value-changed", self.on_codec_clicked)
- self.f_3acodec['grid'].attach(self.spin_ac["spinner"], 1, 0, 1, 1)
- self.spin_ac['spinner'].set_tooltip_text(Tips.faac_q_str)
- #
- self.box_audio_rate = self.make_combobox(
- "48000",
- "44100"
- )
- self.box_audio_rate['cbox'].set_tooltip_text(Tips.audio_samp_str)
- self.box_audio_rate['cbox'].connect("changed", self.on_codec_audio_changed)
- self.f_3acodec['grid'].attach(self.box_audio_rate['cbox'], 2, 0, 1, 1)
- #
- self.box_audio_ch = self.make_combobox(
- "2",
- "1"
- )
- self.box_audio_ch['cbox'].set_tooltip_text(Tips.audio_channels_str)
- self.box_audio_ch['cbox'].connect("changed", self.on_codec_audio_changed)
- self.f_3acodec['grid'].attach(self.box_audio_ch['cbox'], 3, 0, 1, 1)
- def make_video_codec(self):
- self.f_3vcodec = self.make_frame_ag(3, " video codec " , 6, 8, 8, True)
- self.box_vcodec = self.make_combobox(
- "libx264",
- "video copy",
- "mpeg4"
- )
- self.f_3vcodec['grid'].attach(self.box_vcodec['cbox'], 0, 0, 1, 1)
- self.box_vcodec['cbox'].connect("changed", self.on_codec_video_changed)
- #
- self.box_vrc = self.make_combobox(
- "crf",
- "bitrate kb/s"
- )
- self.f_3vcodec['grid'].attach(self.box_vrc['cbox'], 1, 0, 1, 1)
- self.box_vrc['cbox'].connect("changed", self.on_codec_vrc_changed)
- #
- self.spin_vc = self.make_spinbut(21.3 , 15 , 40 , 0.1 , 1 , 1, True )
- self.spin_vc["adj"].connect("value-changed", self.on_codec_vrc_value_change)
- self.f_3vcodec['grid'].attach(self.spin_vc["spinner"], 2, 0, 1, 1)
- #
- self.f3v_label_out = Gtk.Label("")
- self.f_3vcodec['grid'].attach(self.f3v_label_out, 3, 0, 2, 1)
- # x264 preset
- self.box_3v_preset = self.make_combobox(
- "superfast",
- "veryfast",
- "faster",
- "fast",
- "medium",
- "slow"
- ) #(-superfast -veryfast -fast, -medium, -slow, default: faster)
- self.box_3v_preset['cbox'].set_active(2)
- self.box_3v_preset['cbox'].set_tooltip_text(Tips.preset_tooltip_str)
- self.f_3vcodec['grid'].attach(self.box_3v_preset['cbox'], 0, 1, 1, 1)
- self.box_3v_preset['cbox'].connect("changed", self.on_preset_changed)
- # x264 tune
- self.box_3v_tune = self.make_combobox(
- "film",
- "animation",
- "grain",
- "stillimage"
- ) # film,animation,grain,stillimage
- self.box_3v_tune['cbox'].set_active(0)
- self.box_3v_tune['cbox'].set_tooltip_text(Tips.tune_tooltip_str)
- self.f_3vcodec['grid'].attach(self.box_3v_tune['cbox'], 1, 1, 1, 1)
- self.box_3v_tune['cbox'].connect("changed", self.on_preset_changed)
- # x264 opts
- self.box_3v_x264opts = self.make_combobox(
- "x264opts 1",
- "no opts (ssim)"
- )
- self.box_3v_x264opts['cbox'].set_active(0)
- self.f_3vcodec['grid'].attach(self.box_3v_x264opts['cbox'], 2, 1, 1, 1)
- self.box_3v_x264opts['cbox'].connect("changed", self.on_codec_clicked)
- # opencl
- self.check_3v_opencl = Gtk.CheckButton("opencl")
- self.check_3v_opencl.connect("toggled", self.on_codec_clicked)
- self.f_3vcodec['grid'].attach(self.check_3v_opencl, 3, 1, 1, 1)
- def make_other_opts(self):
- #
- self.f3_oth = self.make_frame_ag(3, " other options " , 6, 8, 8, True)
- #
- self.check_2pass = Gtk.CheckButton("2 pass")
- self.check_2pass.connect("toggled", self.on_f3_other_clicked)
- self.f3_oth['grid'].attach(self.check_2pass, 0, 0, 1, 1)
- self.check_2pass.set_sensitive(False)
- #
- self.check_nometa = Gtk.CheckButton("no metatag")
- self.check_nometa.connect("toggled", self.on_f3_other_clicked)
- self.check_nometa.set_tooltip_text(Tips.nometa_tooltip_srt)
- self.f3_oth['grid'].attach(self.check_nometa, 1, 0, 1, 1)
- #
- #
- self.check_scopy = Gtk.CheckButton("sub copy")
- self.check_scopy.connect("toggled", self.on_f3_other_clicked)
- self.check_scopy.set_tooltip_text(Tips.subcopy_tooltip_srt)
- self.f3_oth['grid'].attach(self.check_scopy, 2, 0, 1, 1)
- #
- self.check_cpu = Gtk.CheckButton("cpu 3")
- self.check_cpu.connect("toggled", self.on_f3_other_clicked)
- self.check_cpu.set_tooltip_text(Tips.cpu_tooltip_srt)
- self.f3_oth['grid'].attach(self.check_cpu, 3, 0, 1, 1)
- #
- self.check_debug = Gtk.CheckButton("debug")
- self.check_debug.connect("toggled", self.on_f3_other_clicked)
- self.check_debug.set_tooltip_text(Tips.debug_tooltip_srt)
- self.f3_oth['grid'].attach(self.check_debug, 4, 0, 1, 1)
- #
- self.box_oth_container = self.make_combobox(
- "MKV",
- "MP4",
- "AVI"
- )
- self.f3_oth['grid'].attach(self.box_oth_container['cbox'], 5, 0, 1, 1)
- self.box_oth_container['cbox'].connect("changed", self.on_container_changed)
- def make_run_ffmpeg(self):
- self.f3_run = self.make_frame_ag(3, " execute in terminal " , 6, 8, 8, True)
- #
- self.f3_run_indir_label = Gtk.Label("")
- self.f3_run['grid'].attach(self.f3_run_indir_label, 0, 0, 1, 1)
- self.f3_run_file = Gtk.Label("no input file")
- self.f3_run_file.set_tooltip_text('')
- self.f3_run['grid'].attach(self.f3_run_file, 1, 0, 2, 1)
- self.f3_dur_file = Gtk.Label("")
- self.f3_run['grid'].attach(self.f3_dur_file, 3, 0, 1, 1)
- #
- self.but_f3_run = Gtk.Button(label="RUN")
- self.but_f3_run.connect("clicked", self.on_but_f3_run_clicked)
- self.but_f3_run.set_sensitive(False)
- self.f3_run['grid'].attach(self.but_f3_run, 3, 1, 1, 1)
- #
- #self.f3_run_outdir_label = Gtk.Label("out dir: " + os.getcwd())
- self.f3_run_outdir_label = Gtk.Label("")
- self.f3_run_outdir_label.set_markup("<b>out dir: </b>" + os.getcwd())
- self.f3_run['grid'].attach(self.f3_run_outdir_label, 0, 1, 2, 1)
- #
- # filechooserbutton
- self.out_dir_chooserbut = Gtk.FileChooserButton(title="Dir out")
- self.out_dir_chooserbut.set_action(2)
- #self.filechooserbutton.set_action(2) # 0 open file, 1 save file, 2 select folder, 3 create folder
- acturi = "file://" + os.getcwd()
- self.out_dir_chooserbut.set_uri(acturi)
- self.f3_run['grid'].attach(self.out_dir_chooserbut, 2, 1, 1, 1)
- self.out_dir_chooserbut.connect("selection-changed", self.dir_changed)
- #
- self.reportdata = Gtk.Label('')
- self.f3_run['grid'].attach(self.reportdata, 0, 3, 4, 1)
- # event handlers -----------------------------------------------
- def on_window_destroy(self, *args):
- Gtk.main_quit(*args)
- def on_scale_clicked(self, button):
- if (self.box1['cbox'].get_active() != 0):
- self.calcola_scale()
- else:
- Vars.scalestr = ""
- self.outfilter()
- def on_deint_clicked(self, button):
- Vars.deint_str = ""
- if self.checkdeint.get_active():
- deint_val = self.box_deint['cbox'].get_active()
- if (deint_val == 0):
- Vars.deint_str = "yadif"
- elif (deint_val == 1):
- Vars.deint_str = "pp=lb"
- elif (deint_val == 2):
- Vars.deint_str = "idet"
- self.outfilter()
- def on_dn_clicked(self, button):
- Vars.dn_str = ""
- if self.checkdn.get_active():
- dn_val = int( self.spindn['adj'].get_value() )
- Vars.dn_str = "hqdn3d=" + str(dn_val)
- self.outfilter()
- def on_uns_clicked(self, button):
- Vars.uns_str = ""
- if self.checkuns.get_active():
- luma = self.spinunsl['adj'].get_value()
- chroma = self.spinunsc['adj'].get_value()
- Vars.uns_str = "unsharp=5:5:" + "{0:0.2f}".format(luma) + ":5:5:" + "{0:0.2f}".format(chroma)
- self.outfilter()
- def on_fr_clicked(self, button):
- Vars.fr_str = ""
- if self.checkfr.get_active():
- fr_val = self.spinfr['adj'].get_value()
- Vars.fr_str = "-r " + "{0:0.2f}".format(fr_val)
- self.outfilter()
- def on_crop_clicked(self, button):
- ok = 0
- Vars.crop_str = ""
- if self.checkcr.get_active():
- ok = 1
- if ok:
- inW = int(self.spincw['adj'].get_value())
- inH = int(self.spinch['adj'].get_value())
- crT = int(self.spinct['adj'].get_value())
- crB = int(self.spincb['adj'].get_value())
- crL = int(self.spincl['adj'].get_value())
- crR = int(self.spincr['adj'].get_value())
- finW = inW - crL - crR
- finH = inH - crT - crB
- if ( (finW < 100) or (finH < 100) ):
- Vars.crop_str = ""
- else:
- Vars.crop_str = "crop=" + str(finW) + ":" \
- + str(finH) + ":" \
- + str(crL) + ":" \
- + str(crT)
- if (self.box2['cbox'].get_active() != 2):
- self.outfilter()
- else:
- self.on_scale_clicked(button)
- def file_changed(self, filechooserbutton):
- if Vars.ENCODING:
- return
- if self.filechooserbutton.get_filename():
- self.butplay.set_sensitive(True) # low part ---------
- self.butprobe.set_sensitive(True)
- self.preview_logic() # test and testsplit
- self.butcrode.set_sensitive(True) # crop ----------
- self.spinct['adj'].set_value(0)
- self.spincb['adj'].set_value(0)
- self.spincl['adj'].set_value(0)
- self.spincr['adj'].set_value(0)
- self.but_volume_det.set_sensitive(True) # volume detect
- Vars.VOLDT_DONE = False
- self.but_volume_det.set_label("Volume detect")
- self.label_meanvol.set_label("")
- self.label_maxvol.set_label("")
- self.spin_db["adj"].set_value(0)
- self.compand_test.set_sensitive(True) #compand test
- self.but_black_det.set_sensitive(True) # black detect
- self.but_black_det.set_label("Black detect")
- self.textbuffer.set_text(Tips.black_dt_init_str)
- self.progressbar_black_det.set_fraction(0.0)
- self.but_f3_run.set_sensitive(True) # ffmpeg run
- Vars.BLACKDT_DONE = False
- #
- command = "clear" + "\n"
- length = len(command)
- self.terminal.feed_child(command, length)
- # need ffprobe
- Vars.filename = self.filechooserbutton.get_filename()
- Vars.dirname = os.path.dirname(Vars.filename)
- Vars.basename = os.path.basename(Vars.filename)
- self.check_out_file()
- self.f3_run_indir_label.set_label(Vars.dirname)
- file_4_label = (Vars.basename)
- if ( len(file_4_label) > 50):
- a = file_4_label[:46]
- b = ' ... '
- c = file_4_label[-4:]
- file_4_label = a + b + c
- self.f3_run_file.set_label(file_4_label)
- self.but_f3_run.set_tooltip_text("")
- self.reportdata.set_text("")
- command = [Vars.ffprobe_ex, '-show_format', '-show_streams', '-pretty', '-loglevel', 'quiet', Vars.filename]
- p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = p.communicate()
- out = out.decode() # python3
- self.get_info(out)
- def get_info(self, out):
- def form_to_3(in_str):
- '''
- bitrate and size info formatting
- '''
- a = in_str.split(' ')[0]
- if len(in_str.split(' ')) == 2:
- b = in_str.split(' ')[1]
- a = float(a)
- result = "{0:.3f}".format(a ) + " " + b
- else:
- result = 'N/A'
- return result
- def set_w_h_video_scale():
- self.spincw['adj'].set_value(float(Vars.video_width)) #mettere decimali se no non si vede
- self.spincw['spinner'].set_sensitive(False)
- self.spinch['adj'].set_value(float(Vars.video_height)) #mettere decimali se no non si vede
- self.spinch['spinner'].set_sensitive(False)
- if Vars.add_1_1_dar:
- self.box2['list'].append(["as input"])
- Vars.add_1_1_dar = False
- #x Vars.info_str
- Vars.info_str = ""
- is_stream = 0
- is_format = 0
- for line in out.split('\n'):
- line = line.strip()
- if line.startswith('[STREAM]'):
- Vars.info_str = Vars.info_str + "STREAM "
- is_stream = 1
- elif line.startswith('[/STREAM]'):
- Vars.info_str = Vars.info_str + "\n"
- is_stream = 0
- elif (line.startswith('index=') and (is_stream == 1)):
- s = line
- info = s.split('=')[1]
- Vars.info_str = Vars.info_str + info + ": "
- elif (line.startswith('codec_name=') and (is_stream == 1)):
- s = line
- info = s.split('=')[1]
- Vars.info_str = Vars.info_str + info + ", "
- elif (line.startswith('profile=') and (is_stream == 1)):
- s = line
- info = s.split('=')[1]
- Vars.info_str = Vars.info_str + "profile=" +info + ", "
- elif (line.startswith('codec_type=') and (is_stream == 1)):
- s = line
- info = s.split('=')[1]
- Vars.info_str = Vars.info_str + info + ", "
- elif (line.startswith('width=') and (is_stream == 1)):
- s = line
- info = s.split('=')[1]
- Vars.video_width = info
- Vars.info_str = Vars.info_str + info + "x"
- elif (line.startswith('height=') and (is_stream == 1)):
- s = line
- info = s.split('=')[1]
- Vars.video_height = info
- Vars.info_str = Vars.info_str + info + ", "
- elif (line.startswith('sample_aspect_ratio=') and (is_stream == 1)):
- s = line
- info = s.split('=')[1]
- Vars.info_str = Vars.info_str + "SAR=" + info + ", "
- elif (line.startswith('display_aspect_ratio=') and (is_stream == 1)):
- s = line
- info = s.split('=')[1]
- Vars.info_str = Vars.info_str + "DAR=" + info + ", "
- elif (line.startswith('pix_fmt=') and (is_stream == 1)):
- s = line
- info = s.split('=')[1]
- Vars.info_str = Vars.info_str + info + ", "
- elif (line.startswith('sample_rate=') and (is_stream == 1)):
- s = line
- info = s.split('=')[1]
- info = form_to_3(info)
- Vars.info_str = Vars.info_str + "samplerate=" + info + ", "
- elif (line.startswith('channels=') and (is_stream == 1)):
- s = line
- info = s.split('=')[1]
- Vars.audio_channels = int(info)
- Vars.info_str = Vars.info_str + "channels=" + info + ", "
- elif (line.startswith('r_frame_rate=') and (is_stream == 1)):
- s = line
- info = s.split('=')[1]
- a = info.split('/')[0]
- b = info.split('/')[1]
- a = float(a)
- b = float(b)
- if ((a > 0) and (b > 0)):
- c = float(a)/float(b)
- info = "{0:0.2f}".format(c)
- self.spinfr["adj"].set_value(c)
- Vars.info_str = Vars.info_str + info + " fps, "
- elif (line.startswith('bit_rate=') and (is_stream == 1)):
- s = line
- info = s.split('=')[1]
- info = form_to_3(info)
- Vars.info_str = Vars.info_str + "bitrate=" + info + ", "
- elif (line.startswith('TAG:language=') and (is_stream == 1)):
- s = line
- info = s.split('=')[1]
- Vars.info_str = Vars.info_str + "lang=" + info + ", "
- elif line.startswith('[FORMAT]'):
- Vars.info_str = Vars.info_str + "FORMAT "
- is_format = 1
- elif line.startswith('[/FORMAT]'):
- #Vars.info_str = Vars.info_str + "/n"
- is_format = 0
- elif (line.startswith('nb_streams=') and (is_format == 1)):
- s = line
- info = s.split('=')[1]
- Vars.info_str = Vars.info_str + "streams=" + info + ", "
- elif (line.startswith('duration=') and (is_format == 1)):
- s = line
- info = s.split('=')[1]
- info = info.split('.')[0]
- self.entry_timein.set_text('0')
- self.entry_timeout.set_text(info)
- Vars.duration = info
- Vars.duration_in_sec = self.hms2sec(info)
- Vars.info_str = Vars.info_str + "duration=" + info + ", "
- elif (line.startswith('size=') and (is_format == 1)):
- s = line
- info = s.split('=')[1]
- info = form_to_3(info)
- Vars.info_str = Vars.info_str + "size=" + info + ", "
- elif (line.startswith('bit_rate=') and (is_format == 1)):
- s = line
- info = s.split('=')[1]
- info = form_to_3(info)
- Vars.info_str = Vars.info_str + "bitrate=" + info + ", "
- set_w_h_video_scale()
- self.f3_dur_file.set_label(Vars.duration)
- self.textbuffer_info.set_text(Vars.info_str)
- self.f3_run_file.set_tooltip_text(Vars.info_str)
- self.check_map.set_tooltip_text(Vars.info_str)
- self.check_time.set_tooltip_text(Vars.info_str)
- Vars.in_file_size = self.humansize(Vars.filename)
- def on_butplay_clicked(self, button):
- if Vars.ENCODING:
- return
- command = Vars.ffplay_ex + " \"" + Vars.filename + "\"" +"\n"
- length = len(command)
- self.terminal.feed_child(command, length)
- def on_butprobe_clicked(self, button):
- if Vars.ENCODING:
- return
- command = Vars.ffprobe_ex + " \"" + Vars.filename + "\"" + " 2>&1 | grep 'Input\|Duration\|Stream'" + "\n"
- length = len(command)
- self.terminal.feed_child(command, length)
- def on_butcrode_clicked(self, button):
- # need ffmpeg
- self.butcrode.set_sensitive(False)
- if (Vars.time_start == 0):
- command = Vars.ffmpeg_ex + " -i " + "\"" + Vars.filename + "\"" + " -ss 60 -t 1 -vf cropdetect -f null - 2>&1 | awk \'/crop/ { print $NF }\' | tail -1"
- else:
- command = Vars.ffmpeg_ex + " -i " + "\"" + Vars.filename + "\"" + " -ss " + str(Vars.time_start) + " -t 1 -vf cropdetect -f null - 2>&1 | awk \'/crop/ { print $NF }\' | tail -1"
- p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
- out, err = p.communicate()
- out = out.decode()
- for line in out.split('\n'):
- line = line.strip()
- if "crop=" in line:
- aa = line.split('crop=', 1)
- aaa = aa[1]
- listdata = aaa.split(':')
- w = listdata[0]
- h = listdata[1]
- offx = listdata[2]
- offy = listdata[3]
- ctop = int(offy)
- cbot = int(Vars.video_height) - int(offy) -int(h)
- cleft = int(offx)
- cright = int(Vars.video_width) - int(offx) -int(w)
- self.spinct['adj'].set_value(float(ctop))
- self.spincb['adj'].set_value(float(cbot))
- self.spincl['adj'].set_value(float(cleft))
- self.spincr['adj'].set_value(float(cright))
- break
- self.butcrode.set_sensitive(True)
- def on_buttest_clicked(self, button):
- if Vars.ENCODING:
- return
- # -map preview: only with none -vf option
- if (Vars.maps_str == ""):
- command = Vars.ffplay_ex + " \"" + Vars.filename + "\" " \
- + " " + Vars.time_final_str + " " \
- + "-vf " + Vars.filter_test_str + "\n"
- else:
- command = Vars.ffmpeg_ex + " -i \"" + Vars.filename + "\" " \
- + Vars.maps_str + " " + Vars.time_final_str + " "
- if (Vars.filter_test_str != ""):
- command = command + " -vf " + Vars.filter_test_str
- command = command + " -c copy -f matroska - | ffplay -" + "\n"
- length = len(command)
- self.terminal.feed_child(command, length)
- def on_buttestspl_clicked(self, button):
- if Vars.ENCODING:
- return
- command = Vars.ffplay_ex + " \"" + Vars.filename + "\" " \
- + " " + Vars.time_final_str + " " \
- + " -vf \"split[a][b]; [a]pad=iw:(ih*2)+4:color=888888 [src]; [b]" \
- + Vars.filter_test_str + " [filt]; [src][filt]overlay=((main_w - w)/2):main_h/2\"" + "\n"
- length = len(command)
- self.terminal.feed_child(command, length)
- def on_but_volume_det_clicked(self, button):
- def finish_voldet(meanv, maxv):
- self.label_meanvol.set_label(meanv)
- self.label_maxvol.set_label(maxv)
- self.but_volume_det.set_label("volume detected")
- self.voldet_spin.stop()
- self.voldet_spin.set_sensitive(False)
- def my_thread():
- command = [Vars.ffmpeg_ex, '-i', Vars.filename, '-vn', '-af', 'volumedetect', '-f', 'null', '/dev/null']
- p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
- while True:
- line = p.stderr.read()
- if not line:
- break
- out = line.decode()
- for line in out.split('\n'):
- line = line.strip()
- if "mean_volume:" in line:
- aa = line.split('mean_volume:', 1)
- mea_vol_det = aa[1]
- meanv = "Mean vol: " + mea_vol_det
- if "max_volume:" in line:
- aa = line.split('max_volume:', 1)
- max_vol_det = aa[1]
- maxv = "Max vol: " + max_vol_det
- p.communicate()
- finish_voldet(meanv, maxv)
- if Vars.VOLDT_DONE:
- return
- Vars.VOLDT_DONE = True
- self.voldet_spin.set_sensitive(True)
- self.voldet_spin.start()
- self.but_volume_det.set_label("Wait")
- threading.Thread(target=my_thread).start()
- def on_volume_clicked(self, button):
- ratio = 1
- self.label_ratio_val.set_label("1")
- Vars.final_af_str = ""
- db = self.spin_db["adj"].get_value()
- if (db != 0.00):
- ratio = pow(10, (db/20.0))
- ratio = float("{0:.3f}".format(ratio))
- self.label_ratio_val.set_label(str(ratio))
- if self.check_vol.get_active():
- Vars.final_af_str = "volume=" + str(ratio)
- else:
- Vars.final_af_str = ""
- self.make_p3_out_command()
- def on_compand_reset(self, button):
- self.entry_compand.set_text(Vars.compinit)
- self.on_compand_clicked(button)
- def on_compand_clicked(self, button):
- Vars.compand_time = 0
- Vars.compand_data = ""
- timein_ent = self.entry_timecomp.get_chars(0, -1)
- if (timein_ent != ""):
- if timein_ent.isdigit():
- timein = int(timein_ent)
- if Vars.duration_in_sec != 0:
- if timein > Vars.duration_in_sec:
- self.entry_entry_timecomp.set_text(str(Vars.duration_in_sec -1))
- timein = Vars.duration_in_sec -1
- else:
- timein = self.hms2sec(timein_ent)
- if Vars.duration_in_sec != 0:
- if timein > Vars.duration_in_sec:
- self.entry_entry_timecomp.set_text(str(self.sec2hms(Vars.duration_in_sec -1)))
- timein = Vars.duration_in_sec -1
- Vars.compand_time = timein
- if self.check_compand.get_active():
- compand_data = self.entry_compand.get_chars(0, -1)
- if Vars.audio_channels == 6:
- Vars.compand_data = "aformat=channel_layouts=stereo,aresample=matrix_encoding=dplii,compand=" + compand_data
- else:
- Vars.compand_data = "aformat=channel_layouts=stereo,compand=" + compand_data
- self.make_p3_out_command()
- def on_compand_test(self, button):
- if Vars.compand_data != "":
- command = "ffplay2 -f lavfi \'amovie=" + Vars.filename + " :sp=" + str(Vars.compand_time) + " , " + Vars.compand_data + " ,ebur128=video=1:meter=18 [out0][out1]\'" + "\n"
- else:
- command = "ffplay2 -f lavfi \'amovie=" + Vars.filename + " :sp=" + str(Vars.compand_time) + " ,ebur128=video=1:meter=18 [out0][out1]\'" + "\n"
- length = len(command)
- self.terminal.feed_child(command, length)
- def on_map_clicked(self, button):
- self.map_label.set_label("")
- Vars.maps_str = ""
- if self.check_map.get_active():
- map_in = self.entry_map.get_chars(0, -1)
- if (map_in != ""):
- map_l = map_in.split(",")
- for i in range(len(map_l)):
- if Vars.maps_str == "":
- Vars.maps_str = Vars.maps_str + "-map " + map_l[i]
- else:
- Vars.maps_str = Vars.maps_str + " -map " + map_l[i]
- self.map_label.set_label(Vars.maps_str)
- self.outfilter()
- self.make_p3_out_command()
- def on_time_clicked(self, button):
- Vars.time_final_str = ""
- if self.check_time.get_active():
- timein = 0
- timeout = 0
- timedur = 0
- timein_ent = self.entry_timein.get_chars(0, -1)
- if (timein_ent != ""):
- if timein_ent.isdigit():
- timein = int(timein_ent)
- if Vars.duration_in_sec != 0:
- if timein > Vars.duration_in_sec:
- self.entry_timein.set_text(str(Vars.duration_in_sec -1))
- return
- else:
- timein = self.hms2sec(timein_ent)
- if Vars.duration_in_sec != 0:
- if timein > Vars.duration_in_sec:
- self.entry_timein.set_text(str(self.sec2hms(Vars.duration_in_sec -1)))
- return
- timeout_ent = self.entry_timeout.get_chars(0, -1)
- if (timeout_ent != ""):
- if timeout_ent.isdigit():
- timeout = int(timeout_ent)
- if Vars.duration_in_sec != 0:
- if timeout > Vars.duration_in_sec:
- self.entry_timeout.set_text(str(Vars.duration_in_sec))
- return
- timedur = timeout - timein
- else:
- timeout = self.hms2sec(timeout_ent)
- if Vars.duration_in_sec != 0:
- if timeout > Vars.duration_in_sec:
- self.entry_timeout.set_text(Vars.duration)
- return
- timedur = timeout - timein
- if (timein != 0):
- Vars.time_final_str = Vars.time_final_str + " -ss " + str(timein)
- Vars.time_start = timein
- if (timedur > 0):
- Vars.time_final_str = Vars.time_final_str + " -t " + str(timedur)
- self.time_label.set_text(Vars.time_final_str)
- self.outfilter()
- self.make_p3_out_command()
- def on_codec_audio_changed(self, button):
- a_cod = self.box_ac['cbox'].get_active()
- self.spin_ac['spinner'].set_sensitive(True)
- self.box_audio_ch['cbox'].set_sensitive(True)
- self.box_audio_rate['cbox'].set_sensitive(True)
- if (a_cod == 0): # aaq
- self.adj_change(self.spin_ac['adj'], 100, 80, 160, 10, 1)
- self.spin_ac['adj'].set_value(100.0)
- self.spin_ac['spinner'].set_tooltip_text(Tips.faac_q_str)
- elif (a_cod == 5): # aac_fdk cbr 64-320 def 128
- self.adj_change(self.spin_ac['adj'], 128, 64, 320, 8, 2)
- self.spin_ac['adj'].set_value(128.0)
- self.spin_ac['spinner'].set_tooltip_text(Tips.aak_cbr_str)
- elif (a_cod == 6): # lame cbr 32 - 320 def 128
- self.adj_change(self.spin_ac['adj'], 128, 32, 320, 8, 2)
- self.spin_ac['adj'].set_value(128.0)
- self.spin_ac['spinner'].set_tooltip_text(Tips.lamecbr_str)
- elif (a_cod == 7): # lame vbr 0 - 9 def 6
- self.adj_change(self.spin_ac['adj'], 6, 0, 9, 1, 1)
- self.spin_ac['adj'].set_value(6.0)
- self.spin_ac['spinner'].set_tooltip_text(Tips.lamevbr_str)
- elif (a_cod == 8): # aac cbr 32 - 320 def 128
- self.adj_change(self.spin_ac['adj'], 128, 32, 320, 8, 2)
- self.spin_ac['adj'].set_value(128.0)
- self.spin_ac['spinner'].set_tooltip_text(Tips.aac_cbr_str)
- elif (a_cod == 3 or a_cod == 4): # copy none
- self.spin_ac['spinner'].set_sensitive(False)
- self.spin_ac['spinner'].set_tooltip_text('')
- self.box_audio_ch['cbox'].set_sensitive(False)
- self.box_audio_rate['cbox'].set_sensitive(False)
- else:
- self.spin_ac['spinner'].set_sensitive(False)
- self.spin_ac['spinner'].set_tooltip_text('')
- self.box_audio_ch['cbox'].set_sensitive(False)
- self.box_audio_ch['cbox'].set_active(0)
- self.on_codec_clicked(button)
- def on_codec_video_changed(self, button):
- self.on_codec_clicked(button)
- def on_codec_vrc_changed(self, button):
- video_rc = self.box_vrc['cbox'].get_active() #0 crf, 1 kb/s
- video_codec = self.box_vcodec['cbox'].get_active() #0 x264, 1 -vcopy
- model = self.box_vcodec['cbox'].get_model()
- item = model[video_codec]
- video_codec = item[0]
- if (video_rc == 0):
- self.adj_change(self.spin_vc['adj'], 21.3, 15, 40, 0.1, 1)
- self.spin_vc['adj'].set_value(21.3)
- self.check_2pass.set_active(False)
- self.check_2pass.set_sensitive(False)
- elif (video_rc == 1) and (video_codec == "mpeg4" ):
- self.adj_change(self.spin_vc['adj'], 1200, 300, 5000, 100, 100)
- self.spin_vc['adj'].set_value(1200.0)
- self.check_2pass.set_sensitive(True)
- elif (video_rc == 1):
- self.adj_change(self.spin_vc['adj'], 730, 300, 4000, 10, 100)
- self.spin_vc['adj'].set_value(730.0)
- self.check_2pass.set_sensitive(True)
- def on_codec_clicked(self, button):
- Vars.final_codec_str = ""
- #audio
- Vars.audio_codec_str = self.audio_codec()
- #self.f3ac_label_out.set_label(Vars.audio_codec_str)
- # video
- Vars.v_copy = 0
- Vars.vcodec_is = ""
- video_codec = self.box_vcodec['cbox'].get_active() #0 x264, 1 -vcopy
- model = self.box_vcodec['cbox'].get_model()
- item = model[video_codec]
- video_codec = item[0]
- if (video_codec == "video copy"):
- Vars.v_copy = 1
- Vars.video_codec_str_more = self.v_codec_vcopy()
- elif (video_codec == "mpeg4"): #mpeg4
- Vars.video_codec_str_more = self.v_codec_mpeg4()
- Vars.vcodec_is = "mpeg4"
- elif (video_codec == "libx264"):
- #libx264
- Vars.video_codec_str_more = self.v_codec_x264()
- #
- self.on_codec_vrc_value_change(button)
- def on_codec_vrc_value_change(self, button):
- Vars.video_codec_str = ""
- if (Vars.vcodec_is == "") and (Vars.v_copy == 0): #x264
- #rc
- video_rc = self.box_vrc['cbox'].get_active() #0 crf, 1 kb/s
- if (video_rc == 0):
- video_codec_str = "-c:v libx264 " + "-crf " + str(self.spin_vc['adj'].get_value()) + " " + Vars.video_codec_str_more
- elif (video_rc == 1):
- video_codec_str = "-c:v libx264 " + "-b:v " + str(int(self.spin_vc['adj'].get_value())) + "k " + Vars.video_codec_str_more
- elif (Vars.vcodec_is == "mpeg4"):
- video_codec_str = "-c:v mpeg4 -mpv_flags strict_gop " + "-b:v " + str(int(self.spin_vc['adj'].get_value())) + "k"
- else:
- video_codec_str = Vars.video_codec_str_more
- Vars.video_codec_str = video_codec_str
- #self.f3v_label_out.set_label(video_codec_str)
- Vars.final_codec_str = Vars.audio_codec_str + " " + video_codec_str
- self.make_p3_out_command()
- def audio_codec(self):
- Vars.a_copy = 0
- Vars.audionone = 0
- # channels
- audio_codec_str = ""
- channel_str = "-ac 2"
- channel = self.box_audio_ch['cbox'].get_active()
- if channel == 1:
- channel_str = "-ac 1"
- # sample rate
- sample_str = "-ar 48k"
- sample = self.box_audio_rate['cbox'].get_active()
- if sample == 1:
- sample_str = "-ar 44.1k"
- #
- audio_codec = self.box_ac['cbox'].get_active()
- if self.box_oth_container['cbox'].get_active() == 2: # avi protection
- if (audio_codec != 3) and (audio_codec != 4) and (audio_codec != 6) and (audio_codec != 7):
- self.box_ac['cbox'].set_active(6) # only lame or acopy or noaudio
- audio_codec = 6
- if (audio_codec == 0):
- audio_codec_str = "-c:a libfaac -q:a "
- quality_faac = self.spin_ac['adj'].get_value()
- audio_codec_str = audio_codec_str + str(int(quality_faac)) + " " + sample_str + " " + channel_str
- elif (audio_codec == 1):
- audio_codec_str = "-c:a libaacplus -b:a 64k" + " " + sample_str + " " + channel_str
- elif (audio_codec == 2):
- audio_codec_str = "-c:a libaacplus -b:a 32k" + " " + sample_str + " " + channel_str
- elif (audio_codec == 3):
- audio_codec_str = "-an"
- Vars.audionone = 1
- elif (audio_codec == 4):
- audio_codec_str = "-c:a copy"
- Vars.a_copy = 1
- elif (audio_codec == 5):
- audio_codec_str = "-c:a libfdk_aac -b:a "
- aakcbr = self.spin_ac['adj'].get_value()
- audio_codec_str = audio_codec_str + str(int(aakcbr)) + "k " + sample_str + " " + channel_str
- elif (audio_codec == 6):
- audio_codec_str = "-c:a libmp3lame -b:a "
- lamecbr = self.spin_ac['adj'].get_value()
- audio_codec_str = audio_codec_str + str(int(lamecbr)) + "k " + sample_str + " " + channel_str
- elif (audio_codec == 7):
- audio_codec_str = "-c:a libmp3lame -q:a "
- lamevbr = self.spin_ac['adj'].get_value()
- audio_codec_str = audio_codec_str + str(int(lamevbr)) + " " + sample_str + " " + channel_str
- elif (audio_codec == 8):
- audio_codec_str = "-c:a aac -strict -2 -b:a "
- aaccbr = self.spin_ac['adj'].get_value()
- audio_codec_str = audio_codec_str + str(int(aaccbr)) + "k " + sample_str + " " + channel_str
- return audio_codec_str
- def v_codec_vcopy(self):
- self.box_vrc['cbox'].set_active(0)
- self.box_vrc['cbox'].set_sensitive(False)
- self.spin_vc['spinner'].set_sensitive(False)
- self.box_3v_preset['cbox'].set_active(2)
- self.box_3v_preset['cbox'].set_sensitive(False)
- self.box_3v_tune['cbox'].set_active(0)
- self.box_3v_tune['cbox'].set_sensitive(False)
- self.box_3v_x264opts['cbox'].set_active(0)
- self.box_3v_x264opts['cbox'].set_sensitive(False)
- self.check_3v_opencl.set_active(False)
- self.check_3v_opencl.set_sensitive(False)
- self.check_cpu.set_active(False)
- self.check_cpu.set_sensitive(False)
- video_codec_str = "-c:v copy"
- return video_codec_str
- def v_codec_x264(self):
- video_codec_str = ""
- if "mpeg4" in Vars.p3_command:
- self.box_vrc['cbox'].set_active(0)
- self.box_3v_tune['cbox'].set_active(0)
- self.box_vrc['cbox'].set_sensitive(True)
- self.spin_vc['spinner'].set_sensitive(True)
- self.box_3v_preset['cbox'].set_sensitive(True)
- self.box_3v_tune['cbox'].set_sensitive(True)
- self.box_3v_x264opts['cbox'].set_sensitive(True)
- self.check_3v_opencl.set_sensitive(True)
- self.check_cpu.set_sensitive(True)
- #preset
- preset_str = ""
- preset = self.box_3v_preset['cbox'].get_active()
- # 0 -superfast, 1 -veryfast, 2 -faster, 3 -fast, 4 -medium, 5 -slow, default: 2 faster
- if (preset == 0):
- preset_str = "-preset superfast "
- if (preset == 1):
- preset_str = "-preset veryfast "
- if (preset == 2):
- preset_str = "-preset faster "
- if (preset == 3):
- preset_str = "-preset fast "
- if (preset == 4):
- preset_str = "-preset medium "
- if (preset == 5):
- preset_str = "-preset slow "
- # tune film, animation, grain, stillimage
- tune = self.box_3v_tune['cbox'].get_active()
- if (tune == 0):
- preset_str = preset_str + "-tune film"
- if (tune == 1):
- preset_str = preset_str + "-tune animation"
- if (tune == 2):
- preset_str = preset_str + "-tune grain"
- if (tune == 3):
- preset_str = preset_str + "-tune stillimage"
- video_codec_str = preset_str
- #x264opts
- if (self.box_3v_x264opts['cbox'].get_active() == 1):
- video_codec_str = video_codec_str + " -x264opts ssim"
- else:
- video_codec_str = video_codec_str + " -x264opts ref=4:bframes=4:direct=auto:aq-strength=1.3:ssim"
- #opencl
- if self.check_3v_opencl.get_active():
- video_codec_str = video_codec_str + ":opencl"
- return video_codec_str
- def v_codec_mpeg4(self):
- if not ("mpeg4" in Vars.p3_command):
- self.box_vrc['cbox'].set_active(1)
- self.on_codec_vrc_changed(1)
- self.box_vrc['cbox'].set_sensitive(False)
- self.spin_vc['spinner'].set_sensitive(True)
- self.box_3v_preset['cbox'].set_sensitive(False)
- self.box_3v_tune['cbox'].set_sensitive(False)
- self.box_3v_x264opts['cbox'].set_sensitive(False)
- self.check_3v_opencl.set_active(False)
- self.check_3v_opencl.set_sensitive(False)
- self.check_cpu.set_active(False)
- self.check_cpu.set_sensitive(False)
- video_codec_str = ""
- return video_codec_str
- def on_preset_changed(self, button):
- self.on_codec_clicked(button)
- def on_f3_other_clicked(self, button):
- Vars.final_other_str = ""
- Vars.debug = 0
- Vars.first_pass = 0
- Vars.n_pass = 1
- if self.check_nometa.get_active():
- Vars.final_other_str = "-map_metadata -1"
- if self.check_2pass.get_active():
- Vars.first_pass = 1
- Vars.n_pass = 2
- if self.check_cpu.get_active():
- if (Vars.final_other_str == ""):
- Vars.final_other_str = "-threads 3"
- else:
- Vars.final_other_str = Vars.final_other_str + " " + "-threads 3"
- if self.check_scopy.get_active():
- if (Vars.final_other_str == ""):
- Vars.final_other_str = "-c:s copy"
- else:
- Vars.final_other_str = Vars.final_other_str + " " + "-c:s copy"
- if self.check_debug.get_active():
- Vars.debug = 1
- self.make_p3_out_command()
- def on_container_changed(self,button):
- container = self.box_oth_container['cbox'].get_active() #0 mkv, 1 mp4
- if (container == 1):
- Vars.container_str = "-f mp4"
- self.check_scopy.set_active(False)
- self.check_scopy.set_sensitive(False)
- Vars.ext = ".mp4"
- self.check_out_file()
- if Vars.is_avi:
- it = self.box_vcodec['list'].insert(0)
- self.box_vcodec['list'].set(it, {0: "libx264"})
- self.box_vcodec['cbox'].set_active(0)
- Vars.is_avi = 0
- elif (container == 2):
- Vars.container_str = "-f avi"
- self.check_scopy.set_active(False)
- self.check_scopy.set_sensitive(False)
- audio_codec = self.box_ac['cbox'].get_active()
- if (audio_codec != 3) and (audio_codec != 4) and (audio_codec != 6) and (audio_codec != 7):
- self.box_ac['cbox'].set_active(6) # lame cbr
- model = self.box_vcodec['cbox'].get_model()
- it = Gtk.TreeModel.get_iter(model,0)
- self.box_vcodec['list'].remove(it)
- self.box_vcodec['cbox'].set_active(1) # mpeg4
- Vars.is_avi = 1
- Vars.ext = ".avi"
- self.check_out_file()
- else:
- Vars.container_str = "-f matroska"
- self.check_scopy.set_sensitive(True)
- Vars.ext = ".mkv"
- self.check_out_file()
- if Vars.is_avi:
- it = self.box_vcodec['list'].insert(0)
- self.box_vcodec['list'].set(it, {0: "libx264"})
- self.box_vcodec['cbox'].set_active(0)
- Vars.is_avi = 0
- self.make_p3_out_command()
- def on_but_f3_run_clicked(self, button):
- def restore_dir_button(): # if is changed during encoding
- select = self.out_dir_chooserbut.get_uri()
- decoded = url2pathname(select)
- newdir = decoded.split('//')[1]
- if (newdir != Vars.outdir):
- self.out_dir_chooserbut.disconnect_by_func(self.dir_changed)
- Vars.first_run = 0
- acturi = "file://" + os.getcwd()
- self.out_dir_chooserbut.set_uri(acturi)
- self.out_dir_chooserbut.connect("selection-changed", self.dir_changed)
- def restore_file_button(): # if is changed during encoding
- select = self.filechooserbutton.get_filename()
- if (select != Vars.filename):
- self.filechooserbutton.disconnect_by_func(self.file_changed)
- self.filechooserbutton.set_filename(Vars.filename)
- self.filechooserbutton.connect("file-set", self.file_changed)
- def clear_ff_file():
- if os.path.exists(Vars.outdir + '/' + 'ffmpeg2pass-0.log'):
- os.remove(Vars.outdir + '/' + 'ffmpeg2pass-0.log')
- if os.path.exists(Vars.outdir + '/' + 'ffmpeg2pass-0.log.mbtree'):
- os.remove(Vars.outdir + '/' + 'ffmpeg2pass-0.log.mbtree')
- if os.path.exists(Vars.outdir + '/' + 'x264_lookahead.clbin'):
- os.remove(Vars.outdir + '/' + 'x264_lookahead.clbin')
- def end_run():
- if (Vars.eff_pass == 0) and (Vars.final_command1 == ""):
- Vars.out_file_size = self.humansize(Vars.newname)
- stri = " Done in: " + self.sec2hms(Vars.time_done) + " " + "\n"\
- + " in: " + Vars.in_file_size + "\n"\
- + " out: " + Vars.out_file_size
- self.but_f3_run.set_tooltip_text(stri)
- stri2 = " Done in: " + self.sec2hms(Vars.time_done) + " "\
- + " input size: " + Vars.in_file_size + " "\
- + " output size: " + Vars.out_file_size
- self.reportdata.set_text(stri2)
- clear_ff_file()
- self.but_f3_run.set_label('RUN')
- Vars.ENCODING = False
- restore_dir_button()
- restore_file_button()
- elif (Vars.eff_pass == 0) and (Vars.final_command1 != ""):
- Vars.eff_pass = 1
- Vars.ENCODING = False
- self.on_but_f3_run_clicked(1)
- elif (Vars.eff_pass == 1):
- Vars.out_file_size = self.humansize(Vars.newname)
- stri = " Done in: " + self.sec2hms(Vars.time_done + Vars.time_done_1) + " " + "\n"\
- + " pass 1: " + self.sec2hms(Vars.time_done) + " " + "\n"\
- + " pass 2: " + self.sec2hms(Vars.time_done_1) + " " + "\n"\
- + " in: " + Vars.in_file_size + "\n"\
- + " out: " + Vars.out_file_size
- self.but_f3_run.set_tooltip_text(stri)
- stri2 = " Done in: " + self.sec2hms(Vars.time_done + Vars.time_done_1) + " "\
- + " pass 1: " + self.sec2hms(Vars.time_done) + " "\
- + " pass 2: " + self.sec2hms(Vars.time_done_1) + " "\
- + " input size: " + Vars.in_file_size + " "\
- + " output size: " + Vars.out_file_size
- self.reportdata.set_text(stri2)
- clear_ff_file()
- Vars.eff_pass = 0
- self.but_f3_run.set_label('RUN')
- Vars.ENCODING = False
- restore_dir_button()
- restore_file_button()
- def check_run(name):
- t0 = time.time()
- processname = name
- for line in subprocess.Popen(["ps", "xa"], shell=False, stdout=subprocess.PIPE).stdout:
- fields = line.split()
- pid = fields[0]
- process = fields[4]
- if process.find(processname) >= 0:
- if line.find(Vars.filename) >= 0:
- mypid = pid
- break
- finn = True
- while finn == True:
- time.sleep(1)
- try:
- finn = os.path.exists("/proc/" + mypid)
- except:
- Vars.eff_pass = 0
- self.but_f3_run.set_label('RUN')
- Vars.ENCODING = False
- restore_dir_button()
- restore_file_button()
- return
- if Vars.eff_pass == 0:
- tfin = time.time() - t0
- Vars.time_done = int(tfin)
- else:
- tfin = time.time() - t0
- Vars.time_done_1 = int(tfin)
- end_run()
- if Vars.ENCODING:
- return
- if Vars.eff_pass == 0:
- self.check_out_file()
- Vars.time_done = 0
- Vars.time_done_1 = 0
- if Vars.n_pass == 1:
- Vars.final_command1 = ""
- Vars.final_command2 = Vars.ffmpeg_ex + " -i \"" \
- + Vars.filename + "\" " \
- + Vars.p3_command \
- + " \"" + Vars.newname + "\"" \
- + "\n"
- command = Vars.final_command2
- if Vars.n_pass == 2:
- Vars.final_command1 = Vars.ffmpeg_ex + " -i \"" \
- + Vars.filename + "\" " \
- + Vars.p3_comm_first_p \
- + "\n"
- Vars.final_command2 = Vars.ffmpeg_ex + " -i \"" \
- + Vars.filename + "\" " \
- + Vars.p3_command \
- + " \"" + Vars.newname + "\"" \
- + "\n"
- command = Vars.final_command1
- else:
- command = Vars.final_command2
- if Vars.debug == 1:
- if Vars.n_pass == 1:
- command = "echo $\'\n\n\n" + Vars.final_command2 + "\' \n"
- if Vars.n_pass == 2:
- command = "echo $\'\n\n\n" + Vars.final_command1 + "\n" + Vars.final_command2 + "\' \n"
- length = len(command)
- self.terminal.feed_child(command, length)
- #
- if Vars.debug == 0:
- self.but_f3_run.set_label('ENCODING ...')
- self.but_f3_run.set_tooltip_text('')
- self.reportdata.set_text('')
- Vars.ENCODING = True
- t = threading.Thread(name='child procs', target=check_run, args=(Vars.ffmpeg_ex,))
- t.start()
- def dir_changed(self, button):
- if Vars.ENCODING:
- return
- if Vars.first_run:
- select = self.out_dir_chooserbut.get_uri()
- decoded = url2pathname(select)
- newdir = decoded.split('//')[1]
- command = "cd " + "\"" + newdir + "\"" + "\n"
- length = len(command)
- self.terminal.feed_child(command, length)
- self.f3_run_outdir_label.set_markup("<b>out dir: </b>" + newdir)
- Vars.outdir = newdir
- self.check_out_file()
- else:
- Vars.first_run = 1
- def on_but_black_det_clicked(self, button):
- def update_progress(pprog):
- self.progressbar_black_det.set_fraction(pprog)
- return False
- def update_textv(stri):
- self.textbuffer.insert_at_cursor(stri, -1)
- i = self.textbuffer.get_end_iter()
- self.textview.scroll_to_iter(i, 0.0, True, 0.0, 1.0)
- return False
- def stopped():
- stri = "Stopped by user.\n"
- self.textbuffer.insert_at_cursor(stri, -1)
- i = self.textbuffer.get_end_iter()
- self.textview.scroll_to_iter(i, 0.0, True, 0.0, 1.0)
- self.but_black_det.set_label("Black detect")
- self.blackdet_spin.stop()
- self.blackdet_spin.set_sensitive(False)
- self.progressbar_black_det.set_fraction(0.0)
- Vars.blackdet_is_run = False
- def bd_finish(detected):
- if detected == 0:
- stri = "none black gap found"
- self.textbuffer.insert_at_cursor(stri, -1)
- self.blackdet_spin.stop()
- self.blackdet_spin.set_sensitive(False)
- self.but_black_det.set_label("black detectet")
- self.progressbar_black_det.set_fraction(1.0)
- Vars.blackdet_is_run = False
- Vars.BLACKDT_DONE = True
- def my_thread():
- Vars.blackdet_is_run = True
- command = [Vars.ffmpeg_ex, '-i', Vars.filename, '-y', '-an', '-vf', 'blackdetect=d=.5', '-f', 'null', '/dev/null']
- p = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, universal_newlines=True)
- self.bd_th = False
- detected = 0
- time_step = 0
- pprog = 0.0
- stri = ""
- while True:
- line = p.stderr.readline()
- if 'time=' in line:
- if time_step == 9:
- tml = line.split('time=')[1]
- tml2 = tml.split(' ')[0]
- time_n = tml2.split('.')[0]
- time_n = self.hms2sec(time_n)
- time_step = 0
- pprog = float(time_n)/Vars.duration_in_sec
- GLib.idle_add(update_progress, pprog)
- time.sleep(0.002)
- else:
- time_step = time_step + 1
- if 'blackdetect ' in line:
- a = line
- b = a.split('black_start:')[1]
- start = b.split(' ')[0]
- st_in_s = float(start)
- st_in_s = int(st_in_s)
- start_in_s = ("%4.1i"% (st_in_s))
- start = self.sec2hms(start)
- stri = "black start at: " + start_in_s + " s, " + start + " "
- c = b.split('black_duration:')[1]
- durat = c.split(' ')[0]
- dur_s = float(durat)
- dur_s = "{0:0=3.1f}".format(dur_s)
- stri = stri + "duration: " + dur_s + "s\n"
- detected = 1
- GLib.idle_add(update_textv, stri)
- time.sleep(0.002)
- if line == '' and p.poll() != None:
- break
- if self.bd_th:
- p.communicate("q")
- break
- try:
- p.communicate()
- except:
- stopped()
- return
- bd_finish(detected)
- if Vars.BLACKDT_DONE:
- return
- if Vars.blackdet_is_run == False:
- self.but_black_det.set_label("Stop")
- self.textbuffer.set_text('') # clear for insert from start
- stri = "Detected:\n\n"
- start = self.textbuffer.get_start_iter()
- self.textbuffer.insert(start, stri, -1)
- self.blackdet_spin.set_sensitive(True)
- self.blackdet_spin.start()
- thread = threading.Thread(target=my_thread)
- thread.daemon = True
- thread.start()
- elif Vars.blackdet_is_run == True:
- self.bd_th = True
- # -------------------------------------
- def preview_logic(self):
- if ( not(('-map ' in Vars.p3_command ) or ('-vf ' in Vars.p3_command )) ):
- self.buttest.set_sensitive(False)
- self.buttestspl.set_sensitive(False)
- elif ('-map ' in Vars.p3_command) and ('-vf ' in Vars.p3_command):
- self.buttest.set_sensitive(False)
- self.buttestspl.set_sensitive(False)
- elif '-map ' in Vars.p3_command:
- self.buttest.set_sensitive(True)
- self.buttestspl.set_sensitive(False)
- elif '-vf ' in Vars.p3_command:
- self.buttest.set_sensitive(True)
- self.buttestspl.set_sensitive(True)
- def calcola_scale(self):
- Vars.scalestr = ""
- numero = self.size_spinner['adj'].get_value()
- numero = int(numero/4)*4
- dar = self.box2['cbox'].get_active()
- lato = self.box1['cbox'].get_active()
- if (dar == 1): # 4/3
- if (lato == 1):
- n2 = numero/4*3
- else:
- n2 = numero/3*4
- setdar = ",setdar=4/3,setsar=1/1"
- elif (dar == 0): # 16/9
- if (lato == 1):
- n2 = numero/16*9
- else:
- n2 = numero/9*16
- setdar = ",setdar=16/9,setsar=1/1"
- elif (dar == 2): #1/1 same as input
- w = int(Vars.video_width)
- h = int(Vars.video_height)
- if self.checkcr.get_active():
- crT = int(self.spinct['adj'].get_value())
- crB = int(self.spincb['adj'].get_value())
- crL = int(self.spincl['adj'].get_value())
- crR = int(self.spincr['adj'].get_value())
- h = h - crT - crB
- w = w - crL - crR
- if (lato == 1): # h
- n2 = (float(h)/(w/float(numero)))
- else:
- n2 = (float(w)/(h/float(numero)))
- setdar = ""
- n2 = int(n2/4)*4
- Vars.scalestr = "scale="
- if (lato == 1):
- Vars.scalestr = Vars.scalestr + str(numero) + ":" + str(n2)
- else:
- Vars.scalestr = Vars.scalestr + str(n2) + ":" + str(numero)
- lanc = self.check.get_active()
- if lanc:
- Vars.scalestr = Vars.scalestr + ":flags=lanczos" + setdar
- else:
- Vars.scalestr = Vars.scalestr + setdar
- self.outfilter()
- def outfilter(self):
- final_str = ""
- if (Vars.deint_str != ""):
- final_str = final_str + Vars.deint_str
- if (Vars.crop_str != ""):
- if (final_str == ""):
- final_str = final_str + Vars.crop_str
- else:
- final_str = final_str + "," + Vars.crop_str
- if (Vars.scalestr != ""):
- if (final_str == ""):
- final_str = final_str + Vars.scalestr
- else:
- final_str = final_str + "," + Vars.scalestr
- if (Vars.dn_str != ""):
- if (final_str == ""):
- final_str = final_str + Vars.dn_str
- else:
- final_str = final_str + "," + Vars.dn_str
- if (Vars.uns_str != ""):
- if (final_str == ""):
- final_str = final_str + Vars.uns_str
- else:
- final_str = final_str + "," + Vars.uns_str
- Vars.filter_test_str = final_str
- if (final_str != ""):
- Vars.final_vf_str = "-vf " + final_str
- else:
- Vars.final_vf_str = ""
- label_str = ""
- if (Vars.maps_str != ""):
- label_str = label_str + Vars.maps_str + " "
- if (Vars.time_final_str != ""):
- label_str = label_str + Vars.time_final_str + " "
- if (Vars.fr_str != ""):
- label_str = label_str + Vars.fr_str + " "
- if (Vars.final_vf_str != ""):
- label_str = label_str + Vars.final_vf_str
- self.labelout.set_text(label_str)
- self.make_p3_out_command()
- if (Vars.info_str != ""):
- self.preview_logic()
- def make_p3_out_command(self):
- Vars.p3_command = ""
- Vars.p3_comm_first_p = ""
- self.f3_out_label.set_label("")
- if (Vars.maps_str != ""):
- Vars.p3_command = Vars.maps_str + " "
- if (Vars.time_final_str != ""):
- Vars.p3_command = Vars.p3_command + Vars.time_final_str + " "
- if ( (Vars.fr_str != "") and (Vars.v_copy == 0) ): # check -vcopy
- Vars.p3_command = Vars.p3_command + Vars.fr_str + " "
- if ( (Vars.final_vf_str != "") and (Vars.v_copy == 0) ): # check -vcopy
- Vars.p3_command = Vars.p3_command + Vars.final_vf_str + " "
- # first pass
- if Vars.first_pass:
- Vars.p3_comm_first_p = Vars.p3_command + Vars.video_codec_str + " "
- if self.check_cpu.get_active():
- Vars.p3_comm_first_p = Vars.p3_comm_first_p + "-threads 3 "
- if "libx264" in Vars.p3_comm_first_p:
- Vars.p3_comm_first_p = Vars.p3_comm_first_p + "-pass 1 -fastfirstpass 1 "
- else:
- Vars.p3_comm_first_p = Vars.p3_comm_first_p + "-pass 1 "
- Vars.p3_comm_first_p = Vars.p3_comm_first_p + "-an -f null /dev/null"
- else:
- Vars.p3_comm_first_p = ""
- # -af
- audiof = ""
- if ( (Vars.final_af_str != "") and (Vars.a_copy == 0) and (Vars.audionone == 0) ): # check -acopy -an
- audiof_1 = Vars.final_af_str
- else:
- audiof_1 = ""
- if ( (Vars.compand_data != "") and (Vars.a_copy == 0) and (Vars.audionone == 0) ): # check -acopy -an
- audiof_2 = Vars.compand_data
- else:
- audiof_2 = ""
- if (audiof_1 != "") and (audiof_2 != ""):
- audiof = audiof_1 + "," + audiof_2
- elif (audiof_1 != "") and (audiof_2 == ""):
- audiof = audiof_1
- elif (audiof_1 == "") and (audiof_2 != ""):
- audiof = audiof_2
- if audiof != "":
- Vars.p3_command = Vars.p3_command + "-af \'" + audiof + "\' "
- if (Vars.final_codec_str != ""):
- Vars.p3_command = Vars.p3_command + Vars.final_codec_str + " "
- #second pass
- if Vars.n_pass == 2:
- Vars.p3_command = Vars.p3_command + "-pass 2" + " "
- if (Vars.container_str != ""):
- Vars.p3_command = Vars.p3_command + Vars.container_str + " "
- if (Vars.final_other_str != ""):
- Vars.p3_command = Vars.p3_command + Vars.final_other_str + " "
- self.f3_out_label.set_label(Vars.p3_command)
- def main(self):
- Gtk.main()
- if __name__ == "__main__":
- GObject.threads_init()
- ProgrammaGTK()
- Gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement