Automated FFmpeg Convert Bash Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automated FFmpeg Convert Bash Script
# 1  
Old 05-19-2010
Automated FFmpeg Convert Bash Script

I need a bash script that will.
So here is what I made so far.

1. Convert video files to iPhone format
2. MV converted video to new directory (with domain.com attached to it)
4. Copy a NFO file (from another directory) and add some conversion information
5. Delete old directory
torrent stuff (rtorrent)
6. Make a torrent file out of new converted video directory

Code:
#!/bin/bash
# ffmpeg and mencoder script
# Grab thumb from avi, start encoding to ITU h264 using mencoder, ffmpeg is doing thumb processing

# Bash script for operating system Ubuntu 8.10 
# packages used : FFMPEG, MENCODER ,MPLAYER ENCODING ENGINE
# VIDEO CODEC ITU H264 AUDIO MP3


# Written by FakeOutdoorsman and updated by mysoogal and modified by Domzz
# Attribution-Noncommercial 3.0 Unported
# http://creativecommons.org/licenses/by-nc/3.0/deed.en
# trackback http://ubuntuforums.org/showthread.php?t=960627

# Location of source videos READ this !!! add your user name !
sourcelocation="/var/www/videos/"
# Extension of source videos
sourceext="avi,mpg,mpeg,mov,rmvb,rm,ogm,4v

#http://thomer.com/howtos/ipod_video.html
find ${sourcelocation} -iname "*${sourceext}" -exec mp4ize {}.mp4
# Check to see if videos were encoded, then delete source vids and shutdown
if [ -e "${sourcelocation}/*.avi" ] && [ -e "${sourcelocation}/*.mp4]; then
    # Delete videos    
    rm ${sourcelocation}/*.avi
    rm ${sourcelocation}/*.mpeg
    rm ${sourcelocation}/*.mov
    rm ${sourcelocation}/*.mpg
    rm ${sourcelocation}/*.txt
    rm ${sourcelocation}/*.nfo
    #copys a txt file from my directory to sources directory
    cp /home/admin/file.txt ${sourcelocation}
    #moves directory
    mv ${sourcelocation} /home/admin/${sourcelocation}_domain.com
    #builds the torrent file using: http://claudiusmaximus.goto10.org/cm/torrent.html
    #http://www.torrent-invites.com/tutorials/52022-putty-complete-tutorial.html
    cd /home/admin
    mktorrent -v -p -a http://tracker.url -o ${sourcelocation}_domain.com.torrent ${sourcelocation}_domain.com
else
    echo "Encoding FAILED"
fi

exit


I am not sure if I should use:


Code:
    rm ${sourcelocation}/*.avi
    rm ${sourcelocation}/*.mpeg
    rm ${sourcelocation}/*.mov
    rm ${sourcelocation}/*.mpg
    rm ${sourcelocation}/*.txt
    rm ${sourcelocation}/*.nfo

or if there is a better way.
# 2  
Old 05-19-2010
I noticed a missing quote at the end of sourceext... line, then also a missing quote in the "if..." line between mp4 and the closing square bracket and maybe a missing whitespace between the mentioned quote and closing square bracket.
Code:
    rm ${sourcelocation}/*.avi
    rm ${sourcelocation}/*.mpeg
    rm ${sourcelocation}/*.mov
    rm ${sourcelocation}/*.mpg
    rm ${sourcelocation}/*.txt
    rm ${sourcelocation}/*.nfo

could probably be reduced to
Code:
for ext in avi mpeg mov mpg txt nfo; do rm ${sourcelocation}/*.$ext; done

HTH
# 3  
Old 05-19-2010
ok thanks for that, I also updated the bash script to check if ffmpeg or handbrakecli is running. This is my first bash script.

I know {sourcelocation} is the directory, but I want the script to check for and {sourcelocation} subdirectory.


Code:
#!/bin/bash
# ffmpeg and mencoder script
# Grab thumb from avi, start encoding to ITU h264 using mencoder, ffmpeg is doing thumb processing

# Bash script for operating system Ubuntu 8.10 
# packages used : FFMPEG, MENCODER ,MPLAYER ENCODING ENGINE
# VIDEO CODEC ITU H264 AUDIO MP3


# Written by FakeOutdoorsman and updated by mysoogal and modified by Domzz
# Attribution-Noncommercial 3.0 Unported
# http://creativecommons.org/licenses/by-nc/3.0/deed.en
# trackback http://ubuntuforums.org/showthread.php?t=960627

# Location of source videos READ this !!! add your user name !
sourcelocation="/home/domz/torrents/"
# Extension of source videos
sourceext="avi,mpg,mpeg,mov,rmvb,rm,ogm,4v"
# Wait while any other ffmpeg processes are running
while [ -n "$(ps -ef | egrep "ffmpeg|HandBrakeCLI" | grep -v grep)" ];
do
        echo -e "\n[$(date +%b\ %d\ %Y:\ %H:%M:%S)]\nFound another instance of HandBrake or ffmpeg running, pausing 5 minutes..."
        sleep 300
done
#http://thomer.com/howtos/ipod_video.html
find ${sourcelocation} -iname "*${sourceext}" -exec HandBrakeCLI -i {} -o ${}.mp4  -e x264 -q 0.589999973773956 -a 1 -E faac -B 128 -R 48 -6 dpl2 -f mp4 -X 480 -m -x level=30:cabac=0:ref=2:mixed-refs:analyse=all:me=umh:no-fast-pskip=1
# Check to see if videos were encoded, then delete source vids and shutdown
if [ -e "${sourcelocation}/*.avi" ] && [ -e "${sourcelocation}/*.mp4]; then
	# Delete videos	
	for ext in avi mpeg mov mpg txt nfo; do rm ${sourcelocation}/*.$ext; done	
	#copys a txt file from my directory to sources directory
	cp /home/domz/file.txt ${sourcelocation}
	#moves directory
	mv ${sourcelocation} /home/admin/${sourcelocation}_domain.com
	#builds the torrent file using: http://claudiusmaximus.goto10.org/cm/torrent.html
	#http://www.torrent-invites.com/tutorials/52022-putty-complete-tutorial.html
	cd /home/domz
	mktorrent -v -p -a http://tracker.url -o {sourcelocation}_domain.com.torrent /home/domz/torrents
else
	echo "Encoding FAILED"
fi

exit

# 4  
Old 05-19-2010
Find command with -exec will be used as:

Code:
find find ${sourcelocation} -iname "*${sourceext}" -exec blabal {} blabla \;

Seems your find command missed the last part.

And for this part, you need add a space after mp4:

Code:
if [ -e "${sourcelocation}/*.avi" ] && [ -e "${sourcelocation}/*.mp4 ]; then

# 5  
Old 05-20-2010
Quote:
Originally Posted by rdcwayx
Find command with -exec will be used as:

Code:
find find ${sourcelocation} -iname "*${sourceext}" -exec blabal {} blabla \;

Seems your find command missed the last part.

And for this part, you need add a space after mp4:

Code:
if [ -e "${sourcelocation}/*.avi" ] && [ -e "${sourcelocation}/*.mp4 ]; then

Thanks, I figured I need the \; till later, but so far I got it to convert, it won't do the other functions.

---------- Post updated at 10:19 PM ---------- Previous update was at 09:54 PM ----------

Whenever I run the script, I get:

(handbrake correctly converts)

Code:
Rip done!
HandBrake has exited. 
/home/domz/everything: line 50: unexpected EOF while looking for matching `"'
/home/domz/everything: line 54: syntax error: unexpected end of file

# 6  
Old 05-20-2010
run the script by

Code:
/bin/bash -x yourscript

It will give you more messages to analyze.
# 7  
Old 05-20-2010
thanks checking it now, what should I put in to delete the .avi from my .avi.mp4
cuz when it converts, it saves as full name with avi extension.:

blahblahblah.avi ----> blahblahblah.avi.mp4

---------- Post updated at 11:01 PM ---------- Previous update was at 10:38 PM ----------

Ok, so far I get...


(HandBrakeCli works fine)...

Rip done!
HandBrake has exited.
+ '[' -e '/home/domz/torrents/*.avi' ']'
+ echo 'Encoding FAILED'
Encoding FAILED
+ exit
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Run automated bash commands from sh login shell

I use plink.exe to automate remote commands that return data to Windows machines. This works well on newer servers running Red Hat since the commands were developed for bash and the designated user's login shell is bash. I need to also support older servers which are running Solaris 10 but the... (5 Replies)
Discussion started by: randman1
5 Replies

2. Shell Programming and Scripting

Create automated scan of specific directory using bash

I am trying to use bash to automate the scan of a specific directory using clamav. Having this in place is a network requirement. The below is an attempt to: 1. count the extensions (.txt, .jpeg) in a directory and write them to a virus-scan.log (section in bold) 2. scan each folder in the... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Programming

Convert Bash script to C

dear all, i need your advice for convert bash shell to C programming INDEX=/zpool1/NFS/INDEX/${1} SCRIPT=/zpool1/NFS/script/${1} LIST=SAMPLE cd ${SCRIPT} for i in `cat ${LIST}` do GETDATE=`echo ${i}|awk '{print substr($1,9,8)}'` /usr/xpg4/bin/awk -F ":" '{close(f);f=$4}{print >>... (2 Replies)
Discussion started by: zvtral
2 Replies

4. Shell Programming and Scripting

Help: How to convert this bash+awk script in awk script only?

This is the final first release of the dynamic menu generator for pekwm (WM). #!/bin/bash function param_val { awk "/^${1}=/{gsub(/^${1}="'/,""); print; exit}' $2 } echo "Dynamic {" for CF in `ls -c1 /usr/share/applications/*.desktop` do name=$(param_val Name $CF) ... (3 Replies)
Discussion started by: alexscript
3 Replies

5. Shell Programming and Scripting

Automated Bash Install Script

I'm making an automated bash install script. When you install mysql-server using apt-get, there's a blue dialog screen where it wants you to chose your mysql root password. Is there a way to pre-define the password in the apt-get command, or have it not chose a root password? It's not a... (2 Replies)
Discussion started by: Matezius
2 Replies

6. Shell Programming and Scripting

Bash shell script: Str(007) to int(7),increment it(8) & convert back to string(008)

Hi, I have the following requirement. There will be following text/line in a file (eg: search-build.txt) PRODUCT_VERSION="V:01.002.007.Build1234" I need to update the incremental build number (eg here 007) every time I give a build through script. I am able to search the string and get... (4 Replies)
Discussion started by: drwatson_droid
4 Replies

7. Shell Programming and Scripting

ffmpeg script to convert all movies in a folder for PSP

Hi all, I use ffmpeg to convert my movies to play them with my PSP. I use the terminal version of ffmpeg so i put in the code: ]ffmpeg -i FILENAAM.avi -f psp -r 29.97 -b 512k -ar 24000 -ab 64k -s 320x240 M4V00001.MP4 FILENAAM is the part i replace with the title of the movie i want to see... (17 Replies)
Discussion started by: Ditzyken
17 Replies

8. Shell Programming and Scripting

Need a script to convert csh to bash

Hi, Can anyone give me a script to convert csh to bash? or any key points which can help me to do so as i am new to it. (3 Replies)
Discussion started by: vineet.dhingra
3 Replies

9. Linux

convert avi to cellphone friendly 320x176 mp4 file...ffmpeg to the rescue :)

found a few ffmpeg posts and after a few unsuccessful attempts, I have found a solution :) to encode an avi to to an nokia e71 recognized mp4 format: ffmpeg -y -i inputFILE.avi -acodec aac -ab 72k -s 320x176 -aspect 16:9 -vcodec h264 -b 300k -qcomp 0.6 -qmin 16 -qmax 51 -qdiff 4 -flags +loop... (2 Replies)
Discussion started by: mr_manny
2 Replies

10. Shell Programming and Scripting

having a bash script convert ft to meters with 1 decimal

What is the correct syntax to limit the number of decimals to 1 or 0 in a bash script? Here is the partial code I have which works, but if I echo $meters, it has 4 or 5 decimals: METERS=`echo "$FEET * 0.3048" | bc` I read about scale and length in the bc man page, but I can't seem to get the... (2 Replies)
Discussion started by: audiophile
2 Replies
Login or Register to Ask a Question