Edited the first post. Fixed the bug where mencoder freezes when the movie is ended prematurely, however this comes at the disadvantage of having to run killall -9 mencoder after the playback is finished, which may kill other mencoder processes the user has running. There has to be a better solution here, but I don't know what it is. Also made sure the script always cleans up after itself and adjusted the cache settings since the cache was a bit too small for high intensity scenes when the wifi network couldn't provide the data fast enough (but was still able to provide more than enough in the low intensity scene to fill up the cache in the mean time).