Convert your flash files into avi


This post is actually a follow up on:
How to download youtube videos.

Now that you have all sorts of *.flv files stashed away on your hard drive or ssd (if you’re lucky!?) You may want to think about converting from flash to for example avi, which is what this post is all about.
I keep a copy of the following script stashed here and more of those can be found here.

Also I know that there are possibly plenty of other *read more efficient* ways to accomplish this. When I find one, you’ll be the first to know.

I am here to learn and not to bash.

#!/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 - flv2avi.sh
#
## Source (inspired on): http://www.linux.com/archive/feed/56642
#
## If colors are not defined in .bashrc, then uncomment the next three lines.
#YELLOW="\033[1;33m"
#RED="\033[0;31m"
#ENDCOLOR="\033[0m"
## Root check / Sanity check.  You decide.  >-)
## Just in case someone calls this script with sudo -s,
## or has cd'ed into his/her path.
if [ $USER = root ]; then
  echo -e $RED"Are you Insane!"
  echo -e $RED"Error: In order to use this script, one must NOT be $USER"
  echo -e $YELLOW"Exiting..."$ENDCOLOR
  exit 0
else
  echo ""
  echo "$USER may proceed."  
  echo "May peace be with you."  
fi
ls *.flv
echo -n "Enter filename: "
read INPUT
INPUT=$INPUT
if [ ! -f $INPUT ]; then
  echo ""
  echo -e $RED"Error: File doesn't exist!"
  echo -e $YELLOW"Exiting..."$ENDCOLOR
  echo ""
  exit 0
fi
OUTPUT=${INPUT%.*v}
OUTPUT+=".avi"
# OPTIONS=$(echo "-sameq -ab 256k -ar 48000 -ac 2 ")
# ffmpeg $OPTIONS -i $INPUT $OUTPUT
## This works better\!
OPTIONS=$(echo "-sameq -vcodec copy -acodec copy -ac 2 ")
ffmpeg -i $INPUT $OPTIONS $OUTPUT
## Now if a flash gives you trouble converting into avi
## Then change -vcodec copy into -f flv
## Now it will play your file (the video).
exit 0

Of course we can automate this process. (NOT TESTED!) But honestly, I like to keep in control of what my computer does.

#!/bin/bash
## An alternative automated script.
#  cd /into/path/where/flv.files/are/kept/first
#  e.g. cd $HOME/Videos/YouTube
#  VAR="flv-files.txt"
#  ls *.flv | sort > $VAR # I forgot the sort command\!
#  cat $VAR | while read line; do
#  INPUT=$(echo ${line})
#  OUTPUT=${INPUT%.*v}
#  OUTPUT+=".avi"
#  OPTIONS=$(echo "-sameq -vcodec copy -acodec copy -ac 2 ")
#  ffmpeg $OPTIONS -i $INPUT $OUTPUT;
#  done # IMPORTANT
#  exit 0
##

This is based on:

VAR="wmv-files.txt" # Assign a value.
ls *.wmv | sort > $VAR # list all *.wmv files in current folder and put them in $VAR.
# Concatenate $VAR and while reading a line at a time, do
cat $VAR | while read line; do
INPUT=$(echo ${line}) # echo each line found
OUTPUT=${INPUT%.*v} # Strip off extension for output file (*.wmv)
OUTPUT+=".avi" # add extension (*.avi) for idem
# Do the actual conversion.
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:bitrate=500 -o "$OUTPUT";
done
rm $VAR # Remove the text file with the file names

Enjoy!

Signing off.

Alex/Саша

PS: For examples and the essential P.O.C. go here. See the vinni_puh.txt file for the original sources.

2 thoughts on “Convert your flash files into avi

  1. How did those boxes that contain just a few simple lines of code get so big
    (5 lines wide for each line!?)? I sincerely hope I don’t have to change themes here (my other blog displays code with syntax highlighting just fine!).

    Like

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

Comments are closed.