Skip to content
Permalink
Browse files
feat(sipi): upload video support (DEV-771 / DEV-207) (#1952)
* feat(sipi): upload video

* feat(sipi): upload video

* feat(sipi): upload video

* build: bump sipi version to one with updated knora.json

* build: bump testcontainers

* feat(sipi): add shell lua

* feat(sipi): store video

* feat(sipi): support video upload

* test: activate for video representation

* test: add debugging output

* build: fix missing env file

* refactor(sipi): restore store.lua script

* feat(sipi): support video upload

* refactor(sipi): restore store.lua script

* refactor(sipi): clean up video upload

* build: add new sipi version with knora.info video support

* chore(sipi): hardcoded fps in case of video

* chore(deps): update sipi

* feat(upload): more on video upload

* refactor: remove properties from moving image file value

* test: regenerate ontology test responses

* deps(sipi): bump to newer version with video information support

* refactor(gh-ci): format indent

* chore(deps): bump sipi to latest (incl. bc and imagemagick)

* refactor(sipi): clean up and improve upload script

* refactor(sipi): clean up and improve upload script

* refactor(sipi): clean up and improve upload script

* refactor(sipi): clean up and improve store script

* feat(sipi): add script to export frames from video

* test(ontologie): regenerate test data

* refactor(sipi): remove commented code

* refactor(sipi): add missing newline

* refactor(sipi): update comment

Co-authored-by: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com>

* refactor(sipi): remove author from shell script

* refactor(sipi): remove unused script

* refactor(sipi): fix typo in coment

Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>

* refactor(sipi): update comment

Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>

* refactor(sipi): delete empty and unused function

Co-authored-by: Kilchenmann <github@milchkannen.ch>
Co-authored-by: Balduin Landolt <33053745+BalduinLandolt@users.noreply.github.com>
Co-authored-by: irinaschubert <irina.schubert@dasch.swiss>
  • Loading branch information
4 people committed Apr 5, 2022
1 parent 603efef commit 47f2e28817fc98af9998a19d56248b638d8ceace
Showing with 5,364 additions and 5,054 deletions.
  1. +2 −0 .gitignore
  2. +1 −1 docker-compose.yml
  3. +2 −20 knora-ontologies/knora-base.ttl
  4. +4 −2 project/Dependencies.scala
  5. +213 −0 sipi/scripts/export-moving-image-frames.sh
  6. +8 −4 sipi/scripts/file_info.lua
  7. +388 −0 sipi/scripts/json.lua
  8. +14 −6 sipi/scripts/store.lua
  9. +86 −13 sipi/scripts/upload.lua
  10. +437 −437 test_data/ontologyR2RV2/anythingOntologyWithValueObjects.ttl
  11. +92 −92 test_data/ontologyR2RV2/anythingThingWithAllLanguages.ttl
  12. +33 −33 test_data/ontologyR2RV2/boxOntologyWithValueObjects.ttl
  13. +84 −84 test_data/ontologyR2RV2/imagesBild.ttl
  14. +71 −71 test_data/ontologyR2RV2/incunabulaBook.ttl
  15. +72 −72 test_data/ontologyR2RV2/incunabulaOntologySimple.ttl
  16. +216 −216 test_data/ontologyR2RV2/incunabulaOntologyWithValueObjects.ttl
  17. +69 −69 test_data/ontologyR2RV2/incunabulaPage.ttl
  18. +137 −137 test_data/ontologyR2RV2/incunabulaPageAndBookWithValueObjects.ttl
  19. +33 −33 test_data/ontologyR2RV2/knoraApiDateValue.ttl
  20. +87 −87 test_data/ontologyR2RV2/knoraApiOntologySimple.ttl
  21. +0 −88 test_data/ontologyR2RV2/knoraApiOntologyWithValueObjects.jsonld
  22. +1,747 −1,811 test_data/ontologyR2RV2/knoraApiOntologyWithValueObjects.rdf
  23. +1,154 −1,202 test_data/ontologyR2RV2/knoraApiOntologyWithValueObjects.ttl
  24. +397 −397 test_data/ontologyR2RV2/standoffOntologyWithValueObjects.ttl
  25. +0 −5 webapi/src/main/scala/org/knora/webapi/messages/OntologyConstants.scala
  26. +0 −8 webapi/src/main/scala/org/knora/webapi/messages/util/ConstructResponseUtilV2.scala
  27. +1 −5 webapi/src/main/scala/org/knora/webapi/messages/v1/responder/valuemessages/ValueMessagesV1.scala
  28. +0 −100 ...ra/webapi/messages/v2/responder/ontologymessages/KnoraBaseToApiV2ComplexTransformationRules.scala
  29. +1 −14 webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2.scala
  30. +1 −0 webapi/src/main/scala/org/knora/webapi/store/iiif/SipiConnector.scala
  31. +0 −19 ...g/knora/webapi/messages/twirl/queries/sparql/v2/generateInsertStatementsForValueContent.scala.txt
  32. +4 −0 webapi/src/test/resources/logback-test.xml
  33. +4 −1 webapi/src/test/scala/org/knora/webapi/ITKnoraLiveSpec.scala
  34. +0 −1 webapi/src/test/scala/org/knora/webapi/e2e/v2/OntologyV2R2RSpec.scala
  35. +5 −23 webapi/src/test/scala/org/knora/webapi/it/v2/KnoraSipiIntegrationV2ITSpec.scala
  36. +1 −3 webapi/src/test/scala/org/knora/webapi/models/filemodels/FileModelUtil.scala
@@ -37,6 +37,8 @@ dependencies.txt
/client-test-data.zip
/sipi/images/082E/*
/sipi/images/originals/082E/*
sipi/images/1111/*
sipi/images/originals/1111/*
/dependencies.bzl

.idea/
@@ -31,7 +31,7 @@ services:
environment:
- TZ=Europe/Zurich
- SIPI_EXTERNAL_PROTOCOL=http
- SIPI_EXTERNAL_HOSTNAME=localhost
- SIPI_EXTERNAL_HOSTNAME=0.0.0.0
- SIPI_EXTERNAL_PORT=1024
- SIPI_WEBAPI_HOSTNAME=api
- SIPI_WEBAPI_PORT=3333
@@ -1195,11 +1195,9 @@

:fps rdf:type owl:DatatypeProperty ;

rdfs:label "Frames per second"@en ;

rdfs:subPropertyOf :valueHas ;

:subjectClassConstraint :MovingImageFileValue ;
:subjectClassConstraint :FileValue ;

:objectDatatypeConstraint xsd:decimal .

@@ -2183,23 +2181,7 @@

:MovingImageFileValue rdf:type owl:Class ;

rdfs:subClassOf :FileValue ,
[ rdf:type owl:Restriction ;
owl:onProperty :dimX ;
owl:cardinality "1"^^xsd:nonNegativeInteger
] ,
[ rdf:type owl:Restriction ;
owl:onProperty :dimY ;
owl:cardinality "1"^^xsd:nonNegativeInteger
] ,
[ rdf:type owl:Restriction ;
owl:onProperty :fps ;
owl:maxCardinality "1"^^xsd:nonNegativeInteger
] ,
[ rdf:type owl:Restriction ;
owl:onProperty :duration ;
owl:maxCardinality "1"^^xsd:nonNegativeInteger
] ;
rdfs:subClassOf :FileValue ;

rdfs:comment "Represents a moving image file"@en .

@@ -9,14 +9,16 @@ import sbt.Keys._
import sbt.{Def, _}

object Dependencies {

val fusekiImage = "daschswiss/apache-jena-fuseki:2.0.8" // should be the same version as in docker-compose.yml
val sipiImage = "daschswiss/sipi:3.5.0" // base image the knora-sipi image is created from

// versions
val akkaHttpVersion = "10.2.9"
val akkaVersion = "2.6.19"
val fusekiImage = "daschswiss/apache-jena-fuseki:2.0.8" // should be the same version as in docker-compose.yml
val jenaVersion = "4.4.0"
val metricsVersion = "4.0.1"
val scalaVersion = "2.13.8"
val sipiImage = "daschswiss/sipi:3.3.4" // base image the knora-sipi image is created from
val ZioHttpVersion = "2.0.0-RC3"
val ZioPreludeVersion = "1.0.0-RC10"
val ZioVersion = "2.0.0-RC2"
@@ -0,0 +1,213 @@
#!/bin/bash

# Export moving image frames for preview in search results and on timeline
# Extract frames from mp4 file:
# - 6 frames per minute
# Create matrix file:
# - max. 36 frames per matrix
# - one matrix file corresponds to 6 minutes of film

set -e

dir=$(pwd)
sep='---------------------------------'

die() {
echo >&2 "$@"
exit 1
}

usage() {
echo "usage: <command> -i [infile]>"
echo ${sep}
echo "-i = Inpute file"
echo ${sep}
}

collect() {
film=''
cnt=1
#for b in `ls`; do
for file in *.$1; do
[ -f ${file} ]
name=$2

for c in ${cnt}; do
if [ "$film" == '' ] || [ "$film" == 'VIDEO_TS.VOB' ]; then
film=${file}
else
case $3 in
true) film="$film|$file" ;;
esac
fi
done
cnt=$(expr ${cnt} + 1)
done
needle="|"
num=$(grep -o "$needle" <<<"$film" | wc -l)
num=$(expr ${num} + 1)
}

# default variables
infile=''

# alternative to get some information from the source file:
# ffprobe -v quiet -print_format json -show_format -show_streams ~/sourceFile.mov

while getopts ':i:' OPTION; do
case ${OPTION} in
i) infile=$OPTARG ;;
*) echo 'Unknown Parameter' ;;
esac
done

if [ $# -eq 0 ]; then
usage
die ''
fi

# check the arguments: if they exist
num='^[0-9]+$'

# infile must be given and has to be an mp4
if [ -z "${infile}" ]; then
# must be given
usage
die "ERROR: The Input File (-i) is missing"
fi

# check if mime-type is video/mp4
if file -b --mime-type "${infile}" -ne "video/mp4"; then
die "ERROR: The Input File (-i) is not mp4"
fi

# get the right output path, the file and the filename (without extension)
dir=$(dirname "${infile}")
file=$(basename "${infile}")
name="${file%.*}"

cd $dir

# --
# store the frames and matrix files in specific folder;
# folder has same unique name as the uploaded file
mkdir -p $name
cd $name

# --
# read frame rate from input file
framerate=$(ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate ../"${file}")

IFS="/" read -a array <<<"$framerate"
numerator="${array[0]}"
denumerator="${array[1]}"

fps=$(expr "scale=2;${numerator}/${denumerator}" | bc)

# --
# read aspect ratio from input file
aspect=$(ffprobe -v error -select_streams v:0 -show_entries stream=display_aspect_ratio -of csv=s=x:p=0 ../"${file}")

echo $aspect

# --
# split the aspect ratio to have two separated numbers for calculating
IFS=':' read -a array <<<"$aspect"
aspectW="${array[0]}"
aspectH="${array[1]}"

# --
# framesize
framewidth='256'
frameheight=$(($framewidth * $aspectH / $aspectW))
framesize=${framewidth}'x'${frameheight}

echo ${sep}
echo 'Start with frame export'
# check the outpath for the frames;
# if exists, delete it and create new
if [ -d "frames" ]; then
rm -rf ./frames
fi
mkdir -p 'frames'

framestart=$(echo ${start} + 1 | bc)
ffmpeg -i ../${file} -an -ss 1 -f image2 -s ${framesize} -vf framestep=${fps} frames/${name}'_f_%d.jpg' 2>&1

echo 'Done'
echo ${sep}

# --
# create the matrix files
echo 'Start with creating matrix file'

# change directory frames
cd frames
# Get the number of files: one image = one second of movie
# numfiles is equivalent to the movie duration (in seconds)
numfiles=(*)
numfiles=${#numfiles[@]}

image="${name}_f_1.jpg"

# check if file exists
if [[ ! -f "${image}" ]]; then
die "File not found: ${image}"
fi

# grab the identify string, make sure it succeeded
# IMG_CHARS=$(identify "${image}" 2> /dev/null) || die "${image} is not a proper image"
# grab width and height
IMG_CHARS=$(echo "${IMG_CHARS}" | sed -n 's/\(^.*\)\ \([0-9]*\)x\([0-9]*\)\ \(.*$\)/\2 \3/p')

width=$(echo "${IMG_CHARS}" | awk '{print $1}')
height=$(echo "${IMG_CHARS}" | awk '{print $2}')

ar=$(echo "scale=6; ${width}/${height}" | bc)
# width for the whole output matrix image: 960px
# so one preview image has a width of 160px
# calculate the height for the output matrix image form the aspect ratio
matrix_width="960"
matrix_height=$(echo "scale=0; ${matrix_width}/${ar}" | bc)
matrix_size="${matrix_width}x${matrix_height}"

frame_width="160"
frame_height=$(echo "scale=0; ${matrix_height}/6" | bc)
frame_size="${frame_width}x${frame_height}"
# get every 10th image; start with the image number 5;
# how many matrixes will it produce?
calcmatrix=$(echo "scale=4; (${numfiles}/10)/36" | bc)
echo '#Matrix (calculated) '${calcmatrix}
nummatrix=$(echo ${calcmatrix} | awk '{printf("%.0f\n",$1 + 0.75)}')
echo '#Matrix (rounded) '${nummatrix}

t=0
while [ ${t} -lt ${nummatrix} ]; do
echo 'Matrix nr '${t}
firstframe=$(echo "scale=0; ${t}*360+5" | bc)
MATRIX=$(find *_${firstframe}.jpg)' '

c=1
while [ ${c} -lt 36 ]; do
sec=$(echo "scale=0; ${firstframe}+(${c}*10)" | bc)
if [ $sec -lt $numfiles ]; then
img="${name}_f_${sec}.jpg"
if [ -f ${img} ]; then
MATRIX+=${img}' '
fi
fi

let c=c+1
done

# here we make the montage of every matrix file
# montage -size 320x180 DB_4_5.jpg DB_4_15.jpg DB_4_25.jpg DB_4_35.jpg -geometry +0+0 montage1.jpg
# $(echo "montage -size ${matrix_size} ${MATRIX} -tile 6x6 -geometry +0+0 -resize ${frame_size} ../matrix/${name}'_m_'${t}'.jpg'")
montage -size ${matrix_size} ${MATRIX} -tile 6x6 -geometry +0+0 -resize ${frame_size} ../${name}'_m_'${t}'.jpg' 2>&1

let t=t+1

done

echo 'Done'
echo ${sep}
@@ -144,10 +144,14 @@ function make_audio_file_info(extension)
end

function make_video_file_info(extension)
return {
media_type = VIDEO,
extension = extension
}
if not table.contains(video_extensions, extension) then
return nil
else
return {
media_type = VIDEO,
extension = extension
}
end
end

function make_text_file_info(extension)

0 comments on commit 47f2e28

Please sign in to comment.