Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 17 Apr 2014, 20:17
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Want a Bash script to open mplayer then play a file
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [14 Posts]  
Author Message
steve_s


Joined: 26 May 2008
Posts: 1545
Location: Austin, TX, USA

PostPosted: Thu 14 Jul 2011, 16:22    Post subject:  Want a Bash script to open mplayer then play a file  

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

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:

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:

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
Back to top
View user's profile Send private message Visit poster's website 
jpeps

Joined: 31 May 2008
Posts: 3219

PostPosted: Thu 14 Jul 2011, 16:32    Post subject:  

$1 is for args (filename)

Code:

#!/bin/sh

DEF="-vo x11 -zoom -aspect 4:3"
mplayer  ${DEF} "$1"

Last edited by jpeps on Thu 14 Jul 2011, 16:50; edited 3 times in total
Back to top
View user's profile Send private message 
puppyluvr


Joined: 06 Jan 2008
Posts: 3141
Location: Chickasha Oklahoma

PostPosted: Thu 14 Jul 2011, 16:36    Post subject:  

Very Happy 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
http://puppylinuxstuff.meownplanet.net/puppyluvr/
Puppy Linux Users Group on Facebook

Puppy since 2.15CE...
Back to top
View user's profile Send private message Visit poster's website 
steve_s


Joined: 26 May 2008
Posts: 1545
Location: Austin, TX, USA

PostPosted: Thu 14 Jul 2011, 16:42    Post subject:  

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:

#!/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:

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. Cool

Last edited by steve_s on Thu 14 Jul 2011, 16:54; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
steve_s


Joined: 26 May 2008
Posts: 1545
Location: Austin, TX, USA

PostPosted: Thu 14 Jul 2011, 16:44    Post subject:  

puppyluvr wrote:
Very Happy 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...
Back to top
View user's profile Send private message Visit poster's website 
jpeps

Joined: 31 May 2008
Posts: 3219

PostPosted: Thu 14 Jul 2011, 16:51    Post subject:  

Needed ${DEF} ....I edited the script.
Back to top
View user's profile Send private message 
steve_s


Joined: 26 May 2008
Posts: 1545
Location: Austin, TX, USA

PostPosted: Thu 14 Jul 2011, 17:01    Post subject:  

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:

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


Thanks!
Back to top
View user's profile Send private message Visit poster's website 
Bruce B


Joined: 18 May 2005
Posts: 11049
Location: The Peoples Republic of California

PostPosted: Thu 14 Jul 2011, 18:29    Post subject:  

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:
#!/bin/bash

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

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


~

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
Dougal


Joined: 19 Oct 2005
Posts: 2505
Location: Hell more grotesque than any medieval woodcut

PostPosted: Fri 15 Jul 2011, 15:51    Post subject:  

An even simper way would be to add to your ~/.bashrc:
Code:
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
Back to top
View user's profile Send private message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

PostPosted: Sat 16 Jul 2011, 00:18    Post subject:  

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:
#!/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 "$@"

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send private message 
steve_s


Joined: 26 May 2008
Posts: 1545
Location: Austin, TX, USA

PostPosted: Sat 16 Jul 2011, 10:47    Post subject:  

You guys rock...man I love this forum. Cool
Back to top
View user's profile Send private message Visit poster's website 
01micko


Joined: 11 Oct 2008
Posts: 7547
Location: qld

PostPosted: Sat 16 Jul 2011, 22:04    Post subject:  

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

_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
steve_s


Joined: 26 May 2008
Posts: 1545
Location: Austin, TX, USA

PostPosted: Sun 17 Jul 2011, 19:17    Post subject:  

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!
Back to top
View user's profile Send private message Visit poster's website 
GatorDog


Joined: 12 Sep 2006
Posts: 136

PostPosted: Tue 19 Jul 2011, 02:15    Post subject: Bacon video-play
Subject description: video-play app written in BaCon
 

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/viewtopic.php?t=69647&start=11

rod
video-play.png
 Description   screen shot
 Filesize   354.71 KB
 Viewed   745 Time(s)

video-play.png

Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [14 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0808s ][ Queries: 12 (0.0063s) ][ GZIP on ]