You are not logged in.
Pages: 1
I have an old PC that I use to play videos using mplayer. However, for some reason the graphics card can't handle a width resolution of more than 768 and I have a lot of hi-def videos. I currently have a .bashrc alias that converts the file and then I play it with mplayer using a second command (all over ssh of course :-P) but I would really like to have it all automated so I can type "play file.avi" and it'll convert and then play the file. Here are the commands I currently run:
mencoder [file] -ovc lavc -oac pcm -vf scale=768:432 -o [outputfile]
DISPLAY=:0 mplayer -cache 16384 -fs
Does anyone have a similar script that they can share or help me write one that does this?
Thanks
rocktorrentz
Offline
Something like this?
#!/bin/sh
extension=`echo "$1" | awk -F . '{print $NF}'`
scaled="${1%.$extension}_scaled.$extension"
if [[ -f "$scaled" ]]
then
DISPLAY=:0 mplayer -cache 16384 -fs "$scaled"
else
mencoder "$1" -ovc lavc -oac pcm -vf scale=768:432 -o "$scaled"
DISPLAY=:0 mplayer -cache 16384 -fs "$scaled"
fi
The script must be called with an argument which is the file (ie. play.sh file.avi). I haven't tried it over ssh but it seems to work locally.
EDIT: Version 2 of the script -- now if a converted file exists (from a previous run) the script will just play it without converting.
Last edited by fwojciec (2008-02-15 19:12:40)
Offline
Awesome That's exactly what I needed. I really need to learn bash or python.
Offline
Here's another version -- this one doesn't need awk -- sorry, I'm learning new things here
#!/bin/sh
extension="${1#*.}"
scaled="${1%.$extension}_scaled.$extension"
if [[ -f "$scaled" ]]
then
DISPLAY=:0 mplayer -cache 16384 -fs "$scaled"
else
mencoder "$1" -ovc lavc -oac pcm -vf scale=768:432 -o "$scaled"
DISPLAY=:0 mplayer -cache 16384 -fs "$scaled"
fi
Offline
I've modified it a bit so it saves to my home folder instead of back to my file server and removed the cache options. Thanks I'll no doubt use it as a template for future conversion scripts.
Offline
Since I'm only learning bash scripting at the moment I took this as an opportunity to experiment with some things. Here is a maxi (probably an overkill) version of the script. It allows you to specify the directory where you want the converted file saved and after playback it asks if you want to delete the converted file or not. It also allows you to specify mplayer and mencoder options to be used for conversion and playback. I'm not sure if you'll find it useful, but I'll post it anyways. If anyone has any comments or criticisms please let me know.
#!/bin/sh
# ****Configuration****
# Enter the save directory here; if there is no value here the converted file
# will be saved in the source directory. The correct format is "/aaa/bbb" --
# leave the final slash out. Other options should be self-explanatory.
SAVEDIR=""
MENCODER_OPTIONS="-ovc lavc -oac pcm -vf scale=384:216"
MPLAYER_OPTIONS="-fs -ao alsa"
# ****End of configuration****
# Other variables
EXTENSION="${1##*.}"
SCALED="${1%.$EXTENSION}_scaled.$EXTENSION"
SCALED_SAVEDIR="$SAVEDIR/`basename "$SCALED"`"
# Check if the SAVEDIR exists
if [ ! -z $SAVEDIR ] && [ ! -d "$SAVEDIR" ]
then
echo "$SAVEDIR does not exist or is not a directory. Exiting...";
exit 1
fi
# Play if converted file already exists, otherwise play after converting
if [ -z "$SAVEDIR" ]
then
if [ -f "$SCALED" ]
then
DISPLAY=:0 mplayer $MPLAYER_OPTIONS "$SCALED"
else
mencoder "$1" $MENCODER_OPTIONS -o "$SCALED"
DISPLAY=:0 mplayer $MPLAYER_OPTIONS "$SCALED"
fi
else
if [ -f "$SCALED_SAVEDIR" ]
then
DISPLAY=:0 mplayer $MPLAYER_OPTIONS "$SCALED_SAVEDIR"
else
mencoder "$1" $MENCODER_OPTIONS -o "$SCALED_SAVEDIR"
DISPLAY=:0 mplayer $MPLAYER_OPTIONS "$SCALED_SAVEDIR"
fi
fi
# After playback is done ask if the file should be deleted
while true
do
echo -n "Would you like to delete the converted file? (y or n) "
read CONFIRM
case $CONFIRM in
y|Y|YES|yes|Yes)
break
;;
n|N|no|NO|No)
echo "You entered \"$CONFIRM\" -- the converted file will not be deleted."
exit
;;
*)
echo "Please enter only y or n"
;;
esac
done
# Option to delete file was selected
echo "You entered \"$CONFIRM\" -- deleting the converted file."
if [ -z "$SAVEDIR" ]
then
rm "$SCALED"
else
rm "$SCALED_SAVEDIR"
fi
Offline
Pages: 1