Lazyweb question: Python video manipulation libraries?

May 6th, 2008 § 10 comments

So here’s a ques­tion for the lazy­web — I’m look­ing into doing some command-line/scripted video manip­u­la­tion and I am look­ing for point­ers to current/well-documented modules/libraries to use.

Specif­i­cally — I am look­ing to be able to stream-edit movies pro­gram­mat­i­cally for a vari­ety of for­mats (one of which is quick­time for a per­sonal project) — ide­ally 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 sim­plest use-case I can think of is build­ing a mon­tage of var­i­ous videos, for exam­ple — say I down­loaded non-flv (or flv for­mat­ted) videos of funny-baby scenes from youtube and wanted to chain them together into one big funny-baby montage.

Any­one have any links/pointers — the ones I have glanced at are:

  • VideoP­arser: Mainly just for header information/parsing
  • Flashti­cle: For flash video manip­u­la­tion — no documentation
  • PyMedia: Dated, the last update is from 2006. Does not com­pile on OS/X

Ide­ally, the library would allow stream editing/manipulation and be cross-platform. I’m will­ing to sack the xplat­form require­ment if the library is really good.

  • shred­wheat

    I’d check out the fol­low­ing (in order).
    1. pyglet, http://www.pyglet.org
    2. pyqt4.4 and it’s sup­port for phonon (release emi­nent)
    3. python gstreamer

  • jnoller

    Thanks!

  • http://www.boddie.org.uk/paul Paul Bod­die

    Only this last week­end did I con­front the issue of pro­cess­ing some video files from my cam­era where the shot was “por­trait” as opposed to the “land­scape” ori­en­ta­tion of the out­put file pro­duced by the cam­era. Despite var­i­ous ref­er­ences to MPlayer’s men­coder, the eas­i­est solu­tion proved to be GStreamer once the right syn­tax had been digested for the com­mand line tools pro­vided for that soft­ware, but there are Python bind­ings, too.

    What I ended up doing was set­ting up decod­ing from AVI, demul­ti­plex­ing the audio and video, rotat­ing the video, and con­vert­ing the audio into Ogg Vor­bis and the video into Ogg The­ora, before mul­ti­plex­ing both streams together and pro­duc­ing a .ogg file. And it was a one-liner! More details of GStreamer here:

    http://www.gstreamer.net/

    It’s avail­able in Debian/Ubuntu, although you need gstreamer-tools for the magic gst-launch and gst-inspect com­mands. Here’s the com­mand I used:

    gst-launch filesrc location=$1 ! decode­bin name=decode
    decode. ! queue ! vide­oflip method=clockwise ! ffm­peg­col­or­space ! the­o­raenc ! oggmux name=mux ! filesink location=$2
    decode. ! queue ! audio­con­vert ! vor­bisenc ! queue ! mux.

    Easy when you know how! ;-)

  • jnoller

    That com­mand line makes my eyes bleed.

  • Ross

    You prob­a­bly 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.

  • http://www.boddie.org.uk/paul Paul Bod­die

    Yes, but that’s because the com­ment was badly wrapped. ;-)

    I guess it seems a bit arcane, and I strug­gled for a while until I found someone’s com­ment on some forum about con­vert­ing 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 oper­a­tions con­nected up and you’ve got a com­plete con­ver­sion pipeline that can crunch videos in batch mode with­out hav­ing to mess around in some video edit­ing suite.

    And I have to say that it’s prob­a­bly the first video-related soft­ware I’ve ever used that actu­ally worked out of the box with­out bizarre library depen­dency issues or nasty out­put arti­facts. Hats off to the GStreamer peo­ple, I say! :-)

  • jnoller

    I’m going to try out pyglet as soon as I find a decent copy of every inter­net meme video on youtube for the last 12 months ;)

  • http://teeko.tumblr.com/ rossj

    Or you could wait for this — http://www.freenet.org.nz/dvedit/ Looks impres­sive but only at 0.2

    The sam­ple usage looks nice —

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

    # cre­ate the com­pos­ite clip which is a 5-second tran­si­tion (125 frames)
    result = CrossfadeTransition(part1, part2, 125)

  • http://aruiz.synaptia.net Alberto Ruiz

    Try the GStreamer python bind­ings. GStreamer is a cross plat­form full fea­tured media frame­work based on GLib and GOb­ject (the Gtk+ object frame­work) and it has a high qual­ity bind­ing set.

  • http://aruiz.synaptia.net Alberto Ruiz

    Try the GStreamer python bind­ings. GStreamer is a cross plat­form full fea­tured media frame­work based on GLib and GOb­ject (the Gtk+ object frame­work) and it has a high qual­ity bind­ing set.

What's this?

You are currently reading Lazyweb question: Python video manipulation libraries? at jessenoller.com.

meta