|
|||||||||
| Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here. |
unix and linux operating commands |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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
exitI 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}/*.nfoor if there is a better way. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
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}/*.nfocould probably be reduced to Code:
for ext in avi mpeg mov mpg txt nfo; do rm ${sourcelocation}/*.$ext; doneHTH |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
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
|
||||
|
||||
|
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 |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Quote:
---------- 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 |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
run the script by Code:
/bin/bash -x yourscript It will give you more messages to analyze. |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
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 |
| Sponsored Links | ||
|
|
![]() |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ***convert from perl to bash*** | ferrycorsten73 | Shell Programming and Scripting | 3 | 04-01-2009 08:24 AM |
| convert avi to cellphone friendly 320x176 mp4 file...ffmpeg to the rescue :) | mr_manny | Linux | 2 | 12-23-2008 04:26 PM |
| having a bash script convert ft to meters with 1 decimal | audiophile | Shell Programming and Scripting | 2 | 09-14-2008 11:00 AM |
| Help! Need to convert bash shell to perl | freak | Shell Programming and Scripting | 0 | 06-19-2008 11:42 AM |
| Convert bash to sh URGENT :( | Chris Jones | Shell Programming and Scripting | 2 | 04-18-2004 08:18 AM |
|
|