You are not logged in.

#1 2007-07-10 10:42:30

MAC!EK
Member
Registered: 2005-09-27
Posts: 267

Movie from ram

I wrote a little script which plays copies movie into RAM and plays it from.

Requirements:
- packages:
       mplayer
       bar(optional, can be replaced by normal cp command, bar is used only to show progress of coping to RAMfs)

Preparation (replace "USER" with the username which will play the movie):
1. A line in fstab is needed:

none                   /mnt/ramfs  ramfs     noauto,user,maxsize=705000          0      0

(size of the ram filesystem is set in maxsize, it would be the maximum file size of a move which you can play)
2. Use visudo to add privilages for the user playing the move:

USER ALL=NOPASSWD:/usr/bin/sdparm --command=stop /dev/sda
USER ALL=NOPASSWD:/bin/chown USER /mnt/ramfs

3. Create a file and paste the source (for example to file mplayerRamFs).
4. Set runnable:

chmod +x mplayerRamFs

Some pros and cons of using this script:
5. Start your favourite terminal program and run:

./mplayerRamFs movieName

(You must specify only the name of the file without the file extension. Only .avi files are supported by this script, but it's not a big problem to change it. It's made so only to support copying subtitles.)

Pro:
+ saves your laptop battery (not yet tested how much saves, but a movie about 1,5h long takes 39% of my battery, using laptop-mode and cpufreqd, I'll write how much it saved after I watch a movie today :D )

Contra:
- needs at least 1GB of RAM


Source:

#!/bin/bash

#set -x

echo Preparin to play movie from RAMfs: $1

if [ "`free -m|awk '/Mem:/ {print $2}'`" -lt "999" ]; then
        echo "Not enough RAM!"
        echo "At least 1GB is needed!"
        exit 1
fi

echo Mounting ramfs..
mount /mnt/ramfs || exit 1

echo Setting permissions...
sudo chown macieks /mnt/ramfs || exit 1

echo Copying movie to RAMfs...
bar -o /mnt/ramfs/"$1.avi" "$1.avi" || exit 1
# if you don't have bar, use cp instead:
#cp "$1.avi" /mnt/ramfs
cp "$1.txt" /mnt/ramfs 2> /dev/null

echo Running mplayer in background...
mplayer -fs -vo sdl "/mnt/ramfs/$1.avi" && umount /mnt/ramfs || umount /mnt/ramfs &

echo Waiting 30 secs to spin down the disk...
sleep 30
# Use here any other method you want (sdparm, hdparm)
sudo sdparm --command=stop /dev/sda

What do you think about this idea? Mayby someone has other better/simplier solution?


PS.
To reduce memory and disk usage, I run startx from console. In /etc/X11/xinit/xinitrc I only have twm started.
Also before starting the script it's good to stop all daemons from DAEMON list in rc.conf.
Ofcourse except acpid, cpufreqd, alsa, network, powersaved, laptop-mode (and similar).
Important is to stop syslog-ng, because it's often a reason to spin up the disk.
(I'm thinking of adding a function to stop all the daemons before playing the movie and starting them after that)

Last edited by MAC!EK (2007-07-10 11:22:05)

Offline

#2 2007-07-17 01:49:19

judfilm
Member
Registered: 2004-02-12
Posts: 229

Re: Movie from ram

Interesting idea.
Have you tried this with a full DVD, ie load each VOB in RAM as needed - assuming enough RAM?
It is possible to use tmpfs?

Offline

#3 2007-07-17 04:55:12

nikron
Member
Registered: 2007-05-15
Posts: 130

Re: Movie from ram

Doesn't it use the same amount of power since you read the entire movie into ram anyway?   Or is reading it all at once better?

Offline

#4 2007-07-17 05:13:10

kth5
Member
Registered: 2004-04-29
Posts: 657
Website

Re: Movie from ram

nikron wrote:

Doesn't it use the same amount of power since you read the entire movie into ram anyway?   Or is reading it all at once better?

Well, that depends. Power efficiency with cdrom drives is in fact a little tricky to calculate. For one you have CBR modes/speed, which means the drive spins the disc at a rate that gives a constant performance and if that matches your movie bitrate, it depends on how much loss the motor etc. produces but generally you could say this is the optimum of efficiency when playing a movie directly from cd. If you can't match it perfectly because your drive doesn't support that particular speed in CBR it's probably a better idea to copy the movie first.

With DVDs though, this has changed a little. Basicly every drive can do DVD 1x where 1x is exactly the speed necessary to play a standard DVD. It's hard to beat the efficiency here. It's probably going to turn out just the same.

Last edited by kth5 (2007-07-17 05:17:08)


I recognize that while theory and practice are, in theory, the same, they are, in practice, different. -Mark Mitchell

Offline

#5 2007-08-08 20:56:28

MAC!EK
Member
Registered: 2005-09-27
Posts: 267

Re: Movie from ram

judfilm wrote:

Interesting idea.
Have you tried this with a full DVD, ie load each VOB in RAM as needed - assuming enough RAM?
It is possible to use tmpfs?

Yes, its possible to use tmpfs.
I didn't try playing DVDs. I only have 1GB of RAM so it's impossible to do so.


EDIT:

I found an option for mplayer doing almost the same as this script:

-cache-min 99 -cache 800000

I've done a test and movie from tmpfs and this mplayer option uses the same battery amount.

So my script is useless  cool

Last edited by MAC!EK (2007-08-08 21:02:48)

Offline

Board footer

Powered by FluxBB