Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 200: Proposed way to get ffmpeg home configuration in unit tests #208

Merged
merged 3 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/sonar-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
run: |
if [ -n "$SONAR_TOKEN" ]
then
bash mvnw -B jacoco:prepare-agent verify jacoco:report sonar:sonar -DFFMPEG_BIN=/usr/bin
bash mvnw -B jacoco:prepare-agent verify jacoco:report sonar:sonar
else
echo "Skipping sonar if a PR is created from a fork"
echo "Secrets are not available in such PRs for security reason"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ jobs:
if: startsWith(matrix.os, 'windows')

- name: Build on Ubuntu
run: bash mvnw clean package -B -DFFMPEG_BIN=/usr/bin
run: bash mvnw clean package -B
if: startsWith(matrix.os, 'ubuntu')

- name: Build on MacOS
run: bash mvnw clean package -B -DFFMPEG_BIN=/usr/local/opt/ffmpeg/bin
run: bash mvnw clean package -B
if: startsWith(matrix.os, 'macos')

- name: Build on Windows
run: ./mvnw clean package -B "-DFFMPEG_BIN=C:\ProgramData\chocolatey\lib\ffmpeg\tools\ffmpeg\bin"
run: ./mvnw clean package -B
if: startsWith(matrix.os, 'windows')

test-release:
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/com/github/kokorin/jaffree/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.kokorin.jaffree;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Path;
import java.nio.file.Paths;

public class Config {
private static final Logger LOGGER = LoggerFactory.getLogger(Config.class);
public static final Path FFMPEG_BIN = getFfmpegBin();

private static Path getFfmpegBin() {
String ffmpegHome = System.getProperty("FFMPEG_BIN");
if (ffmpegHome != null) {
LOGGER.info("Using FFMPEG_BIN from system property: {}", ffmpegHome);
return Paths.get(ffmpegHome);
}

ffmpegHome = System.getenv("FFMPEG_BIN");
if (ffmpegHome != null) {
LOGGER.info("Using FFMPEG_BIN from environment variable: {}", ffmpegHome);
return Paths.get(ffmpegHome);
}

LOGGER.warn("FFMPEG_BIN not configured: expecting to find ffmpeg on PATH");
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.kokorin.jaffree.ffmpeg;

import com.github.kokorin.jaffree.Artifacts;
import com.github.kokorin.jaffree.Config;
import com.github.kokorin.jaffree.ffprobe.FFprobe;
import com.github.kokorin.jaffree.ffprobe.FFprobeResult;
import com.github.kokorin.jaffree.ffprobe.Stream;
Expand All @@ -15,21 +16,6 @@

public class FFmpegFilterTest {

public static Path BIN;


@BeforeClass
public static void setUp() throws Exception {
String ffmpegHome = System.getProperty("FFMPEG_BIN");
if (ffmpegHome == null) {
ffmpegHome = System.getenv("FFMPEG_BIN");
}
Assert.assertNotNull(
"Nor command line property, neither system variable FFMPEG_BIN is set up",
ffmpegHome);
BIN = Paths.get(ffmpegHome);
}

/**
* Test, that creates mosaic video from 4 sources
* <p>
Expand All @@ -42,7 +28,7 @@ public void testMosaic() throws Exception {
Path tempDir = Files.createTempDirectory("jaffree");
Path outputPath = tempDir.resolve("mosaic.mkv");

FFmpegResult result = FFmpeg.atPath(BIN)
FFmpegResult result = FFmpeg.atPath(Config.FFMPEG_BIN)
.addInput(UrlInput.fromPath(Artifacts.VIDEO_MP4).setDuration(10, TimeUnit.SECONDS))
.addInput(UrlInput.fromPath(Artifacts.SMALL_FLV).setDuration(10, TimeUnit.SECONDS))
.addInput(UrlInput.fromPath(Artifacts.SMALL_MP4).setDuration(10, TimeUnit.SECONDS))
Expand Down Expand Up @@ -124,7 +110,7 @@ public void testMosaic() throws Exception {

Assert.assertNotNull(result);

FFprobeResult probe = FFprobe.atPath(BIN)
FFprobeResult probe = FFprobe.atPath(Config.FFMPEG_BIN)
.setInput(outputPath)
.setShowStreams(true)
.execute();
Expand Down Expand Up @@ -159,7 +145,7 @@ public void testConcatWithReencode() throws Exception {
Path tempDir = Files.createTempDirectory("jaffree");
Path outputPath = tempDir.resolve("concat.mp4");

FFmpegResult result = FFmpeg.atPath(BIN)
FFmpegResult result = FFmpeg.atPath(Config.FFMPEG_BIN)
.addInput(UrlInput.fromPath(Artifacts.VIDEO_MP4).setDuration(5, TimeUnit.SECONDS))
.addInput(
UrlInput.fromPath(Artifacts.VIDEO_MKV).setPositionEof(-5, TimeUnit.SECONDS))
Expand Down Expand Up @@ -190,7 +176,7 @@ public void testConcatWithReencode() throws Exception {

Assert.assertNotNull(result);

FFprobeResult probe = FFprobe.atPath(BIN)
FFprobeResult probe = FFprobe.atPath(Config.FFMPEG_BIN)
.setInput(outputPath)
.setShowStreams(true)
.execute();
Expand Down
Loading