From wmv to avi loop script


This post is a follow up on:
Conversions.

I am bit of on a deadline now! So come back later for a more detailed explanation say in 12 hrs or so. 😉
Edited today: 11/13/10
If I had to give you one reason (at least) for why I want to get rid of wmv files;
then I would have to say that most of them (except for a few notable exceptions [better compression?]) are just wasting my hard drive space!;
else *Hmm can you say proprietary*;
fi

Though hard drives these days usually have enough room to store just about anything, I still don’t see why I shouldn’t use my space more efficiently (if possible and applicable!?) Which reminds me of my first attempts of ‘converting’ my old word docs (that would be about 8 years ago mesa thinks) into the more efficient odt format or when saving them as html only to discover that all your personal details are shared with the entire world once published. *Whoops* Also when you view the source of such a page one could be astounded by the amount of crap word inserts into freshly generated html pages!

K.i.s.s.

Yet another update. Now=11/14/2010 15:10u
This script features a case select scenario just as its master file does now. Be careful though, ’cause you may want to (re)view your old files before deleting them!

#!/bin/bash
# Modified: Today by E.l.f.
#
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
#
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
#
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the Free Software Foundation, Inc., 51
## Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
## http://www.gnu.org/copyleft/gpl.html
#
## Script-name - wmv2aviloop.sh
#
## Root check / Sanity check.  You decide.  >-)
## Just in case someone calls this script with sudo -s,
## or has cd'ed into his/her path.
RED="\033[0;31m"
BLUE="\033[1;34m"
CYAN="\033[1;36m"
YELLOW="\033[1;33m"
NC="\033[0m"
if [ $USER = root ]; then
  echo -e $RED"   Are you Insane!"
  echo -e $CYAN"   Error: In order to use this script, one must NOT be $USER"
  echo -e $YELLOW"    Exiting..."$NC
  exit 0
else
  echo ""
  echo -e $BLUE"    $USER may proceed."  
  echo -e $CYAN"    May peace be with you."$NC
fi
clear
VAR="wmv-files.txt"
DIVX="divx2pass.log"
## cd into the folder where your *.wmv files are kept.
## e.g.
# cd /home/<user>/Videos/myWmvFiles
## Those could be kept in more than one place of course.
# cd /home/<user>/Videos/AnotherFolderWithwmvFiles
## There could also be subfolders in the current ()working directory [PWD].
# ls -lh could yield something like:
# drwxr-x--T 10 <user> <user>  4.0K 2010-11-11 01:01 AnotherDirWithwmvFiles
# drwxr-x--T 10 <user> <user>  4.0K 2010-11-11 10:10 AndAnotherDirWithFiles
# drwxr-x--T 10 <user> <user>  4.0K 2010-11-11 10:11 AnotherDirWithFiles
# drwxr-x--T 42 <user> <user>  4.0K 2010-11-11 11:11 AndYetAnother
## etc etc etc
## I forgot to credit properly before\!  
## http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-xvid.html
## Fyi, I use *High quality*
## Fwiw:
## My computer:  AMD Turion(tm) X2 Dual-Core Mobile RM-70
## O.S.:  Ubuntu Lucid Lynx 64bit
## First pass: 79fps on average (while using other apps).
## Second pass: 32fps on average (while using other apps).
echo
echo "    What do you want to do?"
echo
echo "    Convert the current working directory into avi?"
echo "    Or"
echo "    Convert them all starting from this folder!?"
echo "    aka as a recursive function."
echo
echo -n "Enter either Current or Recursive: "
read answer
case "$answer" in
"Current" | "CURRENT" | "current" | "C" | "c")
  ## This one will change the audio and video properties of the files it processes.
  ## For the current directory/folder; do
  ls *.wmv | sort > $VAR
  cat $VAR | while read line; do
  INPUT=$(echo ${line})
  OUTPUT=${INPUT%.*v}
  OUTPUT+=".avi"
  mencoder "$INPUT" -ofps 23.976 -oac mp3lame -ovc xvid -xvidencopts pass=1 -o \
  /dev/null && mencoder "$INPUT" -ofps 23.976 -oac mp3lame -lameopts abr:br=128 \
  -ovc xvid \-xvidencopts pass=2:vhq=2:bvhq=1:bitrate=800:chroma_opt:quant_type=mpeg -o "$OUTPUT"
  done
  ;;
"Recursive" | "RECURSIVE" | "recursive" | "R" | "r")
  ## For a recursive function; do
  ## Be careful though\!
  find -iname '*.wmv' -exec ls "{}" \; | sort > $VAR
  cat $VAR | while read line; do
  INPUT=$(echo ${line})
  OUTPUT=${INPUT%.*v}
  OUTPUT+=".avi"
  mencoder "$INPUT" -ofps 23.976 -oac mp3lame -ovc xvid -xvidencopts pass=1 -o \
  /dev/null && mencoder "$INPUT" -ofps 23.976 -oac mp3lame -lameopts abr:br=128 \
  -ovc xvid -xvidencopts pass=2:vhq=2:bvhq=1:bitrate=800:chroma_opt:quant_type=mpeg -o "$OUTPUT"
  done
  ;;
*)
  # Default option.
  # Empty input (hitting RETURN) fits here, too.
  echo "   Wrong answer!!!"
  echo "   Please rerun the script again?"
  echo "   Then: Either enter Current or Recursive." 
  echo "   \"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"
  echo "   Usage: Current|Recursive"
  echo
  exit 1
  ;;
esac
## Then...
if [ -f "$VAR" ] ; then \rm $VAR;fi # Remove the text file with the file names
if [ -f "$DIVX" ] ; then \rm $DIVX;fi # We have no need for this one as well.
  echo "    I'm sorry to bother you again, but...?"
  echo "    I need you to choose again. "
  echo "    Either to remove your old files."
  echo "    From the current directory."
  echo "    Or ALL of them!!!"
  echo "    Starting from within this directory."
  echo
  echo -n "Enter either Folder or All: "
  read Answer
## alias rm='rm -i' hence \rm because I know what I am doing\!  
case "$Answer" in
"Folder" | "FOLDER" | "folder" | "F" | "f")
  \rm *.wmv
  ;;
"All" | "ALL" | "all" | "A" | "a")
  find -iname '*.wmv' -exec \rm "{}" \;
  ;;
*)
 # Default option.
 # Empty input (hitting RETURN) fits here, too.
  echo 
  echo "   You wish to keep them?"
  echo "   Though they take up precious hard drive space?"
  echo "   Your wish is my command!"
  echo 
  echo "   Fwiw: For a manual removal!?"
  echo "   Either choose to run: "
## alias rm='rm -i' hence \rm because I know what I am doing\!
  echo "   \rm *.wmv"
  echo "   For the current folder/directory."
  echo "   Or: "
  echo "   find -iname '*.wmv' -exec \rm "{}" \;"
  echo "   For all of them!"
  echo 
  echo "   Usage: Folder|All"
  echo "   \"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"
  echo
  exit 1
  ;;
esac
exit 0

PS: These new posts of mine will be in line with the notes I post on facebook.com. 😉 Though the formatting won’t be garbled this time. *Say demoronize* >-)

3 thoughts on “From wmv to avi loop script

  1. The newlines \ you see in the script are my attempt at keeping things ‘readable’ i.e. to keep things from overflowing out of the box. Personally I don’t mind pasting in long lines into scripts that much.

    Like

  2. Pingback: Batch processing by means of using any script of your choosing. « Bohemian Wildebeest's Blog

Comments are closed.