0

I have a script for converting Handbrake videos, but I want to make presets. I am having trouble with the script, in the end it outputs something like

    HandBrakeCLI -i file.avi -o file.mp4 flags

But I can't get the flags part to work, so to troubleshoot I want to see what the command line is receiving as a translation of my script.

Here is the link to my working script

How to Install Handbrake and Convert recursive file tree's

Here is what I would like it to look like

Only the changes are shown

    FLAGS="-E ac3 -6 5point1 -R 48 -B 448 --audio-fallback ac3"
    if [ -z "$1" ] ; then
        TRANSCODEDIR="."
    else
        TRANSCODEDIR="$1"
    fi
        find "$TRANSCODEDIR"/* -type f -exec bash -c 'HandBrakeCLI -i "$1" -o "${1%\.*}".mp4 "$FLAGS"' __ {} \;

Basically the $Flags option isnt working, and as I mess around it either doesn't find the file, or does and doesn't see the flags, help with the script is fine, but for future debugging of other scripts i wouldnt mind knowing how to just output the commands it "would" have sent to the shell instead just to the screen or a text file probably is better.

Thanks!

FreeSoftwareServers
  • 1,129
  • 1
  • 14
  • 32

2 Answers2

2

You can add set -x to the top of your bash script or (equivalently) run it using

 bash -x yourscript

See help set or the SHELL BUILTIN COMMANDS section of man bash:

  -x  Print commands and their arguments as they are executed.

There is more discussion at How to debug a bash script? on SE Unix & Linux


What you will probably see in this case is that $FLAGS variable is empty: it is enclosed in single quotes so gets passed literally to the bash -c subshell, where $FLAGS is undefined.

steeldriver
  • 142,475
0
export FLAGS="-f mp4 -O --decomb=bob --loose-anamorphic --modulus 2 -e x264 -q 20 --vfr -E ac3 -6 5point1 -R 48 -B 448 --audio-fallback ac3 --encoder-preset=veryfast  --verbose=1"

Worked for me, thanks for the help guys, see the script in action at How to Install Handbrake and Convert recursive file tree's

FreeSoftwareServers
  • 1,129
  • 1
  • 14
  • 32