Attila Oláh

SRE @ Google Zürich

  • 22 Jan 2011

    Merging mkv files

    A while ago I was looking for a way to merge two separate .mkv files (left and right views of a stereoscopic, 3D movie) into one file, to get a side-by-side or top-bottom view. Since back then I didn’t get any answer on SuperUser I’ve got an answer, I figured I might just look into it myself, google it, read a few man pages, and then write it down for the rest of the world.

    I’m not encouraging anyone to download pirated films. But, if you do have the movies, and they are in separate files, but you want to watch them on a 3DTV or a PS3 that can only play side-by-side, single-file 3D movies, you’ll end up merging your files.

    If you just want to know how to merge these files using the GUI, I’m not going to write it down here, as there exists a very detailed tutorial about this over at Ameic.net. Go read that if you want to do this using the GUI.

    If you’d rather do it in the command line though (which would allow you to create a batch to process all your movies later, nice the process while you’re working on the computer, and ler it rock while you’re away), read on.

    Here’s what you’re going to need:

    • mkvtoolnix
    • ffmpeg
    • avisynth

    mkvtoolnix is a free, open source tool. In Gentoo, you can get it from Portage. ffmpeg is also available for Gentoo. You can find out more about Avisynth on their home page.

    $ sudo emerge -at mkvtoolnix

    Note that if you build it yourself, there’s also an --enable-qt option, but for some reason a qt use flag does not exist in the ebuild. Also, I don’t build ffmpeg here as I already have that on my system.

    Next thing you’ll need to do is extract the audio you want. Use eac3to to do so:

    $ eac3to video-left.mkv sound.ac3

    Update 1

    As Marcin mentioned, you can extract the autio simply using ffmpeg, you don’t need eac3to:

    $ ffmpeg -i video-left.mkv -acodec copy audio.ac3

    Next thing you’re going to do is extract the video streams of both left and right files, and convert them to side-by-side view. To do so, you’ll need to generate an .avs file that looks like this:

    videol=DirectShowSource("/path/to/video-left.mkv")
    videor=DirectShowSource("/path/to/video-right.mkv")
    video=StackHorizontal(videol, videor)
    BicubicResize(video, 1920, 1080)

    Name this file convert.avs, then process it with ffmpeg like this:

    $ ffmpeg -i convert.avs -vcodec libx264 -b 7500000 -bt 7500000 -y video-sbs.h264

    Now merge the audio and the video:

    $ mkvmerge -o result.mkv --default-duration 0:24000/1001fps video-sbs.h264 audio.ac3

    The resulting result.mkv file can now be played on a 3DTV or a PS3. You can now remove the temporary files:

    $ rm sound.ac3 video-sbs.mkv convert.avs

    Update 2

    I’ve just got an answer on SuperUser. In short, here’s how no do it with GStreamer:

    $ gst-launch-0.10 \
        filesrc location=MVI_0735L.MOV ! decodebin2 name=Left \
        filesrc location=MVI_0735R.MOV ! decodebin2 name=Right \
        Left.  ! videoscale ! ffmpegcolorspace ! video/x-raw-yuv, width=1280, \
                 height=720 ! videobox border-alpha=0 right=-1280 ! queue ! mix. \
        Right. ! videoscale ! ffmpegcolorspace ! video/x-raw-yuv, width=1280, \
                 height=720 ! videobox border-alpha=0 left=-1280 ! queue ! mix. \
        Left.  ! decodebin2 ! audioconvert ! audiopanorama panorama=-1.00 ! \
                 queue ! addaudio. \
        Right. ! decodebin2 ! audioconvert ! audiopanorama panorama=1.00 ! \
                 queue ! addaudio. \
        adder name=addaudio ! faac ! avmux. \
        videomixer name=mix ! ffmpegcolorspace ! x264enc ! \
        avimux name=avmux ! progressreport name="Encoding Progress" ! \
        filesink location=out.avi
    • programming
  • 04 Dec 2010

    Two simple widgets for awesome

    The two widgets next to the system tray:

    Awesome WM widgets Awesome WM widgets

    Battery monitor

    This one is pretty simple, based on this wiki page: (requires acpitools):

    The nice thing about it is that it changes its color dynamically (and linearly). 0% battery = #FF0000, 100% = #00FF00.

    CPU temperature monitor

    Based on the same code, looks very similar to the battery widget:

    Update

    I’ve updated the temperature monitor to work without acpitool. Now instead of relying on legacy files in /proc/, it uses the new ACPI interface provided by /sys/ files.

    I have also replaced the battery monitor with the gnome-power-manager applet, as it is more powerful and consumes less on-screan real estate. Start it from your rc.lua like this:

    awful.util.spawn("gnome-power-manager")
    • programming
    Source
  • 21 Nov 2010

    2010 Neoplanta Sprint

    Today is the first day of the 2010 Neoplanta Sprint, Serbia. Now I’m not really an expert in Plone, but I have had some experience with Zope 3 BlueBream, and since the sprint is taking place in my favourite city, I decided to take part.

    The event is taking place at Hotel Putnik, in the city centre. I’m arriving today afternoon, about 5pm. Looking forward to meet new people.

    Novi Sad at night View from Petrovaradin Fortress at night. Picture: EESTEC.

    Petrovaradin Fortress at night Petrovaradin Fortress at night. Picture: me.

    • programming,
    • travel
  • 18 Nov 2010

    Steven Johnson on ideas

    I saw this video today about where innovation and good ideas come from.

    • videos
    Source
  • 08 Aug 2010

    Benchmarking urllib2 vs. urllib3

    urllib3 seems to be a long-abandoned project on PyPI. However, it has some features (like re-using connections, aka HTTP Keep-Alive) that are not present in the Python 2 version of urllib and urllib2. Another package that provides HTTP Keep-Alive is httplib2.

    Benchmark results on a single host

    Keep-Alive can significantly speed up your scraper or API client if you’re connecting to a single host, or a small set of hosts. This example shows the times spent downloading random pages from a single host, using both urllib2 and urllib3:

    urllib-benchmark-results.png

    urllib2 vs. urllib3 benchmark results urllib2 vs. urllib3 benchmark results

    The benchmark script

    Here’s a script that will benchmark urllib2 and urllib3 for the domain theoatmeal.con, and write out the results to a CSV files (easy to importy to Google Docs Spreadsheet and generate a nice chart).

    If you run it, it will also prent the result summary, something like this:

    Starting urllib2/urllib3 benchmark...
     * crawling: https://theoatmeal.com/
     * crawling: https://theoatmeal.com/comics/party_gorilla
     * crawling: https://theoatmeal.com/comics/slinky
     * crawling: https://theoatmeal.com/blog/floss
     ...
    Finishing benchmark, writing results to file `results.cvs`
    Total times:
     * urllib2: 183.593553543
     * urllib3: 95.9748189449
    

    As you can see, urllib3 appears to be twice as fast as urllib2.

    • programming
    Source
  • 07 Aug 2010

    Writing your own DOM ready listener

    Today I asked a question on StackOverflow on how to attach a function to the browser’s DOM ready event, in a cross-browser way, but without exporting any globals (keeping everything in an anonymous function’s closure) and without including any external file. As a result, with some help of a friendly StackOverflow user, I put together a code snippet that:

    • takes a single function as argument,
    • attaches that function to the DOM ready event in all browsers supported by jQuery,
    • is idempotent (will never fire the given function twice),
    • does not export any globals,
    • compiles down to less than 590 bytes (less than 300 bytes gzipped),
    • is based on the jQuery source code (I take no credit for it).

    I take no credit for writing this script. If you want to use it, please include jQuery’s license comment.

    Update

    Here is a CoffeeScript version:

    • programming
    Source
Previous
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
Next
Attila Oláh //
[email protected]