mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-02 06:28:48 +00:00
0.3.0
This commit is contained in:
1 parent
d2a217509f
commit
4d8f896cdf
90 files changed
+2345
-720
No files matched your search
@@ -28,6 +28,7 @@ public enum VideoCodec implements ComboOption {
|
||||
private final String text;
|
||||
private final int codecId;
|
||||
private String[] encoders;
|
||||
private boolean supportsTransparency = false;
|
||||
|
||||
VideoCodec(String text, int codecId) {
|
||||
this.text = text;
|
||||
@@ -43,6 +44,18 @@ public enum VideoCodec implements ComboOption {
|
||||
return this.codecId;
|
||||
}
|
||||
|
||||
public boolean supportsTransparency() {
|
||||
if (this == VP9) {
|
||||
// VP9 supports transparency (yuva420p), but apparently most decoders for it do not. Let's not mark it as supporting transparency
|
||||
// See also: https://trac.ffmpeg.org/ticket/8468
|
||||
return false;
|
||||
}
|
||||
if (this.encoders == null) {
|
||||
this.getEncoders();
|
||||
}
|
||||
return this.supportsTransparency;
|
||||
}
|
||||
|
||||
public String[] getEncoders() {
|
||||
if (this.encoders == null) {
|
||||
List<String> encodersHardware = new ArrayList<>();
|
||||
@@ -70,6 +83,20 @@ public enum VideoCodec implements ComboOption {
|
||||
int capabilities = codec.capabilities();
|
||||
String name = codec.name().getString();
|
||||
|
||||
this.supportsTransparency = false;
|
||||
for (int i = 0;; i++) {
|
||||
int pixFmt = codec.pix_fmts().get(i);
|
||||
if (pixFmt == -1) {
|
||||
break;
|
||||
} else {
|
||||
if (PixelFormatHelper.doesPixelFormatSupportTransparency(pixFmt)) {
|
||||
System.out.println(name + " supports transparency because of " + PixelFormatHelper.pixelFormatToString(pixFmt));
|
||||
this.supportsTransparency = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((capabilities & avcodec.AV_CODEC_CAP_HARDWARE) != 0) {
|
||||
encodersHardware.add(name);
|
||||
} else if ((capabilities & avcodec.AV_CODEC_CAP_HYBRID) != 0 || codecHasHwConfig(codec)) {
|
||||
@@ -126,7 +153,7 @@ public enum VideoCodec implements ComboOption {
|
||||
AVRational time_base = av_inv_q(frameRate);
|
||||
codecContext.time_base(time_base);
|
||||
|
||||
int pixelFormat = PixelFormatHelper.getBestPixelFormat(codec.name().getString());
|
||||
int pixelFormat = PixelFormatHelper.getBestPixelFormat(codec.name().getString(), false);
|
||||
codecContext.pix_fmt(pixelFormat);
|
||||
|
||||
if ((codec.capabilities() & AV_CODEC_CAP_EXPERIMENTAL) != 0) {
|
||||
|
||||
@@ -17,6 +17,7 @@ public enum VideoContainer implements ComboOption {
|
||||
private final String text;
|
||||
private final String extension;
|
||||
private VideoCodec[] supportedVideoCodecs = null;
|
||||
private VideoCodec[] supportedVideoCodecsWithTransparency = null;
|
||||
private AudioCodec[] supportedAudioCodecs = null;
|
||||
|
||||
VideoContainer(String text, String extension) {
|
||||
@@ -33,8 +34,20 @@ public enum VideoContainer implements ComboOption {
|
||||
return extension;
|
||||
}
|
||||
|
||||
public VideoCodec[] getSupportedVideoCodecs() {
|
||||
if (this.supportedVideoCodecs == null) {
|
||||
public static VideoContainer[] findSupportedContainers(boolean transparency) {
|
||||
List<VideoContainer> containers = new ArrayList<>();
|
||||
for (VideoContainer videoContainer : VideoContainer.values()) {
|
||||
if (videoContainer.getSupportedVideoCodecs(transparency).length != 0) {
|
||||
containers.add(videoContainer);
|
||||
}
|
||||
}
|
||||
return containers.toArray(new VideoContainer[0]);
|
||||
}
|
||||
|
||||
public VideoCodec[] getSupportedVideoCodecs(boolean transparency) {
|
||||
VideoCodec[] codecs = transparency ? this.supportedVideoCodecsWithTransparency : this.supportedVideoCodecs;
|
||||
|
||||
if (codecs == null) {
|
||||
List<VideoCodec> supportedCodecs = new ArrayList<>();
|
||||
try (AVOutputFormat outputFormat = avformat.av_guess_format(this.extension, "test."+this.extension, null)) {
|
||||
for (VideoCodec codec : VideoCodec.values()) {
|
||||
@@ -44,6 +57,9 @@ public enum VideoContainer implements ComboOption {
|
||||
if (codec.getEncoders().length == 0) {
|
||||
continue;
|
||||
}
|
||||
if (transparency && !codec.supportsTransparency()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int ret = avformat.avformat_query_codec(outputFormat, codec.codecId(), avcodec.FF_COMPLIANCE_NORMAL);
|
||||
if (ret == 1) {
|
||||
@@ -52,9 +68,14 @@ public enum VideoContainer implements ComboOption {
|
||||
}
|
||||
}
|
||||
|
||||
this.supportedVideoCodecs = supportedCodecs.toArray(new VideoCodec[0]);
|
||||
codecs = supportedCodecs.toArray(new VideoCodec[0]);
|
||||
if (transparency) {
|
||||
this.supportedVideoCodecsWithTransparency = codecs;
|
||||
} else {
|
||||
this.supportedVideoCodecs = codecs;
|
||||
}
|
||||
}
|
||||
return this.supportedVideoCodecs;
|
||||
return codecs;
|
||||
}
|
||||
|
||||
public AudioCodec[] getSupportedAudioCodecs() {
|
||||
|
||||
Reference in new issue
Block a user