user1704620
user1704620

Reputation: 101

How to put a variable to a string in Bash

I am writing a Bash script, and I am trying to figure out a way to get FFmpeg to recognize a global variable in the -force_key_frames option. The -force_key_frames option can take a regular expression as an argument, allowing functionality such as forcing a key frame every 5 seconds:

-force_key_frames 'expr:gte(t,n_forced*5)'

This works fine for forcing a key frame every 5 seconds, but I don't know how to force a key frame every x seconds, x being an input variable from the user gotten by the rest of the script. The exact FFmpeg command that I'm trying is:

ffmpeg -i "video.mp4" -vcodec: libx264 -b:v 500k \
-force_key_frames 'expr:gte(t,n_forced*${SEG_TIME})' -s:v 640x480 \
-r 29.97 -pix_fmt yuv420p -map 0 -f segment -segment_time ${SEG_TIME} \
-reset_timestamps 1 -y "output%01d.mp4"

The variable $SEG_TIME is set to 5 by the script, but the regular expression in the -force_key_frames option doesn't seem to like the $SEG_TIME variable.

Upvotes: 0

Views: 6668

Answers (1)

Zombo
Zombo

Reputation: 1

This part

'expr:gte(t,n_forced*${SEG_TIME})'

your single quotes are causing the string ${SEG_TIME} to be passed literally rather than interpreted as a variable, try this

"expr:gte(t,n_forced*${SEG_TIME})"

Upvotes: 5

Related Questions