Anonymní profil sleepy – Programujte.com
 x   TIP: Přetáhni ikonu na hlavní panel pro připnutí webu

Anonymní profil sleepy – Programujte.comAnonymní profil sleepy – Programujte.com

 

Příspěvky odeslané z IP adresy 158.195.217.–

Anonymní uživatel
Java › Pomoc s upravou kodu v jave…
26. 5. 2011   #142534

To liborb : Dobry den, no ono v podstate funguje vsetko ako ma, teda aspon zatial. Len ako ste si mohli vsimnut tak volam tri classy, kde vo dvoch z nich volam triedu PlayBin a do obi dvoch odosielam ten isty argument File. Tak by som chcel napr. namiesto troch classov vytvorit jeden a trocha to poupravovat nech to nie je take nepriehladne. Sice uz nieco mam ale stale to nie je ono.

sleepy
Java › Pomoc s upravou kodu v jave…
21. 5. 2011   #142356

Dobry den, mohli by ste mi pomoct s touto castou kodu:



class VideoPlayer{

private PlayBin player;
private Element videosink;
private Bus bus;

public VideoPlayer(final Canvas can){
Gst.init();

this.player = new PlayBin("Player",new File("/path/to/videofile.avi").toURI());
this.videosink = ElementFactory.make("xvimagesink", "dest");
this.player.setVideoSink(videosink);
this.bus = player.getBus();
//Sem este treba dopisat kod pre prehravanie v Canvase pod Win
bus.setSyncHandler(new BusSyncHandler() {
public BusSyncReply syncMessage(Message msg) {
Structure s = msg.getStructure();
if (s == null || !s.hasName("prepare-xwindow-id"))
return BusSyncReply.PASS;
XOverlay.wrap(videosink).setWindowID(can);
return BusSyncReply.DROP;
}
});
player.play();

}

}

class VideoFrameCatcher{

private BufferedImage currentImage = null;
private PlayBin2 player = null;
Semaphore sem;


public VideoFrameCatcher() {
Gst.init();
player = new PlayBin2("VideoFrameCatcher");

player.setAudioSink(null);
sem = new Semaphore(0);

RGBDataSink.Listener listener1 = new RGBDataSink.Listener() {
public void rgbFrame(int w, int h, IntBuffer rgbPixels) {

System.out.println(" -> Got a frame:");
currentImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_BGR);
currentImage.setRGB(0, 0, w, h, rgbPixels.array(), 0, w);
sem.release();


}
};

RGBDataSink videoSink = new RGBDataSink("rgb", listener1);
player.setVideoSink(videoSink);
}

public void setInputVideoFile(File inputVideoFile) {
player.setInputFile(inputVideoFile);
}

public BufferedImage CatchFrameAt(long time) throws InterruptedException{
player.pause();

player.getState();
player.seek(time, TimeUnit.MILLISECONDS);
player.play();
sem.acquire();
player.pause();
return this.currentImage;
}

}

class VideoController implements Runnable{
ImageStack imgS;
long step=60;
VideoFrameCatcher vidCatch;
private Thread vid;

public VideoController(ImageStack imgS){
this.vid = new Thread(this, "VideoThread");
this.imgS = imgS;
this.vid.start();
}

public VideoController(ImageStack imgS, long step){
this.vid = new Thread(this, "VideoThread");
this.imgS = imgS;
this.step = step;
this.vid.start();
}

public void run(){
this.vidCatch = new VideoFrameCatcher();
File videoFile = new File("/path/to/videofile.avi");
this.vidCatch.setInputVideoFile(videoFile);
int pos=0;
//Namiesto pos<12 tu bude nieco ako bin.EOS()
while(pos<12){
try {
imgS.putImageToArray(vidCatch.CatchFrameAt(pos*step), pos*step);
} catch (InterruptedException ex) {
Logger.getLogger(VideoController.class.getName()).log(Level.SEVERE, null, ex);
}
pos++;
}

}
}

Ako vidite moj kod je dost neohrabany. Potreboval by som ho zapisat trocha elegantnejsie. V tomto programe potrebujem aby mi bol schopny prehrat cele video v Canvase, co robi class VideoPlayer a aby mi dokazal zachytavat obrazky v urcitych casovych intervaloch toho isteho videa. Samozrejme nie sucasne s prehravanim videa, kazda cast bude cakat na Event ktory ju vyvola. Za Vase reakcie vopred dakujem.

 

 

Hostujeme u Českého hostingu       ISSN 1801-1586       ⇡ Nahoru Webtea.cz logo © 20032024 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý