Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feature/ffmpeg-la…
Browse files Browse the repository at this point in the history
…youts

Conflicts:
	src/main/java/net/bramp/ffmpeg/FFmpeg.java
	src/test/java/net/bramp/ffmpeg/FFmpegTest.java
  • Loading branch information
Euklios committed Mar 11, 2024
2 parents cc213eb + 3ae1f5e commit 5bc79d3
Show file tree
Hide file tree
Showing 21 changed files with 1,479 additions and 109 deletions.
6 changes: 0 additions & 6 deletions .codeclimate.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ A clear and concise description of what you expected to happen.
**Version (if applicable):**
- OS: [e.g. Linux]
- Java Version [e.g. 8]
- FFmpeg version [e.g. 6.1.1]

**Additional context**
Add any other context about the problem here.
52 changes: 52 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

name: Java CI with Maven

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
# Long term supported versions
java-version: [11, 17, 21]

# TODO Add support for 8, but it fails with
# java.lang.UnsupportedClassVersionError: com/spotify/fmt/FMT has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

# TODO Should we test locales? The old travis setup did, see:
# https://github.com/bramp/ffmpeg-cli-wrapper/pull/55

name: JDK ${{ matrix.java-version }}

steps:
- uses: actions/checkout@v3

- name: Set up FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v3
id: setup-ffmpeg
with:
ffmpeg-version: release

- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
cache: maven

- name: Compile with Maven
run: mvn --batch-mode --update-snapshots compile

- name: Test with Maven, Package and Verify with Maven
run: mvn --batch-mode --update-snapshots verify -Dgpg.skip

# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
- name: Update dependency graph
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
48 changes: 0 additions & 48 deletions .travis.yml

This file was deleted.

5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
FFmpeg Java
===========

by Andrew Brampton ([bramp.net](https://bramp.net)) (c) 2013-2014,2016

[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/bramp)

A fluent interface to running FFmpeg from Java.

![Java](https://img.shields.io/badge/Java-8+-brightgreen.svg)
[![Build Status](https://img.shields.io/travis/bramp/ffmpeg-cli-wrapper/master.svg)](https://travis-ci.org/bramp/ffmpeg-cli-wrapper)
[![Build Status](https://github.com/bramp/ffmpeg-cli-wrapper/actions/workflows/maven.yml/badge.svg)](https://github.com/bramp/ffmpeg-cli-wrapper/actions/workflows/maven.yml)
[![Coverage Status](https://img.shields.io/coveralls/bramp/ffmpeg-cli-wrapper.svg)](https://coveralls.io/github/bramp/ffmpeg-cli-wrapper)
[![Maven](https://img.shields.io/maven-central/v/net.bramp.ffmpeg/ffmpeg.svg)](http://mvnrepository.com/artifact/net.bramp.ffmpeg/ffmpeg)
[![Libraries.io](https://img.shields.io/librariesio/github/bramp/ffmpeg-cli-wrapper.svg)](https://libraries.io/github/bramp/ffmpeg-cli-wrapper)
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,12 @@
<compilerId>javac-with-errorprone</compilerId>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<showWarnings>true</showWarnings>
<failOnError>true</failOnError>
<failOnWarning>true</failOnWarning>
<compilerArgs>
<!-- Surpress maven option warnings because we are
focusing on code issues -->
<arg>-Xlint:-options</arg>
<arg>-Xlint:all</arg>
</compilerArgs>
</configuration>
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/net/bramp/ffmpeg/FFmpeg.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class FFmpeg extends FFcommon {
static final Pattern FORMATS_REGEX = Pattern.compile("^ ([ D][ E]) (\\S+)\\s+(.*)$");
static final Pattern PIXEL_FORMATS_REGEX =
Pattern.compile("^([.I][.O][.H][.P][.B]) (\\S{2,})\\s+(\\d+)\\s+(\\d+)$");
static final Pattern FILTERS_REGEX = Pattern.compile("^\\s*(?<timelinesupport>[T.])(?<slicethreading>[S.])(?<commandsupport>[C.])\\s(?<name>[A-Za-z0-9_]+)\\s+(?<inputpattern>[AVN|]+)->(?<outputpattern>[AVN|]+)\\s+(?<description>.*)$");

/** Supported codecs */
List<Codec> codecs = null;
Expand All @@ -77,6 +78,9 @@ public class FFmpeg extends FFcommon {
/** Supported pixel formats */
private List<PixelFormat> pixelFormats = null;

/** Supported filters */
private List<Filter> filters = null;

/** Supported channel layouts */
private List<Layout> layouts = null;

Expand All @@ -92,6 +96,7 @@ public FFmpeg(@Nonnull String path) throws IOException {
this(path, new RunProcessFunction());
}

@SuppressWarnings("this-escape")
public FFmpeg(@Nonnull String path, @Nonnull ProcessFunction runFunction) throws IOException {
super(path, runFunction);
version();
Expand Down Expand Up @@ -148,6 +153,43 @@ private void checkIfFFmpeg() throws IllegalArgumentException, IOException {
return codecs;
}

public synchronized @Nonnull List<Filter> filters() throws IOException {
checkIfFFmpeg();

if (this.filters == null) {
filters = new ArrayList<>();

Process p = runFunc.run(ImmutableList.of(path, "-filters"));
try {
BufferedReader r = wrapInReader(p);
String line;
while ((line = r.readLine()) != null) {
Matcher m = FILTERS_REGEX.matcher(line);
if (!m.matches()) continue;

// (?<inputpattern>[AVN|]+)->(?<outputpattern>[AVN|]+)\s+(?<description>.*)$

filters.add(new Filter(
m.group("timelinesupport").equals("T"),
m.group("slicethreading").equals("S"),
m.group("commandsupport").equals("C"),
m.group("name"),
new FilterPattern(m.group("inputpattern")),
new FilterPattern(m.group("outputpattern")),
m.group("description")
));
}

throwOnError(p);
this.filters = ImmutableList.copyOf(filters);
} finally {
p.destroy();
}
}

return this.filters;
}

public synchronized @Nonnull List<Format> formats() throws IOException {
checkIfFFmpeg();

Expand Down
24 changes: 10 additions & 14 deletions src/main/java/net/bramp/ffmpeg/info/Codec.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.base.Preconditions;
import com.google.errorprone.annotations.Immutable;
import net.bramp.ffmpeg.shared.CodecType;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

Expand All @@ -12,14 +13,6 @@
*/
@Immutable
public class Codec {

public enum Type {
VIDEO,
AUDIO,
SUBTITLE,
DATA
}

final String name;
final String longName;

Expand All @@ -30,7 +23,7 @@ public enum Type {
final boolean canEncode;

/** What type of codec is this */
final Type type;
final CodecType type;

/**
* @param name short codec name
Expand Down Expand Up @@ -58,16 +51,19 @@ public Codec(String name, String longName, String flags) {

switch (flags.charAt(2)) {
case 'V':
this.type = Type.VIDEO;
this.type = CodecType.VIDEO;
break;
case 'A':
this.type = Type.AUDIO;
this.type = CodecType.AUDIO;
break;
case 'S':
this.type = Type.SUBTITLE;
this.type = CodecType.SUBTITLE;
break;
case 'D':
this.type = Type.DATA;
this.type = CodecType.DATA;
break;
case 'T':
this.type = CodecType.ATTACHMENT;
break;
default:
throw new IllegalArgumentException("Invalid codec type '" + flags.charAt(2) + "'");
Expand Down Expand Up @@ -107,7 +103,7 @@ public boolean getCanEncode() {
return canEncode;
}

public Type getType() {
public CodecType getType() {
return type;
}
}
80 changes: 80 additions & 0 deletions src/main/java/net/bramp/ffmpeg/info/Filter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package net.bramp.ffmpeg.info;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

public class Filter {
/** Is timeline editing supported */
private final boolean timelineSupported;

/** Is slice based multi-threading supported */
private final boolean sliceThreading;

/** Are there command line options */
private final boolean commandSupport;

/** The filters name */
private final String name;

/** The input filter pattern */
private final FilterPattern inputPattern;

/** The output filter pattern */
private final FilterPattern outputPattern;

/** A short description of the filter */
private final String description;

public Filter(boolean timelineSupported, boolean sliceThreading, boolean commandSupport, String name, FilterPattern inputPattern, FilterPattern outputPattern, String description) {
this.timelineSupported = timelineSupported;
this.sliceThreading = sliceThreading;
this.commandSupport = commandSupport;
this.name = name;
this.inputPattern = inputPattern;
this.outputPattern = outputPattern;
this.description = description;
}

public boolean isTimelineSupported() {
return timelineSupported;
}

public boolean isSliceThreading() {
return sliceThreading;
}

public boolean isCommandSupport() {
return commandSupport;
}

public String getName() {
return name;
}

public FilterPattern getInputPattern() {
return inputPattern;
}

public FilterPattern getOutputPattern() {
return outputPattern;
}

public String getDescription() {
return description;
}

@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}

@Override
public String toString() {
return name;
}

@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
}
Loading

0 comments on commit 5bc79d3

Please sign in to comment.