Category Archives: Linux

Convert MPEG-2 files to MPEG-4

Image result for Canon XF-105
Canon XF105

This is a note to self, and could potentially also be useful to others in need of converting “old-school” MPEG-2 files into more modern MPEG-4 files using FFmpeg.

In the fourMs lab we have a bunch of Canon XF105 video cameras that record .MXF files with MPEG-2 compression. This is not a very useful format for other things we are doing, so I often have to recompress them to something else.

Inspecting one of the files, I just also discovered that they record the audio onto two mono channels:

Stream #0:0: Video: mpeg2video (4:2:2), yuv422p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], 50000 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc

Stream #0:1: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s

Stream #0:2: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s

So I also want to merge these two mono tracks (which are the left and right inputs of the camera) to a stereo track. FFmpeg comes in handy (as always), and I figured out that this little one-liner will do the trick:

ffmpeg -i input.mxf -vf yadif -vcodec libx264 -q:v 3 -filter_complex "[0:a:0][0:a:1]amerge,channelmap=channel_layout=stereo[st]" -map 0:v -map "[st]" output.mp4

An explanation of some of these settings:

  • yadif: this is for deinterlacing the video
  • libx264: this is probably unnecessary, but forces to use the better MPEG-4 compressor
  • q:v 3: I find this to be a good setting for the video compressor
  • filter_complex: this complex string (courtesy of reddit) does the merging of the two mono sources

Will probably try to add it to MGT-terminal at some point, but this blog post will suffice for now.

Creating individual image files from presentation slides

How do you create full-screen images from each of the slides of a Google Docs presentation without too much manual work? For the previous blog post on my Munin keynote, I wanted to include some pictures from my 90-slide presentation. There is probably a point and click solution to this problem, but it is even more fun to use some command line tools to help out. These commands have been tested on Ubuntu 19.10, but should probably work on many other systems as well, as long as you have installed pdfseparate and convert.

After exporting a PDF from the Google Presentation, I made a separate PDF file of each slide using this command:

pdfseparate input.pdf output%d.pdf

This creates a bunch of PDF files with a running number. Then I ran this little for loop:

for i in *.pdf; do name=`echo $i | cut -d'.' -f1`; convert -density 200 "$i" "$name.png"; done

And voila, then I had nice PNG files of all my slides. I found that the trick is to use the “-density 200” setting (choose the density that suit your needs), since the default resolution and quality is too low.

Converting MXF files to MP4 with FFmpeg

We have a bunch of Canon XF105 at RITMO, a camera that records MXF files. This is not a particularly useful file format (unless for further processing). Since many of our recordings are just for documentation purposes, we often see the need to convert to MP4. Here I present two solutions for converting MXF files to MP4, both as individual files and a combined file from a folder. These are shell scripts based on the very useful FFmpeg.

Convert individual MXF files to individual MP4 files

The first solution is based on converting a bunch of MXF files to individual MP4 files. This is practical if there are multiple, individual shots.

Save the script above as mxf2mp4.sh, make it executable, with a command like:

chmod u+x mxf2mp4.sh

and run the file:

./mxf2mp4.sh

Convert a folder of MXF files to one MP4 file

The second solution is when we have made one long recording, which is split up into individual MXF files of 1.9 GB size (the maximum size of FAT32-formatted drives) in the camera. Then the aim is to merge all of these together to one MP4 file. This script will do the trick:

Do the same as above to run the script.

Installing Ubuntu on a HP Pavilion laptop

So I decided to install Ubuntu on my daughter’s new laptop, more specifically a HP Pavilion. The choice of this particular laptop was because it looked nice, and had good specs for the money. It was first after the purchase I read all the complaints people have about the weird UEFI implementation on HP laptops. So I started the install process with some worries.

Reading on various forums, people seemed to have been doing all sorts of strange things to be able to install Ubuntu on HP laptops, including modifying the UEFI setup, changing the BIOS, and so on. I recall that on my Lenovo laptop I had to work quite a bit to turn off all the fancy auto-Windows-stuff.

I am not sure if HP has changed something recently or not, but the final procedure was super-easy: I just hit the F9 button on startup and got a normal “old-school” boot selector. Here I chose the USB drive, and the Ubuntu installer fired up.

I have installed Linux (primarily various Ubuntu versions) on a number of laptops over the years, and it is very seldom that I get into problems with drivers. Also this time things went smoothly, everything worked perfectly right after the install. I think it is important to continue repeating this message, because I still hear people saying that it is tricky to get Ubuntu to play with different hardware. True, there used to be driver issues some years ago, but personally I haven’t experienced that in five years or so.

Which Linux version to choose for a 9-year old?

My 9-year old daughter is getting her first laptop. But which OS should she get started with?

I have been using various versions of Ubuntu as my main OS for around 5 years now, currently using Ubuntu Studio on my main laptop. This distro is based on XFCE, a very lightweight yet versatile OS. The reason for choosing Ubuntu Studio over the regular XUbuntu was to get a bunch of music apps by default. I haven’t been able to explore these as much as I wanted to, unfortunately, primarily due to everything happening at our new centre (RITMO) and master’s programme (MCT).

Even though I like Ubuntu Studio myself, it is not a distro I would install on my daughter’s machine. Buying a new computer with Windows 10 pre-installed, one could argue that it would be best to leave her with that. This may also help her to be more familiar with the computers they are using at school, which run Windows 7 at the moment. But the question in the store about whether I wanted to buy some antivirus-software with the new laptop, was enough to ensure me that a Linux distro would be a better choice.

I have heard that some people like distros such as Edubuntu for kids, but it does not seem to be maintained? After thinking about it for a little while, I have concluded that it is probably useful for a kid to learn to use a normal OS. If you compare how things were a decade or two ago, most modern-day OSes are comparably easy to use anyways.

Finally I decided to make it simple, and installed the regular Ubuntu distro based on GNOME. It looks “modern”, has large icons, and is fairly easy to navigate due to the streamlining of menus, and so on.