Instantly share code, notes, and snippets.

Embed
What would you like to do?
My 8 drive RAID array is a little weird. Throughput is decent, but latency is kinda bad. This causes World of Warcraft for mac to not be able to keep up when recording in-game video at high data rates (200+ MB/s), which of course is the only way to get large frame size *and* high frame rate :) It took me literally years to finally think of this …
#!/bin/bash
set -x
# 11/3/2013 - dre at mac dot com
# Create a ramdisk big enough for World of Warcraft (mac version only!) to
# store a few video capture files. Shortly after each file is written, copy it
# to rotational storage, delete it from the ramdisk, and then symlink it from
# rotational back to the ramdisk.
# This might sound like a silly thing to do, but this little dance works around
# a real problem. Because WoW's video capture file segment size is fixed, as
# capture rates get higher, more filesystem work is required. Eventually, the
# overhead of managing the files (creating / stating) becomes too much for my
# prosumer grade storage array, and it chokes, even though it has more than
# enough throughput to lay the bytes down in time. It's the latency of the file
# operations that seems to be the problem.
# My workflow goes like this:
# - Start the script; it creates a ramdisk and begins monitoring it
# - Fire up WoW, make sure it's set to store video files on the ramdisk.
# - Do some recording
# At this point, I do one of two things:
# 1) If the finished (compressed) video would fit on the ramdisk, it's safe to
# compress immediately.
# 2) If it wouldn't fit, or if there are many captures, rename the sub-dir in
# the ramdisk, then symlink the rotational storage directory to the same
# path that was used on the ramdisk when capturing. Now the raw files can be
# compressed like normal.
# Size of ramdisk to create (megabytes * 2048)
SIZE=16777216 # 8 GB
RAM="/Volumes/ramdisk"
DIR="wowmovies"
DEST="/Volumes/collider/wowmovies/slurp"
function checkFail {
if [ $? -eq 1 ]; then echo "Failed: ${OP}" && exit 1 ; fi
}
# If there's nothing at our ramdisk mount path, let's make something
if [ ! -d ${RAM} ]
then
# Name of new volume to host the ramdisk
VOLNAME=$(basename ${RAM})
OP="Make a ramdisk device."
DEV=$(hdiutil attach -nomount ram://${SIZE} | cut -d' ' -f1)
checkFail
OP="Install a filesystem on our ramdisk..."
diskutil erasevolume HFS+ ${VOLNAME} ${DEV}
checkFail
# Wait for notifications to ripple out before turning off spotlight
sleep 2
OP="Disable spotlight on our ramdisk."
mdutil -d ${RAM}
checkFail
fi
# Double check that our ramdisk is there before proceeding
if diskutil info ${RAM}
then
echo "ramdisk located... proceeding."
else
echo "ramdisk unavailable!"
exit 1
fi
cd ${RAM}
mkdir -p ${DIR}
cd ${DIR}
# Loop forever, monitoring the ramdisk, and moving the new files.
while true
do
find -s . \
\( -name "*wvd*" -or -name "*wav" -or -name "*wvd" \) \
-type f \
-mtime +3s | while read f
do
#nice -n 20 cp -p ${f} ${DEST}
nice -n 20 mv ${f} ${DEST}
ln -s ${DEST}/${f}
done
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment