salut,
j'ai pri des photos avec ma webcam et j'essaye maintenant de créer une vidéo á partir de ces photos.
mon programme compte trois classes au total:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 import java.util.Vector; import javax.media.MediaLocator; import javax.media.Time; import javax.media.protocol.ContentDescriptor; import javax.media.protocol.PullBufferDataSource; import javax.media.protocol.PullBufferStream; public class ImageDataSource extends PullBufferDataSource{ ImageSourceStream streams[]; private Time DURATION_UNKNOWN; ImageDataSource(int width, int height, int frameRate, Vector images) { streams = new ImageSourceStream[1]; streams[0] = new ImageSourceStream(width, height, frameRate, images); } public void setLocator(MediaLocator source) {} public MediaLocator getLocator() { return null; } public String getContentType() { return ContentDescriptor.RAW; } public void connect() { } public void disconnect() { } public void start() { } public void stop() { } /** * Return the ImageSourceStreams. */ public PullBufferStream[] getStreams() { return streams; } /** * We could have derived the duration from the number of * frames and frame rate. But for the purpose of this program, * it's not necessary. */ public Time getDuration() { return DURATION_UNKNOWN; } public Object[] getControls() { return new Object[0]; } public Object getControl(String type) { return null; } }ces deux classes me permettent de créer un datasource
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 import java.awt.Dimension; import java.io.IOException; import java.io.RandomAccessFile; import java.util.Vector; import javax.media.Buffer; import javax.media.Format; import javax.media.format.VideoFormat; import javax.media.protocol.ContentDescriptor; import javax.media.protocol.PullBufferStream; public class ImageSourceStream implements PullBufferStream { Vector images; int width, height; VideoFormat format; int nextImage = 0; // index of the next image to be read. boolean ended = false; public ImageSourceStream(int width, int height, int frameRate, Vector images) { this.width = width; this.height = height; this.images = images; format = new VideoFormat(VideoFormat.JPEG, new Dimension(width, height), Format.NOT_SPECIFIED, Format.byteArray, (float) frameRate); } /** * We should never need to block assuming data are read from files. */ public boolean willReadBlock() { return false; } /** * This is called from the Processor to read a frame worth of video data. */ public void read(Buffer buf) throws IOException { // Check if we've finished all the frames. if (nextImage >= images.size()) { // We are done. Set EndOfMedia. System.err.println("Done reading all images."); buf.setEOM(true); buf.setOffset(0); buf.setLength(0); ended = true; return; } String imageFile = (String) images.elementAt(nextImage); nextImage++; System.err.println(" - reading image file: " + imageFile); // Open a random access file for the next image. RandomAccessFile raFile; raFile = new RandomAccessFile(imageFile, "r"); byte data[] = null; // Check the input buffer type & size. if (buf.getData() instanceof byte[]) data = (byte[]) buf.getData(); // Check to see the given buffer is big enough for the frame. if (data == null || data.length < raFile.length()) { data = new byte[(int) raFile.length()]; buf.setData(data); } // Read the entire JPEG image from the file. raFile.readFully(data, 0, (int) raFile.length()); System.err.println(" read " + raFile.length() + " bytes."); buf.setOffset(0); buf.setLength((int) raFile.length()); buf.setFormat(format); buf.setFlags(buf.getFlags() | Buffer.FLAG_KEY_FRAME); // Close the random access file. raFile.close(); } /** * Return the format of each video frame. That will be JPEG. */ public Format getFormat() { return format; } public ContentDescriptor getContentDescriptor() { return new ContentDescriptor(ContentDescriptor.RAW); } public long getContentLength() { return 0; } public boolean endOfStream() { return ended; } public Object[] getControls() { return new Object[0]; } public Object getControl(String type) { return null; } }
et enfin ma classe JpegMoviesquand j'exécute un message d'erreur apparait sur la console:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 import java.io.File; import java.util.*; import javax.media.DataSink; import javax.media.Manager; import javax.media.MediaLocator; import javax.media.Processor; import javax.media.format.VideoFormat; import javax.media.protocol.*; public class JpegMovies { public static void main(String []args)throws Exception{ Vector images = new Vector(); // for(int i=0;i<Integer.parseInt(args[2]);++i) images.addElement("c:\\test1.jpg"); images.addElement("c:\\test2.jpg"); images.addElement("c:\\test3.jpg"); images.addElement("c:\\test4.jpg"); images.addElement("c:\\test5.jpg"); ImageDataSource ids = new ImageDataSource(320,240,6,images); Processor processor = Manager.createProcessor(ids); processor.configure(); while(processor.getState() != Processor.Configured) Thread.sleep(10); processor.setContentDescriptor(new FileTypeDescriptor(FileTypeDescriptor.QUICKTIME)); VideoFormat vfmt = new VideoFormat(VideoFormat.CINEPAK); (processor.getTrackControls())[0].setFormat(vfmt); processor.realize(); while(processor.getState() != Processor.Realized) Thread.sleep(10); DataSource procOutput = processor.getDataOutput(); MediaLocator dest = new MediaLocator(new File("C//Bilder").toURL()); DataSink dsink = Manager.createDataSink(procOutput, dest); dsink.open(); processor.start(); dsink.start(); while(processor.getState() != Processor.Started) Thread.sleep(10); while (processor.getState() ==Processor.Started) Thread.sleep(10); processor.close(); dsink.close(); System.exit(0); } }
java.lang.NullPointerException
Exception in thread "main" javax.media.NoProcessorException: Error instantiating class: com.sun.media.processor.unknown.Handler : java.lang.NullPointerException
at javax.media.Manager.createProcessorForSource(Manager.java:1755)
at javax.media.Manager.createProcessor(Manager.java:666)
at JpegMovies.main(JpegMovies.java:26)
il m'indique que l'erreu est sur la ligne suivante:
Processor processor = Manager.createProcessor(ids);
quelqu'un peut il m'aider svp
merci d'avance
Partager