Want a Bash script to open mplayer then play a file

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
steve_s
Posts: 1595
Joined: Mon 26 May 2008, 13:29
Location: Austin, TX, USA
Contact:

Want a Bash script to open mplayer then play a file

#1 Post by steve_s »

Ok, that sounds crazy in the subject 'cause all mplayer users know you can just run:

Code: Select all

mplayer
then the file name and it will run the file.

But due to the speed of my computer (what there is of it) I have given a lot of parameters to mplayer and I seem to keep adding more:

Code: Select all

mplayer -vo x11 -zoom -aspect 4:3 filename.avi
I'm wondering how to set up a bash script that has all my parameters then allows me to run the file I want. For example, if the script were titled 'video-play' it would something like:

Code: Select all

video-play filename.avi
As I write it now I don't know the one key parts of the script, the part that will allow me to input data after the script, to run it. So I write the bash for mplayer with all the parameters, without the file I want to run, but it of course kicks back even if I type in the file I want afterwards.

Would one of you bash/script wizards tell me how to do this, pretty please? :wink:

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#2 Post by jpeps »

$1 is for args (filename)

Code: Select all

#!/bin/sh

DEF="-vo x11 -zoom -aspect 4:3"
mplayer  ${DEF} "$1"
Last edited by jpeps on Thu 14 Jul 2011, 20:50, edited 3 times in total.

User avatar
puppyluvr
Posts: 3470
Joined: Sun 06 Jan 2008, 23:14
Location: Chickasha Oklahoma
Contact:

#3 Post by puppyluvr »

:D Hello,
Using a variable as above wont solve the filename issue, but this will..
At the end of your script, add
"$@"
including the quotes..
EX: mplayer -vo x11 -zoom -aspect 4:3 "$@"
Then put the script on the desktop, and drop your files on it....
Close the Windows, and open your eyes, to a whole new world
I am Lead Dog of the
Puppy Linux Users Group on Facebook
Join us!

Puppy since 2.15CE...

User avatar
steve_s
Posts: 1595
Joined: Mon 26 May 2008, 13:29
Location: Austin, TX, USA
Contact:

#4 Post by steve_s »

Perfect, jpeps, thank you! That is all I needed...
I tried yours but for some reason it kicks back that -vo isn't a recognized command...something about my spacing or something, I'm sure, but this worked great:

Code: Select all

#!/bin/bash
mplayer -vo x11 -zoom -nortc -nocache -lavdopts fast -aspect 4:3 "$1"
save the script in whatever name I want, in this case video-play, then I run whatever file I want with it like this:

Code: Select all

video-play moviefile.avi
and it plays the movie great! Now I can add parameters as I want without having to remember every last little one. Thanks again. 8)
Last edited by steve_s on Thu 14 Jul 2011, 20:54, edited 1 time in total.

User avatar
steve_s
Posts: 1595
Joined: Mon 26 May 2008, 13:29
Location: Austin, TX, USA
Contact:

#5 Post by steve_s »

puppyluvr wrote::D Hello,
Using a variable as above wont solve the filename issue, but this will..
At the end of your script, add
"$@"
including the quotes..
EX: mplayer -vo x11 -zoom -aspect 4:3 "$@"
Then put the script on the desktop, and drop your files on it....
Thanks, puppyluvr, I'm checking that out too! Very appreciated...kinda like that drop it on the desktop idea...

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#6 Post by jpeps »

Needed ${DEF} ....I edited the script.

User avatar
steve_s
Posts: 1595
Joined: Mon 26 May 2008, 13:29
Location: Austin, TX, USA
Contact:

#7 Post by steve_s »

Since I kinda like the definition stuff being seperate, the script now looks like this (added that last mod from jpeps and will probably continue to make changes in mplayer definitions until I get the format I want):

Code: Select all

#!/bin/bash
DEF="-vo xv -zoom -nortc -nocache -lavdopts fast -aspect 4:3"
mplayer ${DEF} "$@"
Thanks!

Bruce B

#8 Post by Bruce B »

I could be mistaken. I think we needed a loop or something like it to play the second and third videos. Depending I suppose on how the script is run.

Code: Select all

#!/bin/bash

DEF="-vo xv -zoom -nortc -nocache -lavdopts fast -aspect 4:3"

for i in "$@" ; do
    mplayer ${DEF} "$i" 
done
~

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

#9 Post by Dougal »

An even simper way would be to add to your ~/.bashrc:

Code: Select all

alias mplayer='mplayer -vo xv -zoom -nortc -nocache -lavdopts fast -aspect 4:3'
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#10 Post by big_bass »

why not one more option so you see there are many ways to get there


edit this file

/usr/local/bin/defaultmediaplayer

to look like this

Code: Select all

#!/bin/bash
#exec gxineshell "$@"
#exec /usr/bin/gmplayer -msglevel all=-1 "$@" &
#exec vlc -vvv "$@"
exec mplayer -vo xv -zoom -nortc -nocache -lavdopts fast -aspect 4:3 "$@"

User avatar
steve_s
Posts: 1595
Joined: Mon 26 May 2008, 13:29
Location: Austin, TX, USA
Contact:

#11 Post by steve_s »

You guys rock...man I love this forum. 8)

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#12 Post by 01micko »

Hi steve_s

I don't know about many mplayer options but I do know you can at least put sound and video options in your ~/.mplayer/config file. (I'm fairly sure you can put others in there too). It should be faster than bash.
eg: vo=x11
Puppy Linux Blog - contact me for access

User avatar
steve_s
Posts: 1595
Joined: Mon 26 May 2008, 13:29
Location: Austin, TX, USA
Contact:

#13 Post by steve_s »

01micko wrote:Hi steve_s

I don't know about many mplayer options but I do know you can at least put sound and video options in your ~/.mplayer/config file. (I'm fairly sure you can put others in there too). It should be faster than bash.
eg: vo=x11

Thanks, micko!

User avatar
GatorDog
Posts: 138
Joined: Tue 12 Sep 2006, 16:43

Bacon video-play

#14 Post by GatorDog »

This isn't a bash script and it is overkill in the extreme.
FWIW here is a BaCon program for video-play.

http://www.murga-linux.com/puppy/viewto ... 7&start=11

rod

Post Reply