private void buildMediaInfoContext() throws XmlParsingException, IOException, MediaInfoException { logger.debug("Building Media Info contexts...\n"); new MediaInfoContextBuilder( contextProvider, new ConversionEngine().getExecuteStrategyFactory()).build(); logger.debug("Built Media Info contexts: OK\n"); }
private File getMediaInfo(SequenceType seqType, String essence) throws IOException { // 1. fill dynamic context's mediaInfoInput contextProvider.getDynamicContext().addParameter(DynamicContextParameters.MEDIA_INFO_INPUT, essence, false); // 2. prepare the output file File outputFile = getOutputFile(seqType, essence, contextProvider.getWorkingDir()); // 2. execute media info command. the output will be the provided file. executeMediaInfoCommand(seqType, essence, outputFile); // 3. add output as a dynamic parameter to delete on exit contextProvider.getDynamicContext().addParameter( getOutputDynamicParamName(seqType, essence), outputFile.getAbsolutePath(), true); return outputFile; }
@Override FfprobeType parseOutputFile(File outputFile, ContextInfo contextInfo) throws XmlParsingException, FileNotFoundException { switch (contextInfo.getSequenceType()) { case AUDIO: outputFile = audioMediaInfoXml; break; case VIDEO: outputFile = videoMediaInfoXml; break; default: throw new RuntimeException(); } return super.parseOutputFile(outputFile, contextInfo); }
private VirtualTrackInfo doBuild(ContextInfo contextInfo, VirtualTrackInfo prevVirtualTrack) throws IOException, XmlParsingException, MediaInfoException { // 1. get the corresponding essence String essence = contextProvider.getResourceContext().getParameterValue( ResourceContextParameters.ESSENCE, contextInfo); String trackFileId = contextProvider.getResourceContext().getParameterValue( ResourceContextParameters.TRACK_FILE_ID, contextInfo); // 2. check if we already have media info loaded for this track. If no - load it by executing an external program. ImmutablePair<SequenceType, String> key = ImmutablePair.of(contextInfo.getSequenceType(), trackFileId); VirtualTrackInfo processedInfo = processedMediaInfo.get(key); if (processedInfo == null) { File outputFile = getMediaInfo(contextInfo.getSequenceType(), essence); processedInfo = getTrackInfo(outputFile, contextInfo, essence); processedMediaInfo.put(key, processedInfo); } // 3. we assume that some parameters within a sequence must be equal (for example, channels number). validateSequenceHomogeneous(prevVirtualTrack, processedInfo); // 4. add to resource context buildResourceContext(processedInfo, contextInfo); return processedInfo; }
MediaInfoContextBuilder.getOutputDynamicParamName(SequenceType.VIDEO, essenceVideo1)); CustomParameterValue outputVideo2 = dynamicContext.getParameterValue( MediaInfoContextBuilder.getOutputDynamicParamName(SequenceType.VIDEO, essenceVideo2)); CustomParameterValue outputAudio1 = dynamicContext.getParameterValue( MediaInfoContextBuilder.getOutputDynamicParamName(SequenceType.AUDIO, essenceAudio1)); CustomParameterValue outputAudio2 = dynamicContext.getParameterValue( MediaInfoContextBuilder.getOutputDynamicParamName(SequenceType.AUDIO, essenceAudio2)); assertTrue(outputVideo1.isDeleteOnExit()); assertEquals( MediaInfoContextBuilder.getOutputFile(SequenceType.VIDEO, essenceVideo1, contextProvider.getWorkingDir()).getAbsolutePath(), outputVideo1.getValue()); assertTrue(outputVideo2.isDeleteOnExit()); assertEquals( MediaInfoContextBuilder.getOutputFile(SequenceType.VIDEO, essenceVideo2, contextProvider.getWorkingDir()).getAbsolutePath(), outputVideo2.getValue()); assertTrue(outputAudio1.isDeleteOnExit()); assertEquals( MediaInfoContextBuilder.getOutputFile(SequenceType.AUDIO, essenceAudio1, contextProvider.getWorkingDir()).getAbsolutePath(), outputAudio1.getValue()); assertTrue(outputAudio2.isDeleteOnExit()); assertEquals( MediaInfoContextBuilder.getOutputFile(SequenceType.AUDIO, essenceAudio2, contextProvider.getWorkingDir()).getAbsolutePath(), outputAudio2.getValue());
public void testNoExceptionOnOtherMismatchedParameters() throws Exception { TemplateParameterContextProvider contextProvider = createDefaultContextProviderWithCPLContext( 2, 2, 2, EnumSet.of(SequenceType.VIDEO, SequenceType.AUDIO)); // create a test builder that uses different mediaInfo files with different parameters for the same sequence MediaInfoContextBuilder mediaInfoContextBuilder = new MediaInfoContextBuilder(contextProvider, new TestExecuteStrategyFactory()) { @Override FfprobeType parseOutputFile(File outputFile, ContextInfo contextInfo) throws XmlParsingException, FileNotFoundException { try { switch (contextInfo.getSequenceType()) { case AUDIO: outputFile = contextInfo.getResourceUuid().getUuid().contains("-0-") ? MediaInfoUtils.getCorrectMediaInfoAudio() : MediaInfoUtils.getCorrectMediaInfoAudio2(); break; case VIDEO: outputFile = contextInfo.getResourceUuid().getUuid().contains("-0-") ? MediaInfoUtils.getCorrectMediaInfoVideo() : MediaInfoUtils.getCorrectMediaInfoVideo2(); break; default: throw new RuntimeException(); } } catch (URISyntaxException e) { throw new RuntimeException(e); } return super.parseOutputFile(outputFile, contextInfo); } }; mediaInfoContextBuilder.build(); }
/** * Gets a media info XML file name created for the given sequence of the given type. The file is created in the working directory. * * @param seqType a virtual track type (video, audio, subtitle) * @param essence a full path to the essence file * @param workingDir a full path to the working directory. * @return media info XML file name for the given sequence of the given type */ public static File getOutputFile(SequenceType seqType, String essence, File workingDir) { return new File(workingDir, getOutputFileName(seqType, essence)); }
.setSequenceUuid(seqUuid) .setSequenceType(seqType).build(); prevVirtualTrack = doBuild(contextInfo, prevVirtualTrack);
mediaInfoContextBuilder.build();
/** * Gets a unique name of a dynamic parameter to store the output media info XML file created to the given essence of the given type * (see {@link #getOutputFileName(SequenceType, String)}). * * @param seqType a virtual track type (video, audio, subtitle) * @param essence a full path to the essence file * @return a unique dynamic parameter name. */ public static String getOutputDynamicParamName(SequenceType seqType, String essence) { return String.format("%s_%s", DynamicContextParameters.MEDIA_INFO_OUTPUT.getName(), getOutputFileName(seqType, essence)); }
private VirtualTrackInfo getTrackInfo(File outputFile, ContextInfo contextInfo, String essence) throws XmlParsingException, MediaInfoException, FileNotFoundException { // 1. parse output xml FfprobeType mediaInfo = parseOutputFile(outputFile, contextInfo); // 2. check that info is available if (mediaInfo.getStreams() == null || mediaInfo.getStreams().getStream().isEmpty()) { throw new MediaInfoException("No streams output", essence); } StreamType stream = mediaInfo.getStreams().getStream().get(0); // 3. fill info return new VirtualTrackInfo(contextInfo.getSequenceType(), stream); }
mediaInfoContextBuilder.build();
@Override FfprobeType parseOutputFile(File outputFile, ContextInfo contextInfo) throws XmlParsingException, FileNotFoundException { try { switch (contextInfo.getSequenceType()) { case AUDIO: outputFile = contextInfo.getResourceUuid().getUuid().contains("-0-") ? MediaInfoUtils.getCorrectMediaInfoAudio() : MediaInfoUtils.getCorrectMediaInfoAudio2(); break; case VIDEO: outputFile = contextInfo.getResourceUuid().getUuid().contains("-0-") ? MediaInfoUtils.getCorrectMediaInfoVideo() : MediaInfoUtils.getCorrectMediaInfoVideo2(); break; default: throw new RuntimeException(); } } catch (URISyntaxException e) { throw new RuntimeException(e); } return super.parseOutputFile(outputFile, contextInfo); } };
@Override FfprobeType parseOutputFile(File outputFile, ContextInfo contextInfo) throws XmlParsingException, FileNotFoundException { try { switch (contextInfo.getSequenceType()) { case AUDIO: outputFile = contextInfo.getResourceUuid().getUuid().endsWith("-0-0") ? MediaInfoUtils.getCorrectMediaInfoAudio() : MediaInfoUtils.getCorrectMediaInfoAudio2(); break; case VIDEO: outputFile = contextInfo.getResourceUuid().getUuid().endsWith("-0-0") ? MediaInfoUtils.getCorrectMediaInfoVideo() : MediaInfoUtils.getCorrectMediaInfoVideo2(); break; default: throw new RuntimeException(); } } catch (URISyntaxException e) { throw new RuntimeException(e); } return super.parseOutputFile(outputFile, contextInfo); } };
@Override FfprobeType parseOutputFile(File outputFile, ContextInfo contextInfo) throws XmlParsingException, FileNotFoundException { try { switch (contextInfo.getSequenceType()) { case AUDIO: outputFile = contextInfo.getResourceUuid().getUuid().contains("-0-") ? MediaInfoUtils.getCorrectMediaInfoAudio() : MediaInfoUtils.getCorrectMediaInfoAudio3(); break; case VIDEO: outputFile = contextInfo.getResourceUuid().getUuid().contains("-0-") ? MediaInfoUtils.getCorrectMediaInfoVideo() : MediaInfoUtils.getCorrectMediaInfoVideo2(); break; default: throw new RuntimeException(); } } catch (URISyntaxException e) { throw new RuntimeException(e); } return super.parseOutputFile(outputFile, contextInfo); } };