Blog |Follow Nick on Twitter| About
 

I got a new computer, w00t! My family like to use the point-and-click camera for adhoc videos whilst we're out and about, the thing is it's very old and records in a rubbish AVI format which consumes massive amounts of disk space, b000!

After a bit of googling I wrote the below, it'll search through your disk and find AVI files, check that the file extension is .AVI and then convert it to .mp4; for bonus points it'll change the timestamp of the mp4 to match the avi so that it'll import into iPhoto albums nicely.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#!/bin.bash
export IFS=$'\n'
for i in $(find ./ -type f -name '*.AVI') 
    do 
        if [ ${i: -4} == ".AVI" ]
            then
            echo "Converting $i"
            ffmpeg -i "$i" -s 480x320 -aspect 4:3 -b 768k -ab 64k -ar 22050 -r 30000/1001 "${i%.AVI}.mp4"
            sleep 5
            TSTAMP=`gls -l --time-style=+%Y%m%d%H%m "$i" | awk '{print $6}'`
            touch -mt $TSTAMP "${i%.AVI}.mp4"
            sleep 5 
            rm -f "$i"
        fi
    done

Quick Note: gls is the GNU version of ls not the built in BSD-MAC version, you get it via homebrew (brew install coreutils)

 

 
Nick Bettison ©