Home > Software design >  Understanding a script which uses ffmpeg to send rtmp input to node.js script
Understanding a script which uses ffmpeg to send rtmp input to node.js script

Time:06-05

I was trying to understand this shell script which uses ffmpeg to take an rtmp input stream and send it to a node.js script. But I am having trouble understanding the syntax. What is going on here?

The script:

while :
do
  echo "Loop start"

  feed_time=$(ffprobe -v error -show_entries format=start_time -of default=noprint_wrappers=1:nokey=1 $RTMP_INPUT)
  printf "feed_time value: ${feed_time}"

  if [ ! -z "${feed_time}" ]
  then
  ffmpeg -i $RTMP_INPUT -tune zerolatency -muxdelay 0 -af "afftdn=nf=-20, highpass=f=200, lowpass=f=3000" -vn -sn -dn -f wav -ar 16000 -ac 1 - 2>/dev/null | node src/transcribe.js $feed_time

  else
  echo "FFprobe returned null as a feed time."
  
  fi

  echo "Loop finish"
  sleep 3
done
  • What is feed_time here? What does it represent?
  • What is this portion doing - 2>/dev/null | node src/transcribe.js $feed_time?
  • What is the use of sleep 3? Does this mean that we are sending audio stream to node.js in chuncks of 3 seconds?

CodePudding user response:

  • feed_time variable represents standard output of ffprobe command. This value needs to be passed to node script.
  • - character doesn't have special meaning in bash, i.e. it is interpreted by ffmpeg command itself (see here). According to ffmpeg docs:

A - character before the stream identifier creates a "negative" mapping. It disables matching streams from already created mappings.

  • 2>/dev/null is a redirection that sends standard error output of ffmpeg command to /dev/null device, thus effectively discarding the error output (see here). It is done because you want only the standard output (not error output) to be passed to node script.
  • | is a pipe. It sends standard output of ffmpeg command to standard input of node script.
  • sleep just delays execution of a script.
  • Related