LinuxQuestions.org Member Success StoriesJust spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've created a video conversion script for getting video into DVD, SVCD, or VCD format. Now I've taken a dive, learned some Python, and written a GUI for that script. I decided to go ahead and register a SourceForge project for the script and GUI, which I will post the URL of when (or if) it is approved. In the meantime, here is the GUI script. Requires wxPython and the 'tovid' script located somewhere in your path. Comments welcome!
Code:
#! /usr/bin/env python
# tovidGUI
# ===============
# A wxPython frontend for the 'tovid' script
# By Eric Pierce
# yahoo com preceded by wapcaplet88
#
# My first Python program; be kind!
import os
from wxPython.wx import *
# IDs for buttons and whatnot
ID_ABOUT = 101
ID_EXIT = 102
ID_BROWSE = 103
ID_QUIT = 104
ID_ENCODE = 105
ID_FORMAT = 106
ID_ASPECT = 107
ID_NORMALIZE = 108
ID_DENOISE = 109
# Main frame class for the GUI
class TovidFrame(wxFrame):
def __init__(self, parent, ID, title):
wxFrame.__init__(self, parent, wxID_ANY, title,
size = (600, 500),
style = wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE )
# ================================
# File in/out selection controls
# ================================
lblInFile = wxStaticText( self, -1, "File to convert" )
self.txtInFile = wxTextCtrl( self, -1 )
self.txtInFile.SetToolTipString( "Type the full filename of the video you want "
"to encode, or use the browse button." )
btnBrowseInFile = wxButton( self, ID_BROWSE, "Browse" )
btnBrowseInFile.SetToolTipString( "Browse your computer to find the video "
"you want to encode." )
lblOutPrefix = wxStaticText( self, -1, "Name of output" )
self.txtOutPrefix = wxTextCtrl( self, -1 )
self.txtOutPrefix.SetToolTipString( "Type the name you want to use for "
"your finished video. You do not need to include a file extension. "
"The completed video will be called YOURFILENAME.mpg, and will be "
"saved in the same directory as the original video." )
# Sizers to hold file controls
fileLayout = wxFlexGridSizer( 2, 4, 8, 8 )
fileLayout.AddMany( [ (lblInFile, 0, wxEXPAND),
(5, 5),
(50, 5),
(lblOutPrefix, 0, wxEXPAND),
(self.txtInFile, 0, wxEXPAND),
(btnBrowseInFile, 0, wxEXPAND),
(50, 5),
(self.txtOutPrefix, 0, wxEXPAND)
] )
fileLayout.AddGrowableCol(0)
fileLayout.AddGrowableCol(3)
# ================================
# Radio buttons
# ================================
# Format-selection radio buttons
outFormatList = ['720x480 DVD',
'352x240 VCD',
'480x480 SVCD',
'352x480 Half-DVD',
'352x240 VCD on DVD']
self.tovidFormats = ['dvd ', 'vcd ', 'svcd ', 'half-dvd ', 'dvd-vcd ']
# Default format (DVD)
self.tovidFormat = self.tovidFormats[0]
# Aspect ratio radio buttons
aspectList = ['16:9 Widescreen TV',
'4:3 Fullscreen TV',
'2.35:1 Theatrical widescreen']
self.tovidAspects = ['wide ', 'full ', 'pana ']
# Default aspect (wide)
self.tovidAspect = self.tovidAspects[0]
rbOutFormat = wxRadioBox( self, ID_FORMAT, "Output format",
wxDefaultPosition, wxDefaultSize,
outFormatList, 1, wxRA_SPECIFY_COLS )
rbOutFormat.SetToolTipString( "Select which video format you want to "
"encode your video in. For example, if your video is high-quality, "
"and you plan to burn it to a DVD disc, select 'DVD'." )
rbAspect = wxRadioBox( self, ID_ASPECT, "Aspect ratio of input",
wxDefaultPosition, wxDefaultSize,
aspectList, 1, wxRA_SPECIFY_COLS )
rbAspect.SetToolTipString( "Select which aspect ratio the original video "
"is in. If it is roughly TV-shaped, use '4:3'. If it is more than "
"twice as wide as it is tall, use '2.35:1'. If it's somewhere in "
"between, use '16:9'." )
# Create a horizontal sizer and append format-selection panels
fmtHorizLayout = wxBoxSizer( wxHORIZONTAL )
fmtHorizLayout.Add( rbOutFormat, 1, wxEXPAND | wxALL, 10 )
fmtHorizLayout.Add( rbAspect, 1, wxEXPAND | wxALL, 10 )
# ================================
# Additional option checkboxes
# ================================
chkNormalize = wxCheckBox( self, ID_NORMALIZE, "Normalize audio" )
chkNormalize.SetToolTipString( "Set audio to a preset volume. Useful "
"if the audio is too quiet or too loud." )
chkDenoise = wxCheckBox( self, ID_DENOISE, "Denoise video" )
chkDenoise.SetToolTipString( "Try to remove noise, blockiness, and "
"annoying fuzzy edges from the video." )
optionsLayout = wxBoxSizer( wxHORIZONTAL )
optionsLayout.Add( chkNormalize, 1, wxEXPAND )
optionsLayout.Add( (100, 5) )
optionsLayout.Add( chkDenoise, 1, wxEXPAND )
# Do not normalize or denoise by default
self.tovidNormalize = ""
self.tovidDenoise = ""
# ================================
# Log window to show output
# ================================
lblLogWindow = wxStaticText( self, -1, "Log" )
self.logWindow = wxTextCtrl( self, -1, style = wxTE_MULTILINE )
logLayout = wxBoxSizer( wxVERTICAL )
logLayout.Add( lblLogWindow, 0, wxEXPAND )
logLayout.Add( self.logWindow, 1, wxEXPAND )
# ================================
# Quit and Encode buttons
# ================================
self.btnQuit = wxButton( self, ID_QUIT, "Quit" )
self.btnQuit.SetToolTipString( "Quit the program" )
self.btnEncode = wxButton( self, ID_ENCODE, "Encode!" )
self.btnEncode.SetToolTipString( "Start encoding the video" )
# Flag to indiciate whether encoding is taking place
self.encoding = False
buttonLayout = wxBoxSizer( wxHORIZONTAL )
buttonLayout.Add( self.btnQuit, 1, wxEXPAND )
buttonLayout.Add( (100, 5) )
buttonLayout.Add( self.btnEncode, 1, wxEXPAND )
# ================================
# Add controls to main vertical sizer
# ================================
mainLayout = wxBoxSizer( wxVERTICAL )
mainLayout.AddSizer( fileLayout, 0, wxEXPAND | wxALL, 5 )
mainLayout.AddSizer( fmtHorizLayout, 0, wxEXPAND | wxALL, 5 )
mainLayout.AddSizer( optionsLayout, 0, wxEXPAND | wxALL, 5 )
mainLayout.AddSizer( logLayout, 1, wxEXPAND | wxALL, 5 )
mainLayout.AddSizer( buttonLayout, 0, wxEXPAND | wxALL, 5 )
self.SetSizer( mainLayout )
# Statusbar
self.CreateStatusBar();
self.SetStatusText("Ready");
# Create menu bar
filemenu = wxMenu()
filemenu.Append(ID_ABOUT, "&About", "About tovidGUI")
filemenu.AppendSeparator()
filemenu.Append(ID_EXIT, "E&xit", "Exit tovidGUI")
# Initialize menu bar
menuBar = wxMenuBar()
menuBar.Append( filemenu, "&File" )
self.SetMenuBar(menuBar)
# ================================
# Set up events
# ================================
EVT_MENU( self, ID_ABOUT, self.OnAbout )
EVT_MENU( self, ID_EXIT, self.OnExit )
EVT_BUTTON( self, ID_BROWSE, self.OnBrowse )
EVT_BUTTON( self, ID_QUIT, self.OnExit )
EVT_BUTTON( self, ID_ENCODE, self.OnEncode )
EVT_RADIOBOX( self, ID_FORMAT, self.OnFormat )
EVT_RADIOBOX( self, ID_ASPECT, self.OnAspect )
EVT_CHECKBOX( self, ID_NORMALIZE, self.OnNormalize )
EVT_CHECKBOX( self, ID_DENOISE, self.OnDenoise )
EVT_IDLE( self, self.OnIdle )
EVT_END_PROCESS( self, -1, self.OnProcessEnded )
self.process = None
self.Show(true)
def OnAbout( self, evt ):
aboutDlg = wxMessageDialog( self, "tovid GUI\n"
"A video conversion program\n"
"By Eric Pierce (wapcaplet99@yahoo.com)",
"About tovidGUI", wxOK | wxICON_INFORMATION )
aboutDlg.ShowModal()
aboutDlg.Destroy()
def OnExit( self, evt ):
self.Close(true)
def OnBrowse( self, evt ):
# Browse for a filename and put the result in the text box
inFileDlg = wxFileDialog( self, "Select a file", "", "", "*.*", wxOPEN )
if inFileDlg.ShowModal() == wxID_OK:
# Put the chosen path and filename into the InFile textbox
self.txtInFile.SetValue( inFileDlg.GetPath() )
# Store the directory name for later use
self.outDirname = inFileDlg.GetDirectory()
self.SetStatusText( "Input filename set to " + inFileDlg.GetPath() )
inFileDlg.Destroy()
def OnEncode( self, evt ):
# If encoding is already in progress, cancel it
if self.encoding:
self.encoding = False
os.system( "kill %d" %self.scriptPID )
self.btnEncode.SetLabel( "Encode!" )
self.SetStatusText( "Encoding cancelled" )
return
# Make sure input file exists and is readable
if not os.access( self.txtInFile.GetValue(), os.F_OK | os.R_OK ):
messageDlg = wxMessageDialog( self, "The input file '" +
self.txtInFile.GetValue() +
"' does not exist, or can't be read. Please choose a valid filename.",
"Cannot open file",
wxOK | wxICON_EXCLAMATION )
messageDlg.ShowModal()
messageDlg.Destroy()
return
elif self.txtOutPrefix.GetValue() == "":
# Make sure the user has chosen an output prefix
messageDlg = wxMessageDialog( self, "It looks like you haven't chosen a "
"name for your output file. Please do that before encoding.",
"No output file specified",
wxOK | wxICON_EXCLAMATION )
messageDlg.ShowModal()
messageDlg.Destroy()
return
else:
txtCommand = "tovid "
txtCommand += self.tovidFormat + self.tovidAspect
txtCommand += self.tovidNormalize + self.tovidDenoise
txtCommand += self.txtInFile.GetValue() + " "
txtCommand += self.outDirname + "/" + self.txtOutPrefix.GetValue()
messageDlg = wxMessageDialog( self, "Ready to encode using the following "
"command line:\n\n" + txtCommand + "\n\nProceed with encoding?",
"Confirm", wxYES_NO | wxICON_QUESTION )
# Confirm and begin encoding
if messageDlg.ShowModal() == wxID_YES:
self.SetStatusText( "Encoding..." )
self.btnEncode.SetLabel( "Cancel encoding" )
self.encoding = True
# Run encoding script
self.process = wxProcess( self )
self.process.Redirect()
self.scriptPID = wxExecute( txtCommand, wxEXEC_ASYNC, self.process )
else:
self.SetStatusText( "Encoding cancelled" )
messageDlg.Destroy()
return
def OnFormat( self, evt ):
# Set appropriate format depending on what radio button was selected
self.tovidFormat = self.tovidFormats[ evt.GetInt() ]
self.SetStatusText( "Format set to %s" %evt.GetString() )
def OnAspect( self, evt ):
# Set appropriate aspect depending on what radio button was selected
self.tovidAspect = self.tovidAspects[ evt.GetInt() ]
self.SetStatusText( "Aspect set to %s" %evt.GetString() )
def OnNormalize( self, evt ):
# Turn normalization on/off depending on checkbox value
if evt.Checked():
self.SetStatusText( "Normalization turned on" )
self.tovidNormalize = "normalize "
else:
self.SetStatusText( "Normalization turned off" )
self.tovidNormalize = ""
def OnDenoise( self, evt ):
# Turn denoising on/off depending on checkbox value
if evt.Checked():
self.SetStatusText( "Denoising turned on" )
self.tovidDenoise = "denoise "
else:
self.SetStatusText( "Denoising turned off" )
self.tovidDenoise = ""
def OnIdle( self, evt ):
if self.process is not None:
stream = self.process.GetInputStream()
if stream.CanRead():
text = stream.read()
self.logWindow.AppendText( text )
def OnProcessEnded( self, evt ):
stream = self.process.GetInputStream()
if stream.CanRead():
text = stream.read()
self.logWindow.AppendText( text )
self.process.Destroy()
self.process = None
self.btnEncode.SetLabel( "Encode!" )
self.SetStatusText( "Encoding finished" )
TovidGUI = wxPySimpleApp()
frame = TovidFrame(None, -1, "tovid GUI")
TovidGUI.MainLoop()
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.