My scripting knowledge in bash is very basic and I've cobbled together stuff in the past to accomplish some automation I need over the years.
The latest project is about some video processing, and based on a format of the file, I want to do some post-processing.
ffprobe will output meta-data about a video file, with the following excerpt:
ISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=eng
[/STREAM]
[STREAM]
index=1
codec_name=dts
codec_long_name=DCA (DTS Coherent Acoustics)
profile=DTS
codec_type=audio
codec_time_base=1/48000
codec_tag_string=[0][0][0][0]
In particular, i want to detect whether or not the string codec_name=dts is present, then get the index value represented in the line prior. In the above case, it does contain codec_name=dts, and I want to be able to use the value 1 later in the script because of the line index=1 right before it.
In my script, I'm using this logic to do the first string detection using grep:
if (/usr/sbin/ffprobe -show_streams -i "$source" | grep -q "codec_name=dts"); then
<do some work here>
fi
What's the best way to do what I want to accomplish?