Filter by topic: spe, python, ubuntu

Monday, March 31, 2008

How to write a wxPython video player with Gstreamer

wxPython ships by default with the wx.MediaCtrl for very basic playback of music or videos. As I would like to do more advanced video manipulation, I was curious if I could use Gstreamer directly in wxPython to create my own pipelines. It was surprisingly easy.
For those who don't know Gstreamer, I quote the website (http://www.gstreamer.org):

GStreamer is a library that allows the construction of graphs of media-handling components, ranging from simple playback to complex audio (mixing) and video (non-linear editing) processing. Applications can take advantage of advances in codec and filter technology transparently.


There are python bindings for it, of which the documentation can be found on http://pygstdocs.berlios.de
I would also suggest to read these introductions to gstreamer & python:

I translated the video player example 2.2 of the tutorial from pyGtk to wxPython:
http://pygstdocs.berlios.de/pygst-tutorial/playbin.html

It should be straightforward to use this as a base for implementing your own pipelines. I work on Ubuntu, where I could install everything straight from the standard repositories.

Here is the source code:
#!/usr/bin/env python
#Example 2.2 http://pygstdocs.berlios.de/pygst-tutorial/playbin.html

import sys, os
import wx
import pygst
pygst.require("0.10")
import gst

import gobject
gobject.threads_init()

class WX_Main(wx.App):

def OnInit(self):
window = wx.Frame(None)
window.SetTitle("Video-Player")
window.SetSize((500, 400))
window.Bind(wx.EVT_CLOSE,self.destroy)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
self.entry = wx.TextCtrl(window)
hbox.Add(self.entry, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)
self.button = wx.Button(window,label="Start")
hbox.Add(self.button, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 4)
self.button.Bind(wx.EVT_BUTTON, self.start_stop)
vbox.Add(hbox, 0, wx.EXPAND, 0)
self.movie_window = wx.Panel(window)
vbox.Add(self.movie_window,1,wx.ALL|wx.EXPAND,4)
window.SetSizer(vbox)
window.Layout()
window.Show()
self.SetTopWindow(window)

self.player = gst.element_factory_make("playbin", "player")
bus = self.player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect('message', self.on_message)
bus.connect('sync-message::element', self.on_sync_message)

return True

def start_stop(self, event):
if self.button.GetLabel() == "Start":
filepath = self.entry.GetValue()
if os.path.exists(filepath):
self.button.SetLabel("Stop")
self.player.set_property('uri',"file://" + filepath)
self.player.set_state(gst.STATE_PLAYING)
else:
self.player.set_state(gst.STATE_NULL)
self.button.SetLabel("Start")

def on_message(self, bus, message):
t = message.type
if t == gst.MESSAGE_EOS:
self.player.set_state(gst.STATE_NULL)
self.button.SetLabel("Start")
elif t == gst.MESSAGE_ERROR:
self.player.set_state(gst.STATE_NULL)
self.button.SetLabel("Start")

def on_sync_message(self, bus, message):
if message.structure is None:
return
message_name = message.structure.get_name()
if message_name == 'prepare-xwindow-id':
imagesink = message.src
imagesink.set_property('force-aspect-ratio', True)
imagesink.set_xwindow_id(self.movie_window.GetHandle())

def destroy(self,event):
#Stop the player pipeline to prevent a X Window System error
self.player.set_state(gst.STATE_NULL)
event.Skip()

app = WX_Main()
app.MainLoop()

Tuesday, March 25, 2008

SPE packaged for Mac OS X

Krzysztof Olczyk did a wonderful job by packaging SPE for Mac OS X. You can download it here:
http://olczyk.krzysztof.googlepages.com/SPE.dmg

He commented:

You can install now SPE in your Macintosh in a way you do with native applcation.
Simply mount the DMG and drag the SPE to Applications folder.

Another advantage is, that now SPE will have its own icon in dock, like any application in Mac.

Have fun.

I will release soon SPE 0.8.4.e with some important bug fixes and I hope Krzysztof Olczyk will update the package for the Mac.

Please test the package and let Krystof know how it works.

Thanks Krystof!
Stani

Thursday, February 14, 2008

SPE 0.8.4.c Python IDE editor released

As SPE was being developed for more than a year in subversion, I thought it is time for a release again. This is a major bugfix release. It ships updated plugins and also some new features, especially if you use Linux or Blender, for which Witold did a great job. Thanks to the big help of MOTU pochu, this is added to Ubuntu Hardy. I would also like to thank in particular the webhost Zindep.com for their support and patience.

New features:

  • new versions of WinPdb debugger, PyChecker, wxGlade & XRCed gui designer
  • clear output pane
  • support for wxPython 2.8
  • linux support for nautilus, gnome-terminal, konqueror, konsole, thunar
  • improved blender support up to 2.45 (by Witold)
Fixes:
  • sidebar sash more tolerant
  • show path in title (linux)
  • run with filename with spaces
  • nicer debug dialog box
  • kill process fix
  • notebook
  • insert signature
  • numpad keys (by isolationism)
  • find tab with nonexisting files
  • add environment to SPE.py (linux)
  • better warning for documentation for unsaved files
  • better handling of new empty files
  • many more...
Installing on Debian(unstable) and Ubuntu Hardy:
sudo apt-get install spe
Installing on all other platforms:
  1. Download either the zip or tar ball from here
  2. Unzip it where you want and do NOT rename the _spe folder
  3. Start SPE from within the _spe folder with "python SPE.py"

Wednesday, February 6, 2008

Howto install sK1, a powerful alternative for Illustrator on Ubuntu

This post is deprecated as sk1 now has an official ubuntu installer:
http://sk1project.org/modules.php?na...ts&product=sk1

So this is for archival purposes only:

Igor, the icon king of Phatch, asked me if I could get sk1 to work on Ubuntu Gutsy. After playing around I found a way. Try this on your own risk.

I never heard about sk1 and looked it up on the website:
http://sk1project.org/

Why sk1project?

We think that sK1 is a powerful illustration program for the Linux platform that can substitute professional proprietary software like CorelDRAW or Adobe Illustrator and we hope the program and its derivatives will be helpful for you.

About sK1 vector graphics editor

sK1 is an open source vector graphics editor similar to CorelDRAW, Adobe Illustrator, or Freehand.
First of all sK1 is oriented for PostScript processing.
The major sK1 features:

* CMYK colorspace support
* CMYK support in Postscript
* Cairo-based engine
* Color managment
* Universal CDR importer (7-X3 versions)
* Modern Ttk based (former Tile widgets) user interface
It looks quite impressive and in five steps you can have it up and running on your Ubuntu Gutsy. It is a KDE application.

1) Installing required modules
Type this at a terminal:
sudo apt-get install liblcms-utils python-liblcms python-imaging-tk kdebase-bin
2) Installing tcl/tk8.5
Download the tk8.5 and tcl8.5 packages of Gustavo A. Díaz for the amsn project:
http://download.tuxfamily.org/amsnskins/packages/ubuntu/tcl-tk/

Open and install these files in this order with gdebi:
tcl8.5_8.5.0-2_i386.deb
tk8.5_8.5.0-2_i386.deb

3) Installing sk1
Now download the latest version of sk1 from:
http://sk1project.org/modules.php?name=Products&product=sk1

And convert it to a debian installer:
sudo alien sK1-0.9.0-rev324-0.mdv2008.i586.rpm
4) Patching sk1
We need to patch this file:
sudo gedit /usr/lib/python2.5/site-packages/sk1/app/managers/colormanager.py

Replace there on line 9:
from lcms import (...)
into
from lcms.lcms import (...)
5) Start sk1
Press Alt+F2 and type "sk1" at the terminal and sk1 is up and running! You can create a menu entry with alacarta or a desktop launcher with the command "sk1". I have not tested how well it works.

This is a screenshot, turned into perspective with Phatch:

Wednesday, January 16, 2008

Latest wxGlade, XRCed and Winpdb in subversion

So SPE is up to date again. The Winpdb debugger now features autocompletion. It is looking for a new name, as most people associate win with Windows (while winpdb is being developed on ubuntu now). The new XRCed (gui designer for wxpython) looks really slick. This is a screenshot on ubuntu:

Thursday, November 1, 2007

How to change or recreate your Desktop folder on Ubuntu

The default location of your Desktop folder is ~/Desktop. You might prefer another location. If you by accident deleted the Dekstop folder, it will be stuck in your Trash folder as you can't put it back. These two steps enable you to change or restore your desktop folder:

gedit ~/.config/user-dirs.dirs
killall nautilus
In step 1 look for this entry: XDG_DESKTOP_DIR. Make it like this: XDG_DESKTOP_DIR="$HOME/Desktop"
Instead of step 2 you might also log off and log in again.

This is only tested on Gutsy.

Wednesday, October 31, 2007

How to install pymedia on Ubuntu (Gutsy)

"Pymedia is a Python library for accessing and manipulating media files. It makes audio and video playback/creation a snap for even a newcomer to programming." There is a deb installer available for pymedia 1.3.5 but not for 1.3.7 So I decided to write this howto.

First install all the dependencies:

sudo apt-get install python-dev libogg-dev libvorbis-dev liblame-dev libfaad2-dev libasound2-dev python-pygame
(Pygame is not really necessary, but recommended.)

Extract a download of pymedia-*.tgz and open a terminal in the extracted folder, so we can build pymedia:
python setup.py build

This should display:
Using UNIX configuration...

OGG : found
VORBIS : found
FAAD : found
MP3LAME : found
VORBISENC : found
ALSA : found
Continue building pymedia ? [Y,n]:

If everything is found press Y

Finally install pymedia:
sudo python setup.py install


Test if pymedia installed correctly by typing this at the python shell:
import pymedia


You may now proceed to the pymedia tutorials.

Monday, October 22, 2007

SPE 0.8.4.b works fine in Ubuntu Gutsy

The latest version of SPE 0.8.4.b works very well in Ubuntu Gutsy. It is available through subversion. However the repository package is outdated, as it is still on 0.8.2.a What SPE needs to solve this issue is a Debian packager with love for python. This is the related bug on launchpad, from which I quote Scott:
"Ubuntu gets this package from Debian and it appears that it's been orphaned in Debian.
(...) it'd be hugely helpful if someone concerned about spe would adopt it in Debian. There is a Debian Python Applications Team with active DD support, so you need not be a DD to do this."
If you are not a packager it would be nice if you leave your comment on the launchpad bug.
https://bugs.launchpad.net/ubuntu/+source/spe/+bug/124896
So this gets more attention and will be fixed sooner as there is more demand. If someone steps up to package this for debian, I will release a new version of SPE.

Sunday, September 2, 2007

Winpdb 1.2.2, wxGlade0.6 & XRCed 0.1.8-5...

...all landed in subversion (rev255). wxGlade and XRCed are taken from their repositories, so they might be bleeding edge. Thanks to Diaa Sami some issues on Windows are fixed (eg running files with spaces). Check out the new SPE in the usual way:

svn checkout svn://svn.berlios.de/python/spe/trunk/_spe

Friday, June 8, 2007

Latest wxGlade in SPE subversion

I've uploaded the latest wxGlade cvs into the subversion repository of SPE.