0

I have a .bash_profile script that uses FFMPEG to create a ProRes file from an image sequence. The name of the FFMPEG output file is taken from the current working directory. I'm fine taking the name from the parent directory because After Effects is set to create a folder for each image sequence render that has the same the name as the sequence.

This works fine if there's no spaces in the name. Example: My_Movie/My_Movie_00001.tif, etc gives me My_Movie_ProRes.mov

But I'd like to have it also work for folders with spaces in the name. I've tried adding quotes to various places but it just either fails or outputs as _ProRes.mov with no folder name at all.

pro () {

OUTPUT_NAME=${PWD##*/}

local fps=24;
local filename="${OUTPUT_NAME}"_ProRes.mov;
local ext=tif;

while test $# -gt 0; do
    case "$1" in
        -fps)
            shift
            fps=$1
            shift
            ;;
        -filename)
            shift
            filename=$1
            shift
            ;;
        -quality)
            shift
            quality=$1
            shift
            ;;
        *)
            echo "$1 is not a recognized flag!"
            return 0;
            ;;
    esac
done 

    /usr/local/bin/ffmpeg -r $fps \
    -f image2 -pattern_type glob \
    -i "*?$ext" \
    -codec:v prores_ks \
    -pix_fmt yuva444p10le \
    -vf scale=out_color_matrix=bt709 \
    -profile:v 4444 \
    $filename
}

SUCCESS! Thanks for your insight, especially John1024 and Jesse_b!

pro () {

OUTPUT_NAME="${PWD##*/}"

local fps=24;
local filename="${OUTPUT_NAME}"_ProRes.mov;
local ext=tif;

while test $# -gt 0; do
           case "$1" in
                -fps)
                    shift
                    fps=$1
                    shift
                    ;;
                -filename)
                    shift
            filename=$1
                    shift
                    ;;
                *)
                   echo "$1 is not a recognized flag!"
                   return 0;
                   ;;
          esac
  done  

    /usr/local/bin/ffmpeg -r $fps \
    -f image2 -pattern_type glob \
    -i "*?$ext" \
    -codec:v prores_ks \
    -pix_fmt yuva444p10le \
    -vf scale=out_color_matrix=bt709 \
    -profile:v 4444 \
    "$filename"
}
  • 2
    For starters, in the second to last line, replace $filename with "$filename". Also, whenever you have a shell script error, a good first step is to cut and paste your code into shellcheck.net and correct the errors (important) and warnings (might be important) that it identifies. If you have trouble understanding its messages, then come here and ask. – John1024 Sep 27 '19 at 17:52
  • oops OUTPUT_NAME_BACK was an error on my part, a backup of the line while I tried other things. Just forgot to correct it when pasting into Stack Exchange. Corrected it now. Still doesn't work though lol – markpaterson Sep 27 '19 at 17:59
  • @markpaterson: Does it work if you properly quote your variables as John1024 suggested? – jesse_b Sep 27 '19 at 18:00
  • @Jesse_b I double quoted "$filename" at the bottom but it still outputs as _ProRes.mov. Also tried adding double quotes to OUTPUT_NAME"${PWD##*/}" as suggested by ShellCheck. Same result, _ProRes.mov – markpaterson Sep 27 '19 at 18:03
  • What if you add right below the OUTPUT_NAME=${PWD##*/} line the following: echo "OUTPUT_NAME is: $OUTPUT_NAME" – jesse_b Sep 27 '19 at 18:05
  • 1
    @markpaterson Good work so far! My next suggestion is to run your script as bash -x scriptname which will print debugging info so that you can see exactly where the code went wrong. – John1024 Sep 27 '19 at 18:06
  • Since it's a function, if you are simply running it interactively from the command line you can just run set -x; pro ... . Then set +x to disable debugging. – jesse_b Sep 27 '19 at 18:08
  • @Jesse_b ok added echo "OUTPUT_NAME is: $OUTPUT_NAME". same result :( – markpaterson Sep 27 '19 at 18:08
  • 1
    Well what is the result of the echo output_name line...? If OUTPUT_NAME is not being set at all you might have a syntax error in your actual code that is not reflected here. – jesse_b Sep 27 '19 at 18:09
  • @Jesse_b I ran set -x; pro and got + pro + 'OUTPUT_NAMEMy Movie v4' -bash: OUTPUT_NAMEMy Movie v4: command not found + local fps=24 + local filename=_ProRes.mov + local ext=tif + test 0 -gt 0 + /usr/local/bin/ffmpeg -r 24 -f image2 -pattern_type glob -i '*?tif' -codec:v prores_ks -pix_fmt yuva444p10le -vf scale=out_color_matrix=bt709 -profile:v 4444 _ProRes.mov – markpaterson Sep 27 '19 at 18:16
  • 1
    You're missing an = between OUTPUT_NAME and ${PWD##*/}. You wrote this in a comment above but I assumed it was just a typo. It's very important that you paste your code into the question exactly as it is being run for us to help you. – jesse_b Sep 27 '19 at 18:16
  • 1
    @Jesse_b that did it! I probably just goofed up when "correcting" the OUTPUT_NAME_BACK. Between that, and the double quote suggestions from John1024 it now works! Thanks guys – markpaterson Sep 27 '19 at 18:19
  • Awesome. It seems like the original problem was the quoting issue that John pointed out and then you just had that typo that was created during troubleshooting. – jesse_b Sep 27 '19 at 18:22
  • You should be able to provide an answer to your own question that you later can accept. This would mark the question as resolved. – Kusalananda Sep 27 '19 at 19:21

0 Answers0