Unverified Commit 0190b4c8 authored by Sebastian Schüpbach's avatar Sebastian Schüpbach
Browse files

don't convert images files into jp2 anymore

parent 31a30c6a
......@@ -11,10 +11,6 @@ include:
ref: modular
file: 'docker/base.yml'
.install_kakadu: &install_kakadu
- wget https://kakadusoftware.com/wp-content/uploads/2020/06/KDU805_Demo_Apps_for_Linux-x86-64_200602.zip
- unzip KDU805_Demo_Apps_for_Linux-x86-64_200602.zip && cd KDU805_Demo_Apps_for_Linux-x86-64_200602/ && mv kdu_compress libkdu_v80R.so ../ && cd ..
cache:
key: "$CI_BUILD_REF_NAME"
paths:
......@@ -26,26 +22,15 @@ cache:
test-sbt:
extends: .test-sbt
before_script:
- apt-get update && apt-get install -y ffmpeg imagemagick
- wget https://kakadusoftware.com/wp-content/uploads/2020/06/KDU805_Demo_Apps_for_Linux-x86-64_200602.zip
- unzip KDU805_Demo_Apps_for_Linux-x86-64_200602.zip && cd KDU805_Demo_Apps_for_Linux-x86-64_200602/ && mv kdu_compress libkdu_v80R.so ../ && cd ..
- export PATH=$PATH:`pwd`
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`
- apt-get update && apt-get install -y ffmpeg
assembly-sbt:
extends: .assembly-sbt
build-tagged-image:
extends: .build-tagged-image
before_script:
- *install_kakadu
build-latest-image:
extends: .build-latest-image
before_script:
- *install_kakadu
build-feature-branch-image:
extends: .build-feature-branch-image
before_script:
- *install_kakadu
extends: .build-feature-branch-image
\ No newline at end of file
FROM openjdk:8-jre
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
RUN apt-get update && \
apt-get install -y ffmpeg imagemagick && \
apt-get install -y ffmpeg && \
apt-get autoremove -y && \
apt-get clean
ADD target/scala-2.12/app.jar /app/app.jar
ADD kdu_compress /usr/local/bin/
ADD libkdu_v80R.so /usr/local/lib/
CMD java -jar /app/app.jar
......@@ -97,11 +97,9 @@ class DisseminationCopyHandler(audioSnippetDuration: Int) extends Logging {
* @return true if copy was overwritten, false otherwise
*/
def createImageCopy(data: ByteArrayOutputStream, destFile: String, sourceFileType: MimeType): Try[Boolean] = Try {
val tempFilePath = Files.createTempFile("media-", "." + Conversions.getFileTypeExtension(sourceFileType).get)
writeData(data, tempFilePath)
val copyRemoved = removeExistingFile(Paths.get(destFile))
MediaTransformations.imageToJp2(tempFilePath.toString, destFile).get
Files.delete(tempFilePath)
val destFileAsPath = Paths.get(destFile)
val copyRemoved = removeExistingFile(destFileAsPath)
writeData(data, destFileAsPath)
copyRemoved
}
......
......@@ -33,8 +33,8 @@ trait FileUtils {
val videoFilePath: (String, MimeType) => String =
(id, mimeType) => s"${normalize(rootPath)}/$id.${getFileTypeExtension(mimeType).get}"
val videoPosterPath: String => String =
id => s"${normalize(rootPath)}/${id.replace("/derived", "")}-poster.jp2"
val videoPosterPath: (String, MimeType) => String =
(id, mimeType) => s"${normalize(rootPath)}/${id.replace("/derived", "")}-poster.${getFileTypeExtension(mimeType)}"
val audioFilePath: String => String =
id => s"${normalize(rootPath)}/$id.mp4"
......@@ -42,7 +42,7 @@ trait FileUtils {
val audioSnippetPath: String => String =
id => s"${normalize(rootPath)}/$id-intro.mp3"
val imageFilePath: String => String =
id => s"${normalize(rootPath)}/$id.jp2"
val imageFilePath: (String, MimeType) => String =
(id, mimeType) => s"${normalize(rootPath)}/$id.${getFileTypeExtension(mimeType)}"
}
......@@ -19,11 +19,9 @@
package ch.memobase
import java.io.IOException
import java.nio.file.Files
import org.apache.logging.log4j.scala.Logging
import java.io.IOException
import scala.util.Try
/**
......@@ -47,7 +45,7 @@ object MediaTransformations extends Logging {
* Repacks audio files in a MP4 container and adds a moov atom at the beginning of the file
*
* @param sourceFilePath Path to the source file
* @param destFile Path to the final file
* @param destFile Path to the final file
* @return
*/
def audioToMp4(sourceFilePath: String, destFile: String): Try[String] = {
......@@ -62,7 +60,7 @@ object MediaTransformations extends Logging {
* Creates an audio snippet used as a base for producing sonograms
*
* @param sourceFilePath Path to the source file
* @param destFile Path to the final file
* @param destFile Path to the final file
* @param duration Duration of snippet (counts from beginning of track)
* @return
*/
......@@ -77,27 +75,4 @@ object MediaTransformations extends Logging {
destFile
}
}
/**
* Converts image file to jpeg2000
*
* @param sourceFilePath Path to the source file
* @param destFile Path to the final file
* @return
*/
def imageToJp2(sourceFilePath: String, destFile: String): Try[String] = Try {
val intermediaryFile = Files.createTempFile("image-", ".tif")
val imagemagickCommand = s"convert -format tif -compress none $sourceFilePath ${intermediaryFile.toString}"
// scalastyle:off
val kduCompressCommand = s"""kdu_compress -i ${intermediaryFile.toString} -o $destFile -rate 3 -flush_period 1024 -quiet Creversible=no Clevels=6 Clayers=6 Cprecincts={256,256},{256,256},{128,128} Corder=RPCL Cuse_sop=yes Cuse_eph=yes Cblk={64,64} ORGgen_plt=yes ORGtparts=R Stiles={512,512}"""
// scalastyle:on
try {
executeCommand(imagemagickCommand).get
executeCommand(kduCompressCommand).get
} finally {
Files.delete(intermediaryFile)
}
destFile
}
}
......@@ -97,12 +97,12 @@ class RecordProcessor(fileHandler: DisseminationCopyHandler,
val destFile = videoFilePath(id, mT)
val res = fileHandler.deleteVideoCopy(destFile)
deleteOutcome(res, id, DigitalObject, destFile)
case _: ImageFile if resource == DigitalObject =>
val destFile = imageFilePath(id)
case mT: ImageFile if resource == DigitalObject =>
val destFile = imageFilePath(id, mT)
val res = fileHandler.deleteImageCopy(destFile)
deleteOutcome(res, id, DigitalObject, destFile)
case _: ImageFile if resource == Thumbnail =>
val destFile = videoPosterPath(id)
case mT: ImageFile if resource == Thumbnail =>
val destFile = videoPosterPath(id, mT)
val res = fileHandler.deleteImageCopy(destFile)
deleteOutcome(res, id, Thumbnail, destFile)
}
......@@ -120,11 +120,11 @@ class RecordProcessor(fileHandler: DisseminationCopyHandler,
val res = fileHandler.createVideoCopy(data, destFile, mT)
createOutcome(res, id, DigitalObject, destFile)
case mT: ImageFile if resource == DigitalObject =>
val destFile = imageFilePath(id)
val destFile = imageFilePath(id, mT)
val res = fileHandler.createImageCopy(data, destFile, mT)
createOutcome(res, id, DigitalObject, destFile)
case mT: ImageFile if resource == Thumbnail =>
val destFile = videoPosterPath(id)
val destFile = videoPosterPath(id, mT)
val res = fileHandler.createImageCopy(data, destFile, mT)
createOutcome(res, id, Thumbnail, destFile)
}
......
......@@ -120,15 +120,10 @@ class DisseminationCopyHandlerTest extends AnyFunSuite with BeforeAndAfter {
}
}
/**
* ATTENTION: Requires that Kakadu and imagemagick are properly installed!
*/
test("calling the copyImage function should create temporary file") {
runWithKakaduAndIM {
val f = fixture
testCopy(f.resPath, "sample.jpg", "test.jp2", JpegFile, f.fileHandler.createImageCopy)
deleteFiles("src/test/resources/test.jp2")
}
val f = fixture
testCopy(f.resPath, "sample.jpg", "test.jpg", JpegFile, f.fileHandler.createImageCopy)
deleteFiles("src/test/resources/test.jpg")
}
/**
......
......@@ -44,13 +44,4 @@ class MediaTransformationsTest extends AnyFunSuite {
}
}
test("Sample jpeg should be transformed into jp2") {
runWithKakaduAndIM {
val outFile = Files.createTempFile(Paths.get("src/test/resources"), "test-", ".jp2")
val res = MediaTransformations.imageToJp2("src/test/resources/sample.jpg", outFile.toString)
outFile.toFile.delete()
assert(res.isSuccess, res)
}
}
}
......@@ -34,16 +34,4 @@ object TestUtilities {
println("No ffmpeg binary found in $PATH")
}
}
def runWithKakaduAndIM[T](f: => T): Unit = {
if (appExists("kdu_compress -v") && appExists("convert -version")) {
f
} else if (!appExists("kdu_compress -v")) {
println("No kdu_compress binary found in $PATH")
}
else if (!appExists("convert -version")) {
println("No convert binary found in $PATH")
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment