LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories
User Name
Password
LinuxQuestions.org Member Success Stories Just 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


Reply
  Search this Thread
Old 07-04-2004, 08:37 PM   #1
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
tovid DVD/VCD video converter GUI


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()
 
Old 07-06-2004, 02:26 PM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Original Poster
Rep: Reputation: 48
Sourceforge has accepted this project, and I've posted a webpage and a tarball containing the scripts:

Tovid homepage
Tovid project summary page

Check it out, and please feel free to contribute patches!
 
Old 07-06-2004, 02:27 PM   #3
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Nice one Wapcaplet
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Video Converter? gauge73 Linux - Software 13 01-21-2009 08:20 PM
Video Converter in Linux kaon Linux - Software 6 01-21-2009 02:12 AM
DISCUSSION: Converting video to VCD, SVCD, or DVD wapcaplet LinuxAnswers Discussion 665 12-29-2005 02:02 AM
Linux version to play dvd, vcd only preferrably without gui to save battery btcore Linux - Newbie 8 12-05-2005 02:08 AM
Encoding video for VCD and DVD wapcaplet LinuxQuestions.org Member Success Stories 3 08-01-2004 01:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories

All times are GMT -5. The time now is 07:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration