Pure Daft

Fun linux command line tools for media

15 Mar 2009

Don’t get too excited everyone, but I’ve found some mighty useful command line tools for processing certain files in Kubuntu - pictures and film to be specific. As this is the time of the year for photos and home videos, I post them here for reference.

For images

convert input.jpg -resize 800 -font /usr/share/fonts/truetype/freefont/FreeSans.ttf -pointsize 10 -draw "gravity SouthWest fill black text 1,1 'signature' fill white text 2,2 'signature'" output.jpg

Will resize and add a signature to input.jpg.

for img in `ls *.jpg`
do
convert $img -resize 800 -font /usr/share/fonts/truetype/freefont/FreeSans.ttf -pointsize 10 -draw "gravity SouthWest fill black text 1,1 'signature' fill white text 2,2 'signature'" sd\_$img
done

Will resize and add a signature to all jpg images in a directory appending sd_ to the filename for the exported images.

For film

mencoder -ovc lavc -oac copy -vf eq2=1:1.4:0.3:1,rotate=1 input.avi -o output.avi

Will re-encode input.avi with unchanged alpha, 140% the original contrast, 30% more brightness and retain the original saturation, i.e. a:c:b:s. It will also rotate the video on to it’s right edge (90° CW).

mencoder input.avi -of rawaudio -oac mp3lame -srate 8000 -ovc copy -o output.mp3

Will extract the audio from a movie file and convert it to mp3.

mencoder -audiofile "dye scene.wav" -o ~/dye_scene.avi "dye scene.m1v" -ovc xvid -oac mp3lame -lameopts abr:br=92 -xvidencopts fixed_quant=6

Conversely, this will ‘mux’ together a video and an audio file.

ls [0-9]*.avi |
while read file
do
mencoder -oac mp3lame -ovc xvid -xvidencopts fixed_quant=5 -mc 0 -noskip "$file" -o "xvid.$file"
done

Loop through a directory, re-encoding the avi’s which begin with a number, with the xvid codec for video and mp3lame for audio.

For archives

To make a tar.gz archive:

tar czvf myfolder.tar.gz abcfolder/