Adding subtitles to a video

This is mostly a note pad for myself with quick instructions about how to add subtitles streams to an existent video.

Although I’m personally more in favor of using Ogg, reality is that Matroska is the one that is getting the biggest support among the Open Source container formats and it also has a great deal of features.

Also, because of widespread adoption, in spite of not having a really formal syntax and many features, SubRip is my chosen format for subtitles.

Now, I’m the owner of a Samsung 3D SmartTV which allows external SubRip .srt files. However, it also supports Matroska files with embedded subtitles and having the subtitles in the same container than the audio and video streams have some advantages. The main one is that I would be able to play such file through UPnP, with subtitles included, meanwhile that’s not possible with some UPnP servers if the subtitles are in a different file than the video. That’s the case, for example, with BubbleUPnP for Android, which I use from a tablet.

Anyway, enough introduction.

For creating a Matroska file from an existing video and a SubRip file I would use the MKVToolNix package. In a Debian based system you can install it with the following command:

In order to merge video and a subtitles (actually, many multiple streams), the proper command for this would be mkvmerge. Its usage is quite straight forward:

That’s basically it. With this command we will get, from a .mp4 and a .srt file, a .mkv file with both merged together. Now, if we would be wanting to add more languages we could have done something like this:

This way we would be having Spanish and English subtitles, and the former would be the default one.

For more information, just check mkvmerge’s manual.

Extract, cut, join and merge audio and video streams

This is mostly a note pad for myself with quick instructions about how to extract, cut, join and merge audio and video streams.

In Igalia we often hold meetings with several parties attending remotely. The easy setting of such meetings usually involve a shared desktop through VNC and a SIP call in a multi user room hold in our Asterisk installation.

When some of my Igalian mates cannot attend we may want to record the meeting so they can play it later. Fortunately, GNOME Shell provides integrated desktop recording out of the box and we have Asterisk set to record automatically our calls in specific multi user rooms.

So, all what it is left after a meeting is just to get both files, edit them slightly and sync them to merge them in a single multimedia container.

Usually, I would use Kdenlive in my video editing tasks. However, Kdenlive doesn’t support “video edition” without re-encoding and I would really like not to re-encode the whole stuff. Specially, the video stream. Therefore, I still will use Kdenlive for the task of syncing both streams and looking for the cutting points for both, the video and the audio file.

For most of this “without re-encoding” actions I will use the great avconv tool.

First, I will cut the video in the time 00:07:45 as starting point and 02:05:20 as ending point:

This command basically demuxes the WebM container and extract the video stream between those two points to mux it again into a Matroska container.

Then, I will cut the audio in the starting point 00:02:13 and ending point 01:59:48. For editing OGG files we can use Oggscissors or OGG Video Tools’ oggCut .

You won’t find Oggscissors in Debian (the distribution I use). Therefore, you will have to download it and install pyvorbis and pyogg and, maybe, modify slightly the script to use the proper python interpreter. You can install the missing packages like this:

Once with Oggscissors working, we can get the interesting audio chunk like:

or, with oggCut, like:

It may happen that we actually want to extract the audio from another video file. This has happened to us, eventually, when wanting to use the audio from a synced file into another video with higher quality.

We will also use avconv for this:

It may also happen that we want to join a couple of OGG files since our SIP conf-calls sometimes have hiccups. With Oggscissors this will be done as follows:

With oggCat this will be done like:

Finally, we will merge or mux the resulting video and audio files into a single media container. Again, with avconv this will be done like:

Following the examples above this will result in a Matroska video file which contains a VP8 video stream and a Vorbis audio stream.

Hope you find this useful!

Switching between nouveau and the nVIDIA proprietary OpenGL driver in (Debian) GNU/Linux

So lately I’ve been devoting my time in Igalia around the GNU/Linux graphics stack focusing, more specifically, in Mesa, the most popular open-source implementation of the OpenGL specification.

When working in Mesa and piglit, its testing suite, quite often you would like to compare the results obtained when running a specific OpenGL code with one driver or another.

In the case of nVIDIA graphic cards we have the chance of comparing the default open source driver provided by Mesa, nouveau, or the proprietary driver provided by nVIDIA. For installing the nVIDIA driver you will have to run something like:

Changing from one driver to another involves several steps so I decided to create a dirty script for helping with this.

The actions done by this script are:

  1. Instruct your X Server to use the adequate X driver.
    These instructions apply to the server only.
    When using the default nouveau driver in Debian, the server is able to configure itself automatically. However, when using the nVIDIA driver you most probably will have to instruct the proper settings to
    nVIDIA provides the package nvidia-xconfig. This package provides a tool of the same name that will generate a configuration file suitable to work with the nVIDIA X driver:

    I have embedded this generated file into the provided custom script since it is suitable for my system:

    I would recommend you to substitute this with another configuration file generated with nvidia-xconfig on your system.

  2. Select the proper GLX library.
    Fortunately, Debian provides the alternatives mechanism to select between one or the other.

  3. Black list the module we don’t want the Linux kernel to load on start up.
    Again, in Debian, the nVIDIA driver package installs the file /etc/nvidia/nvidia-blacklists-nouveau.conf that is linked, then, from /etc/modprobe.d/nvidia-blacklists-nouveau.conf instructing that the open source nouveau kernel driver for the graphic card should be avoided.
    When selecting nouveau, this script removes the soft link creating a new file which, instead of black listing nouveau’s driver, does it for the nVIDIA proprietary one:

    When selecting nVIDIA, the previous file is removed and the soft link is restored.

  4. Re-generate the image used in the inital booting.
    This will ensure that we are using the proper kernel driver from the beginning of the booting of the system:

With these actions you will be already able to switch your running graphic driver.

You will switch to nouveau with:

And to the nVIDIA proprietary driver with:

It is recommended to reboot the system although theoretically you could unload the kernel driver and restart the server. The reason is that it has been reported that unloading the nVIDIA kernel driver and loading a different one is not always working correctly.

I hope this will be helpful for your hacking time!