/** * 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)); }
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); }
private void checkMediaInfoCommand(MediaInfoCommandOthersTypeMap commandsMap, String commandName) throws MediaInfoException { if (!commandsMap.getMap().containsKey(commandName)) { throw new MediaInfoException(commandName, String.format( "%s command must be set in conversion.xml", commandName)); } }
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; }
@Test(expected = FileNotFoundException.class) public void testParseInvalidFilePathVideo() throws Exception { new TestMediaInfoContextBuilder(new File("invalid-path"), MediaInfoUtils.getCorrectMediaInfoAudio()) .build(); }
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"); }
@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); }
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(); }
private void validateSequenceHomogeneous(VirtualTrackInfo prevVirtualTrackInfo, VirtualTrackInfo nextVirtualTrackInfo) { if (prevVirtualTrackInfo == null) { return; } if (nextVirtualTrackInfo == null) { return; } if (!Objects.equals( prevVirtualTrackInfo.getParameters().get(ResourceContextParameters.CHANNELS_NUM), nextVirtualTrackInfo.getParameters().get(ResourceContextParameters.CHANNELS_NUM))) { throw new ConversionException( "All audio resource tracks within an audio sequence (virtual track) must have the same number of channels!"); } if (!Objects.equals( prevVirtualTrackInfo.getParameters().get(ResourceContextParameters.FRAME_RATE), nextVirtualTrackInfo.getParameters().get(ResourceContextParameters.FRAME_RATE))) { throw new ConversionException( "All video resource tracks within an video sequence (virtual track) must have the same fps!"); } }
public VirtualTrackInfo(SequenceType seqType, StreamType stream) { this.seqType = seqType; // audio addParameter(ResourceContextParameters.CHANNELS_NUM, stream.getChannels()); addParameter(ResourceContextParameters.SAMPLE_RATE, stream.getSampleRate()); addParameter(ResourceContextParameters.BITS_PER_SAMPLE, stream.getBitsPerSample()); // video addParameter(ResourceContextParameters.WIDTH, stream.getWidth()); addParameter(ResourceContextParameters.HEIGHT, stream.getHeight()); addParameter(ResourceContextParameters.BIT_DEPTH, stream.getBitsPerRawSample()); addParameter(ResourceContextParameters.PIXEL_FORMAT, stream.getPixFmt()); String rFrameRate = stream.getRFrameRate(); if (rFrameRate != null) { addParameter(ResourceContextParameters.FRAME_RATE, ConversionHelper.rFrameRateToEditRate(rFrameRate)); } }
@Test public void testMediaInfoOutputFileName() throws Exception { assertEquals("mediaInfo_audio_filename.mxf.xml", TestMediaInfoContextBuilder.getOutputFileName(SequenceType.AUDIO, "C:/parent/filename.mxf")); assertEquals("mediaInfo_video_filename.mxf.xml", TestMediaInfoContextBuilder.getOutputFileName(SequenceType.VIDEO, "C:/parent/filename.mxf")); assertEquals("mediaInfo_audio_filename.mxf.xml", TestMediaInfoContextBuilder.getOutputFileName(SequenceType.AUDIO, "filename.mxf")); assertEquals("mediaInfo_video_filename.mxf.xml", TestMediaInfoContextBuilder.getOutputFileName(SequenceType.VIDEO, "filename.mxf")); assertEquals("mediaInfo_audio_filename.mxf.xml", TestMediaInfoContextBuilder.getOutputFileName(SequenceType.AUDIO, "/tmp/parent/filename.mxf")); assertEquals("mediaInfo_video_filename.mxf.xml", TestMediaInfoContextBuilder.getOutputFileName(SequenceType.VIDEO, "/tmp/parent/filename.mxf")); }
@Test(expected = FileNotFoundException.class) public void testParseInvalidFilePathAudio() throws Exception { new TestMediaInfoContextBuilder(MediaInfoUtils.getCorrectMediaInfoVideo(), new File("invalid-path")) .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 void buildResourceContext(VirtualTrackInfo virtualTrackInfo, ContextInfo contextInfo) { virtualTrackInfo.getParameters().forEach( (paramName, paramValue) -> contextProvider.getResourceContext().addResourceParameter( ResourceKey.create(contextInfo), contextInfo.getResourceUuid(), paramName, paramValue)); }
@Test(expected = XmlParsingException.class) public void testParseBrokenXmlAudio() throws Exception { new TestMediaInfoContextBuilder(MediaInfoUtils.getCorrectMediaInfoVideo(), MediaInfoUtils.getBrokenXmlMediaInfoAudio()) .build(); }
@Test(expected = XmlParsingException.class) public void testParseBrokenXmlVideo() throws Exception { new TestMediaInfoContextBuilder(MediaInfoUtils.getBrokenXmlMediaInfoVideo(), MediaInfoUtils.getCorrectMediaInfoAudio()) .build(); }
@Test public void testParseCorrectMediaInfo() throws Exception { new TestMediaInfoContextBuilder(MediaInfoUtils.getCorrectMediaInfoVideo(), MediaInfoUtils.getCorrectMediaInfoAudio()) .build(); }
@Test(expected = XmlParsingException.class) @Ignore public void testParseInvalidXsdVideo() throws Exception { new TestMediaInfoContextBuilder(MediaInfoUtils.getInvalidXsdMediaInfoVideo(), MediaInfoUtils.getCorrectMediaInfoAudio()) .build(); }
@Test(expected = XmlParsingException.class) @Ignore public void testParseInvalidXsdAudio() throws Exception { new TestMediaInfoContextBuilder(MediaInfoUtils.getCorrectMediaInfoVideo(), MediaInfoUtils.getInvalidXsdMediaInfoAudio()) .build(); }
@Test public void testDynamicContextMediaInfoInputNotForDelete() throws Exception { TemplateParameterContextProvider contextProvider = createDefaultContextProviderWithCPLContext( 2, 2, 2, EnumSet.of(SequenceType.VIDEO, SequenceType.AUDIO)); new TestMediaInfoContextBuilder(contextProvider).build(); DynamicTemplateParameterContext dynamicContext = contextProvider.getDynamicContext(); CustomParameterValue input = dynamicContext.getParameterValue(DynamicContextParameters.MEDIA_INFO_INPUT); // input not in context for delete on exit! assertNotNull(input); assertFalse(input.isDeleteOnExit()); }