Skip to content

Commit

Permalink
Server: Add other accelerators.
Browse files Browse the repository at this point in the history
IDK if these actually work, as I don't have the hardware for them...
  • Loading branch information
e3ndr committed Oct 3, 2023
1 parent 7828236 commit d6491d3
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 23 deletions.
2 changes: 1 addition & 1 deletion server/src/main/java/xyz/e3ndr/athena/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static void main(String[] args) throws Exception {

if (args.length > 0) {
if (args[0].equalsIgnoreCase("runtests")) {
FastLoggingFramework.setDefaultLevel(LogLevel.DEBUG);
// FastLoggingFramework.setDefaultLevel(LogLevel.DEBUG);
TranscodeAcceleration.runTests();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
public class FFMpegArgs {

public static @NonNull List<String> acc_getFF() {
List<String> args = Athena.config.transcoding.acceleration.acc_getFF();
return args == null ? Collections.emptyList() : args;
return Collections.emptyList();
}

public static @NonNull List<String> a_getFF(@NonNull AudioCodec codec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

public interface Accelerator {

public @Nullable List<String> acc_getFF();

public @Nullable List<String> v_getFF(@NonNull VideoCodec codec, @NonNull VideoQuality quality);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package xyz.e3ndr.athena.transcoding.accelerator;

import java.util.Arrays;
import java.util.List;

import org.jetbrains.annotations.Nullable;

import lombok.NonNull;
import xyz.e3ndr.athena.types.VideoCodec;
import xyz.e3ndr.athena.types.VideoQuality;

class AmdPreferred implements Accelerator {

@Override
public @Nullable List<String> v_getFF(@NonNull VideoCodec codec, @NonNull VideoQuality quality) {
switch (codec) {
case H264_BASELINE:
return Arrays.asList(
"-c:v", "h264_amf",
"-profile:v", "baseline",
"-pix_fmt", "yuv420p"
);

case H264_HIGH:
return Arrays.asList(
"-c:v", "h264_amf",
"-profile:v", "high",
"-pix_fmt", "yuv420p",
"-level", "5.0",
"-preset", "slow"
);

// TODO the more advanced parameters for HEVC and AV1
case HEVC:
return Arrays.asList(
"-c:v", "hevc_amf"
);

case AV1:
return Arrays.asList(
"-c:v", "av1_amf"
);

default:
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@

class NvidiaPreferred implements Accelerator {

@Override
public @Nullable List<String> acc_getFF() {
return null; // TODO some good logic for this so we can accelerate decoding.
// return Arrays.asList(
// "-hwaccel", "cuda",
// "-hwaccel_output_format", "cuda"
// );
}

@Override
public @Nullable List<String> v_getFF(@NonNull VideoCodec codec, @NonNull VideoQuality quality) {
switch (codec) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package xyz.e3ndr.athena.transcoding.accelerator;

import java.util.Arrays;
import java.util.List;

import org.jetbrains.annotations.Nullable;

import lombok.NonNull;
import xyz.e3ndr.athena.types.VideoCodec;
import xyz.e3ndr.athena.types.VideoQuality;

class QuickSyncPreferred implements Accelerator {

@Override
public @Nullable List<String> v_getFF(@NonNull VideoCodec codec, @NonNull VideoQuality quality) {
switch (codec) {
case H264_BASELINE:
return Arrays.asList(
"-c:v", "h264_qsv",
"-profile:v", "baseline",
"-pix_fmt", "yuv420p"
);

case H264_HIGH:
return Arrays.asList(
"-c:v", "h264_qsv",
"-profile:v", "high",
"-pix_fmt", "yuv420p",
"-level", "5.0",
"-preset", "slow"
);

// TODO the more advanced parameters for HEVC and AV1
case HEVC:
return Arrays.asList(
"-c:v", "hevc_qsv"
);

case AV1:
return Arrays.asList(
"-c:v", "av1_qsv"
);

default:
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@

class SoftwareOnly implements Accelerator {

@Override
public @Nullable List<String> acc_getFF() {
return null;
}

@Override
public @Nullable List<String> v_getFF(@NonNull VideoCodec codec, @NonNull VideoQuality quality) {
switch (codec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
public enum TranscodeAcceleration {
SOFTWARE_ONLY(new SoftwareOnly()),
NVIDIA_PREFERRED(new NvidiaPreferred()),
AMD_PREFERRED(new AmdPreferred()),
QUICKSYNC_PREFERRED(new QuickSyncPreferred()),
VAAPI_PREFERRED(new VaapiPreferred()),
V$L_PREFERRED(new V4lPreferred()),
// TODO AMD & Intel encoders.
// TODO Implement hardware decoding to speed up the transcode pipeline.
// https://trac.ffmpeg.org/wiki/HWAccelIntro
Expand All @@ -31,10 +35,6 @@ private TranscodeAcceleration(@NonNull Accelerator instance) {
this.instance = instance;
}

public @Nullable List<String> acc_getFF() {
return this.instance.acc_getFF();
}

public @Nullable List<String> v_getFF(@NonNull VideoCodec codec, @NonNull VideoQuality quality) {
if (this.supported.contains(codec)) {
return this.instance.v_getFF(codec, quality);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package xyz.e3ndr.athena.transcoding.accelerator;

import java.util.Arrays;
import java.util.List;

import org.jetbrains.annotations.Nullable;

import lombok.NonNull;
import xyz.e3ndr.athena.types.VideoCodec;
import xyz.e3ndr.athena.types.VideoQuality;

class V4lPreferred implements Accelerator {

@Override
public @Nullable List<String> v_getFF(@NonNull VideoCodec codec, @NonNull VideoQuality quality) {
switch (codec) {
case H264_BASELINE:
return Arrays.asList(
"-c:v", "h264_v4l2m2m",
"-profile:v", "baseline",
"-pix_fmt", "yuv420p"
);

case H264_HIGH:
return Arrays.asList(
"-c:v", "h264_v4l2m2m",
"-profile:v", "high",
"-pix_fmt", "yuv420p",
"-level", "5.0",
"-preset", "slow"
);

// TODO the more advanced parameters for HEVC and AV1
case HEVC:
return Arrays.asList(
"-c:v", "hevc_v4l2m2m"
);

case AV1:
return Arrays.asList(
"-c:v", "av1_v4l2m2m"
);

default:
return null;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package xyz.e3ndr.athena.transcoding.accelerator;

import java.util.Arrays;
import java.util.List;

import org.jetbrains.annotations.Nullable;

import lombok.NonNull;
import xyz.e3ndr.athena.types.VideoCodec;
import xyz.e3ndr.athena.types.VideoQuality;

class VaapiPreferred implements Accelerator {
private static final String VAAPI_DEVICE = System.getProperty("athena.vaapi.device", "/dev/dru/renderD128");

@Override
public @Nullable List<String> v_getFF(@NonNull VideoCodec codec, @NonNull VideoQuality quality) {
switch (codec) {
case H264_BASELINE:
return Arrays.asList(
"-vaapi_device", VAAPI_DEVICE,
"-c:v", "h264_vaapi",
"-profile:v", "baseline",
"-pix_fmt", "yuv420p"
);

case H264_HIGH:
return Arrays.asList(
"-vaapi_device", VAAPI_DEVICE,
"-c:v", "h264_vaapi",
"-profile:v", "high",
"-pix_fmt", "yuv420p",
"-level", "5.0",
"-preset", "slow"
);

// TODO the more advanced parameters for HEVC and AV1
case HEVC:
return Arrays.asList(
"-vaapi_device", VAAPI_DEVICE,
"-c:v", "hevc_vaapi"
);

case AV1:
return Arrays.asList(
"-vaapi_device", VAAPI_DEVICE,
"-c:v", "av1_vaapi"
);

default:
return null;
}
}

}

0 comments on commit d6491d3

Please sign in to comment.