LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-15-2011, 12:11 PM   #1
hpladd
Member
 
Registered: Feb 2003
Distribution: Kubuntu
Posts: 142

Rep: Reputation: 15
Bash Script


The following command works beautifully from the cmdline.

mencoder -oac copy -ovc copy -o ./Test.avi /tmp/Film/*

Note: The command concatenates a series of avi video clips into a single video file. The parameter "./Test.avi" is the output file, and "/tmp/Film/*" is the input file.

However, place the same command in a Bash script and it only works sometimes. If I ask the script to process 6 to 7 files then it works. If I ask the script to process 10 or more it fails. I believe the problem is caused by the rate at which the files are fed to the application (mencoder) by the script.

The entire script with comments is below:
Quote:
#!/bin/bash

# Dear Linuxquestions.org readers -- the troublesome line is the second to last one.

#The following script takes numerous still photos and concatinates them into a video.

DIR=`basename $PWD`

sudo mkdir /tmp/Film
sudo chmod 777 /tmp/Film
sudo rm /tmp/Film/*

#Iterate through directories and subdirectories and remove the files with "analyse" in the name.
for file in `find . -type f -name '*analyse*' -print`
do
echo "Processing $file"
sudo -s rm -rf $file
done

#Concatinate all .jpg files into a film clip.
for JPGDIR in `find ./* -type d -print`
do
echo
echo "<<<<<<<<<<<<<<<<<<<<PROCESSING $JPGDIR>>>>>>>>>>>>>>>>>>>>>>"
echo
mencoder mf://${JPGDIR}/*.jpg -mf w=640:h=480:fps=10.21:type=jpg -ovc\
lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o /tmp/Film/${JPGDIR}.avi
done

#Concatinate all film clips into an video.
for AVI in `find /tmp/Film -iname "*.avi" | sort -g`
do
mencoder -oac copy -ovc copy -o ./Test.avi /tmp/Film/*
done
 
Old 09-15-2011, 12:26 PM   #2
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,329

Rep: Reputation: 254Reputation: 254Reputation: 254
In your final loop you are not using the variable $AVI. Maybe it should read:
Code:
#Concatenate all film clips into a video.
for AVI in `find /tmp/Film -iname "*.avi" | sort -g`
do
mencoder -oac copy -ovc copy -o ./Test.avi $AVI
done
 
Old 09-15-2011, 12:46 PM   #3
hpladd
Member
 
Registered: Feb 2003
Distribution: Kubuntu
Posts: 142

Original Poster
Rep: Reputation: 15
Thanks Reuti,

I tried that first. No go. The "for" statement is a legacy from that attempt. It seems the use of variable $avi causes the trouble. I get slightly better results when giving the path. Thanks again.
 
Old 09-15-2011, 08:34 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,566

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
I would have said that if the script did the same thing as the command line maybe it would work??

I presume when the command line option is presented with 10 or more files it works just fine? If so then just remove
the for loop altogether and all should be rosy
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Run multiple bash and php scripts from a bash script charu Programming 5 07-26-2011 03:40 AM
Variables and Mkvextract in a bash script and a good resource for bash help? gohmifune Linux - General 9 04-13-2011 09:37 AM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 09:56 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 12:10 PM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 07:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration