
How do I turn a command line into a shell script?I've been experimenting with mencoder to convert my AVI movies into a format that I can download onto my cellphone and finally found a site where they explain the various parameters needed for the mencoder program to get it to work. Problem is, they're a pain to type in each time. How do I turn an ugly command line invocation into a nice shell script? Through an eerie coincidence, I too have been going through that same task, converting movies to dump onto my new Blackberry Pearl, which actually does quite a good job with video, rather to my surprise! It's not much bigger than a postage stamp, but it's watchable, and heck, it's a cellphone... :-) Anyway, the information I found on using mencoder is from the8thsign.com. If you're on a PC, then you might find this posting in Pinstack.com's Blackberry forums useful. The command I used is: mencoder -vf scale=240:135 input -o output -of avi -ofps 15 -ovc \
lavc -oac lavc -lavcopts vcodec=mpeg4:vbitrate=230:acodec=mp3:abitrate=64 Scary, isn't it? No wonder you're looking for a way to avoid typing that in each time you want to convert a movie! Fortunately, it's a very regular pattern and that means that it's not hard to replace "input" and "output" with specific variables and just prompt for those values when the script is started. That's exactly what the following script does: #!/bin/sh
# This script converts regular AVI into the format needed for the # Blackberry Pearl ... mencoder=/Users/taylor/bin/mencoder echo -n "input file: " read input echo -n "output file: " read output echo "Converting $input to $output..." $mencoder -vf scale=240:135 "$input" -o "$output" -of avi -ofps 15 -ovc \ lavc -oac lavc -lavcopts vcodec=mpeg4:vbitrate=230:acodec=mp3:abitrate=64 exit 0 Save this as, say, "convert-movies", make it an executable with the command chmod +x convert-movies, and now you can just type "convert-movies" to get the script running: $ ./convert-movies
input file: ../Movies/Bourne-Identity.avi output file: ~/Desktop/bourne-identity.avi Converting ../Movies/Bourne-Identity.avi to ~/Desktop/bourne-identity.avi... MEncoder dev-CVS-051126-18:35-3.3 (C) 2000-2005 MPlayer Team Mac OSX static build for ffmpegX AltiVec found CPU: PowerPC . . . Nice, simple, and far easier to remember. Note that I already knew the name of the input file, so you can't use filename completion as you could on the command line (in fact, it would be pretty easy to add the ability to specify the input and/or output filenames on the command line itself, allowing you to type in "convert-movie bourne-identity.avi bourne-identity-out.avi" or similar. I'll leave that as an exercise for you, dear reader, however!)
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.
Categorized:
Shell Script Programming
(Article 7182)
Tagged: avi conversion, blackberry pearl, mencoder, shell script programming Previous: What's the difference between BitTorrent, Limewire and Kazaa? Next: How do I switch my Blackberry Pearl from Multitap to SureType? Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader. Hi, alternatively tou can use mencoder.conf file. It is a file where you can store your options and what is nice about it is that you can set some profiles there. This file should be found in ~/.mplayer/mencoder.conf if it's not you can create it. So your file could look like this : [bb] # name of the profile You can also set default output filename: o=output.avi You can have many profiles like one above, you can set default settings using [default] profile. mencoder -profile bb -o You could make an alias of it or wrap a little script around it, which would for example save output file with the same name as input file but with ex. .avi.new extension. So it would take only to type: yourscriptname to convert your file. And 'yourscriptname' can be shorter of course :) With a script like that you can even make some batch conversion: for i in *.avi ; do yourscriptname $i ; done Those are just examples and you should tweak them to fit your needs jot Posted by: jot at March 4, 2007 6:39 PMhello dave we all very thankfull to you to update us in such usefully ways with regard chetan Posted by: chetanM at December 29, 2007 6:11 AMI have a lot to say, but ...
I do have a comment, now that you mention it!
|
Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Join the List!
Book Links
|