#!/bin/bash
test -z "$CIN_RENDER" && exit 

exec >& /tmp/render_mux.log
echo == $0 $@

# Render output mux-ed into a single file
ffmpeg -hide_banner -safe 0 -y \
	 -f concat -i <(for f in "$CIN_RENDER"0*; do echo "file '$f'"; done) -c copy $CIN_RENDER
RC=$?

DIALOG="notify-send kdialog xmessage"
NOTIFY() {
  notify-send "$1" "$2"
}
KDIALOG() {
  kdialog --title "$1" --passivepopup "$2" 7
}
XMESSAGE() {
  xmessage -center -default 'okay' -title "$1" "$2" &
}

case $RC in
  0) TITLE="Cinelerra: RenderMux completed" ;;
  *) TITLE="Cinelerra: RenderMux failed"
	 CIN_RENDER="$(cat /tmp/render_mux.log)" ;;
esac

for j in $DIALOG; do
  case "$(which $j)" in
	*notify-send) NOTIFY "$TITLE" "$CIN_RENDER" ; break ;;
	*kdialog) KDIALOG "$TITLE" "$CIN_RENDER" ; break ;;
	*xmessage) XMESSAGE "$TITLE" "$CIN_RENDER" ;;
  esac
done
