#!/bin/sh
fifo=tcp://127.0.0.1:9090
#frame_rate MUST match the encoder framerate
frame_rate=25
FIREFOX="Firefox/"

#This might be relevant if we make the frame discrepancy work on chrome browsers
if echo $USER_AGENT | grep -q $FIREFOX;
then
  f_in=`expr $frame_rate \* 2`;
else
  f_in=60;
fi

echo 'Cache-Control: no-cache'
echo 'Pragma: no-cache'
echo ''

killall -9 ffmpeg

PROCS=`ps`
echo $PROCS | grep ffmpeg > /dev/null 2>&1
if [ $? -ne 0 ]; then
    ffmpeg -r $f_in -framerate $f_in -f h264 -listen 1 -i $fifo -codec copy -movflags +empty_moov -movflags +frag_keyframe -f mp4 -r $frame_rate -framerate $frame_rate -
fi

