LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 10-12-2010, 12:36 PM   #1
jeffmiller45
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Rep: Reputation: 0
Small Script help


Okay, I'm rather new to linux, and I have a dedi server. I know how to browse, install, remove etc, all the basics needed to use it.

I've installed flvtool2, memcoder and ffmpeg, and at the moment im converting avi files in to flv. Im then passing metadata using yamdi.

However, this process is very timely as im converting loads of avi files at a time.

Im looking for a script, or a way where I can execute one command/script and which will convert all files in the directory I specify, then run those converted files through yamdi.

Please help. Im guessing it would be some sort of loop, and then changing for each file?
Thanks in advance!

Jeff..

Last edited by Tinkster; 10-12-2010 at 01:28 PM.
 
Old 10-12-2010, 01:41 PM   #2
mf93
Member
 
Registered: Jun 2009
Distribution: Debian Squeeze, centOS
Posts: 229

Rep: Reputation: 36
try
Code:
$ <whatever command you are running> <address of directory for files>/*
ie
$ convert /home/user/files/*
 
Old 10-12-2010, 02:04 PM   #3
jeffmiller45
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Im slightly confused.

Doesnt a script have to start with

PHP Code:
#!/bin/bash 
Basically the process im running manually at the moment is this.

PHP Code:
ffmpeg --/home/user/public_html/video/Video.avi -b 800k -r 25 -f flv -ar 44100 /home/user/public_html/video/Video.flv 
Once this has completed (takes about ten minutes on my server) I then manually execute this to add metadata.

PHP Code:
yamdi -/home/user/public_html/video/Video.flv -/home/user/public_html/video/Video2.flv 
Obviously this process can be very timely. So is there a bash script I can use that will count all avi files in a directory. Then for each avi, convert it, then add meta using yamdi, then move onto the next?

I;ve been looking around google to try and find something similar that someone else might of written and change it, but I'm having no luck.

Thanks

Last edited by jeffmiller45; 10-12-2010 at 02:05 PM.
 
Old 10-12-2010, 02:19 PM   #4
jeffmiller45
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Hi again,

I found this thread, would this work ?

http://www.linuxquestions.org/questi...pt-wip-718990/

I also found this, this should work right? I just need to change the hardcode to what I need

Quote:
#!/bin/bash
#
# Convert files for Tivo

DIR=/media/TiVo/queue

for i in `find $DIR -type f *`; do

ffmpeg -i $i -target ntsc-dvd /media/TiVo/GoBack/$i.MPG
mv $i /media/TiVo/original

done

Last edited by jeffmiller45; 10-12-2010 at 02:23 PM.
 
Old 10-12-2010, 06:29 PM   #5
mf93
Member
 
Registered: Jun 2009
Distribution: Debian Squeeze, centOS
Posts: 229

Rep: Reputation: 36
copy and paste
Code:
#!/bin/bash
echo "make sure this is run from the directory in which the videos are stored"
ls | grep .avi > avifiles
cut -d . -f 1 avifiles > filenames
for f in $(cat filenames)
do
ffmpeg -y -i "$f".avi -b 800k -r 25 -f flv -ar 44100 "$f".flv
yamdi -i "$f".flv -o "$f2".flv 
done
that should do it---make sure you run this from the director where you put your videos
 
Old 10-13-2010, 01:58 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Well at least one issue I see with both scripts is that if any of the file have spaces in them then the for loop will perform word splitting and you will not get what you want.
You need to remember that the idea of a script is to take what you would do say 10 times and make it so you only run the script once.

So let us break down what you have so far:
Quote:
ffmpeg -y -i /home/user/public_html/video/Video.avi -b 800k -r 25 -f flv -ar 44100 /home/user/public_html/video/Video.flv
yamdi -i /home/user/public_html/video/Video.flv -o /home/user/public_html/video/Video2.flv
So these are the two command you would run by hand as many times as required.

Quote:
Doesnt a script have to start with
Code:
#!/bin/bash
Well not necessarily but we will assume, based on your subsequent posts, that this is the shell you wish to use.

So the starting script to work with just one file would look like:
Code:
#!/bin/bash

ffmpeg -y -i /home/user/public_html/video/Video.avi -b 800k -r 25 -f flv -ar 44100 /home/user/public_html/video/Video.flv
yamdi -i /home/user/public_html/video/Video.flv -o /home/user/public_html/video/Video2.flv
Easy enough. I would then leave this part and then try and find a way to get all the files you are looking for.
Example 1
Code:
#!/bin/bash

for i in /media/TiVo/queue/*
do
    echo "$i"
done
This will work just fine as long as you know that there are no files in here that are not what you want and that there are no directories (note: word splitting is not an issue here)
Should you want only those items ending in '.avi' this can be appended to the asterix but will not rule out directories.

So then, as you rightly guessed you can go with find. The problem is that output from a command substitution [`` for you or $() for mf93] do undergo word splitting so any files returned that have
a space (ie. this is a nice.avi) will return each part, so not what you want.

A more robust solution is to redirect your find into a while / read loop, like so:
Code:
#!/bin/bash

while read -r line
do
    echo "$line"
done< <(find /media/TiVo/queue/ -type f -iname '*.avi')
Now you can still use your DIR variable, I am just overstating here.
Things to note here:

1. * at the end of your find would have yielded an error
2. -iname allows us to ignore case so we get, avi AVI aVi
3. there is a space between the 2 symbols < ... this is very important

So let me know if you get stuck but this should help, you only have to put the 2 together and work out your variables.
Remember also that as we may be worried about spaces that quotes ("") around your variables are a must.
 
1 members found this post helpful.
  


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
help with a very small script hamish Linux - General 3 06-09-2004 03:10 AM
Need help with very small script. Franklin Programming 8 10-14-2003 01:37 PM
Please Help with a small script ? juglugs Programming 2 11-14-2001 03:39 AM
Small Script msj Linux - Newbie 2 08-27-2001 07:59 AM
small script msj Programming 1 08-26-2001 12:42 PM


All times are GMT -5. The time now is 08:35 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