1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

Make sure that 748x574 resolution resolves to 576p

This commit is contained in:
Reinhard Pointner 2017-08-03 12:01:36 +08:00
parent 7a7af2b386
commit e10ef895cc
4 changed files with 64 additions and 21 deletions

View File

@ -53,6 +53,7 @@ import net.filebot.Settings;
import net.filebot.hash.HashType; import net.filebot.hash.HashType;
import net.filebot.media.MetaAttributes; import net.filebot.media.MetaAttributes;
import net.filebot.media.NamingStandard; import net.filebot.media.NamingStandard;
import net.filebot.media.VideoFormat;
import net.filebot.mediainfo.ImageMetadata; import net.filebot.mediainfo.ImageMetadata;
import net.filebot.mediainfo.MediaInfo; import net.filebot.mediainfo.MediaInfo;
import net.filebot.mediainfo.MediaInfo.StreamKind; import net.filebot.mediainfo.MediaInfo.StreamKind;
@ -352,27 +353,11 @@ public class MediaBindingBean {
@Define("vf") @Define("vf")
public String getVideoFormat() { public String getVideoFormat() {
int width = Integer.parseInt(getMediaInfo(StreamKind.Video, 0, "Width")); int w = Integer.parseInt(getMediaInfo(StreamKind.Video, 0, "Width"));
int height = Integer.parseInt(getMediaInfo(StreamKind.Video, 0, "Height")); int h = Integer.parseInt(getMediaInfo(StreamKind.Video, 0, "Height"));
int[] ws = new int[] { 15360, 7680, 3840, 1920, 1280, 1024, 854, 748, 720, 688, 512, 320 };
int[] hs = new int[] { 8640, 4320, 2160, 1080, 720, 576, 576, 480, 480, 360, 240, 240 };
int ns = 0;
for (int i = 0; i < ws.length - 1; i++) {
if ((width >= ws[i] || height >= hs[i]) || (width > ws[i + 1] && height > hs[i + 1])) {
ns = hs[i];
break;
}
}
if (ns > 0) {
// e.g. 720p, nobody actually wants files to be tagged as interlaced, e.g. 720i // e.g. 720p, nobody actually wants files to be tagged as interlaced, e.g. 720i
return String.format("%dp", ns); return String.format("%dp", VideoFormat.DEFAULT_GROUPS.guessFormat(w, h));
}
return null; // video too small
} }
@Define("hpi") @Define("hpi")

View File

@ -0,0 +1,39 @@
package net.filebot.media;
import static java.util.ResourceBundle.*;
import static net.filebot.util.RegularExpressions.*;
public class VideoFormat {
public static final VideoFormat DEFAULT_GROUPS = new VideoFormat();
private final int[] ws;
private final int[] hs;
public VideoFormat() {
this.ws = getIntArrayProperty("resolution.steps.w");
this.hs = getIntArrayProperty("resolution.steps.h");
}
public int guessFormat(int width, int height) {
int ns = 0;
for (int i = 0; i < ws.length - 1; i++) {
if ((width >= ws[i] || height >= hs[i]) || (width > ws[i + 1] && height > hs[i + 1])) {
ns = hs[i];
break;
}
}
if (ns > 0) {
return ns;
}
throw new IllegalArgumentException(String.format("Illegal resolution: [%d, %d]", width, height));
}
private int[] getIntArrayProperty(String key) {
return SPACE.splitAsStream(getBundle(getClass().getName()).getString(key)).mapToInt(Integer::parseInt).toArray();
}
}

View File

@ -8,6 +8,7 @@ import net.filebot.format.ExpressionFormatTest;
import net.filebot.hash.VerificationFormatTest; import net.filebot.hash.VerificationFormatTest;
import net.filebot.media.MediaDetectionTest; import net.filebot.media.MediaDetectionTest;
import net.filebot.media.ReleaseInfoTest; import net.filebot.media.ReleaseInfoTest;
import net.filebot.media.VideoFormatTest;
import net.filebot.mediainfo.MediaInfoTest; import net.filebot.mediainfo.MediaInfoTest;
import net.filebot.similarity.EpisodeMetricsTest; import net.filebot.similarity.EpisodeMetricsTest;
import net.filebot.similarity.SimilarityTestSuite; import net.filebot.similarity.SimilarityTestSuite;
@ -18,7 +19,7 @@ import net.filebot.util.UtilTestSuite;
import net.filebot.web.WebTestSuite; import net.filebot.web.WebTestSuite;
@RunWith(Suite.class) @RunWith(Suite.class)
@SuiteClasses({ ExpressionFormatTest.class, VerificationFormatTest.class, MatchModelTest.class, SupportDialogTest.class, EpisodeMetricsTest.class, ReleaseInfoTest.class, MediaDetectionTest.class, MediaInfoTest.class, SimilarityTestSuite.class, WebTestSuite.class, SubtitleReaderTestSuite.class, UtilTestSuite.class }) @SuiteClasses({ ExpressionFormatTest.class, VerificationFormatTest.class, MatchModelTest.class, SupportDialogTest.class, EpisodeMetricsTest.class, ReleaseInfoTest.class, VideoFormatTest.class, MediaDetectionTest.class, MediaInfoTest.class, SimilarityTestSuite.class, WebTestSuite.class, SubtitleReaderTestSuite.class, UtilTestSuite.class })
public class AllTests { public class AllTests {
} }

View File

@ -0,0 +1,18 @@
package net.filebot.media;
import static org.junit.Assert.*;
import org.junit.Test;
public class VideoFormatTest {
VideoFormat vf = new VideoFormat();
@Test
public void trickyResolutions() {
assertEquals(1080, vf.guessFormat(1920, 1040));
assertEquals(720, vf.guessFormat(1280, 528));
assertEquals(576, vf.guessFormat(748, 574));
}
}