How to pass a Bash variable to the timecode overlay field in ffmpeg drawtext filter?

-1

So I am trying to build a folder action in Automator that will take any mp4 file dropped into it and overlay that file's ahem... "timecode" (actually it's just a start reference for the timecode that I want to overlay, that has been pasted into the file's title like so:

00/58/47;02-test.mp4

with 00/58/47;02 being the timecode starting reference that i want to pass to the drawtext filter timecode field to overlay onto the new video file.

So as I am very new to bash I went about first stripping out the part I wanted and when I thought I had a properly formatted timecode reference I tried to pass it to the drawtext filter but it doesn't work...

I think it must have something to do with the way the $TC variable is or isn't expanding in the ffmpeg command. Any thoughts or tips on how to properly pass the timecode start reference variable to the drawtext overlay timecode field would be much appreciated.

here's where I'm at

    for f in "$@"
    do
    FILENAME=$(basename "$f")

    #grab TC start reference from Filename
    DTC=${FILENAME:0:11}

    # create variables for first string replace
    MATCH='/'
    REPL='\\:'

    # Replace "/" with "\\:"
    CTC="${DTC//$MATCH/$REPL}"

    # create variables for second string replace
    MATCH2=';'
    REPL2='\\;'

    # Replace ";" with "\\;"
    FTC="${CTC/$MATCH2/$REPL2}"

    #put formatted timecode in a variable
    TC="$FTC"

    /usr/local/bin/ffmpeg -i "$f" -vf \
    "format=yuv444p, \ 

    #### This ${TC} Variable doesn't work... if I type out a timecode ie. 
    #### '00\:58\:47\;02' within the single quotes it works fine
    drawtext=fontfile=/Library/Fonts/Arial.ttf :timecode='${TC}' \

    :rate=30000/1001 :x=(w-tw)/2: y=(h-th)/2: fontcolor=white: fontsize=36: \
    box=1: boxcolor=0x00000099, \
    format=yuv420p" \
    -c:v libx264 -r 30000/1001 \
    -x264opts "keyint=180:min-keyint=180:no-scenecut" \
    -c:a copy -movflags +faststart 
    "/Users/Station1/Desktop/TCDONE/${FILENAME%.*}.mp4"
    mv "$f" "/Users/Station-1/Desktop/TCOG/${FILENAME%.*}.mp4"
    done

Any solutions or explanations on how to properly pass the $TC variable to the drawtext filter timecode overlay field would be greatly appreciated. Thanks for reading!

bash
video
ffmpeg
environment-variables
overlay
asked on Super User Apr 27, 2017 by Derker • edited Apr 27, 2017 by Derker

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0