So, those that know me well know that I play quite a few computer games. Recently, I have been recording quite a bit of the gameplay. My primary drive (C:) has Windows 7 64-bit Premium loaded on it. It is a 60GB SSD that runs really nice and fast. I pretty much only use it for the OS and my primary games. I have the majority of the games installed to (D:). It’s a 1TB Seagate drive with pretty good response times. There’s very little on this drive other than games and other large media.
Naturally, this drive (D:) was a perfect location to save recordings from my games. I have FRAPS installed to the (D:) drive and that is also where the videos get saved. What you may or may not know is that every ~2 minutes of gameplay equates to a 4GB file. The files are saved in a RAW format with no compression. One night I realized I had over 500GB of video. I began formulating the best way to regulate how much drive space was required without losing any of the videos. I settled on the idea of transferring the files to my linux box using a Scheduled Task and having a cron job on the linux box that would automatically re-encode the files with a divx codec and save the files in a MUCH smaller file.
I setup my Windows machine to Schedule a Task. See the link for a tutorial. I setup the task to execute a batch file every night at 4AM. I did restrict the scheduler to kill the process if it runs more than 12 hours and I also made sure that the scheduler does not start a new process if it is already running. So what does this batch file do? Glad you asked:
@echo off echo Moving Fraps videos to samba GameVideos folder move /Y D:\FRAPS\Movies\* M:\Downloads\GameVideos\
So basically, the batch file just moves all of my local Fraps videos off my local drive and places it into a folder on my Samba share. For clarification, my Samba share is a 12 TB (or so) share that I have setup and mounted as my (M:) drive. It is hosted by a Linux server. It currently runs Fedora 9.
Next, I setup my linux box to automatically re encode all of the videos in XVid format. After some brief googling, I opted for a 2-pass encoding. See the mencoder wiki for additional examples and command-line options. My setup might not be the best one out there. For reference, this file is located at /home/jday/bin/smallvideo.sh on my system.
#!/bin/bash ls -1 /mnt/media/Downloads/GameVideos > /tmp/parsevideolist while read myline; do mencoder "/mnt/media/Downloads/GameVideos/$myline" -ovc xvid -oac mp3lame -xvidencopts threads=7:pass=1 -o /dev/null && _ mencoder "/mnt/media/Downloads/GameVideos/$myline" -ovc xvid -oac mp3lame -xvidencopts threads=7:pass=2:bitrate=-100000 -o "/mnt/media/Downloads/GameVideos_smaller/$myline" && _ rm -f "/mnt/media/Downloads/GameVideos/$myline" done < /tmp/parsevideolist
One thing you may quickly notice is that I added an xvidencopts switch for multi-threading. I have a quad-core Intel Q6600 running hyperthreaded. This means it is capable of processing 8 threads simultaneously. I wanted to leave one core available so that the system would still be usable. The other thing you may quickly notice is the negative bitrate. This allows me to say I want to target a 100MB file for the output. mencode will calculate the bitrate accordingly.
After verifying that the shell script works as expected, it was added to my cron.daily list (I added the file /etc/cron.daily/fraps_video_shrinker and chmod’ed it to allow it to be executed). The contents of the cron file:
/home/jday/bin/smallvideo.sh >> /dev/null
Pretty simple. As an FYI, the smallvideo.sh file is the one shown above.
Now, every day at 4AM my Windows system starts moving the Fraps videos off onto my linux box. The next morning, my linux box will re-encode the video and upon successful encoding, it will delete the original.
Next Day Additions:
So, the next day after I set this all up, I am STILL processing videos. Admittedly, it’s a lot of data to encode. What I did notice is that I have over 200 video files. I also found that all of the files have less than 2 minutes of video time. I wanted to figure out a way to “tar” all of the videos together from the same day. Here’s what I came up with. I run mencoder again and have it put all files from the same day together as one AVI file. This file I have saved as /home/jday/bin/videoquilter.sh:
#!/bin/bash
viddir="/mnt/media/Downloads/GameVideos_smaller";
outdir="/mnt/media/Downloads/GameVideos_quilts";
ls -1 $viddir > /tmp/videoquiltlist
while read myline; do
this_prog=`echo "$myline" | awk '{ print $1 }'`;
this_date=`echo "$myline" | awk '{ print $2 }'`;
this_time=`echo "$myline" | awk '{ print $3 }'`;
if [ "$prev_date" = "" ]; then
## This is our first line ##
runcmd="mencoder -ovc copy -oac copy -o $outdir/$this_prog-$this_date.avi";
prev_date=$this_date
else
runcmd="$runcmd \"$viddir/$prev_line\"";
fi
echo "$myline" | awk '{ print $1" "$2" "$3 }';
if [ "$prev_date" != "$this_date" ]; then
## run the merging ##
# echo $runcmd;
bash -c "$runcmd";
# echo "";
## reset the runcmd ##
runcmd="mencoder -ovc copy -oac copy -o $outdir/$this_prog-$this_date.avi";
fi
prev_prog=$this_prog;
prev_date=$this_date;
prev_time=$this_time;
prev_line=$myline;
# echo "$myline";
done < /tmp/videoquiltlist
runcmd="$runcmd \"$viddir/$prev_line\"";
#echo $runcmd;
bash -c "$runcmd";
I have also added this file to my cron job. /etc/cron.daily/fraps_video_shrinker now looks like this:
/home/jday/bin/smallvideo.sh >> /dev/null /home/jday/bin/videoquilter.sh >> /dev/null

[...] more: Fraps and mencoder « Linux / Gaming Blog Posted in: Gaming ADD [...]