BashScripts.org
http://bashscripts.org/forum/

cat --> mencode --> ffmpeg using bash script
http://bashscripts.org/forum/viewtopic.php?f=7&t=851
Page 1 of 1

Author:  awisher [ Sat Jul 25, 2009 7:53 pm ]
Post subject:  cat --> mencode --> ffmpeg using bash script

I have 9.04 running motion webcam software, which captures movies and writes them to avi files. I would like to have an automated way of concatenating the days avi files, converting them to h.264 m4a files and cleaning up the directory afterward. I have created a bash script that I thought should work, but doesn't. I'm not sure what I've done wrong, but it fails to make the final m4a.

Code:
#! /bin/sh

# at midnight we move everything into its own dated directory

TEMP=`date +%F`

cd /webcam/Security
mkdir $TEMP

ls -1 | grep avi | xargs -n 10 -i mv {} $TEMP/

mv $TEMP /webcam/archive/$TEMP

# --------------------------------------------------------------------------------
# Concatenate all of the daily AVIs, re-index them, and convert them to H.264 MP4s

mkdir /webcam/archive/$TEMP/temp

# sort the avi files by time and cat them (sort doesn't seem to work?? )
cat $( ls -rt /webcam/archive/$TEMP/*.avi) > /webcam/archive/$TEMP/temp/noindex_A.avi

# reindex the cat avi (works)
mencoder /webcam/archive/$TEMP/temp/noindex_A.avi -o /webcam/archive/$TEMP/temp/noindex_B.avi -forceidx -ovc copy -oac copy

cd /webcam/archive/$TEMP/temp

# convert to m4a (works outside bash script, but not in???)
ffmpeg -y -i noindex_B.avi -pass 1 -vcodec libx264 -vpre fastfirstpass -vpre ipod640 -b 512k -bt 512k -s 640x480 -threads 0 -f ipod -an /dev/null && ffmpeg -i noindex_B.avi -pass 2 -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre ipod640 -b 512k -bt 512k -s 640x480 -threads 0 -f ipod output.m4a


mv output.m4a ../$TEMP.m4a
# rm -f -R /webcam/archive/$TEMP/temp
# rm -f /webcam/archive/$TEMP/*.avi

# -------------------------------------------------------------------------------
it is all called in a cronjob as:
59 23 * * * /webcam/motion-organize.sh >/dev/null 2>&1


I would like to log what is happening, but am not sure how to implement that part of it.
The script builds the noindex_A.avi and noindex_b.avi with out trouble, just no m4a file.
Also, the cat part doesn't sort the files by time like it should.

Thanks for any pointers.
aaron

Author:  crouse [ Mon Aug 03, 2009 8:38 pm ]
Post subject:  Re: cat --> mencode --> ffmpeg using bash script

Code:
mv $TEMP /webcam/archive/$TEMP


maybe try
mv ${TEMP}/ /webcam/archive/

Author:  awisher [ Mon Aug 10, 2009 9:24 pm ]
Post subject:  Re: cat --> mencode --> ffmpeg using bash script

actually it fails on the "# convert to m4a" part I can run the ffmpeg from the terminal with no trouble, but it won't run in the bash script.

Author:  crouse [ Sat Aug 15, 2009 9:47 am ]
Post subject:  Re: cat --> mencode --> ffmpeg using bash script

There are 2 debugging tools you might try.

set -xv at the top of your script, and set +xv at the bottom of your script.

your output when run will have lines that have ++ in front of them showing that they are executing. The first one turns on the debugging, the second turns it off.

Alternatively, you could use script.

Type
script testing.log
./runyourscripthere

Then CTRL + D to exit. you will have a "testing.log" of your script running.

There are other ways to do this as well, but those two methods work best for me. ;) Good luck.

Author:  awisher [ Mon Aug 17, 2009 9:25 am ]
Post subject:  Re: cat --> mencode --> ffmpeg using bash script

Thanks. I figured it out, I had to add a symbolic link to ffmpeg in the directory where the script is running. Works great now.
Aaron

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com