I wrote a script that would identify all *.CD01.avi files in the directory, count how many *.CD* would there be for that particular movie (2 for the Boat ride case above), and iterate a loop to build the command-line for avimerge. The problem is that I have no clue on how to tackle the dreaded spaces and other special chars, and avimerge is not receiving the file names properly to do its work. Please do not tell me "get rid of spaces and other special chars" as they are mandatory.

For my future knowledge, a question: what happens exactly in the line, regarding the expansion of "${NAME}".CD[0-9][0-9].avi in several file names? :

Code:

avimerge -i "${NAME}".CD[0-9][0-9].avi -o "$OUTPUTFILE"

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.

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):

If you really want to know what is happening and why your script is behaving like it is, you can put 'set -x' before a part you want to debug and 'set +x' to turn debugging off again. Turning debugging on will generate a lot of output and can look quite scary, but it's faster than waiting for someone to answer on a forum

Using '$(ls)' in your for loop will execute first and all filenames, including the spaces are then passed to the for loop which will see them as separate parts.I strongly suggest getting rid of the spaces in your filenames first, before processing them any further. It really makes scripting against it hell.Just replace them with i.e. underscores and after merging/encoding replace them again with spaces if you must.

thanks for the tip on set -x. Will use it from now on to understand better my scripts.

I realized it is much simpler to use this for the multiparts:

Code:

for FILE in *.CD01.avi

What I really need is to figure out a way to match files not containing .CD??.avi in their names, with proper escaping. Substituting the spaces seems to me a little bit scary. This script will be handling movies from my family members, and I cannot force them to not use special chars, particularly as we are non-english speakers (lots of cedillas, etc). Will keep trying and will post the final script here for reference when I eventually get at it.

In ksh and bash you have to turn on 'extended file globbing'Check if it's on/off with 'shopt extglob' and turn it on with 'shopt -s extglob'Then you can use '!(*.CD[0-9][0-9].avi)' to do an inverse of a fileglob.You can turn it off again with 'shopt -u extglob'

Well, after some more learning, here is my final complete script. It suits my needs very well. Thanks Patsie for your help.

Code:

#!/bin/sh

############################################################################### Script to encode home movies recorded by a Canon IXUS 860 IS to H.264## Author: partimers@gmail.com## Requires: ffmpeg and mencoder on your $PATH## * This script will encode all *.avi movies on the current dir. It does# not recurse sub-directories## * Multi-part movies will be merged with mencoder and then encoded.# Multi-parts should be named like this: ## Movie Name.CD01.avi# Movie Name.CD02.avi# Movie Name.CD03.avi## * At the end, the encoded movies will be abailable on directory ./_ENC_###############################################################################

mkdir -p _ENC_

for FILE in *.avi;do # Firt process the multi-parts if [[ "$FILE" =~ \.CD[[:digit:]][[:digit:]]\.avi ]] then set +x # Match the first part of the multi-part movies if [[ "$FILE" =~ \.CD01\.avi ]] then NAME=${FILE%.CD01.avi} OUTPUTFILE="$NAME".mp4 NUMFILES=`ls "$NAME".CD* | wc -l`

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum