Problem playing videos of different resolutions.VLCj Ubuntu

This forum is about all development around libVLC.
herculano
New Cone
New Cone
Posts: 6
Joined: 28 Feb 2014 15:22

Problem playing videos of different resolutions.VLCj Ubuntu

Postby herculano » 28 Feb 2014 15:54

I am using VLCj (java) 2.1.0 and am having trouble playing videos of different resolutions.

The first video to play using the entire area of the container, then play all videos with black bars top and bottom of the container.

If I take a stop in the player before playing the next video, the video container occupies the entire space.

Code: Select all

private EmbeddedMediaPlayer player; private MediaPlayerFactory factory; private Frame videoFrame; private Canvas videoSurfaceCanvas; private CanvasVideoSurface videoSurface; public VLC(Composite parent){ super(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND); setBackground(getDisplay().getSystemColor(SWT.COLOR_BLACK)); setBounds(getParent().getBounds()); } @Override public void init() { // argumentos padr�es do vlc String[] args = new String[] { "--no-video-title-show", "--no-xlib" }; // se existem argumentos passados para o java recupera // os mesmos e usa ao invez do valor padr�o if (((String[]) Session.get("args")).length > 0) args = (String[]) Session.get("args"); // cria um AWT Frame necess�rio para conter // o canvas usado como video surface videoFrame = SWT_AWT.new_Frame(this); videoFrame.setBackground(java.awt.Color.BLACK); // canvas usado como video surface videoSurfaceCanvas = new Canvas(); videoSurfaceCanvas.setSize(newSize().width, newSize().height); videoSurfaceCanvas.setBackground(java.awt.Color.BLACK); videoFrame.add(videoSurfaceCanvas); // instancia libvlc libvlc = LibVlcFactory.factory().create(); factory = new MediaPlayerFactory(libvlc, args); videoSurface = factory.newVideoSurface(videoSurfaceCanvas); // cria uma instancia unica do VLC player usando MediaPlayerFactory player = factory.newEmbeddedMediaPlayer(new DefaultFullScreenStrategy(videoFrame)); player.setVideoSurface(videoSurface); player.setPlaySubItems(true); player.setFullScreen(true); } @Override public void play(final MediaElement elem) { /** @TODO * Propriedade que armazena o caminho do vídeo. * Pode ser utilizada para gravar log de exibição * A hora da exibição pode ser capturada com G.timestamp() */ caminhoVideo = elem.path(); if(forceVideoAdjust) player.stop(); player.playMedia(caminhoVideo); }

Sorry, my bad.
Last edited by herculano on 28 Feb 2014 18:20, edited 1 time in total.

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: Problem playing videos of different resolutions.VLCj Ubu

Postby sherington » 28 Feb 2014 17:53

There's too much code here to review, do you have a *minimal* test case that demonstrates the problem?

herculano
New Cone
New Cone
Posts: 6
Joined: 28 Feb 2014 15:22

Re: Problem playing videos of different resolutions.VLCj Ubu

Postby herculano » 05 Mar 2014 22:30

I have a playlist with 2 videos.
  • Second video has resolution 848x480 and uses extension flv
  • First video has resolution 1280x720 and uses extension mp4.

The first video plays in full screen after that the others do not play occupying the entire videoSurfaceCanvas.
I set the background color of the videosurfacecanvas with red for better visualization.

Image

Image

Image

Any ideas ?:

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: Problem playing videos of different resolutions.VLCj Ubu

Postby sherington » 05 Mar 2014 23:32

The code you posted does this:

Code: Select all

videoSurfaceCanvas.setSize(newSize().width, newSize().height);
But you didn't show what newSize() does, or you removed it when you edited your post. You are using that method to size your Canvas, so the bug is likely in that method, or you are calling it at the wrong time.

There is a test video player application in the vlcj test sources that resizes the video surface correctly, did you look there to see how it's done and compare it with your own application?

herculano
New Cone
New Cone
Posts: 6
Joined: 28 Feb 2014 15:22

Re: Problem playing videos of different resolutions.VLCj Ubu

Postby herculano » 06 Mar 2014 14:11

The code still on the post.

Code: Select all

videoSurfaceCanvas.setSize(newSize().width, newSize().height);
Following the implementation of newSize method. My class extends org.eclipse.swt.widgets.Composite

Code: Select all

private java.awt.Rectangle newSize() { return G.toAwt(getBounds()); } public static java.awt.Rectangle toAwt(Rectangle rect) { // TODO Auto-generated method stub return new java.awt.Rectangle(rect.x, rect.y, rect.width, rect.height); }
Where i find the source code test ?

Sorry about that, but I was not that developed this application, and i don't know much about the VLCj.

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: Problem playing videos of different resolutions.VLCj Ubu

Postby sherington » 06 Mar 2014 18:02

I still don't quite understand what your issue is.

From the code you posted you appear to be setting your video surface size to match the size of some other component, not the size of the video itself, is that right?

Well, when your video is being rendered into the available video surface it will use as much space as possible while preserving the video aspect ratio. So if the available video surface size is larger than the actual video size you will inevitably get the black (or red in your case) bars at the top and bottom (or maybe even left and right).

Maybe you don't care about preserving the aspect ratio and instead want to fill the screen?

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: Problem playing videos of different resolutions.VLCj Ubu

Postby sherington » 06 Mar 2014 18:21

So I wrote a quick full-screen media player test that basically played the first five seconds of each file in a particular directory, the files having various different video dimensions...

As expected the video scales up to the screen resolution 1920x1200, preserving the aspect ratio of each video file individually, and I see red bars.

Now I add this after playing the video:

Code: Select all

mediaPlayer.setAspectRatio("16:10"); // 1920:1200 === 16:10
Now the screen is completely filled for each video and the red bars disappear, but the video is stretched a bit of course.

I do not need to stop the media player first (like your workaround does).

I don't see anything wrong.

So I think either you size your video surface Canvas to the same size as the video, or you set an appropriate aspect ratio.

herculano
New Cone
New Cone
Posts: 6
Joined: 28 Feb 2014 15:22

Re: Problem playing videos of different resolutions.VLCj Ubu

Postby herculano » 06 Mar 2014 20:28

I don't care about preserving the aspect ratio. I want the video occupying the entire container.

This application runs on different screen resolutions.

What I have to do to not show the red bars ?

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: Problem playing videos of different resolutions.VLCj Ubu

Postby sherington » 06 Mar 2014 22:44

I already told you one way in my previous post. Set the media player aspect ratio to that of your 'container'. That might work well enough for you if you have a full-screen application, but if you are going to allow your users to resize the window however they like then there's nothing you can do that I know of, short of limiting the window resizing to the correct aspect ratio. There is no magic switch that I know of that just says "fill this arbitrary size container with video".

herculano
New Cone
New Cone
Posts: 6
Joined: 28 Feb 2014 15:22

Re: Problem playing videos of different resolutions.VLCj Ubu

Postby herculano » 12 Mar 2014 19:51

I tried some ways to fix this issue. In one of cases i installed the Vlc 2.1.0 and fixed this issue.

See the images

Image

Image

Previously i had used the Vlc ( 2.0.8 ) the default repository of ubuntu 12:04 LTS.

My question is, if I can use vlc 2.1.0 on ubuntu 12:04 LTS even it not being on the official ubuntu repository ? What is the repository for vlc 2.1.0 in a ubuntu 12.04 LTS?


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 45 guests