From your code it looks like you're creating a temporary file so that you can deliver a video to a specific user for a specific amount of time. This is a highly inefficient approach. You'd be better off:
- Using your database to track which users have access to which videos, and how how long
- On a request to the video page, assert that the user has the right to access that file and, if the assertion passes, generate a signed url which is valid only for a short period of time and which may be used in the video page to deliver your movie.
A signed URL would look something like:
http://path.to/your/movie.m4v?timestamp=2309583240&signature=234p9345u234234092wjdfl
Where timestamp is the current UNIX timestamp and signature is a SHA1 hash of the timestamp and some secret known only to your application.
Amazon S3 supports this feature - you could also store the movie files on Amazon S3 with limited read privileges, and use one of the many popular S3 libraries to generate time-limited signed URLs for your users.
This would obviate the need to shift large files around the disk, and thereby greatly increase performance. It would also scale better as the maximum concurrent viewers would no longer by tied to disk size.