# All Versions since 2.2, which is the first one supporting decklink
TAGS="n2.2.16 n2.3.6 n2.4.9 n2.5.9 n2.6.9 n2.7.7 n2.8.9 n3.0.9 n3.1.9 n3.2.7 n3.3.3 master"

# Build a static version of ffmpeg for each tag
function build {
  git checkout $1
  ./configure --enable-static --disable-shared --enable-decklink --extra-cflags="-I$HOME/VOC/Blackmagic_DeckLink_SDK_10.9.5/Linux/include" --extra-ldflags="-L$HOME/VOC/Blackmagic_DeckLink_SDK_10.9.5/Linux/include" --extra-ldflags="-ldl" --extra-libs=-ldl
  make clean
  make -j8
  mkdir $1
  cp ffmpeg ffprobe ffserver $1
  make distclean
}
for tag in $TAGS; do build $tag; done

# n2.2.16 n2.3.6 n2.4.9 and n2.5.9 did not recognize the decklink card
TAGS="n2.5.9 n2.6.9 n2.7.7 n2.8.9 n3.0.9 n3.1.9 n3.2.7 n3.3.3 master"

# With progressive source
function test_1080p25_default {
  echo "$1 default"
  ./$1/ffmpeg -v warning -y -nostdin \
    -t 1 -f decklink -i 'DeckLink Mini Recorder@7' \
    -c:v rawvideo \
    -c:a pcm_s16le \
    -pix_fmt yuv420p \
    -f matroska \
    /tmp/out.mkv

  mkvinfo /tmp/out.mkv | grep -iA5 "+ Video track"
  echo ""
}
for tag in $TAGS; do test_1080p25_default $tag; done >test_1080p25_default


function test_1080p25_field_order_progressive_out {
  echo "$1 default"
  ./$1/ffmpeg -v warning -y -nostdin \
    -t 1 -f decklink -i 'DeckLink Mini Recorder@7' \
    -c:v rawvideo \
    -c:a pcm_s16le \
    -pix_fmt yuv420p \
    -field_order progressive -f matroska \
    /tmp/out.mkv

  mkvinfo /tmp/out.mkv | grep -iA5 "+ Video track"
  echo ""
}
for tag in $TAGS; do test_1080p25_field_order_progressive_out $tag; done > test_1080p25_field_order_progressive_out 2>&1


function test_1080p25_field_order_progressive_in {
  echo "$1 default"
  ./$1/ffmpeg -v warning -y -nostdin \
    -t 1 -field_order progressive -f decklink -i 'DeckLink Mini Recorder@7' \
    -c:v rawvideo \
    -c:a pcm_s16le \
    -pix_fmt yuv420p \
    -f matroska \
    /tmp/out.mkv

  mkvinfo /tmp/out.mkv | grep -iA5 "+ Video track"
  echo ""
}
for tag in $TAGS; do test_1080p25_field_order_progressive_in $tag; done > test_1080p25_field_order_progressive_in 2>&1


function test_1080p25_field_order_progressive_in_out {
  echo "$1 default"
  ./$1/ffmpeg -v warning -y -nostdin \
    -t 1 -field_order progressive -f decklink -i 'DeckLink Mini Recorder@7' \
    -c:v rawvideo \
    -c:a pcm_s16le \
    -pix_fmt yuv420p \
    -field_order progressive -f matroska \
    /tmp/out.mkv

  mkvinfo /tmp/out.mkv | grep -iA5 "+ Video track"
  echo ""
}
for tag in $TAGS; do test_1080p25_field_order_progressive_in_out $tag; done > test_1080p25_field_order_progressive_in_out 2>&1




# With interlaced source
function test_1080i25_default {
  echo "$1 default"
  ./$1/ffmpeg -v warning -y -nostdin \
    -t 1 -f decklink -i 'DeckLink Mini Recorder@10' \
    -c:v rawvideo \
    -c:a pcm_s16le \
    -pix_fmt yuv420p \
    -f matroska \
    /tmp/out.mkv

  mkvinfo /tmp/out.mkv | grep -iA5 "+ Video track"
  echo ""
}
for tag in $TAGS; do test_1080i25_default $tag; done >test_1080i25_default


function test_1080i25_field_order_progressive_out {
  echo "$1 default"
  ./$1/ffmpeg -v warning -y -nostdin \
    -t 1 -f decklink -i 'DeckLink Mini Recorder@10' \
    -c:v rawvideo \
    -c:a pcm_s16le \
    -pix_fmt yuv420p \
    -field_order progressive -f matroska \
    /tmp/out.mkv

  mkvinfo /tmp/out.mkv | grep -iA5 "+ Video track"
  echo ""
}
for tag in $TAGS; do test_1080i25_field_order_progressive_out $tag; done >test_1080i25_field_order_progressive_out


function test_1080i25_field_order_progressive_in {
  echo "$1 default"
  ./$1/ffmpeg -v warning -y -nostdin \
    -t 1 -field_order progressive -f decklink -i 'DeckLink Mini Recorder@10' \
    -c:v rawvideo \
    -c:a pcm_s16le \
    -pix_fmt yuv420p \
    -f matroska \
    /tmp/out.mkv

  mkvinfo /tmp/out.mkv | grep -iA5 "+ Video track"
  echo ""
}
for tag in $TAGS; do test_1080i25_field_order_progressive_in $tag; done >test_1080i25_field_order_progressive_in


function test_1080i25_field_order_progressive_in_out {
  echo "$1 default"
  ./$1/ffmpeg -v warning -y -nostdin \
    -t 1 -field_order progressive -f decklink -i 'DeckLink Mini Recorder@10' \
    -c:v rawvideo \
    -c:a pcm_s16le \
    -pix_fmt yuv420p \
    -field_order progressive -f matroska \
    /tmp/out.mkv

  mkvinfo /tmp/out.mkv | grep -iA5 "+ Video track"
  echo ""
}
for tag in $TAGS; do test_1080i25_field_order_progressive_in_out $tag; done >test_1080i25_field_order_progressive_in_out
