Category Archives: Linux Tools

Jinja to Visualize Shot Threads and Scenes

Jinja2 (docs) – a template rendering system for Python – is quite useful to visualize results in a quick and consistent way. In this post we see some images (frames of a video) which need to be presented in a repetitive structure. In case you do your research work in Matlab this is also easy since you can export your data as a mat file and load it up in Python with (follow these instructions to make it easier).

The main idea is
import jinja2
template = jinja2.Template(open("path_template").read())
data = loadmat("path_to_matfile")

In my case of working with TV series and movies, one popular problem is shot threading. TV series and movies are typically shot from multiple cameras, and are heavily edited. Reverse engineering the editing can help put together shots from the same camera, which then goes on to help tasks such as person identification (they might be the same person!).

Threaded Shots from different cameras capturing a scene

Shots from different cameras capturing a scene

Visual analysis of the threading results can be quite hard due to the massive scale of the problem (imagine 700-1000 shots per 40min episode, and 20+ such episodes in a season). In the example above, we use Jinja to generate an HTML file with tables and links to the images. We see that the shot number below the image is staggered and indicates the editing pattern (click to view larger image and actually see the numbers).

Another popular problem is to divde the video into scenes, typically defined as a set of shots at the same location with the same set of people. Again visual analysis of the scene break detection algorithm yields itself very well to a template rendering system.

Scene break detection (5 shots per row)

Scene break detection (5 shots per row)

We see a correctly inserted scene break here (yaay!) as the characters in the story have changed.

Just as a final note, Jinja can do any form of template rendering. It is not restricted to HTML. Automatically generated LaTeX and then PDF files are certainly something to try ๐Ÿ™‚


SSH and screen

I just learnt the amazing power of screen with ssh, and put it to use for my first time, so here’s a post ๐Ÿ™‚ Consider you are working on some data on a remote computer/server. You can access this server, but only intermittently. Also, you dont have the patience to keep some window open to stare at the progress of your work, but would like to visit it now and then to know how much of it is complete. Screen is the answer to your problem. The work could be from running simulations (C / C++ / other Terminal executable languages) and even can be extended to Matlab! On a console-only SSH, running matlab defaults to the terminal since it cannot open a graphical interface, and this aspect is exploited here.

The most useful feature of screen is the ability to disconnect / close the terminal, without quitting the associated programs. Further, you can reconnect to this “screen” whenever you wish. The terminology used is “detach” and “attach”. Here’s how its done.

  1. SSH to your account, wherever it is…
  2. Start a session of screen by typing: screen This will auto-generate a weird session id. This can be renamed, but details later
  3. Now, start your simulation/work in this terminal.
  4. Detach: Next, you can just close this terminal window, knowing well that your work is being carried out by the server
  5. In case you want to look at the status, firstly SSH back to the account and do a screen -ls to get a list of running screens
  6. Attach: Connect to your screen by typing screen -r <name_as_in_list>, and you are back to your work!

For more details on the usage of screen, visit this nice and short tutorial.

Sound Converter

I wanted to convert some large mp3 files to wav for processing yesterday, and here’s what I found. Its extremely good. The name is Sound Converter and is available on Ubuntu by doing just a sudo apt-get install soundconverter.

This simple tool supports MP3, WAV, OGG, FLAC and the AAC formats, which are the most commonly used audio formats. So next time you want to convert a file, and its huge enough making the use of tough, use this ๐Ÿ™‚

Thats it.. small post this one.

pdftk – The PDF ToolKit

We are all familiar with a Swiss Army Knife. Ever required something small, handy and similar for your PDF documents ?

pdftk is definitely going to be your ultimate choice. This small tool, available on all platforms can work wonders.

All the operations are described with examples on the above mentioned page, but I would just list a few commonly used ones:

  • Merge PDF Documents
  • Split PDF Pages into a New Document
  • Rotate PDF Pages or Documents
  • Apply a Background Watermark or a Foreground Stamp
  • Attach Files to PDF Pages or the PDF Document

etc. This is a very brief glimpse of the operations this software can perform. Installation on all OS’s seems to be very easy.

DOT – Graphviz

Graphviz is Open Source, CPL licensed, cross-platform software to generate and manipulate graphs. Graph visualization is a nice way of representing information as diagrams of abstract graphs and networks. Many important applications in software engineering, database and web design, networking, etc.

We had used one of these tools called the DOT Language or also DOTTY for generating a graph image from given code like structure.

Image of a Graph generated using DOT

Image of a Graph generated using DOT

was the image generated using the code as given below. Many a times a problem is faced wherein, one needs to show an output in the form of a graph, and drawing graphs on command line interface, can get extremely complicated.

digraph robdd{
node [shape = circle];
n4 -> n2 [label = “0” style=”dotted”];
n4 -> n3ย  [label = “1”];
n4 [label = “c”];
n2 -> n0 [label = “0” style=”dotted”];
n2 -> n1ย  [label = “1”];
n2 [label = “a”];
n3 -> n0 [label = “0” style=”dotted”];
n3 -> n1ย  [label = “1”];
n3 [label = “b”];
n0 [label = “0”];
n1 [label = “1”];

The layout engines in Graphviz are put down here and detailed user guides can be obtained for each at their documentation page

  • dot – Hierarchical drawing of directed graphs
  • neato – Force layout of undirected graphs
  • twopi – Radial layout
  • circo – Circular layout
  • fdp – Force layout of undirected graphs

Though our usage is restricted to the DOT language whose guide can be found here. The good point is that only that executable can be included (dot.exe) in your project, and it alone is sufficient to generate graphs.

Good luck with Graphs!


This Impressive has a version assigned to it. Its Impressive! – v0.10.2

Was just idling around with these Ubuntu forums the Education & Science section, and I hit upon this interesting link.

This software is written in Python, and hence will run on most operating systems. They also have a nice bundled package of python, pdftk, mplayer, gplay, etc. for Windows users so that they can directly use the tool.

For Ubuntu / Linux users, its an extract, installation of python-opengl, python-game and I guess that should be able to run it successfully.

It definitely seems like making presentations nicer, more attractive and focussed (with all those highlighters) is even more easier ๐Ÿ™‚

I am definitely going to try this out for some of the upcoming presentations.

Well… that should be it for now, more posts will come around on such interesting softwares / technologies.