Zsh script using formatted date string in FFMPEG command
In my zsh script, I am receiving a string that represents a Unix epoch, like:
myTimestamp="1719742786"
I want to change that date into a formatted string, and then store it in a variable so it can be used in an upcoming ffmpeg script. I’m doing it this way:
theDate=$(date -u -r "$myTimestamp" "+%b %d, %H:%M:%S")
echo "$theDate"
which prints to my screen what I want:
Jun 30, 06:19:48
but when I try to use this variable in my ffmpeg script, I get errors:
ffmpeg -y -i "$file" -vf \
"drawtext=text="$theDate":fontcolor=gray:fontsize=$fontSize:x=$width:y=$height:" \
"$output"
Note that if I change out '$theDate' in the script (to something like '$myTimestamp'), I do not get errors.
What I do get, along with Error initializing filters, is this (possibly important?) error:
Both text and text file provided. Please provide only one
My full script:
#!/bin/zsh
outDir="printed"
width=200
height=650
fontSize=95
for file in initial/*.png; do
filename=$(basename "$file")
prefix="${filename%.*}"
theDate=$(date -u -r "$prefix" "+%b %d, %H:%M:%S")
output="$outDir/$filename"
echo "$theDate"
ffmpeg -y -i "$file" -vf \
"drawtext=text="$theDate":fontcolor=gray:fontsize=$fontSize:x=$width:y=$height:" \
"$output"
done
exit
Read more here: Source link
