1 10 package org.mmbase.module.builders.vwms; 11 12 import java.util.Calendar ; 13 import java.util.Date ; 14 import java.util.GregorianCalendar ; 15 import java.util.StringTokenizer ; 16 import java.util.TimeZone ; 17 18 import org.mmbase.util.*; 19 20 import org.mmbase.util.logging.Logger; 21 import org.mmbase.util.logging.Logging; 22 23 29 public class VideoObject { 30 31 private static Logger log = Logging.getLoggerInstance(VideoObject.class.getName()); 32 33 Execute exec=new Execute(); 34 private String filename; 35 private int samples; 36 private int channels; 37 private int frequency; 38 private int time; private float length; 40 41 public VideoObject() { 42 } 43 44 public static VideoObject get(String pool) { 45 return getInfo(pool+"/0.mov"); 46 } 47 48 public static VideoObject getInfo(String filename) { 49 Execute sexec=new Execute(); 50 String inf,t,dat="",tim=""; 51 VideoObject ao=new VideoObject(); 52 StringTokenizer tok; 53 int line=0,word=0; 54 float len; 55 56 57 log.info("file " + filename); 58 ao.setFilename(filename); 59 inf=sexec.execute("/usr/local/bin/InfoVideo "+filename); 60 61 tok=new StringTokenizer (inf," \n\r\t",true); 62 while(tok.hasMoreTokens()) { 63 t=tok.nextToken(); 64 log.debug(t); 65 if (t.equals(" ") || t.equals("\t") || t.equals("\r")) { 66 } else if (t.equals("\n")) { 68 word=0; 69 line++; 70 } else { 71 switch(line) { 72 case 0: break; 74 case 1: if (word==4) { ao.setSamples(Integer.parseInt(t)); 77 } 79 if (word==5) { 80 dat=t; } 82 if (word==6) { 83 tim=t; } 85 break; 87 case 2: if (word==2) { 89 ao.setFrequency(Integer.parseInt(t)); 90 } 91 break; 92 case 3: if (word==3) { 94 ao.setChannels(Integer.parseInt(t)); 95 } 96 break; 97 default: 98 break; 99 } 100 word++; 101 } 102 } 103 ao.setSamples(ao.getSamples()/ao.getChannels()); 105 TimeZone tz=TimeZone.getTimeZone("GMT"); 107 Calendar calendar = new GregorianCalendar (tz); 108 Calendar cl=DateSupport.parseDateRev(calendar,dat+" "+tim); 109 Date d = cl.getTime (); 110 long l = d.getTime (); 111 if ((cl.getTimeZone ()).inDaylightTime (d)) { 112 l += 60 * 60 * 1000; 113 } 114 ao.setTime((int)((l-DateSupport.getMilliOffset())/1000)); 116 len=(float)(ao.getSamples()/(1.0*ao.getFrequency())); 117 ao.setLength(len); 118 119 return ao; 120 } 121 122 public VideoObject cut(String name,int start,int stop,int len) { 123 int astart; 124 int sampstart,sampstop; 125 String ex; 126 127 astart=getTime()-(getSamples()/getFrequency()); 128 if (log.isDebugEnabled()) { 129 log.debug("VideoObject start "+astart+","+DateSupport.date2string(astart)); 130 log.debug("VideoObject cutting from "+DateSupport.date2string(start)+" to "+DateSupport.date2string(stop)); 131 } 132 if (astart>start) { 133 log.warn("VideoObject : start smaller than start of wav"); 134 sampstart=0; 135 } else { 136 sampstart=(start-astart)*getFrequency(); 137 } 138 if (stop>time) { 139 log.warn("VideoObject stop larger than end of wav"); 140 sampstop=getSamples(); 141 } else { 142 sampstop=(stop-astart)*getFrequency(); 143 } 144 if (log.isDebugEnabled()) { 145 log.debug("VideoObject about to cut "+sampstart+","+sampstop); 146 } 147 ex="/usr/local/bin/CopyVideo -l "+sampstart+":"+sampstop+" "+getFilename()+" -F WAVE "+name; 148 if (log.isDebugEnabled()) { 149 log.debug("VideoObject cut exec "+ex); 150 } 151 String s=exec.execute(ex); 152 log.info("VideoObject Exec result "+s); 153 return getInfo(name); 154 } 155 156 public String getFilename() { 157 return filename; 158 } 159 160 public void setFilename(String s) { 161 filename=s; 162 } 163 164 public int getSamples() { 165 return samples; 166 } 167 168 public void setSamples(int s) { 169 samples=s; 170 } 171 172 public int getChannels() { 173 return channels; 174 } 175 176 public void setChannels(int s) { 177 channels=s; 178 } 179 180 public int getFrequency() { 181 return frequency; 182 } 183 184 public void setFrequency(int s) { 185 frequency=s; 186 } 187 188 public int getTime() { 189 return time; 190 } 191 192 public void setTime(int s) { 193 time=s; 194 } 195 196 public void setLength(float l) { 197 length=l; 198 } 199 200 public float getLength() { 201 return length; 202 } 203 204 public String toString() { 205 return "VideoObject w="+filename+",s="+samples+",c="+channels+",f="+frequency+",t="+time+"=="+DateSupport.date2string(time)+",l="+getLength(); 206 } 207 208 public static void main(String args[]) { 209 VideoObject ao; 210 211 ao=VideoObject.getInfo(args[0]); 212 log.info(ao); 213 } 214 } 215 | Popular Tags |