KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > module > builders > vwms > VideoObject


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.module.builders.vwms;
11
12 import java.util.Calendar JavaDoc;
13 import java.util.Date JavaDoc;
14 import java.util.GregorianCalendar JavaDoc;
15 import java.util.StringTokenizer JavaDoc;
16 import java.util.TimeZone JavaDoc;
17
18 import org.mmbase.util.*;
19
20 import org.mmbase.util.logging.Logger;
21 import org.mmbase.util.logging.Logging;
22
23 /**
24  * @javadoc
25  * @deprecated not used anywhere
26  * @author vpro
27  * @version $Id: VideoObject.java,v 1.8 2004/10/08 10:48:07 pierre Exp $
28  */

29 public class VideoObject {
30
31     private static Logger log = Logging.getLoggerInstance(VideoObject.class.getName());
32
33     Execute exec=new Execute();
34     private String JavaDoc filename;
35     private int samples;
36     private int channels;
37     private int frequency;
38     private int time; // Ending time
39
private float length;
40
41     public VideoObject() {
42     }
43
44     public static VideoObject get(String JavaDoc pool) {
45         return getInfo(pool+"/0.mov");
46     }
47
48     public static VideoObject getInfo(String JavaDoc filename) {
49         Execute sexec=new Execute();
50         String JavaDoc inf,t,dat="",tim="";
51         VideoObject ao=new VideoObject();
52         StringTokenizer JavaDoc 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 JavaDoc(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                 // skip
67
} else if (t.equals("\n")) {
68                 word=0;
69                 line++;
70             } else {
71                 switch(line) {
72                     case 0: // filetype and filename
73
break;
74                     case 1: // number of samples and date and time
75
if (word==4) { // should be number of samples
76
ao.setSamples(Integer.parseInt(t));
77                             // Note divide by channels is needed;
78
}
79                         if (word==5) {
80                             dat=t; // datum
81
}
82                         if (word==6) {
83                             tim=t; // time
84
}
85                         // we convert to time_t later
86
break;
87                     case 2: // sampling frequency
88
if (word==2) {
89                             ao.setFrequency(Integer.parseInt(t));
90                         }
91                         break;
92                     case 3: // number of channels and sample-size
93
if (word==3) {
94                             ao.setChannels(Integer.parseInt(t));
95                         }
96                         break;
97                     default:
98                         break;
99                 }
100                 word++;
101             }
102         }
103         // Info video reports *total* samples not per channel
104
ao.setSamples(ao.getSamples()/ao.getChannels());
105         // Decode the time (as usual)
106
TimeZone JavaDoc tz=TimeZone.getTimeZone("GMT");
107         Calendar JavaDoc calendar = new GregorianCalendar JavaDoc(tz);
108         Calendar JavaDoc cl=DateSupport.parseDateRev(calendar,dat+" "+tim);
109         Date JavaDoc d = cl.getTime ();
110         long l = d.getTime ();
111         if ((cl.getTimeZone ()).inDaylightTime (d)) {
112                 l += 60 * 60 * 1000;
113         }
114         // RICO timetrouble looks good as it uses GMT with MilliOffset
115
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 JavaDoc name,int start,int stop,int len) {
123         int astart;
124         int sampstart,sampstop;
125         String JavaDoc 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 JavaDoc s=exec.execute(ex);
152         log.info("VideoObject Exec result "+s);
153         return getInfo(name);
154     }
155
156     public String JavaDoc getFilename() {
157             return filename;
158     }
159
160     public void setFilename(String JavaDoc 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 JavaDoc 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 JavaDoc args[]) {
209             VideoObject ao;
210
211             ao=VideoObject.getInfo(args[0]);
212             log.info(ao);
213     }
214 }
215
Popular Tags