@Test public void testGetNearestResolution() throws Exception { Fraction frac43 = Fraction.getFraction(4, 3); Fraction frac169 = Fraction.getFraction(16, 9); List<Fraction> aspects = new ArrayList<>(); aspects.add(frac43); aspects.add(frac169); int[][] aspect43 = {{640, 480},{768, 576}, {720, 576}, {703, 576}, {720, 576}, {720, 480}, {240, 180}, {638, 512}, {704, 576}, {756, 576}, {800, 600}, {1024, 768}, {1280, 1023}, {1016, 768}, {1280, 1024}}; int[][] aspect169 = {{1024, 576}, {1280, 720}, {1068, 600}, {1248, 702}, {1278, 720}}; for (int[] resArr: aspect43) { Fraction res = Fraction.getFraction(resArr[0], resArr[1]); Fraction aspect = operationHandler.getNearestAspectRatio(res, aspects); logger.info("res: {} -> aspect: {} | expected 4/3", res, aspect); assertEquals(frac43, aspect); } for (int[] resArr: aspect169) { Fraction res = Fraction.getFraction(resArr[0], resArr[1]); Fraction aspect = operationHandler.getNearestAspectRatio(res, aspects); logger.info("res: {} -> aspect: {} | expected 16/9", res, aspect); assertEquals(frac169, aspect); } }
Fraction getNearestAspectRatio(final Fraction videoAspect, final List<Fraction> aspects) { Fraction nearestAspect = aspects.get(0); for (Fraction aspect: aspects) { if (videoAspect.subtract(nearestAspect).abs().compareTo(videoAspect.subtract(aspect).abs()) > 0) { nearestAspect = aspect; } } return nearestAspect; }
AnalyzeTracksWorkflowOperationHandler extends AbstractWorkflowOperationHandler { Fraction getNearestAspectRatio(final Fraction videoAspect, final List<Fraction> aspects) { Fraction nearestAspect = aspects.get(0); for (Fraction aspect: aspects) { if (videoAspect.subtract(nearestAspect).abs().compareTo(videoAspect.subtract(aspect).abs()) > 0) { nearestAspect = aspect; } } return nearestAspect; } }
AnalyzeTracksWorkflowOperationHandler extends AbstractWorkflowOperationHandler { Fraction getNearestAspectRatio(final Fraction videoAspect, final List<Fraction> aspects) { Fraction nearestAspect = aspects.get(0); for (Fraction aspect: aspects) { if (videoAspect.subtract(nearestAspect).abs().compareTo(videoAspect.subtract(aspect).abs()) > 0) { nearestAspect = aspect; } } return nearestAspect; }  }
AnalyzeTracksWorkflowOperationHandler extends AbstractWorkflowOperationHandler { Fraction getNearestAspectRatio(final Fraction videoAspect, final List<Fraction> aspects) { Fraction nearestAspect = aspects.get(0); for (Fraction aspect: aspects) { if (videoAspect.subtract(nearestAspect).abs().compareTo(videoAspect.subtract(aspect).abs()) > 0) { nearestAspect = aspect; } } return nearestAspect; }  @Override WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context); }
AnalyzeTracksWorkflowOperationHandler extends AbstractWorkflowOperationHandler { Fraction getNearestAspectRatio(final Fraction videoAspect, final List<Fraction> aspects) { Fraction nearestAspect = aspects.get(0); for (Fraction aspect: aspects) { if (videoAspect.subtract(nearestAspect).abs().compareTo(videoAspect.subtract(aspect).abs()) > 0) { nearestAspect = aspect; } } return nearestAspect; }  @Override WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context);  }