Changing canvas while Playing video

This forum is about all development around libVLC.
ronins
New Cone
New Cone
Posts: 9
Joined: 17 Nov 2010 12:43

Changing canvas while Playing video

Postby ronins » 18 Nov 2010 17:14

Well is there any way to change canvas while playing a video file?
i have panel1 with canvas1 and panel 2 with canvas2
When the video starts the videosurface points to canvas1.
Is there any way after a click in a button to point the output of the video in canvas 2?
One solution i found is when i want to change canvas is to take the mediaTime, stop the player , set the videosurface to canvas2, start the player and set the media time to the previous stopping position because when i stop the player and starting it again from the beggining.
Is there any easier solution??

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: Changing canvas while Playing video

Postby XilasZ » 18 Nov 2010 20:51

try to disable the video track, assign the surface to canvas2, and renable the video track, in theory this should work.

ronins
New Cone
New Cone
Posts: 9
Joined: 17 Nov 2010 12:43

Re: Changing canvas while Playing video

Postby ronins » 19 Nov 2010 12:13

That i try to do.
mediaPlayer.Stop() disables everything
How i disable only the video track??

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: Changing canvas while Playing video

Postby XilasZ » 19 Nov 2010 13:16

use libvlc_video_set_track and libvlc_video_get_track.

get_track will give you the track id, set_track(-1) will disable the video track, and then set_track(id) to renable it.

ronins
New Cone
New Cone
Posts: 9
Joined: 17 Nov 2010 12:43

Re: Changing canvas while Playing video

Postby ronins » 19 Nov 2010 14:50

If I do
int it=mediaPlayer.getVideoTrack();
mediaPlayer.setVideoTrack(-1);
Thread.sleep(2000);
mediaPlayer.setVideoTrack(it);

the result is
playing video & audio
when the video_track is -1
playing audio - Black image in canvas
after 2 secs
palying audio - still black image in canvas
All that without changing canvas,
So not working..

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: Changing canvas while Playing video

Postby XilasZ » 19 Nov 2010 19:26

Ah yes, i forgot, the getVideoTrack is buggy, it returns the index of the track (starting at 1) instead of the id, and -1 if it's disabled.

but setVideoTrack need the id of the track, which can be any number > 0.
So you need to use libvlc_video_get_track_description to get the track list with there id.

What wrapper are you using ?

I'll see if i can submit a patch, i already know how to fix it in vlc :mrgreen:

ronins
New Cone
New Cone
Posts: 9
Joined: 17 Nov 2010 12:43

Re: Changing canvas while Playing video

Postby ronins » 19 Nov 2010 20:16

Well i am making a java application for my university.
It's a Server-Client application for streaming audio-video.
I use vlcj and libvlc both to windows and linux
I want to make a stream application based on tcp but us i see vlcj support http,rtp.,rtcp
I don't want to use the mrl wrapper from vlc for streaming ex ( mediaPlayer.playMedia("xx.mpg", ":sout=#duplicate{dst=std{access=http,mux=ts,dst=127.0.0.1:5555}}"
The application works like this:
Server : Open socket
Client : connect to socket
SErver & client make input ouput streams
client: choose from list video or audio
Server sends the file in packets of 60kb
client takes the packets then it writes them to disk and vlcj open the written file mediaPlayer.play(file) which is grows up and plays the file while downloades it.(progressive streaming).The problem is that it plays only mpeg files .If it's another format it gives header missing error.logically us i cut the file to pieces..
The problem is that vlcj can;t play from buffer neither from stream but i plays from file or Mrl..
So i try now to find how vlcj uses the mrl to connect to server and how the server sends the mediaFile using mrl Any source code or doc?
I will try the libvlc_video_get_track_description and i will tell you if it is work..

ronins
New Cone
New Cone
Posts: 9
Joined: 17 Nov 2010 12:43

Re: Changing canvas while Playing video

Postby ronins » 19 Nov 2010 20:42

Not working
mediaPlayer.setVideoSurface(canvas1)
if i disable the video track i hear only sound,the video stop working
If i enable it after 2 secs it dispalys the video in the canvas 1 (nice)
So if i disable it and set the video surface to canvas 2 and enable the track again canvas1 & canvas 2 shows black image...
the only think that it work fine is with the mediaPlayer.stop() It clears the videoSurface and you can point it to new canvas but it restarts the media...

XilasZ
Developer
Developer
Posts: 189
Joined: 16 Jun 2009 20:35

Re: Changing canvas while Playing video

Postby XilasZ » 19 Nov 2010 22:35

I tweaked my program to test this.

- i added a new panel (a smaller one on top of the other one).
- the play button already did something like "setsurface(hwnd1); play()", i use the pause button to do the same on the second surface "setsurface(hwnd2); play()"
- i already have a way to deactivate or change the video track (using set_track)

press button play => set surface 1, and starts playing
press button pause => set surface 2, and play() again does nothing, as it's already playing (a quick look at vlc's source code confirms it does nothing)
disable video track => surface1 turns black
enable video track => surface1 stays black, and video appears on surface2
press button play => set surface 1, and play() again does nothing
disable/enable video track => video come back to surface1

So i was guessing without any test before, now i confirm it works exactly as i though, and audio never stopped, not even a small glitch :D

ronins
New Cone
New Cone
Posts: 9
Joined: 17 Nov 2010 12:43

Re: Changing canvas while Playing video

Postby ronins » 19 Nov 2010 23:03

Yeap it's working
I forgot the play() command.
It does all the working as it "registers" the new video surface ..
(videoSurface alone doesn't do anything).
Thks in advance..

Rémi Denis-Courmont
Developer
Developer
Posts: 15148
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Changing canvas while Playing video

Postby Rémi Denis-Courmont » 20 Nov 2010 09:14

There's no way to change canvas on the fly because this is:
  • completely useless,
  • inefficient, and
  • intricate to implement, sometimes even impossible.
Anyway. Any decent windowing system, including Win32 and X11, support reparenting a window without destroying it.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

sjd3078
New Cone
New Cone
Posts: 1
Joined: 05 Dec 2010 16:39

Re: Changing canvas while Playing video

Postby sjd3078 » 05 Dec 2010 16:53

ronins,

I am having a similar issue with VLCJ. I have a main JPanel window and a smaller JPanel window, each with a canvas and a player. I would like to hit a button and "swap" the canvases. The only thing that appears to work is stop(), setVideoSurface() on each of the players with the opposite Canvas, then play().

As you pointed out, it re-starts the video in both windows. Not what I need.

I attempted to capture the trackCount and set it, but I could not follow the post above. I alos tried to grab the getTime() and use setTIme() to "advance" the video playing back to where it was stopped but with little luck.

Can you possibly share the snippet or the pseudo code solution, just looking for the proper order of the API calls to do this correctly ?

For the others, I want to solve this with VLCJ( Java) API calls if possible. It's also possible the trunk of VLCJ could have added this feature, not sure.

Thanks

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: Changing canvas while Playing video

Postby sherington » 06 Dec 2010 14:02

For the others, I want to solve this with VLCJ( Java) API calls if possible. It's also possible the trunk of VLCJ could have added this feature, not sure.
There's nothing in the latest release of vlcj nor the trunk that can help you with this.

I did do some investigation to see if it could be supported in some way, but even the approach outlined in this thread had subtle problems - i.e. after you swap the video surface over it looked to me that you're left with the 'wrong' track/meta information on each player until you do a play().

The short version is this functionality is not in vlcj and I doubt it will be in the future either. It's not a common use-case so you'll have to try and do your own thing.

Rémi Denis-Courmont
Developer
Developer
Posts: 15148
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Changing canvas while Playing video

Postby Rémi Denis-Courmont » 07 Dec 2010 01:27

I still do not see the point anyway. All you need is to add an extra level of nested windows, and then swap the windows. LibVLC does not need to know about that.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

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: Changing canvas while Playing video

Postby sherington » 07 Dec 2010 09:32

I still do not see the point anyway. All you need is to add an extra level of nested windows, and then swap the windows. LibVLC does not need to know about that.
And neither do the Java bindings! :-D


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 3 guests