Lazyweb question: Python video manipulation libraries?

So here’s a question for the lazyweb - I’m looking into doing some command-line/scripted video manipulation and I am looking for pointers to current/well-documented modules/libraries to use.

Specifically - I am looking to be able to stream-edit movies programmatically for a variety of formats (one of which is quicktime for a personal project) - ideally I would be able to load the video file and edit the stream (insert bit from other videos, append videos, etc) inside of Python.

The simplest use-case I can think of is building a montage of various videos, for example - say I downloaded non-flv (or flv formatted) videos of funny-baby scenes from youtube and wanted to chain them together into one big funny-baby montage.

Anyone have any links/pointers - the ones I have glanced at are:

  • VideoParser: Mainly just for header information/parsing
  • Flashticle: For flash video manipulation - no documentation
  • PyMedia: Dated, the last update is from 2006. Does not compile on OS/X

Ideally, the library would allow stream editing/manipulation and be cross-platform. I’m willing to sack the xplatform requirement if the library is really good.

  • shredwheat
    I'd check out the following (in order).
    1. pyglet, http://www.pyglet.org
    2. pyqt4.4 and it's support for phonon (release eminent)
    3. python gstreamer
  • Thanks!
  • Only this last weekend did I confront the issue of processing some video files from my camera where the shot was "portrait" as opposed to the "landscape" orientation of the output file produced by the camera. Despite various references to MPlayer's mencoder, the easiest solution proved to be GStreamer once the right syntax had been digested for the command line tools provided for that software, but there are Python bindings, too.

    What I ended up doing was setting up decoding from AVI, demultiplexing the audio and video, rotating the video, and converting the audio into Ogg Vorbis and the video into Ogg Theora, before multiplexing both streams together and producing a .ogg file. And it was a one-liner! More details of GStreamer here:

    http://www.gstreamer.net/

    It's available in Debian/Ubuntu, although you need gstreamer-tools for the magic gst-launch and gst-inspect commands. Here's the command I used:

    gst-launch filesrc location=$1 ! decodebin name=decode \
    decode. ! queue ! videoflip method=clockwise ! ffmpegcolorspace ! theoraenc ! oggmux name=mux ! filesink location=$2 \
    decode. ! queue ! audioconvert ! vorbisenc ! queue ! mux.

    Easy when you know how! ;-)
  • That command line makes my eyes bleed.
  • Yes, but that's because the comment was badly wrapped. ;-)

    I guess it seems a bit arcane, and I struggled for a while until I found someone's comment on some forum about converting both the sound and the images at the same time (which was the really tricky bit), but I think that it's potent stuff: a few UNIX-like operations connected up and you've got a complete conversion pipeline that can crunch videos in batch mode without having to mess around in some video editing suite.

    And I have to say that it's probably the first video-related software I've ever used that actually worked out of the box without bizarre library dependency issues or nasty output artifacts. Hats off to the GStreamer people, I say! :-)
  • Ross
    You probably want Pyglet 1.1 and the pyglet.media.StreamingSource's get_next_video_frame() might help you out, but I've no idea about the audio - sorry.
  • I'm going to try out pyglet as soon as I find a decent copy of every internet meme video on youtube for the last 12 months ;)
  • Or you could wait for this - http://www.freenet.org.nz/dvedit/ Looks impressive but only at 0.2

    The sample usage looks nice -

    clip = File("myrawclip.vob")
    part1 = clip[:1125] # first 45 secs (1125 frames @ 25fps)
    part2 = clip[3250:3750] # 20 secs, starting at 2mins10

    # create the composite clip which is a 5-second transition (125 frames)
    result = CrossfadeTransition(part1, part2, 125)
  • Try the GStreamer python bindings. GStreamer is a cross platform full featured media framework based on GLib and GObject (the Gtk+ object framework) and it has a high quality binding set.
blog comments powered by Disqus