Need help on ffmpeg batch script

by Olung

Trying to make a ffmpeg batch scripts that makes proress 422 proxy files from raw .mov files thats located in many subfolders. So far i got this:

#!/bin/bash

echo "drop source folder: "
read source

echo "drop destination folder: "
read des

find "$source" -name '*.mov' -exec sh -c 'ffmpeg -i "$0" -vcodec prores -profile:v 0 -an "$des/${0%%.mov}.mov"' {} \;
exit;

But it doesn't output to the destination folder, only the source folder and ask for an overwrite - not what I want.

I guess it's a simple parameter error that maybe some of you can spot out?

All help is kindly appreciated!

Answers

  1. konsolebox answer

    This would be my suggestion. Looks like this was follow-up from your previous thread.

    #!/bin/bash
    
    [ -n "$BASH_VERSION" ] || {
        echo "You need Bash to run this script."
        exit
    }
    
    shopt -s extglob || {
        echo "Unable to enable exglob."
        exit 1
    }
    
    until
        read -erp "Drop source folder: " SOURCE
        [[ -d $SOURCE ]]
    do
        echo "Drop source folder does not exist: $SOURCE"
        echo "You can abort this script by pressing CTRL-C."
    done
    
    until
        read -erp "Drop destination folder: " DES
        [[ -d $DES ]]
    do
        echo "Drop destination folder does not exist: $DES"
        echo "You can abort this script by pressing CTRL-C."
    done
    
    while IFS= read -r FILE; do
        BASE=${FILE##*/}
        NOEXT=${BASE%.???}
        echo ffmpeg -i "$FILE" -vcodec prores -profile:v 0 -an "$DES/${NOEXT}.mov"  ## Remove echo if it's already correct.
    done < <(exec find "$SOURCE" -type f -name '*.mov')  ## You could also use -iname '*.sh' instead to also match files like .MOV.
    

    Notes: Using -e option for read is helpful to easily generate paths by pressing tab.

  2. Jdamian answer

    I guess you need to export the des variable.

    In this kind of cases I always suggest to insert a "echo" just before the target command ("ffmpeg")

    find "$source" -name '*.mov' -exec sh -c 'echo ffmpeg -i "$0" -vcodec prores -profile:v 0 -an "$des/${0%%.mov}.mov"' {} \;
    

    This way you will see what you are trying to run