Skip to content

Commit 3812fdc

Browse files
Use 2-pass encoding for FFmpeg (#397)
Co-authored-by: Roberto Cella <[email protected]>
1 parent bc0b943 commit 3812fdc

34 files changed

+11111
-10809
lines changed

.github/workflows/unit-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858

5959
qodana:
6060
name: Perform Qodana analysis
61+
if: ${{ vars.QODANA_ENABLED == 'true' }}
6162
needs: tests
6263
runs-on: ubuntu-latest
6364
permissions:

Dockerfile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ FROM eclipse-temurin:24-alpine AS builder
22

33
WORKDIR /app
44
COPY . .
5-
RUN --mount=type=cache,target=/root/.gradle ./gradlew jlink shadowJar
5+
RUN --mount=type=cache,target=/root/.gradle ./gradlew installDist
66

77
# bump: alpine /FROM alpine:([\d.]+)/ docker:alpine|^3
88
# bump: alpine link "Release notes" https://alpinelinux.org/posts/Alpine-$LATEST-released.html
99
FROM alpine:3.22.1 AS bot
1010

11-
RUN apk --no-cache add libwebp-tools
12-
1311
# bump: ffmpeg /static-ffmpeg:([\d.]+)/ docker:mwader/static-ffmpeg|~7.0
1412
COPY --from=mwader/static-ffmpeg:7.0.2 /ffmpeg /usr/bin/
15-
ENV FFMPEG_PATH=/usr/bin/ffmpeg
13+
COPY --from=builder /app/build/install/Stickerify/ .
1614

17-
COPY --from=builder /app/build/jlink/jre jre
18-
COPY --from=builder /app/build/libs/*-all.jar Stickerify.jar
19-
20-
CMD ["jre/bin/java", "-Dcom.sksamuel.scrimage.webp.binary.dir=/usr/bin", "-jar", "Stickerify.jar"]
15+
ENV CONCURRENT_PROCESSES=5
16+
ENV FFMPEG_PATH=/usr/bin/ffmpeg
17+
CMD ["./bin/Stickerify"]

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ therefore counting towards the four-contribution goal.
118118
* The bot is deployed on [Railway](https://railway.app?referralCode=rob)
119119
* The official documentation of the Telegram Bot API can be found [here](https://core.telegram.org/bots)
120120
* The library used by the bot to work with Telegram is [Java Telegram Bot API](https://github.com/pengrad/java-telegram-bot-api)
121-
* Video conversion uses [FFmpeg](https://ffmpeg.org/) and [JAVE2](https://github.com/a-schild/jave2)
122-
* Image conversion uses [Scrimage](https://github.com/sksamuel/scrimage), [ImageIO](https://docs.oracle.com/en/java/javase/20/docs/api/java.desktop/javax/imageio/ImageIO.html), and [TwelveMonkeys](https://github.com/haraldk/TwelveMonkeys)
121+
* Video and image conversions use [FFmpeg](https://ffmpeg.org/) and [JAVE2](https://github.com/a-schild/jave2)
123122
* Animated sticker validation uses [Gson](https://github.com/google/gson)
124123
* MIME type analysis is performed using [Apache Tika](https://tika.apache.org/)
125124

Railway.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ARG DOCKER_TAG=latest
22
FROM rob93c/stickerify:$DOCKER_TAG
33
ARG STICKERIFY_TOKEN
44
ARG LOG_LEVEL
5-
ARG CONCURRENT_THREADS
5+
ARG CONCURRENT_PROCESSES
66
ENV STICKERIFY_TOKEN=$STICKERIFY_TOKEN \
77
LOG_LEVEL=$LOG_LEVEL \
8-
CONCURRENT_THREADS=$CONCURRENT_THREADS
8+
CONCURRENT_PROCESSES=$CONCURRENT_PROCESSES

build.gradle

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,32 @@ import com.github.stickerifier.stickerify.JlinkJavaLauncher
22
import com.github.stickerifier.stickerify.JlinkTask
33

44
plugins {
5-
id('application')
65
id('java')
76
id('jacoco')
8-
alias(libs.plugins.shadow)
7+
id('application')
8+
alias(libs.plugins.spring.nullability)
99
}
1010

1111
repositories {
1212
mavenCentral()
1313
}
1414

1515
dependencies {
16-
implementation(libs.batik)
16+
compileOnly(libs.jspecify)
1717
implementation(libs.gson)
18-
implementation(libs.imageio.batik)
19-
implementation(libs.imageio.psd)
2018
implementation(libs.jave)
2119
implementation(libs.logback.classic)
22-
implementation(libs.logback.core)
23-
implementation(libs.scrimage.core)
24-
implementation(libs.scrimage.formats.extra)
25-
implementation(libs.scrimage.webp)
26-
implementation(libs.slf4j.api)
2720
implementation(libs.telegram.bot.api)
2821
implementation(libs.tika)
2922

3023
testImplementation(libs.hamcrest)
3124
testImplementation(libs.junit.jupiter)
3225
testImplementation(libs.mockwebserver)
3326
testRuntimeOnly(libs.junit.platform)
34-
35-
constraints {
36-
implementation('org.apache.commons:commons-lang3') {
37-
version {
38-
strictly('[3.18.0, 4)')
39-
}
40-
because('CVE-2025-48924: Apache Commons Lang is vulnerable to Uncontrolled Recursion when processing long inputs')
41-
}
42-
}
4327
}
4428

4529
group = 'com.github.stickerifier'
46-
version = '1.0'
30+
version = '2.0'
4731
description = 'Telegram bot to convert medias in the format required to be used as Telegram stickers'
4832

4933
java.toolchain {
@@ -58,7 +42,12 @@ updateDaemonJvm {
5842

5943
def jlink = tasks.register('jlink', JlinkTask) {
6044
options = ['--strip-debug', '--no-header-files', '--no-man-pages']
61-
modules = ['java.desktop', 'java.instrument', 'java.naming', 'java.sql', 'jdk.crypto.ec', 'jdk.unsupported']
45+
modules = [
46+
'java.instrument', // for junit
47+
'java.naming', // for logback
48+
'java.sql', // for tika
49+
'jdk.unsupported' // for gson
50+
]
6251
includeModulePath = false
6352

6453
group = 'build'
@@ -73,7 +62,7 @@ test {
7362
finalizedBy(jacocoTestReport)
7463

7564
testLogging {
76-
events 'passed', 'failed', 'skipped'
65+
events('passed', 'failed', 'skipped')
7766
}
7867
}
7968

@@ -99,19 +88,16 @@ application {
9988
mainClass = 'com.github.stickerifier.stickerify.runner.Main'
10089
}
10190

102-
shadowJar {
103-
duplicatesStrategy = DuplicatesStrategy.INCLUDE
104-
mergeServiceFiles()
105-
failOnDuplicateEntries = true
106-
107-
exclude('dist_webp_binaries/',
108-
'META-INF/LICENSE',
109-
'META-INF/LICENSE.txt',
110-
'META-INF/NOTICE',
111-
'META-INF/NOTICE.txt',
112-
'license/LICENSE',
113-
'license/LICENSE.dom-documentation.txt',
114-
'license/LICENSE.dom-software.txt',
115-
'license/NOTICE',
116-
'license/README.dom.txt')
91+
distributions {
92+
main {
93+
contents {
94+
//noinspection GroovyAssignabilityCheck
95+
from(jlink)
96+
}
97+
}
98+
}
99+
100+
tasks.named('startScripts', CreateStartScripts) {
101+
unixStartScriptGenerator.template = resources.text.fromFile('src/main/resources/customUnixStartScript.txt')
102+
windowsStartScriptGenerator.template = resources.text.fromFile('src/main/resources/customWindowsStartScript.txt')
117103
}

buildSrc/src/main/java/com/github/stickerifier/stickerify/JlinkTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public JlinkTask(ProjectLayout layout, JavaToolchainService javaToolchain) {
5353
getOptions().convention(List.of());
5454
getModules().convention(List.of("ALL-MODULE-PATH"));
5555
getIncludeModulePath().convention(true);
56-
getOutputDirectory().convention(layout.getBuildDirectory().dir("jlink"));
56+
getOutputDirectory().convention(layout.getBuildDirectory().dir(getName()));
5757

5858
var toolchain = getProject().getExtensions().getByType(JavaPluginExtension.class).getToolchain();
5959
getJavaCompiler().convention(javaToolchain.compilerFor(toolchain));

gradle/libs.versions.toml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
1-
[versions]
2-
logback = "1.5.18"
3-
scrimage = "4.3.3"
4-
twelvemonkeys = "3.12.0"
5-
61
[libraries]
7-
batik = "org.apache.xmlgraphics:batik-transcoder:1.19"
82
gson = "com.google.code.gson:gson:2.13.1"
93
hamcrest = "org.hamcrest:hamcrest:3.0"
10-
imageio-batik = { module = "com.twelvemonkeys.imageio:imageio-batik", version.ref = "twelvemonkeys" }
11-
imageio-psd = { module = "com.twelvemonkeys.imageio:imageio-psd", version.ref = "twelvemonkeys" }
124
jave = "ws.schild:jave-core:3.5.0"
5+
jspecify = "org.jspecify:jspecify:1.0.0"
136
junit-jupiter = "org.junit.jupiter:junit-jupiter:5.13.4"
14-
junit-platform = { module = "org.junit.platform:junit-platform-launcher" }
15-
logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
16-
logback-core = { module = "ch.qos.logback:logback-core", version.ref = "logback" }
7+
junit-platform = "org.junit.platform:junit-platform-launcher:1.13.4"
8+
logback-classic = "ch.qos.logback:logback-classic:1.5.18"
179
mockwebserver = "com.squareup.okhttp3:mockwebserver3-junit5:5.1.0"
18-
scrimage-core = { module = "com.sksamuel.scrimage:scrimage-core", version.ref = "scrimage" }
19-
scrimage-formats-extra = { module = "com.sksamuel.scrimage:scrimage-formats-extra", version.ref = "scrimage" }
20-
scrimage-webp = { module = "com.sksamuel.scrimage:scrimage-webp", version.ref = "scrimage" }
21-
slf4j-api = "org.slf4j:slf4j-api:2.0.17"
2210
telegram-bot-api = "com.github.pengrad:java-telegram-bot-api:9.2.0"
2311
tika = "org.apache.tika:tika-core:3.2.2"
2412

2513
[plugins]
26-
shadow = "com.gradleup.shadow:9.1.0"
14+
spring-nullability = "io.spring.nullability:0.0.4"

0 commit comments

Comments
 (0)