I have the following code and after the transcode finishes i wish to move the newly created file. But only after, i don't want to write to the other folder as it trancodes. That is why i presume using exec is better as this will only be processed if the previous exec read true. Also note that there maybe more than one file in the current folder.
#!/bin/bash
#
# Change this to specify a different handbrake preset. You can list them by running: "HandBrakeCLI --preset-list"
#
PRESET="AppleTV 2"
if [ -z "$1" ] ; then
TRANSCODEDIR="/path/to/folder"
else
TRANSCODEDIR="$1"
fi
find "$TRANSCODEDIR"/* -type f -exec bash -c 'HandBrakeCLI -i "$1" -o "${1%.*}".mp4 -- preset="$PRESET"' __ {} \; -exec rm {} \;
My little knowledge of linux i thought maybe:
#!/bin/bash
#
# Change this to specify a different handbrake preset. You can list them by running: "HandBrakeCLI --preset-list"
#
PRESET="AppleTV 2"
if [ -z "$1" ] ; then
TRANSCODEDIR="/path/to/folder"
else
TRANSCODEDIR="$1"
fi
find "$TRANSCODEDIR"/* -type f -exec bash -c 'HandBrakeCLI -i "$1" -o "${1%.*}".mp4 -- preset="$PRESET"' __ {} \; -exec rm {} \; -exec mv '"${1%.*}".mp4' "/path to/converted/folder" \;
But this just puts out:
mv: cannot stat â"${1%.*}".mpâ4: No such file or directory
Now i thought maybe this was some characters from notepad++ hiding in there somewhere so i ran it through dos2uunix. But still i am getting the same error.
Now i thinking that "${1%.}".mp4 isn't actually getting the newly create file rather it is looking for a file called "${1%.}".mp4, which doesn't exist.
Any help would be appreciated.
find
does not support parameter substitutions, you need to pass ${1%.*}
to the shell. But fortunately, that's not very hard to do:
find "$TRANSCODEDIR" -type f -exec bash -c 'HandBrakeCLI -i "$1" -o "${1%.*}".mp4 -- preset="$PRESET";
rm "$1";
mv "${1%.*}".mp4 "/path/to/converted/folder"' _ {} \;
So just to clarify; the "top level" is find -exec bash -c '...' _ {} \;
and the Bash script inside the single quotes contains three commands, all of which operate on the same input file.