Tag Archives: Linux

Reclaiming disk space from TIF files*

Okay. So it’s disk cleanup time. Over the years I’ve accumulated a fair amount of images, not all of them have been saved with compression – which vastly reduces their file size. When I say compression, I mean lossless compression. (think zip files)

In my case I’m looking at TIF and SGI files. Many time Flame operators forget to click the ‘compression’ button when they save out these formats due mostly to ignorance. What they don’t realize is that it’s loss-less compression. I digress.

So let’s reclaim disk space! Here is one stab at it using a bash script. Requires imagemagick. This will recursively descend from the current working directory.

*this code could be modified to deal with SGI’s, or targa (TGA) files. Make sure to check that convert’s -compress option is valid for those types!

#!/bin/bash

tifs=$(mktemp)
utifs=$(mktemp)
utifsizes=$(mktemp)

echo "Finding TIF files... (Please wait) > $tifs"
find . -iname "*.tif" -exec du {} \; > $tifs

echo -n "Disk usage of tif files "
awk 'BEGIN { sum = 0 } {sum = sum + $1} END {print sum " MB"}' $tifs

echo "Finding uncompressed TIF files... (Please wait) > $utifs"
cut -f2- $tifs | while read line ; do
identify -quiet -format "image-compression %C %d/%f" "$line" | grep None >> $utifs
done

echo -n "Number of uncompressed TIF files... "
count=$(wc -l $utifs | cut -d' ' -f1)
echo $count

if [ "$count" -ne "0" ] ; then

echo -n "Computing disk space used by uncompressed TIF files... > $utifsizes"
cut -f2- $tifs | while read line ; do
du -m "$line" >> $utifsizes
done
awk 'BEGIN { sum = 0 } {sum = sum + $1} END {print sum " MB"}' $utifsizes

echo "Compressing TIF files... (Please wait) "
cut -d' ' -f3- $utifs | while read line ; do
echo convert -compress lzw \""$line"\" \""$line"\"
convert -quiet -compress lzw "$line" "$line"
done

fi

My 2011 Visual Effects Demo Reel

I present my 2011 VFX Demo Reel with all new content.
Pinkreel 2011. 113MB. HD720p. 24fps. 3:03. H.264. Help from many. Music by Plaid.
High resolution version of the above picutre.
It’s been a few years since my 2007 demo reel, I hope you enjoy it.

You can find a detailed list of my responsibilities for the various spots on my resume page. Plus I’m happy to discuss ‘how we did it’. That’s the fun part.

This was edited on my Debian Linux 6.0 “squeeze” distribution (64-bit) with Kdenlive. I used Quicktime compressed with JPEG maximum quality for the intermediate codec from original source material. Running on an Intel Core i7 CPU. The playback was pretty amazing. This is why I donate to free and open source software and you should to.

Bash manipulation on sequences.

I’m going to come at you today with a very common situation. Renaming a series of files, bash and GNU utils style. This applies to something as trivial as importing my camera photos which typically gives me a bunch of files named IMG_2042.JPG, IMG_2043.JPG, IMG_2044.JPG and so on. I’m here to show you how to deal with that.

We’re gonna tackle this ground up. Firstly, I need a way to increment a number. seq is our tool.

seq -f %04g 1 3
0001
0002
0003

Sexy huh? We’ve already have a major building block right here. Let’s dissect this quickly. The ‘-f’ tells seq that we want a specially formatted list of numbers. In our case, zero padded numbers, at least 4 wide (%04). The letter ‘g’ gets replaced the current number in the following range (1 thru 3 in our case). If you don’t have padded numbers you can omit the use of ‘-f %04g’ altogether. The last two arguments are the range to start and end.

seq 1 3
1
2
3

Sweet, now we have way of representing pretty much any sequence of numbers, thanks seq! Now let’s tackle looping over this sequence of numbers and use them for renaming using a simple ‘for’ loop. In our case below the letter ‘n’ will get the results of the seq command.


for n in $(seq -f %04g 2042 2044) ; do mv IMG_$n.JPG utah.$n.jpg ; done
`IMG_2042.JPG' -> `utah.2042.jpg'
`IMG_2043.JPG' -> `utah.2043.jpg'
`IMG_2044.JPG' -> `utah.2044.jpg'

That one-liner is so unbelievably flexible (replace `mv’ with `cp’ or `ln’ for instance) it will probably be your number one oft used idiom while working with bash in production. As a matter of fact, pretty much every thing I do is looping over a list of things – yum, sounds lispy.

I’ve always found this to be a great (re)read. In the beginning was the command line. It’s a zip archive, with an ol’ fashioned text file for you to read authored by Neal Stephenson.