Patsie wrote:
Before calling avimerge, your shell will first evaluate all variables.
First it will expand ${NAME} to for example 'My Movie File'.
Then it will evaluate "My Movie File".CD[0-9][0-9].avi to all matching filenames, like an 'ls' command.
Finally it will start avimerge with all expanded filenames found.
Hi Patsie,
Thanks a lot for your help and explanation. I need one more thing before my script is like I need it to be. I need to process the files differently if they are multi-parts (*.CD??.avi) or not. For the the multiparts I need to perform the merge and then encode. For the single parts, there is no merging, just the encoding. Basically I need:
- Match anything named <some name>.CD01.avi, then merge all <some name>.CD??.avi and encode the avi
- Match anything not name *.CD??.avi (excluding *.CD02.avi, *.CD03.avi, etc) and just encode.
This was my try (real action is commented out, ffmpeg and avimerge, as I am still strugling to get the right OUTPUTFILENAME):
Code:
#!/bin/sh
echo "Processing Multi-parts"
for FILE in $(ls | egrep '\.CD01\.avi');
do
NAME=${FILE%.CD01.avi}
OUTPUTFILE="$NAME".mp4
echo $OUTPUTFILE
#avimerge -i "${NAME}".CD[0-9][0-9].avi -o "$OUTPUTFILE"
#ffmpeg -y -i "$FILE" -acodec libfaac -vcodec libx264 -b 5000k -threads 0 -r 30 "$NAME".mp4
done
echo "Processing Single-parts"
for FILE in $(ls | grep avi | egrep -v '\.CD[0-9][0-9]\.avi');
do
NAME="${FILE%.CD01.avi}"
OUTPUTFILE="$NAME.mp4"
echo $OUTPUTFILE
#ffmpeg -y -i "$FILE" -acodec libfaac -vcodec libx264 -b 5000k -threads 0 -r 30 "$NAME".mp4
done
I am sure I messing up with the escapes and ls command, because I am not getting correctly at the files. For example, if I run the scripts againts these files:
Code:
090110 01 Barbecue at Sam's.CD01.avi
090110 01 Barbecue at Sam's.CD01.txt
090110 01 Barbecue at Sam's.CD01part.avi
090110 01 Barbecue at Sam's.CD02.avi
090110 01 Barbecue at Sam's.CD03.avi
090110 06 Pier!.avi
090110 07 Boat ride.CD01.avi
090110 07 Boat ride.CD02.avi
_ENC_
testCD01.avi
I get this if I echoed $NAME
Code:
Processing Multi-parts
090110 01 Barbecue at Sam's.CD01.avi 090110 07 Boat ride.mp4
Processing Single-parts
090103 Arriving at Home.avi 090110 01 Barbecue at Sam's.CD01part.avi 090110 06 Pier!.avi testCD01.avi.mp4
If I change the for statement to something like
Code:
for FILE in $(ls | egrep '\.CD01\.avi');
...
for FILE in $(ls | grep avi | egrep -v '\.CD[0-9][0-9]\.avi');
then I get
Code:
Processing Multi-parts
090110.mp4
01.mp4
Barbecue.mp4
at.mp4
Sam's.mp4
090110.mp4
07.mp4
Boat.mp4
ride.mp4
Processing Single-parts
090103.mp4
Arriving.mp4
at.mp4
Home.avi.mp4
090110.mp4
01.mp4
Barbecue.mp4
at.mp4
Sam's.CD01part.avi.mp4
090110.mp4
06.mp4
Pier!.avi.mp4
testCD01.avi.mp4
