Added support for preview the conversion

Now allows to choose how many cores to use during conversion
This commit is contained in:
Sergio Costas 2014-07-27 19:53:07 +02:00
parent 70fadeef22
commit cba0352d33
14 changed files with 334 additions and 92 deletions

View file

@ -5,7 +5,6 @@
<object class="GtkTextBuffer" id="debug_buffer"/> <object class="GtkTextBuffer" id="debug_buffer"/>
<object class="GtkDialog" id="dialog_error"> <object class="GtkDialog" id="dialog_error">
<property name="width_request">640</property> <property name="width_request">640</property>
<property name="height_request">240</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="modal">True</property> <property name="modal">True</property>
<property name="window_position">center</property> <property name="window_position">center</property>
@ -53,8 +52,9 @@
<property name="label" translatable="yes">There was an error while creating the disc.</property> <property name="label" translatable="yes">There was an error while creating the disc.</property>
</object> </object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="padding">31</property>
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
@ -70,7 +70,7 @@
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<child> <child>
<object class="GtkScrolledWindow" id="scrolledwindow1"> <object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="height_request">200</property> <property name="height_request">240</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="shadow_type">in</property> <property name="shadow_type">in</property>

View file

@ -174,22 +174,6 @@
<property name="height">1</property> <property name="height">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">baseline</property>
<property name="margin_left">8</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Original video rate (Kbits/sec):</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child> <child>
<object class="GtkLabel" id="label6"> <object class="GtkLabel" id="label6">
<property name="visible">True</property> <property name="visible">True</property>
@ -217,48 +201,6 @@
<property name="height">1</property> <property name="height">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkLabel" id="label8">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">8</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Original audio rate (Kbits/sec):</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="original_videorate">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="original_audiorate">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="ellipsize">end</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child> <child>
<object class="GtkLabel" id="label9"> <object class="GtkLabel" id="label9">
<property name="visible">True</property> <property name="visible">True</property>
@ -344,6 +286,64 @@
<property name="height">1</property> <property name="height">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkLabel" id="original_audiorate">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="ellipsize">end</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="original_videorate">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label8">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">8</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Original audio rate (Kbits/sec):</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">baseline</property>
<property name="margin_left">8</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Original video rate (Kbits/sec):</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object> </object>
</child> </child>
</object> </object>
@ -1025,7 +1025,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkRadioButton" id="size_720x480_ntsc"> <object class="GtkRadioButton" id="size_720x480">
<property name="label" translatable="yes">720x480</property> <property name="label" translatable="yes">720x480</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
@ -1042,7 +1042,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkRadioButton" id="size_704x480_ntsc"> <object class="GtkRadioButton" id="size_704x480">
<property name="label" translatable="yes">704x480</property> <property name="label" translatable="yes">704x480</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
@ -1059,7 +1059,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkRadioButton" id="size_480x480_ntsc"> <object class="GtkRadioButton" id="size_480x480">
<property name="label" translatable="yes">480x480</property> <property name="label" translatable="yes">480x480</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
@ -1076,7 +1076,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkRadioButton" id="size_352x480_ntsc"> <object class="GtkRadioButton" id="size_352x480">
<property name="label" translatable="yes">352x480</property> <property name="label" translatable="yes">352x480</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
@ -1093,7 +1093,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkRadioButton" id="size_352x240_ntsc"> <object class="GtkRadioButton" id="size_352x240">
<property name="label" translatable="yes">352x240</property> <property name="label" translatable="yes">352x240</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>

View file

@ -357,6 +357,7 @@
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="yalign">0.4699999988079071</property> <property name="yalign">0.4699999988079071</property>
<property name="image_position">top</property> <property name="image_position">top</property>
<signal name="clicked" handler="on_preview_file_clicked" swapped="no"/>
<child> <child>
<object class="GtkBox" id="box11"> <object class="GtkBox" id="box11">
<property name="visible">True</property> <property name="visible">True</property>

131
data/interface/wpreview.ui Normal file
View file

@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkAdjustment" id="length">
<property name="lower">10</property>
<property name="upper">1000</property>
<property name="value">60</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkDialog" id="dialog_preview">
<property name="can_focus">False</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button1">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Preview video&lt;/b&gt;
Devede will create a preview with the selected parameters, so you will be able to check the video quality, audio sync and so on.</property>
<property name="use_markup">True</property>
<property name="justify">center</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Preview length:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="spinbutton1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">length</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">button1</action-widget>
<action-widget response="1">button2</action-widget>
</action-widgets>
</object>
</interface>

View file

@ -3,6 +3,7 @@
<interface> <interface>
<requires lib="gtk+" version="3.10"/> <requires lib="gtk+" version="3.10"/>
<object class="GtkWindow" id="progress"> <object class="GtkWindow" id="progress">
<property name="width_request">640</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="title" translatable="yes">Creating...</property> <property name="title" translatable="yes">Creating...</property>
<property name="resizable">False</property> <property name="resizable">False</property>
@ -16,6 +17,19 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Creating disc</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">28</property>
<property name="position">0</property>
</packing>
</child>
<child> <child>
<object class="GtkFrame" id="progress_frame"> <object class="GtkFrame" id="progress_frame">
<property name="visible">True</property> <property name="visible">True</property>
@ -32,7 +46,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">0</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -44,7 +58,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">1</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -60,7 +74,7 @@
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="padding">8</property> <property name="padding">8</property>
<property name="position">2</property> <property name="position">3</property>
</packing> </packing>
</child> </child>
</object> </object>

View file

@ -53,7 +53,10 @@ class avconv_converter(devede.executor.executor):
self.text = _("Converting %(X)s") % {"X" : file_project.title_name} self.text = _("Converting %(X)s") % {"X" : file_project.title_name}
self.final_length = file_project.original_length if (video_length == 0):
self.final_length = file_project.original_length
else:
self.final_length = video_length
self.command_var=[] self.command_var=[]
self.command_var.append("avconv") self.command_var.append("avconv")
self.command_var.append("-i") self.command_var.append("-i")

View file

@ -110,10 +110,7 @@ class configuration(GObject.GObject):
self.tmp_folder=linea[12:].strip() self.tmp_folder=linea[12:].strip()
continue continue
if linea[:10]=="multicore:": if linea[:10]=="multicore:":
if linea[10:].strip()=="1": self.multicore = int(linea[10:].strip())
self.multicore = False
else:
self.multicore = True
continue continue
if linea[:13]=="final_folder:": if linea[:13]=="final_folder:":
self.final_folder=linea[13:].strip() self.final_folder=linea[13:].strip()
@ -166,11 +163,7 @@ class configuration(GObject.GObject):
config_data.write("ntsc\n") config_data.write("ntsc\n")
if (self.tmp_folder != None): if (self.tmp_folder != None):
config_data.write("temp_folder:"+str(self.tmp_folder)+"\n") config_data.write("temp_folder:"+str(self.tmp_folder)+"\n")
config_data.write("multicore:") config_data.write("multicore:"+str(self.multicore))
if (self.multicore):
config_data.write("0\n")
else:
config_data.write("1\n")
if (self.final_folder != None): if (self.final_folder != None):
config_data.write("final_folder:"+str(self.final_folder)+"\n") config_data.write("final_folder:"+str(self.final_folder)+"\n")
if (self.sub_language != None): if (self.sub_language != None):

View file

@ -109,6 +109,13 @@ class converter:
return ( analizers, players, converters, menuers ) return ( analizers, players, converters, menuers )
def get_film_player(self):
""" returns a class for the desired film player, or the most priviledged if the desired is not installed """
if (self.config.film_player == None) or (self.players.has_key(self.config.film_player) == False):
return self.default_player
else:
return self.players[self.config.film_analizer]
def get_film_analizer(self): def get_film_analizer(self):
""" returns a class for the desired film analizer, or the most priviledged if the desired is not installed """ """ returns a class for the desired film analizer, or the most priviledged if the desired is not installed """

View file

@ -60,7 +60,8 @@ class executor(GObject.GObject):
child.add_dependency(dep) child.add_dependency(dep)
def remove_dependency(self,process): def remove_dependency(self,process):
# dependencies are removed only in the parent because the running class have all the processes, parents and childs, and calls
# this method on all of them
if (self.dependencies != None): if (self.dependencies != None):
tmp2 = [] tmp2 = []
for dep in self.dependencies: for dep in self.dependencies:

View file

@ -22,6 +22,7 @@ import devede.configuration_data
import devede.interface_manager import devede.interface_manager
import devede.converter import devede.converter
import devede.ask_subtitles import devede.ask_subtitles
import devede.preview
class file_movie(devede.interface_manager.interface_manager): class file_movie(devede.interface_manager.interface_manager):
@ -42,8 +43,6 @@ class file_movie(devede.interface_manager.interface_manager):
self.add_text("title_name", os.path.splitext(os.path.basename(file_name))[0]) self.add_text("title_name", os.path.splitext(os.path.basename(file_name))[0])
self.add_label("original_size",None) self.add_label("original_size",None)
self.add_label("original_length",None) self.add_label("original_length",None)
self.add_label("original_videorate",None)
self.add_label("original_audiorate",None)
self.add_label("original_aspect_ratio",None) self.add_label("original_aspect_ratio",None)
self.add_label("original_fps",None) self.add_label("original_fps",None)
@ -440,4 +439,26 @@ class file_movie(devede.interface_manager.interface_manager):
disc_converter = cv.get_disc_converter() disc_converter = cv.get_disc_converter()
converter = disc_converter() converter = disc_converter()
converter.convert_file(self,output_path,duration) converter.convert_file(self,output_path,duration)
return converter return converter
def on_button_preview_clicked(self,b):
self.do_preview()
def do_preview(self):
wpreview = devede.preview.preview_window()
if (wpreview.run() == False):
return
run_window = devede.runner.runner()
p = self.do_conversion(os.path.join(self.config.tmp_folder,"movie_preview.mpg"),wpreview.lvalue)
run_window.add_process(p)
run_window.connect("done",self.preview_done)
run_window.run()
def preview_done(self,o,retval):
if (retval == 0):
cv = devede.converter.converter()
disc_player = (cv.get_film_player())()
disc_player.play_film(os.path.join(self.config.tmp_folder,"movie_preview.mpg"))

View file

@ -44,6 +44,17 @@ class mplayer_detector(devede.executor.executor):
devede.executor.executor.__init__(self) devede.executor.executor.__init__(self)
self.config = devede.configuration_data.configuration.get_config() self.config = devede.configuration_data.configuration.get_config()
def play_film(self,file_name):
command_line = ["mplayer", file_name]
self.launch_process(command_line)
def process_stdout(self,data):
return
def process_stderr(self,data):
return
def get_film_data(self, file_name): def get_film_data(self, file_name):
""" processes a file, refered by the FILE_MOVIE movie object, and fills its """ processes a file, refered by the FILE_MOVIE movie object, and fills its
main data (resolution, FPS, length...) """ main data (resolution, FPS, length...) """
@ -79,7 +90,7 @@ class mplayer_detector(devede.executor.executor):
self.original_audiorate_uncompressed = 0 self.original_audiorate_uncompressed = 0
self.original_fps = 0 self.original_fps = 0
self.original_aspect_ratio = 0 self.original_aspect_ratio = 0
try: try:
stdout2 = stdout.decode("utf-8") stdout2 = stdout.decode("utf-8")
except: except:

46
src/devede/preview.py Normal file
View file

@ -0,0 +1,46 @@
# Copyright 2014 (C) Raster Software Vigo (Sergio Costas)
#
# This file is part of DeVeDe-NG
#
# DeVeDe-NG is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# DeVeDe-NG is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
from gi.repository import Gtk
import os
import devede.configuration_data
class preview_window:
def __init__(self):
self.config = devede.configuration_data.configuration.get_config()
def run(self):
builder = Gtk.Builder()
builder.set_translation_domain(self.config.gettext_domain)
builder.add_from_file(os.path.join(self.config.glade,"wpreview.ui"))
builder.connect_signals(self)
wpreview_window = builder.get_object("dialog_preview")
wlength = builder.get_object("length")
wpreview_window.show_all()
wlength.set_value(60.0)
retval = wpreview_window.run()
self.lvalue = int(wlength.get_value())
wpreview_window.destroy()
if (retval == 1):
return True
else:
return False

View file

@ -278,7 +278,14 @@ class devede_project:
run_window.connect("done",self.disc_done) run_window.connect("done",self.disc_done)
self.wmain_window.hide() self.wmain_window.hide()
run_window.run() run_window.run()
def disc_done(self,object,value): def disc_done(self,object,value):
self.wmain_window.show() self.wmain_window.show()
def on_preview_file_clicked(self,b):
(element, position, model, treeiter) = self.get_current_file()
if (element == None):
return
element.do_preview()

View file

@ -29,10 +29,16 @@ class runner(GObject.GObject):
GObject.GObject.__init__(self) GObject.GObject.__init__(self)
self.config = devede.configuration_data.configuration.get_config() self.config = devede.configuration_data.configuration.get_config()
if (self.config.multicore): max_cores = self.count_cores()
self.count_cores() if (self.config.multicore > 0):
if max_cores < self.config.multicore:
self.cores = max_cores
else:
self.cores = self.config.multicore
else: else:
self.cores = 1 self.cores = max_cores - self.config.multicore
if (self.cores <= 0):
self.cores = 1
self.proc_list = [] self.proc_list = []
self.running = 0 self.running = 0
@ -80,11 +86,12 @@ class runner(GObject.GObject):
def count_cores(self): def count_cores(self):
self.cores = 0 cores = 0
proc_file = open("/proc/cpuinfo","r") proc_file = open("/proc/cpuinfo","r")
for line in proc_file: for line in proc_file:
if (line.startswith("processor")): if (line.startswith("processor")):
self.cores += 1 cores += 1
return cores
def run(self, clear_log = True): def run(self, clear_log = True):