/** * Create Xml file * * @param fname file name * @param pics Map of SubPictures and their original indexes which were used to generate the png * file names * @throws CoreException */ public static void writeXml(String fname, SortedMap<Integer, SubPicture> pics) throws CoreException { double fps = configuration.getFpsTrg(); double fpsXml = XmlFps(fps); BufferedWriter out = null; String name = FilenameUtils.removeExtension(FilenameUtils.getName(fname)); try { out = new BufferedWriter(new FileWriter(fname)); out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); out.newLine(); out.write( "<BDN Version=\"0.93\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"BD-03-006-0093b BDN File Format.xsd\">"); out.newLine(); out.write(" <Description>"); out.newLine(); out.write(" <Name Title=\"" + name + "\" Content=\"\"/>"); out.newLine(); out.write(" <Language Code=\"" + LANGUAGES[configuration.getLanguageIdx()][2] + "\"/>"); out.newLine(); String res = configuration.getOutputResolution().getResolutionNameForXml(); out.write( " <Format VideoFormat=\"" + res + "\" FrameRate=\"" + ToolBox.formatDouble(fps) + "\" DropFrame=\"False\"/>"); out.newLine(); long t = pics.get(pics.firstKey()).getStartTime(); if (fps != fpsXml) { t = (t * 2000 + 1001) / 2002; } String ts = ptsToTimeStrXml(t, fpsXml); t = pics.get(pics.lastKey()).getEndTime(); if (fps != fpsXml) { t = (t * 2000 + 1001) / 2002; } String te = ptsToTimeStrXml(t, fpsXml); out.write( " <Events Type=\"Graphic\" FirstEventInTC=\"" + ts + "\" LastEventOutTC=\"" + te + "\" NumberofEvents=\"" + pics.size() + "\"/>"); out.newLine(); out.write(" </Description>"); out.newLine(); out.write(" <Events>"); out.newLine(); for (int idx : pics.keySet()) { SubPicture p = pics.get(idx); t = p.getStartTime(); if (fps != fpsXml) { t = (t * 2000 + 1001) / 2002; } ts = ptsToTimeStrXml(t, fpsXml); t = p.getEndTime(); if (fps != fpsXml) { t = (t * 2000 + 1001) / 2002; } te = ptsToTimeStrXml(t, fpsXml); String forced = p.isForced() ? "True" : "False"; out.write(" <Event InTC=\"" + ts + "\" OutTC=\"" + te + "\" Forced=\"" + forced + "\">"); out.newLine(); String pname = getPNGname(name, idx + 1); out.write( " <Graphic Width=\"" + p.getImageWidth() + "\" Height=\"" + p.getImageHeight() + "\" X=\"" + p.getXOffset() + "\" Y=\"" + p.getYOffset() + "\">" + pname + "</Graphic>"); out.newLine(); out.write(" </Event>"); out.newLine(); } out.write(" </Events>"); out.newLine(); out.write("</BDN>"); out.newLine(); } catch (IOException ex) { throw new CoreException(ex.getMessage()); } finally { try { if (out != null) { out.close(); } } catch (IOException ex) { } } }