1 # Main Window class for the BiaMovE application
11 import ConfigParser
as CP
13 # import all the dialog classes
14 from audiocodecdialogs
import *
15 from videofilterdialogs
import *
16 from videocodecdialogs
import *
17 from videomuxerdialogs
import *
18 from miscdialogs
import *
20 class MainWindow (Tkinter
.Frame
):
21 """The main window class of the BiaMovE application"""
22 def on_misc_options (self
):
23 """ Called when the misc options button is clicked"""
24 miscdlg
= MiscOptionsDialog (self
)
25 if miscdlg
.result
!= None:
26 self
.otherparameters
.set (miscdlg
.result
)
28 def on_videofilters (self
):
29 """Called when the video filters button is clicked"""
30 if self
.outputvideo
.get().split()[0] == "copy":
31 tkMessageBox
.showinfo ("Video filters", "You cannot apply filters when the video stream is directly copied. Change the video codec.")
33 filtersdlg
= VideoFiltersDialog (self
)
34 if filtersdlg
.result
!= None:
35 self
.videofilters
.set (filtersdlg
.result
)
37 def build_mencoder_command (self
):
38 """ To build the mencoder command """
40 # mencoder command line
41 commandlist
= ["mencoder",]
43 # dvd options (if present)
44 for item
in self
.dvdopts
.get().split():
45 commandlist
.append (item
)
48 commandlist
.append ("-of")
49 commandlist
.append (self
.outputcontainer
.get().split()[0])
51 for item
in self
.outputcontaineropts
.get().split():
52 commandlist
.append (item
)
55 commandlist
.append ("-ovc")
56 commandlist
.append (self
.outputvideo
.get().split()[0])
58 for item
in self
.videoopts
.get().split():
59 commandlist
.append (item
)
62 commandlist
.append ("-oac")
63 commandlist
.append (self
.outputaudio
.get().split()[0])
65 for item
in self
.audioopts
.get().split():
66 commandlist
.append (item
)
69 if self
.videofilters
.get().strip() != "":
70 commandlist
.append ("-vf")
71 commandlist
.append (self
.videofilters
.get().strip())
74 for item
in self
.otherparameters
.get().split():
75 commandlist
.append (item
)
78 commandlist
.append (self
.inputfile
.get())
81 commandlist
.append ("-o")
82 commandlist
.append (self
.outputfile
.get())
87 """Called when the encode button is clicked"""
88 if self
.inputfile
.get().strip() == "" or self
.outputfile
.get().strip() == "":
89 tkMessageBox
.showerror ("Cannot encode", "No input and/or output file specified")
91 commandlist
= self
.build_mencoder_command ()
93 # this line is commented out because the confirmation dialog box is not working properly
95 # if tkMessageBox.askyesno ("Confirm", "Are you sure you wish to encode (in *NIX you must have TERM environment variable set)?"):
96 if sys
.platform
.startswith ('win'):
97 po
, pi
= os
.popen2 ("cmd /K " + subprocess
.list2cmdline (commandlist
))
99 if "TERM" in os
.environ
:
100 if os
.environ
["TERM"] == "xterm":
101 term_command
= os
.environ
["TERM"] + " -hold -e " + subprocess
.list2cmdline (commandlist
)
103 term_command
= os
.environ
["TERM"] + " -e " + subprocess
.list2cmdline(commandlist
)
104 po
, pi
= os
.popen2 (term_command
)
106 tkMessageBox
.showerror ("Cannot encode", "The TERM environment variable is not set. Cannot find a suitable terminal.")
108 def on_save_profile (self
):
109 """ Called when the save profile button is clicked"""
110 profile_name
= tkSimpleDialog
.askstring ("Save profile", "Give a name for this profile")
111 if profile_name
!= None:
112 config
= CP
.SafeConfigParser ()
114 cfgfile
= os
.path
.join (os
.path
.expanduser ("~"), ".biamoverc")
116 config
.read ( cfgfile
)
117 if (config
.has_section (profile_name
)):
118 if not tkMessageBox
.askyesno ("Section exists", "This section exists. Do you wish to overwrite the settings?"):
121 config
.add_section (profile_name
)
123 config
.set (profile_name
, "ContainerFormat", self
.outputcontainer
.get())
124 config
.set (profile_name
, "VideoCodec", self
.outputvideo
.get())
125 config
.set (profile_name
, "AudioCodec", self
.outputaudio
.get())
126 config
.set (profile_name
, "ContainerParameters", self
.outputcontaineropts
.get())
127 config
.set (profile_name
, "VideoParameters", self
.videoopts
.get())
128 config
.set (profile_name
, "AudioParameters", self
.audioopts
.get())
129 config
.set (profile_name
, "VideoFilters", self
.videofilters
.get())
130 config
.set (profile_name
, "OtherParameters", self
.otherparameters
.get())
132 config
.write (file (cfgfile
, "w"))
134 def on_load_profile (self
):
135 """ Called when the load profile button is clicked"""
136 loaddlg
= ProfileLoadDialog (self
)
137 sect
= loaddlg
.result
139 config
= CP
.SafeConfigParser ()
140 cfgfile
= os
.path
.join (os
.path
.expanduser("~"), ".biamoverc")
141 config
.read (cfgfile
)
143 if (config
.has_section (sect
)):
144 self
.outputcontainer
.set (config
.get (sect
, "ContainerFormat"))
145 self
.outputvideo
.set (config
.get (sect
, "VideoCodec"))
146 self
.outputaudio
.set (config
.get (sect
, "AudioCodec"))
147 self
.outputcontaineropts
.set (config
.get (sect
, "ContainerParameters"))
148 self
.videoopts
.set (config
.get (sect
, "VideoParameters"))
149 self
.audioopts
.set (config
.get (sect
, "AudioParameters"))
150 self
.videofilters
.set (config
.get (sect
, "VideoFilters"))
151 self
.otherparameters
.set (config
.get (sect
, "OtherParameters"))
153 def on_container_options (self
):
154 """ Called when the container options button is clicked"""
155 containerfmt
= self
.outputcontainer
.get().split()[0]
156 if (containerfmt
== "lavf"):
157 lavfdlg
= LAVFMuxerDialog (self
)
158 if lavfdlg
.result
!= None:
159 self
.outputcontaineropts
.set (lavfdlg
.result
)
160 elif (containerfmt
== "mpeg"):
161 mpegdlg
= MPEGMuxerDialog (self
)
162 if mpegdlg
.result
!= None:
163 self
.outputcontaineropts
.set (mpegdlg
.result
)
165 tkMessageBox
.showinfo ("Muxer options","No options for this muxer or options not implemented yet")
166 self
.outputcontaineropts
.set ("")
168 def on_codec_video (self
):
169 """ Called when the video codec options button is clicked"""
170 videocodec
= self
.outputvideo
.get().split()[0]
171 if (videocodec
== "nuv"):
172 nuvdlg
= NUVDialog (self
)
173 if nuvdlg
.result
!= None:
174 self
.videoopts
.set (nuvdlg
.result
)
175 elif (videocodec
== "lavc"):
176 lavcdlg
= LAVCVideoDialog (self
)
177 if lavcdlg
.result
!= None:
178 self
.videoopts
.set (lavcdlg
.result
)
179 elif (videocodec
== "xvid"):
180 xviddlg
= XvidEncDialog (self
)
181 if xviddlg
.result
!= None:
182 self
.videoopts
.set (xviddlg
.result
)
183 elif (videocodec
== "x264"):
184 x264dlg
= X264EncDialog (self
)
185 if x264dlg
.result
!= None:
186 self
.videoopts
.set (x264dlg
.result
)
188 tkMessageBox
.showinfo ("Video options", "No options for this codec or options not implemented yet")
189 self
.videoopts
.set ("")
191 def on_codec_audio (self
):
192 """ Called when the audio codec options button is clicked"""
194 # if the output audio codec is lavc show the lavc codec dialog
195 audiocodec
= self
.outputaudio
.get().split()[0]
196 if (audiocodec
== "lavc"):
197 lavcdlg
= LAVCAudioDialog (self
)
198 if lavcdlg
.result
!= None:
199 self
.audioopts
.set (lavcdlg
.result
)
200 # if the output audio codec is lame show the lame codec dialog
201 elif (audiocodec
== "mp3lame"):
202 lamedlg
= LAMEDialog (self
)
203 if lamedlg
.result
!= None:
204 self
.audioopts
.set (lamedlg
.result
)
205 elif (audiocodec
== "twolame"):
206 twolamedlg
= TwolameDialog (self
)
207 if twolamedlg
.result
!= None:
208 self
.audioopts
.set (twolamedlg
.result
)
209 elif (audiocodec
== "faac"):
210 faacdlg
= FAACDialog (self
)
211 if faacdlg
.result
!= None:
212 self
.audioopts
.set (faacdlg
.result
)
214 tkMessageBox
.showinfo ("Audio options", "No options for this codec or options not implemented yet")
215 self
.audioopts
.set ("")
217 def on_input_browse (self
):
218 """Called when the input browse button is clicked"""
219 infile
= tkFileDialog
.askopenfilename ()
221 self
.inputfile
.set (infile
)
223 def on_output_browse (self
):
224 """ Called when the output browse button is clicked"""
225 outfile
= tkFileDialog
.asksaveasfilename ()
227 self
.outputfile
.set (outfile
)
229 def on_dvd_device (self
):
230 """ called when the DVD options button is clicked"""
231 dvddlg
= DVDDialog (self
)
232 if dvddlg
.result
!= None:
233 self
.inputfile
.set (dvddlg
.result
)
234 self
.dvdopts
.set (dvddlg
.result_args
)
236 def create_widgets (self
):
237 """ Called during __init__ """
238 Tkinter
.Label (self
, text
="You need Mencoder installed (compiled with appropriate codecs) for this program to function properly. This program does NOT detect which codecs are available and which are not.", fg
= "darkblue", wraplength
=600).grid(column
=0, row
=0, columnspan
=4)
240 Tkinter
.Label (self
, text
="Input file/source URL").grid (column
=0, row
=1)
242 self
.inputfile
= Tkinter
.StringVar ()
243 Tkinter
.Entry (self
, textvariable
=self
.inputfile
).grid (column
=1, row
=1)
245 Tkinter
.Button (self
, text
="browse...", command
=self
.on_input_browse
).grid (column
=2, row
=1)
247 dvdframe
= Tkinter
.Frame (self
)
249 self
.dvdopts
= Tkinter
.StringVar ()
251 Tkinter
.Button (dvdframe
, text
="DVD...", command
=self
.on_dvd_device
).pack (side
=Tkinter
.LEFT
)
252 Tkinter
.Entry (dvdframe
, textvariable
=self
.dvdopts
).pack (side
=Tkinter
.RIGHT
)
254 dvdframe
.grid (column
=3, row
=1, columnspan
=2)
256 Tkinter
.Label (self
, text
="Output file").grid (column
=0, row
=2)
258 self
.outputfile
= Tkinter
.StringVar ()
259 Tkinter
.Entry (self
, textvariable
=self
.outputfile
).grid (column
=1, row
=2)
261 Tkinter
.Button (self
, text
="browse...", command
=self
.on_output_browse
).grid (column
=2, row
=2)
263 Tkinter
.Label (self
, text
="mencoder options", fg
="darkblue").grid (column
=0, row
=3, pady
=5, columnspan
=4)
265 Tkinter
.Label (self
, text
="Output container format").grid (column
=0, row
=4)
267 self
.outputcontainer
= Tkinter
.StringVar()
268 self
.outputcontainer
.set ("avi Microsoft AVI")
269 Tkinter
.OptionMenu (self
, self
.outputcontainer
, "avi Microsoft AVI", "mpeg MPEG 1/2 stream", "lavf FFMPEG libavformat muxers", "rawvideo Raw video (only) stream", "rawaudio Raw audio (only) stream").grid (column
=1, row
=4)
271 Tkinter
.Button (self
, text
="Container options...", command
=self
.on_container_options
).grid (column
=2, row
=4)
273 self
.outputcontaineropts
= Tkinter
.StringVar ()
274 Tkinter
.Entry (self
, textvariable
=self
.outputcontaineropts
).grid (column
=3, row
=4)
276 Tkinter
.Label (self
, text
="Output video codec").grid (column
=0, row
=5)
278 self
.outputvideo
= Tkinter
.StringVar ()
279 self
.outputvideo
.set ("copy Frames copy")
280 Tkinter
.OptionMenu (self
, self
.outputvideo
, "copy Frames copy", "raw Uncompressed video", "nuv Nuppel video", "lavc FFMPEG codecs ", "xvid XviD encoding", "x264 H.264 encoding").grid (column
=1, row
=5)
282 Tkinter
.Button (self
, text
="codec options...", command
=self
.on_codec_video
).grid (column
=2, row
=5)
284 self
.videoopts
= Tkinter
.StringVar ()
285 Tkinter
.Entry (self
, textvariable
=self
.videoopts
).grid (column
=3, row
=5)
287 Tkinter
.Label (self
, text
="Output audio codec").grid (column
=0, row
=6)
289 self
.outputaudio
= Tkinter
.StringVar ()
290 self
.outputaudio
.set ("copy Frames copy")
291 Tkinter
.OptionMenu (self
, self
.outputaudio
, "copy Frames copy", "pcm Uncompressed PCM", "mp3lame MP3 using LAME", "lavc FFMPEG codecs", "twolame TwoLAME MP2", "faac FAAC AAC Audio").grid (column
=1, row
=6)
293 Tkinter
.Button (self
, text
="codec options...", command
= self
.on_codec_audio
).grid (column
=2, row
=6)
295 self
.audioopts
= Tkinter
.StringVar ()
296 Tkinter
.Entry (self
, textvariable
= self
.audioopts
).grid (column
=3, row
=6)
298 Tkinter
.Label (self
, text
="Video filters").grid (column
=0, row
=7)
299 Tkinter
.Button (self
, text
="setup filters...", command
=self
.on_videofilters
).grid (column
=1, row
=7)
301 self
.videofilters
= Tkinter
.StringVar ()
302 Tkinter
.Entry (self
, textvariable
=self
.videofilters
).grid (column
=2, row
=7)
304 Tkinter
.Label (self
, text
="Other Mencoder parameters").grid (column
=0, row
=8, pady
=10)
306 Tkinter
.Button (self
, text
="Misc Options...", command
=self
.on_misc_options
).grid (column
=1, row
=8)
308 self
.otherparameters
= Tkinter
.StringVar ()
309 Tkinter
.Entry (self
, textvariable
=self
.otherparameters
).grid (column
=2, row
=8)
311 Tkinter
.Label (self
, text
="Save/Load Profile", fg
="darkblue").grid (column
=0, row
=9, pady
=5, columnspan
=2)
313 leftframe
= Tkinter
.Frame (self
)
314 Tkinter
.Button (leftframe
, text
="Save...", command
=self
.on_save_profile
).pack (side
=Tkinter
.LEFT
)
315 Tkinter
.Button (leftframe
, text
="Load...", command
=self
.on_load_profile
).pack (side
=Tkinter
.RIGHT
)
316 leftframe
.grid (column
=0, row
=10, columnspan
=2)
318 Tkinter
.Label (self
, text
="Actions", fg
="darkblue").grid (column
=2, row
=9, pady
=5, columnspan
=2)
320 rightframe
= Tkinter
.Frame (self
)
321 Tkinter
.Button (rightframe
, text
="Encode", command
=self
.on_encode
).pack (side
=Tkinter
.LEFT
)
322 Tkinter
.Button (rightframe
, text
="Quit", command
=self
.quit
).pack (side
=Tkinter
.RIGHT
)
323 rightframe
.grid (column
=2, row
=10, columnspan
=2)
325 def __init__ (self
, master
=None):
326 Tkinter
.Frame
.__init
__ (self
, master
)
328 self
.grid (padx
=10,pady
=10)
329 self
.create_widgets ()