Register
It is currently Fri Dec 19, 2014 10:50 am

cat --> mencode --> ffmpeg using bash script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Sat Jul 25, 2009 7:53 pm   

Joined: Sat Jul 25, 2009 7:22 pm
Posts: 3
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


Top
 Profile  
 PostPosted: Mon Aug 03, 2009 8:38 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 673
Location: Des Moines, Iowa
Code:
mv $TEMP /webcam/archive/$TEMP


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


Top
 Profile WWW  
 PostPosted: Mon Aug 10, 2009 9:24 pm   

Joined: Sat Jul 25, 2009 7:22 pm
Posts: 3
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.


Top
 Profile  
 PostPosted: Sat Aug 15, 2009 9:47 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 673
Location: Des Moines, Iowa
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.


Top
 Profile WWW  
 PostPosted: Mon Aug 17, 2009 9:25 am   

Joined: Sat Jul 25, 2009 7:22 pm
Posts: 3
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


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP