#!/bin/bash

#!/bin/bash

if [ $# -ne 2 ]; then
    echo $0: usage: jpegEncode [0-5] [/path/to/store] to open /dev/videoX and store images on given location
    exit 1
fi
dev=$(echo /dev/video$1)

FPS=10
JPEG_QUALITY=90;

EXIF_META='exifmake="a company" exifmodel="model 1234" exifartist="the artist" exifcopyright="arbitrary copyright text"'

v4l2-ctl -d $dev -c delayed_start=0
v4l2-ctl -d $dev -c singleshot_mode=0

# Inspect the plugin. This will update the gst-registry recognize the elements in the plugin.
/home/ubuntu/gst_1.9.1/out/bin/gst-inspect-1.0  ./librxproc_plugin.0.5.arm64.so 

# Start the GStreamer pipeline
/home/ubuntu/gst_1.9.1/out/bin/gst-launch-1.0  --gst-disable-registry-fork --gst-plugin-path=. v4l2src device=$dev io-mode=GST_V4L2_IO_USERPTR  ! "video/x-bayer,width=3840,height=2160,framerate=$FPS/1,format=rggb" ! rxautoadapt device=$dev ! rxcudaupload ! rxcudadebayer ! rxcudajpegsink quality=$JPEG_QUALITY location=$2/image_%05d.jpg  $EXIF_META
