Register
It is currently Thu Oct 02, 2014 8:29 am

Act on all files in a directory, and record stderr


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Thu Dec 07, 2006 10:41 pm   

Joined: Thu Sep 07, 2006 3:56 pm
Posts: 8
Location: Toronto, Canada
Hello,

I would like to execute a command ('ffmpeg'), against each file in a given directory, and record stderr to a log file. Additionaly, if possible, I'd like to insert the name of the current file into the log file. I'm trying to run through some sample conversions to determine the proportion that generate errors.

Cheers!

Neal


Top
 Profile WWW  
 PostPosted: Thu Dec 07, 2006 10:57 pm   

Joined: Tue Dec 05, 2006 8:37 pm
Posts: 30
Location: Thiruvananthapuram / India
Hi,

Are you sure you want to run the ffmpeg command on all files in the directory and not on files with specific extension(s) ?


Top
 Profile WWW YIM  
 PostPosted: Fri Dec 08, 2006 12:01 am   

Joined: Tue Dec 05, 2006 8:37 pm
Posts: 30
Location: Thiruvananthapuram / India
Hi Neal,

I have written an initial script. Give the directory name as a command line argument:

eg. ./script.sh /home/neal/ffmpeg-data

Code:
#!/bin/bash

FFMPEG='ffmpeg -i' # Replace with correct options
LOG_FILE='ffmpeg.log' # Replace with correct log file

if [ ! -f $LOG_FILE ]
then
  touch $LOG_FILE
fi

for file in $(find $1)
do
  if [ -f $file ]
  then
    err_msg=$($FFMPEG $file 2>&1)
  else
    continue
  fi
  len=$(expr length "$err_msg")
  if [ $len -gt 0 ]
  then
    echo "$file : $err_msg" >> $LOG_FILE
  fi
  err_msg=''
done

exit



Please verify if this script works for you.


Top
 Profile WWW YIM  
 PostPosted: Fri Dec 08, 2006 2:16 pm   

Joined: Thu Sep 07, 2006 3:56 pm
Posts: 8
Location: Toronto, Canada
Thanks Lijeesh, the script worked well!

I made a few additions to the script:
__________
#!/bin/bash

FFMPEG='ffmpeg -i' # Replace with correct options
LOG_FILE='ffmpeg.log' # Replace with correct log file
OPTIONS='-s 320x240 -vcodec flv -ar 44100 -b 600000 -y script_test.flv'

if [ ! -f $LOG_FILE ]
then
touch $LOG_FILE
fi

for file in $(find $1)
do
if [ -f $file ]
then
err_msg=$($FFMPEG $file $OPTIONS 2>&1)
else
continue
fi
len=$(expr length "$err_msg")
if [ $len -gt 0 ]
then
echo -e "\n\n$file ::::::::\n $err_msg" >> $LOG_FILE
fi
err_msg=''
done

exit


Top
 Profile WWW  
 PostPosted: Fri Dec 08, 2006 2:19 pm   

Joined: Thu Sep 07, 2006 3:56 pm
Posts: 8
Location: Toronto, Canada
Lijeesh,

How can I modify this script to only execute on .mov, .mwv, .mpg extensions?

Thanks,

Neal


Top
 Profile WWW  
 PostPosted: Fri Dec 08, 2006 7:29 pm   

Joined: Tue Dec 05, 2006 8:37 pm
Posts: 30
Location: Thiruvananthapuram / India
Hi Neal,

It can be easily achieved by modifying the 'find' command in the 'for ' loop.

Change the line "for file in $(find $1)" as follows :

for file in $(find $1 -name "*.mpg" -o -name "*.mov" -o -name "*.mwv")

If you need to add more extensions ( say .wmv ), just do it with appending -o -name "*.wmv" to the find command.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


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