# Convert Black/White footage to thermographic-like video

I am doing some really cool research lately concerning video conversion and one of the issues I ran into concerns infrared imaging. In short: all the ‘cool’ thermographic (colour is dependent on radiated temperature) images are in color, and the images you get from cheap IR cameras is black and white. How do you convert the B/W into colour?

First of all: we’re talking about two different imaging technologies: the ‘real’ thermographic cameras measure only infra-red (not visible) light, are very precise, expensive and are created by companies like FLIR. They make the cameras that you might have seen in CSI.

On the other hand, you have the cheaper webcam/IP-cam devices that have ‘night-vision’. This means that, in addition to all visible light, the cameras are also sensitive to a part of the IR spectrum, and with some additional IR-lighting, one is capable of seeing in very dark places. They produce B/W images or colour, but then sometimes they show green grass as a bit purple/pink.

What I was trying to do is convert a ‘cheap’ B/W video into the coloured thermographic equivalent, but without expecting that e.g. orange will always mean 38°-39°. Since we start from a mixed visible/IR light video, brightness does not correlate perfectly with temperature. Still, the end result might be easier to interpret.

So this is my source material: a Foscam FI8918W video from Youtube: two cats playing in a kitchen.

I find some inspiration from a guy who did something similar with ImageMagick. The dark/cold areas are supposed to be black/blue, the medium areas more green, then going to yellow, orange, red and white. This seems like a job for the FFMPEG video filter.

I use the ‘curves’ filter and try first with really strong contrast colours:

The color scheme is kind of OK, but we lose a lot of detail (the cats become hard to distinguish). So then I try a more gradual approach:

And this is rather OK. I like it. The cats come out nice.

For the record: the curves used are approximately this:

`curves=r='0.4/0 0.6/1':g='.25/1 .75/.5 .9/0 1/1':b='0/1 .25/0 .75/0 1/1'`

All scripts and parameters are on my GitHub account: https://github.com/pforret/pfor_ffmpeg/tree/master/thermography

# Create your own iPhone ring tones

I’ve had my iPhone for a week (loving it!) and of course I want to make custom ring tones for some of my contacts. I figured out how it worked from posts like create-free-iphone-ringtones-using-itunes-in-windows but I developed my own workflow:

1. Find a source file

• I typically start from an existing MP3 file. It might be a CD I have ripped to MP3, or a soundtrack from DVDs or other sound bites. I also have a collection of accapella samples that are a nice source.

2. Create the 15 – 30 sec tone in MP3 format

• You don’t need a 5 min ringtone, just 15 to 30 seconds will be enough
• I use Audacity (with the LAME MP3 encoder add-on) to load the full source MP3 file, trim out the piece I want and then add a fade-in and fade-out.

3. Export to MP3

• I then export the file to an MP3 file of 128kbps. You don’t need better quality than that anyway. If you want, you can convert the file to mono here, or it can happen in the next step
• Result: ringtone.mp3

4. Convert with ffmpeg to MPEG4 ringtone

• I prefer using the command-line ffmpeg for transcoding of audio and video.
• The simple way of doing it: `ffmpeg -i ringtone.mp3 -y ringtone.m4a` (.m4a stands for MPEG4 audio, ffmpeg will see this extension and use default settings for the conversion.) Afterwards you then have to change the extension to .m4r (MPEG4 ringtone).
• The detailed one-step-only way to do this: `ffmpeg.exe -i ringtone.mp3 -ac 1 -ab 128000 -f mp4 -acodec libfaac -y ringtone.m4r`

5. Open file with iTunes

• Just double-click the file, that should do it.

The lazy way:

let’s make a batch file that will automatically convert the first 30 seconds of any MP3 file into an iPhone ringtone:
```SET INPUT=%1 SET NAME=%INPUT:.mp3=% SET OUTPUT=%NAME%.m4r echo CONVERT %INPUT% to %OUTPUT% ... ffmpeg.exe -i %INPUT% -t 30 -ac 1 -ab 128000 -f mp4 -acodec libfaac -genre Ringtone -y %OUTPUT%```

# Screenshots of a DVD with ‘ffmpeg’

I’ve been playing around a lot with video conversion lately and one of the tools I use often is the Swiss armyknife for video manipulation ‘ffmpeg‘. It does format conversion (MPEG1/2/4, Quicktime, AVI …) , rescaling, recompressing, frame rate conversion … almost everything. It exists for all flavours of Linux/Unix, and also for Windows.

To give you an example: this is a script I wrote to extract screenshots of DVD files, straight from the disk.

1) the naive version
`ffmpeg -i [input file] -r .05 -y [output name]%%03d.png`
This does indeed extract a PNG image every 20 seconds (framerate = 0.05), but it does not take into account that the DVD image material is stored anamorphically. What you get is this:

Natalie Portman looks really thin, but that’s because the image dimensions (720×576 pixels – PAL standard) are for 5:4 aspect ratio, and whereas the actual image should be 16:9. So let’s make the image wider while keeping it the same height.

2) Rescale to 16:9
`ffmpeg -i [input file] -r .05 -s 1024x576 -y [output name]%%03d.png`
The result looks better:

As you see, there are still black borders on the top and bottom. This is because a feature film is made in ‘scope’ format, with an aspect ratio of 2.39 instead of 1.78 (the decimal equivalent of 16/9). So, while the full width of the image is used, only 428 pixels of the height are actually in use. Let’s crop those black borders off.

3) Crop black borders away
`ffmpeg -i [input file] -r .05 -croptop 74 -cropbottom 74 -s 1024x428 -y [output name]%%03d.png`

4) old 4:3 movies
The older movies used a 4:3 aspect ratio, so when you extract them as 16:9 they look like a weight feel on them:

In those cases, you can use the ‘naive’ version above, which will give you:

Here also, the actual 4:3 image is ‘letterboxed’ to the 5:4 DVD image.