Author: andre Date: 2010-03-26 17:51:30 +0100 (Fri, 26 Mar 2010) New Revision: 41646
Modified: mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/AnalyzerUtils.java mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpeg2TheoraAnalyzer.java mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpeg2TheoraTranscoder.java mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpegAnalyzer.java mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpegTranscoder.java mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/SegmenterAnalyzer.java Log: refined reading in and outputs for values, added output(source, dest, l) to set boolean flag when we're handling a dest. node, tried to make sure setting of values of dest. node is not with values of source stream Modified: mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/AnalyzerUtils.java =================================================================== --- mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/AnalyzerUtils.java 2010-03-26 16:49:05 UTC (rev 41645) +++ mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/AnalyzerUtils.java 2010-03-26 16:51:30 UTC (rev 41646) @@ -59,6 +59,7 @@ private final ChainedLogger log = new ChainedLogger(LOG); private boolean updateSource; + private boolean updateDestination = false; AnalyzerUtils(Logger... loggers) { for (Logger l : loggers) { @@ -72,6 +73,9 @@ public boolean getUpdateSource() { return updateSource; } + public void setUpdateDestination(boolean b) { + updateDestination = b; + } /** * This fixes the first part (f.e. audio/*) when needed, not the complete MimeType. @@ -214,6 +218,20 @@ return false; } + /* Output #0, mpeg, to 'presto.mpeg': */ + private static final Pattern PATTERN_OUTPUT = Pattern.compile("^Output #\\d+?, (.*), to.*?"); + + public boolean output(String l, Node source, Node dest) { + Matcher m = PATTERN_OUTPUT.matcher(l); + if (m.matches()) { + log.info("### OUTPUT match: " + l); + if (log.isDebugEnabled()) log.debug("format: " + m.group(1)); + updateDestination = true; + return true; + } + return false; + } + /* ffmpeg reports sometimes no start and on some video's bitrate: N/A */ private static final Pattern PATTERN_DURATION = Pattern.compile("\\s*Duration: (.*?),.* bitrate:.*?"); private static final Pattern PATTERN_BITRATE = Pattern.compile("\\s*Duration: .* bitrate: (.*?) kb/s.*?"); @@ -237,7 +255,7 @@ if (updateSource) { source.setLongValue("length", length); } - if (dest != null) { + if (updateDestination && dest != null) { dest.setLongValue("length", length); } @@ -245,8 +263,12 @@ if (m.matches()) { if (log.isDebugEnabled()) log.debug("bitrate: " + m.group(1)); int bitrate = 1000 * Integer.parseInt(m.group(1)); - if (updateSource) source.setIntValue("bitrate", bitrate); - if (dest != null) dest.setIntValue("bitrate", bitrate); + if (updateSource) { + source.setIntValue("bitrate", bitrate); + } + if (updateDestination && dest != null) { + dest.setIntValue("bitrate", bitrate); + } } m = PATTERN_START.matcher(l); @@ -287,8 +309,12 @@ if (m.matches()) { if (log.isDebugEnabled()) log.debug("bitrate: " + m.group(1)); int bitrate = 1000 * Integer.parseInt(m.group(1)); - if (updateSource) source.setIntValue("bitrate", bitrate); - if (dest != null) dest.setIntValue("bitrate", bitrate); + if (updateSource) { + source.setIntValue("bitrate", bitrate); + } + if (updateDestination && dest != null) { + dest.setIntValue("bitrate", bitrate); + } } return true; @@ -315,6 +341,7 @@ } private static final Pattern PATTERN_DIMENSIONS = Pattern.compile(".*?\\sVideo: (.*?), (.*?), ([0-9]+)x([0-9]+).*"); + private static final Pattern VIDEOBITRATE2_PATTERN = Pattern.compile(".*?\\sVideo: .*, (.*?) kb/s.*"); /** * Looks for width and height when it finds a match for Video, and looks for bitrate after that. @@ -343,7 +370,7 @@ source.setIntValue("width", Integer.parseInt(m.group(3))); source.setIntValue("height", Integer.parseInt(m.group(4))); } - if (dest != null) { + if (updateDestination && dest != null) { if (dest.getIntValue("codec") < 0) { dest.setIntValue("codec", libtoCodec(m.group(1)).toInt() ); } @@ -352,10 +379,24 @@ } m = VIDEOBITRATE_PATTERN.matcher(l); + Matcher m2 = VIDEOBITRATE2_PATTERN.matcher(l); if (m.matches()) { - if (log.isDebugEnabled()) log.debug("bitRate: " + m.group(1)); - if (updateSource) source.setIntValue("bitrate", Integer.parseInt(m.group(1))); - if (dest != null) dest.setIntValue("bitrate", Integer.parseInt(m.group(1))); + if (log.isDebugEnabled()) log.debug("bitrate: " + m.group(1)); + if (updateSource) { + source.setIntValue("bitrate", Integer.parseInt(m.group(1))); + } + if (updateDestination && dest != null) { + dest.setIntValue("bitrate", Integer.parseInt(m.group(1))); + } + } else if (m2.matches()) { + if (log.isDebugEnabled()) log.debug("bitrate: " + m2.group(1)); + int bitrate = 1000 * Integer.parseInt(m2.group(1)); + if (updateSource) { + source.setIntValue("bitrate", bitrate); + } + if (updateDestination && dest != null) { + dest.setIntValue("bitrate", bitrate); + } } return true; @@ -365,7 +406,6 @@ } private static final Pattern PATTERN_AUDIO = Pattern.compile(".*?\\sAudio: (.*?), (.*?) Hz, (stereo|mono|([0-9]+) channels), .*?"); - private static final Pattern PATTERN_BITRATE2 = Pattern.compile("\\s*Audio: .* bitrate: (.*?) kb/s.*?"); /** * Looks for audio channel(s). @@ -396,17 +436,17 @@ source.setIntValue("codec", libtoCodec(m.group(1)).toInt() ); } } - if (dest != null) { - if (dest.getIntValue("channels") < 0) dest.setIntValue("channels", ch); - + if (updateDestination && dest != null) { + if (dest.getIntValue("channels") < 0) { + dest.setIntValue("channels", ch); + } if (dest.getNodeManager().hasField("acodec") && dest.getIntValue("acodec") < 0) { dest.setIntValue("acodec", libtoCodec(m.group(1)).toInt() ); } else if (source.getIntValue("codec") < 0) { dest.setIntValue("codec", libtoCodec(m.group(1)).toInt() ); } - } - + return true; } else { return false; Modified: mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpeg2TheoraAnalyzer.java =================================================================== --- mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpeg2TheoraAnalyzer.java 2010-03-26 16:49:05 UTC (rev 41645) +++ mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpeg2TheoraAnalyzer.java 2010-03-26 16:51:30 UTC (rev 41646) @@ -40,7 +40,7 @@ return Integer.MAX_VALUE; } - private static final Pattern NORESIZE = Pattern.compile("\\s*Resize: ([0-9]+)x([0-9]+).*"); + private static final Pattern NORESIZE = Pattern.compile("\\s*Resize: ([0-9]+)x([0-9]+).*"); private static final Pattern RESIZE = Pattern.compile("\\s*Resize: ([0-9]+)x([0-9]+) => ([0-9]+)x([0-9]+).*"); private static final Pattern PROGRESS = Pattern.compile("\\s*(.*?) audio: ([0-9]+)kbps video: ([0-9]+)kbps, time remaining: .*"); @@ -52,7 +52,7 @@ private AnalyzerUtils util = new AnalyzerUtils(log); - private List<Throwable> errors =new ArrayList<Throwable>(); + private List<Throwable> errors = new ArrayList<Throwable>(); public void addThrowable(Throwable t) { errors.add(t); @@ -69,23 +69,19 @@ length = source.getLongValue("length"); return; } - - if (util.dimensions(l, source, des)) { - return; - } - + if (util.audio(l, source, des)) { + util.setUpdateDestination(true); + util.audio(l, source, des); + util.setUpdateDestination(false); return; } - + { Matcher m = RESIZE.matcher(l); if (m.matches()) { util.toVideo(source, des); log.debug("Found " + m); - source.setIntValue("width", Integer.parseInt(m.group(1))); - source.setIntValue("height", Integer.parseInt(m.group(2))); - source.commit(); des.setIntValue("width", Integer.parseInt(m.group(3))); des.setIntValue("height", Integer.parseInt(m.group(4))); des.commit(); @@ -95,9 +91,6 @@ if (n.matches()) { log.debug("Found " + n); util.toVideo(source, des); - source.setIntValue("width", Integer.parseInt(n.group(1))); - source.setIntValue("height", Integer.parseInt(n.group(2))); - source.commit(); des.setIntValue("width", Integer.parseInt(n.group(1))); des.setIntValue("height", Integer.parseInt(n.group(2))); des.commit(); @@ -112,7 +105,6 @@ long videoBitrate = Integer.parseInt(m.group(3)); bits += ((double) (audioBitrate + videoBitrate)) * ((double) pos - prevPos) * 1000; //System.out.println("" + pos + "ms " + (audioBitrate + videoBitrate) + " -> " + (bits / pos) + " " + (100 * pos / length) + " %"); - prevPos = pos; } } Modified: mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpeg2TheoraTranscoder.java =================================================================== --- mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpeg2TheoraTranscoder.java 2010-03-26 16:49:05 UTC (rev 41645) +++ mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpeg2TheoraTranscoder.java 2010-03-26 16:51:30 UTC (rev 41646) @@ -72,7 +72,15 @@ public void setWidth(int x) { width = x; } - + + /* Saving values codec, acodec */ + public void init(Node dest) { + dest.setIntValue("codec", Codec.THEORA.toInt() ); + if (dest.getNodeManager().hasField("acodec")) { + dest.setIntValue("acodec", Codec.VORBIS.toInt() ); + } + } + @Override protected String getCommand() { return "ffmpeg2theora"; Modified: mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpegAnalyzer.java =================================================================== --- mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpegAnalyzer.java 2010-03-26 16:49:05 UTC (rev 41645) +++ mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpegAnalyzer.java 2010-03-26 16:51:30 UTC (rev 41646) @@ -84,6 +84,11 @@ return; } + if (util.output(l, source, des)) { + util.setUpdateDestination(true); + return; + } + if (util.duration(l, source, des)) { return; } Modified: mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpegTranscoder.java =================================================================== --- mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpegTranscoder.java 2010-03-26 16:49:05 UTC (rev 41645) +++ mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/FFMpegTranscoder.java 2010-03-26 16:51:30 UTC (rev 41646) @@ -33,11 +33,10 @@ /** - * The transcoder that uses <code>ffmpeg</code> to transcode media. Possible parameters to be set in + * Transcoder that uses <code>ffmpeg</code> to transcode media. Possible parameters to be set in * 'createcaches.xml' are: format, forceFormat (-f), acodec (-acodec), vcodec (-vcodec), * vpre (-vpre), aq (-aq), ab (-ab), bitrate or b (-b), async (-async), framesPerSecond or - * r (-r), audioChannels or ac (-ac), - * width and height (combined to -s). + * r (-r), audioChannels or ac (-ac), width and height (combined to -s). * Others can be added as extra parameters but will be at the end of the commands parameters. See the * documentation for FFmpeg for more information. * @@ -148,7 +147,18 @@ format = Format.AVI; } - + /* Saving values like width, height */ + public void init(Node dest) { + /* + if (width != null && dest.getNodeManager().hasField("width")) { + dest.setIntValue("width", width); + if (height != null) { + dest.setIntValue("height", height); + } + } + */ + } + @Override protected String getCommand() { return "ffmpeg"; Modified: mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/SegmenterAnalyzer.java =================================================================== --- mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/SegmenterAnalyzer.java 2010-03-26 16:49:05 UTC (rev 41645) +++ mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/transcoders/SegmenterAnalyzer.java 2010-03-26 16:51:30 UTC (rev 41646) @@ -65,6 +65,7 @@ public void analyze(String l, Node source, Node des) { synchronized(util) { + /* Cloud cloud = source.getCloud(); if (util.duration(l, source, des)) { @@ -78,7 +79,7 @@ if (util.audio(l, source, des)) { return; } - + */ // TODO: progress matcher /* { _______________________________________________ Cvs mailing list Cvs@lists.mmbase.org http://lists.mmbase.org/mailman/listinfo/cvs