Saturday, March 19, 2011

video to mp3

I had a desire to take a video file and extract the audio track into an mp3 file, so I ended up using a variant of the mp4 converter script to do the job.

[ "$1" ] || {
  echo use: $0 file...
  exit 0

for file in "$@"; do
  ffmpeg -i "$file" -acodec libmp3lame -aq 100 "$file.mp3"

This script should work on most audio or video formats and makes variable bit rate high quality mp3 files.

Wednesday, March 2, 2011

mount on plug of external disk

For the home server we got an external USB powered hard disk for the public file share. Because this disk may not be present when the computer is started up, and may change device name since it is USB attached, I desired a way to mount that specific hard disk when it was plugged in.

The answer was a fairly long but simple udev rule, and a script to do the mounting.

ATTRS{idVendor}=="0bc2", ATTRS{idProduct}=="5031", ATTRS{serial}=="NA0B3DKV", ENV{DEVTYPE}=="partition", ACTION=="add", RUN+="/usr/local/sbin/mount-storage"

mount -t vfat -o uid=nobody,gid=nogroup,dmask=000,fmask=111 \
 "$DEVNAME" /mnt/store

I found how to write the rule after referring to Writing udev rules and an example of a rule that matches the type of device.

It is still required to unmount the disk before unplugging it, as is the case with any operating system at the moment.