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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| /**
*
*/
package media;
import java.io.IOException;
import javax.media.CannotRealizeException;
import javax.media.Format;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoPlayerException;
import javax.media.Processor;
import javax.media.control.TrackControl;
import javax.media.format.AudioFormat;
import javax.media.format.VideoFormat;
/**
* @author millie
*
*/
public class Main {
static boolean waitState(Processor processor, int state) {
boolean transition = false;
Object object = new Object();
synchronized (object) {
try {
while (processor.getState() != state)
object.wait(1000);
transition = true;
} catch (Exception e) {
}
}
return transition;
}
/**
* @param args
* @throws IOException
* @throws NoPlayerException
* @throws CannotRealizeException
*/
public static void main(String[] args) throws NoPlayerException,
IOException, CannotRealizeException {
MediaLocator mediaLocaltor = new MediaLocator(
"file://C:/tmp/workspace/Media/video/test_ecoles.avi");
Processor processor = Manager.createProcessor(mediaLocaltor);
processor.realize();
if (!waitState(processor, Processor.Realized)) {
System.err.println("Failed");
return;
}
double timeD = processor.getDuration().getSeconds();
System.out.println("Durée : " + (int) timeD);
System.out.println("Content descriptor : "
+ processor.getContentDescriptor().toString());
TrackControl[] tracks = processor.getTrackControls();
for (int i = 0; i < tracks.length; i++) {
Format format = tracks[i].getFormat();
System.out.println(format.toString());
if (format instanceof VideoFormat) {
VideoFormat videoFormat = (VideoFormat) format;
System.out.println("Video Format : ");
System.out
.println(" * Encoding : " + videoFormat.getEncoding());
System.out.println(" * Framerate : "
+ videoFormat.getFrameRate());
System.out.println(" * Max data lenght : "
+ videoFormat.getMaxDataLength());
System.out.println(" * Size largeur : : "
+ videoFormat.getSize().getWidth());
System.out.println(" * Size hauteur : : "
+ videoFormat.getSize().getHeight());
}
if (format instanceof AudioFormat) {
System.out.println("Audio Format : ");
AudioFormat audioFormat = (AudioFormat) format;
System.out
.println(" * Encoding : " + audioFormat.getEncoding());
System.out
.println(" * Channels : " + audioFormat.getChannels());
System.out.println(" * FrameSizeInBits : "
+ audioFormat.getFrameSizeInBits());
System.out.println(" * Endian : " + audioFormat.getEndian());
System.out.println(" * Signed : " + audioFormat.getSigned());
System.out.println(" * SampleRate Hz : "
+ audioFormat.getSampleRate());
System.out.println(" s* SampleSizeInBit : "
+ audioFormat.getSampleSizeInBits());
System.out.println(" * FrameRate : "
+ audioFormat.getFrameRate());
}
}
processor.deallocate();
processor.close();
System.out.println("Fini");
}
} |
Partager