VLCJ - Auto snapshots

This forum is about all development around libVLC.
Logod
New Cone
New Cone
Posts: 9
Joined: 18 May 2010 08:55

VLCJ - Auto snapshots

Postby Logod » 04 Nov 2010 11:24

Hi,

I developed this software
http://sourceforge.net/projects/cover/

I use VLCJ for playing video and make automatically snapshots.
The snapshots are use to resume a video for example take snapshot every 20 seconds during all the video (like thumbnails).

Actually, I have a working code, but it is not satisfactory at all.
I have a problem, I can not know if VLC has move the video in the right position. I use « mediaPlayer.setTime(time) » to move the player to the right frame. After that I have to wait than VLC moves to the right position, but this time change with the type of video format, codec, size of the video.

There is the method « getTime() », but even if the video has not move to the right position, it send me the same position I put with setTime(time).

Another problem is the time the file takes to be written on the disk. I use the same trick and wait generally one second.

The only code I found about the snapshot is this one http://wiki.videolan.org/LibVLC_SampleCode_Thumbnailer

Thanks you for your help

This is a part of the concerning source code:

Code: Select all

/** * Make a all the snapShot from the time list */ private void makeAllSnapShot() { // "There is a race condition in native libraries when starting up, so // do not play immediately - empirically the most reliable way to avoid // a native library crash is to sleep for a bit. Not ideal, if you find // a better way let me know" // I play the media during 5 seconds to be sure it is corretly loaded // I put my treatement in pause long debut = System.currentTimeMillis(); long fin = debut + 5000; while (System.currentTimeMillis() < fin) { } // we put the player in pause mediaPlayer.pause(); updateIsPlaying(false); debut = System.currentTimeMillis(); fin = debut + 1000; while (System.currentTimeMillis() < fin) { } // we can make the list only when the video is load // its is a list of times (the player gos to each time and makes a snapshot makeTimeList(); for (int i = 0; i < timeList.size(); i++) { // We say to the player to go to the time store in the list Long currenttime = timeList.get(i); mediaPlayer.setTime(currenttime); // we need to wait for the internal update of the vlclib // waitMoveInt : this information is given by the user debut = System.currentTimeMillis(); fin = debut + waitMoveInt; while (System.currentTimeMillis() < fin) { } makeSnapShot(); // wait to be sure the file is finished to write on the disk // waitWriteInt : this information is given by the user debut = System.currentTimeMillis(); fin = debut + waitWriteInt; while (System.currentTimeMillis() < fin) { } } } /** * Make a SnapShot to the current frame The video need to be put in pause */ private void makeSnapShot() { if (isPlaying == false) { // code....... File filePathSnapshot = new File(stgPathSnapshot); mediaPlayer.saveSnapshot(filePathSnapshot); // code ..... } }

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: VLCJ - Auto snapshots

Postby sherington » 04 Nov 2010 21:11

Hi,
Unfortunately I can't help with your main problem, but why are you doing this busy looping everywhere?

Code: Select all

long debut = System.currentTimeMillis(); long fin = debut + 5000; while (System.currentTimeMillis() < fin) { }
When this is equivalent but behaves 'nicer':

Code: Select all

Thread.sleep(5000);

Logod
New Cone
New Cone
Posts: 9
Joined: 18 May 2010 08:55

Re: VLCJ - Auto snapshots

Postby Logod » 04 Nov 2010 23:56

Hi Sherington,

Thanks you very much for your answer.

I am not a programmer (I learn by myself) and when I made this part of the code I had not experience in thread. I will update my code (it will be clearest).

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: VLCJ - Auto snapshots

Postby sherington » 05 Nov 2010 17:17

I may have misunderstood you, but is your main problem that you do not know when vlc is "ready" at the correct time after you call setTime()?

I did some tests using setTime when the video was paused and it takes vlc a short moment, presumably while it's buffering/seeking, to display the video at the new time. I did not see any events firing to say what it was doing so I'm not sure what you can do about this to be honest.

Logod
New Cone
New Cone
Posts: 9
Joined: 18 May 2010 08:55

Re: VLCJ - Auto snapshots

Postby Logod » 05 Nov 2010 20:43

your main problem that you do not know when vlc is "ready" at the correct time after you call setTime()?
Yes, it is exactly that.
I did not see any events firing to say what it was doing so I'm not sure what you can do about this to be honest.
Ok, so there is no solution. Thanks you for having a look on it.

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: VLCJ - Auto snapshots

Postby sherington » 13 Nov 2010 08:51

I did not see any events firing to say what it was doing so I'm not sure what you can do about this to be honest.
The events do fire if the video is not paused.

I looked at the code sample you linked to and there's no reason you can't do the same type of thing using the Java bindings.

Logod
New Cone
New Cone
Posts: 9
Joined: 18 May 2010 08:55

Re: VLCJ - Auto snapshots

Postby Logod » 15 Nov 2010 12:55

The problem is that I put the video on pause to make the snapshot.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 16 guests