private void checkFrameRate(ContextInfo contextInfo) throws ConversionNotAllowedException { checkParameter(ResourceContextParameters.FRAME_RATE, ConversionParameterNameType.FRAME_RATE, contextInfo, (f1, f2) -> Objects.equals(ConversionHelper.parseEditRate(f1), ConversionHelper.parseEditRate(f2))); }
private BigFraction parseFrameRate(String frameRate) { try { return ConversionHelper.parseEditRate(frameRate); } catch (ConversionHelperException e) { throw new ParseException("Value of -f(--frameRate) option must be correct frame rate in format numerator/[denominator])"); } } }
public BigFraction getValueAsFrameRate(String paramName) { String value = getValue(paramName); return value != null ? ConversionHelper.parseEditRate(value) : null; }
/** * Transforms a timecode string (hh:mm:ss:ff) to milliseconds according to the given edit rate (frame rate). * <p> * Currently works with non-drop timecodes only. * </p> * * @param tc an SMPTE timecode (hh:mm:ss:ff) * @param unitsInSecStr edit unit rate in a form "25 1" * @return a number of milliseconds */ public static long smpteTimecodeToMilliSeconds(String tc, String unitsInSecStr) { BigFraction unitsInSec = parseEditRate(unitsInSecStr); return smpteTimecodeToMilliSeconds(tc, unitsInSec); }
@Test(expected = ConversionHelperException.class) public void parseIncorrectEditRateMoreArguments() { ConversionHelper.parseEditRate("30000 1001 1"); }
@Test(expected = ConversionHelperException.class) public void parseIncorrectEditRateNotNumber() { ConversionHelper.parseEditRate("aaaaa"); }
public TtmlParagraphResolver(TtEltype tt) { this.tt = tt; this.frameRate = ConversionHelper.parseEditRate(tt.getFrameRateMultiplier()).multiply(tt.getFrameRate()); }
@Test public void parseCorrectEditRate() { assertEquals(new BigFraction(30000, 1001), ConversionHelper.parseEditRate("30000 1001")); assertEquals(new BigFraction(50, 1), ConversionHelper.parseEditRate("50")); assertEquals(new BigFraction(30000, 1001), ConversionHelper.parseEditRate("30000/1001")); assertEquals(new BigFraction(50, 1), ConversionHelper.parseEditRate("50 1")); }
@Test(expected = ConversionHelperException.class) public void parseIncorrectEditRateEmpty() { ConversionHelper.parseEditRate(""); }
private long getDestStartTime() { // composition timecode as specified in CPL String cplStartTime = getCompositionTimecodeStart(); BigFraction cplRate = getCompositionTimecodeRate(); // start time as specified in conversion.xml (destination parameter). DestTemplateParameterContext destContext = contextProvider.getDestContext(); String destStartTime = destContext.getParameterValue(DestContextParameters.START_TIME); String destRateStr = destContext.getParameterValue(DestContextParameters.FRAME_RATE); BigFraction destRate = StringUtils.isEmpty(destRateStr) ? null : ConversionHelper.parseEditRate(destRateStr); // values from conversion.xml has higher priority String startTime = StringUtils.isEmpty(destStartTime) ? cplStartTime : destStartTime; BigFraction rate = destRate == null ? cplRate : destRate; // convert to milliseconds if (!StringUtils.isEmpty(startTime) && (rate != null)) { return ConversionHelper.smpteTimecodeToMilliSeconds(startTime, rate); } // default fallback 00:00:00:00 return 0L; }
private void resolveSameFpsParameter() { ContextInfo contextInfo = new ContextInfoBuilder() .setSequenceType(SequenceType.VIDEO) .setSequenceUuid(getVideoSequenceUUID()) .build(); BigFraction seqFrameRate = ConversionHelper.parseEditRate(contextProvider.getSequenceContext().getParameterValue( SequenceContextParameters.FRAME_RATE, contextInfo)); BigFraction destFrameRate = ConversionHelper.parseEditRate(contextProvider.getDestContext().getParameterValue( DestContextParameters.FRAME_RATE)); DynamicTemplateParameterContext dynamicContext = contextProvider.getDynamicContext(); dynamicContext.addParameter(DYNAMIC_PARAM_SAME_FPS, Boolean.toString(seqFrameRate.equals(destFrameRate))); }
private void resolveSameFpsParameter() { ContextInfo contextInfo = new ContextInfoBuilder() .setSequenceType(SequenceType.VIDEO) .setSequenceUuid(getVideoSequenceUUID()) .build(); BigFraction seqFrameRate = ConversionHelper.parseEditRate(contextProvider.getSequenceContext().getParameterValue( SequenceContextParameters.FRAME_RATE, contextInfo)); BigFraction destFrameRate = ConversionHelper.parseEditRate(contextProvider.getDestContext().getParameterValue( DestContextParameters.FRAME_RATE)); DynamicTemplateParameterContext dynamicContext = contextProvider.getDynamicContext(); dynamicContext.addParameter(DYNAMIC_PARAM_SAME_FPS, Boolean.toString(seqFrameRate.equals(destFrameRate))); }
@Override protected void doBuildDestContext() { DestTemplateParameterContext destContext = contextProvider.getDestContext(); // set interlaced to false if not specified String interlaced = destContext.getParameterValue(INTERLACED); destContext.addParameter(INTERLACED, interlaced == null ? Boolean.FALSE.toString() : interlaced); // define is dar provided destContext.addParameter(DEST_PARAM_VIDEO_IS_DAR_SPECIFIED, Boolean.toString(destContext.getParameterValue(DAR) != null)); // set frame rate for interlaced scan // for ffmpeg iFrameRate=frameRate*2 // for prenc iFrameRate=frameRate BigFraction iFrameRate = ConversionHelper.parseEditRate(destContext.getParameterValue(FRAME_RATE)); if (!SystemUtils.IS_OS_MAC_OSX) { iFrameRate = iFrameRate.multiply(2); } destContext.addParameter(DEST_PARAM_VIDEO_IFRAME_RATE, ConversionHelper.toREditRate(iFrameRate)); }
/** * Check that total duration specified in Metadata.xml is less than total duration of the output file. * Otherwise conversion will abort at the very last step (BMX). It may make the user unhappy after a long conversion. */ private void checkTotalDuration() { String metadataTotalDurationTc = metadataXmlProvider.getDpp().getTechnical().getTimecodes().getTotalProgrammeDuration().getValue(); if (StringUtils.isEmpty(metadataTotalDurationTc)) { return; } String destFps = contextProvider.getDestContext().getParameterValue(DestContextParameters.FRAME_RATE); if (destFps == null) { destFps = MetadataXmlProvider.DEST_FRAME_RATE; } BigFraction fps = ConversionHelper.parseEditRate(destFps); long metadataTotalDurationMs = ConversionHelper.smpteTimecodeToMilliSeconds( metadataTotalDurationTc, fps); long cplTotalDurationMs = getCplTotalDurationMs(); // BMX accepts any total duration if zero timecode is specified in metadata.xml if (metadataTotalDurationMs == 0) { return; } if (metadataTotalDurationMs > cplTotalDurationMs) { throw new ConversionException( String.format("A total programme duration as specified in metadata.xml (%s, %s ms) exceeds a " + "total duration of the output as defined by the CPL (%s, %s ms) ", metadataTotalDurationTc, String.valueOf(metadataTotalDurationMs), ConversionHelper.msToSmpteTimecode(cplTotalDurationMs, fps), String.valueOf(cplTotalDurationMs))); } }
@Override protected void buildFromCpl() { // 1. get a composition edit rate (it's used if no specific edit rate is specified for a segment). this.compositionEditRate = ConversionHelper.parseEditRate(cpl2013.getEditRate()); // 2. go through all segments and all sequences and build segment, sequence and resource contexts. for (SegmentType segment : cpl2013.getSegmentList().getSegment()) { this.currentSegmentUuid = SegmentUUID.create(segment.getId()); contextProvider.getSegmentContext().initSegment(currentSegmentUuid); for (Object anySeqJaxb : segment.getSequenceList().getAny()) { if (!(anySeqJaxb instanceof JAXBElement)) { throw new ConversionException(String.format("Could not understand a sequence '%s'", anySeqJaxb.toString())); } JAXBElement jaxbElement = (JAXBElement) (anySeqJaxb); Object anySeq = jaxbElement.getValue(); SequenceTypeCpl currentSequenceTypeCpl = SequenceTypeCpl.fromName(jaxbElement.getName().getLocalPart()); if ((currentSequenceTypeCpl != null) && (anySeq instanceof SequenceType)) { this.currentSequence = (SequenceType) anySeq; this.currentSequenceType = currentSequenceTypeCpl.toSequenceType(); this.currentSequenceUuid = SequenceUUID.create(currentSequence.getTrackId()); processSequence(); } } } }
@Override protected void buildFromCpl() { // 1. get a composition edit rate (it's used if no specific edit rate is specified for a segment). this.compositionEditRate = ConversionHelper.parseEditRate(cpl2016.getEditRate()); // 2. go through all segments and all sequences and build segment, sequence and resource contexts. for (SegmentType segment : cpl2016.getSegmentList().getSegment()) { this.currentSegmentUuid = SegmentUUID.create(segment.getId()); contextProvider.getSegmentContext().initSegment(currentSegmentUuid); for (Object anySeqJaxb : segment.getSequenceList().getAny()) { if (!(anySeqJaxb instanceof JAXBElement)) { throw new ConversionException(String.format("Could not understand a sequence '%s'", anySeqJaxb.toString())); } JAXBElement jaxbElement = (JAXBElement) (anySeqJaxb); Object anySeq = jaxbElement.getValue(); SequenceTypeCpl currentSequenceTypeCpl = SequenceTypeCpl.fromName(jaxbElement.getName().getLocalPart()); if ((currentSequenceTypeCpl != null) && (anySeq instanceof SequenceType)) { this.currentSequence = (SequenceType) anySeq; this.currentSequenceType = currentSequenceTypeCpl.toSequenceType(); this.currentSequenceUuid = SequenceUUID.create(currentSequence.getTrackId()); processSequence(); } } } }
BigFraction editRate = ConversionHelper.parseEditRate(contextProvider.getResourceContext() .getParameterValue(ResourceContextParameters.EDIT_RATE, contextInfo)); BigInteger durationEU = new BigInteger(contextProvider.getResourceContext()
? ConversionHelper.parseEditRate(trackFileResource.getEditRate()) : compositionEditRate; contextProvider.getResourceContext().addResourceParameter(resourceKey, resourceId, ResourceContextParameters.EDIT_RATE, ConversionHelper.toEditRate(editRate));
? ConversionHelper.parseEditRate(trackFileResource.getEditRate()) : compositionEditRate; contextProvider.getResourceContext().addResourceParameter(resourceKey, resourceId, ResourceContextParameters.EDIT_RATE, ConversionHelper.toEditRate(editRate));
BigFraction frameRate = ConversionHelper.parseEditRate(prevVirtualTrack.getParameters() .get(ResourceContextParameters.FRAME_RATE)); sequenceContext.addSequenceParameter(