Monday, March 18, 2013

OLPC Video Editor: Looks like we can cut a file

(Here's what I'm doing, why I'm doing it, and why One Laptop Per Child friggin' rocks)

It has been a busy few weeks at work and with my family visiting, but I had a couple spare hours tonight to get back to this project which was suuuper sweeeeeeeeet.

Made some good progress on figuring out which technologies NOT to use for video splicing on Linux... and man are there a lot complicated solutions! I read documentation pages for about 8 different options, none of them ultimately a good choice. D'oh. After trying a few things out and not making any progress, I opted to try "oggCut" and "oggCat", and had success running this from a standalone Python script (running in my virtualized Linux environment, not on the OLPC itself yet... it'll be a while till we can get that sorted).

As I mentioned in my previous post, it may turn out to make most sense to just "cut" the video using command-line programs launched from a subprocess call from the XO activity. We know those calls are blocking, and it's not too too disk intensive so it should run fast enough without freezing the UI too badly.

I first tried trimming and splicing together a random .OGG video file I found online and it worked, which was exciting. The audio seems to be lined up too which is good, cause that can always be an issue when you splice files which contain both an audio and video stream. So that was a good first step.

Then I recorded myself talking in a couple of different quality settings from the existing OLPC Activity called "Camera", on my XO itself. It's important to test this solution with "real" video data that's actually recorded from the XO device itself, because I had roughly no idea what frame rate or encoding it uses and this oggCut/oggCat combination could have failed for the ogg files from the XO. Good news, it seems to work (or at least, in most cases). These are part of the oggvideotools and are working quite well. http://www.streamnik.de/78.html and http://en.flossmanuals.net/ogg-theora/ch052_cat-files/

Edited Ogg Video file, spliced together into a single file from 2 separate original Ogg files recoded on the XO laptop

To get this to work, I needed to install oggvideotools:
yum install oggvideotools

I believe I read that you can bundle whatever libraries you need installed with an Activity installer itself, which is good, cause oggvideotools is not available by default on the XO machines. So hopefully I can work that out when needed.

Then I called a subprocess from Python, calling out to oggCut (to slice the videos) and oggCat (to compile the sliced videos together into a final, single video).

> import subprocess
> subprocess.Popen("oggCut -i 1.ogg -s 1000 -e 5000 -o fromPython.ogg; oggCut -i 2.ogg -s 0 -e 2000 -o fromPython2.ogg; oggCat editFromPython.ogg fromPython.ogg fromPython2.ogg", shell=True)

The "s" and "e" times are in milliseconds, and specify the start and end points for the video. This generally worked, though I got an error a couple of times on one of the videos. Not sure why - perhaps I am trying to edit past the end of the video or something... so it wasn't 100% bulletproof, but it seemed to roughly work for the moment!

I also spent some time reading about GStreamer and am trying to figure out how best to playback these videos from a GTK window. I haven't used GStreamer before and was hoping their GNonLin linear video editing stuff would be straightforward but it seems like a bit of a learning curve... so it might be better just let the kids mark the start and end points in the GStreamer UI, and leave the actual editing work to the command line oggvideotools.

Anyhow! Made some progress which is good. Glad to keep this moving, and although it's been tough to make time lately to work on this, I am excited to see some progress and I think this is gonna be cool as time progresses. More updates when I get another chance to work on it.

In other news, I'm thinking of running an OLPC "Birds of a Feather" meeting at the SIGGRAPH Computer Graphics Conference in Anaheim, California in July this year. I still gotta confirm whether or not I am going to the conference, but if I am it seems like a good idea to help mobilize and excite the community of developers about what's going on and how they can contribute... sounds exciting eh? Ideally I'd like to have some interesting work to show by then on my XO at the conference... so we'll see how it all progresses. I better keep at it :) Anyway, fun times and I'm getting a chance to learn some of this crazy Linux sysadmin/build setup/installer/video editing stuff, so that's a really cool side benefit too. Good times :)

Aside: Hmm, this is interesting: https://blogs.gnome.org/edwardrv/2009/11/30/the-result-of-the-past-few-months-of-hacking/ It looks like the guys who made Pitivi, a non-linear Linux video editor (that I basically want to make a super simple, kid-friendly version of) made a library that might help you in writing applications like this. I am gonna give them a shout and see if they have some advice for me on this. Haha, hilarious quote from Edward Hervey, the writer of the GStreamer Editing Services library about why he wrote it:
"Because writing audio/video-editors is a lot of work, and we should make it as easy as possible for people to write such applications while being able to leverage the power of GStreamer and not requiring a PhD in nuclear engineering."
haha :)