yann9
Posts: 3
Joined: Wed Jul 13, 2016 5:58 pm

VLCJ and Hardware acceleration

Wed Jul 13, 2016 6:41 pm

Hi guys. I hope you can help me, even if my english isn't excellent.

Soo... for last exam I have to write a program in Java to speed up or reduce speed video on RPi. Idea is, that when the video is playing, you can write a number in terminal, and if you write 2, the video start to play at double speed, if you write 0.5, the speed is reduce by 0.5.

I wrote a program in Eclipse using VLC program and VLCJ libraries on laptop and everything works OK, but when I moved the program on RPi, I realized, the biggest problem will be hardware acceleration.

So I bought official RPi codecs MPEG-2 and VC-1 and installed it, but nothing happened. Then I found out, that there has to be enabled GL driver in raspi-config menu. And now the problem started:

If i leave GL driver disabled:
-- if I start MPEG2 video using VLC program from accessories menu, the video starts play, but is playing very slow (every 5 sec one frame).
-- if I start MPEG2 video using my java program, the video starts play, but is also played very slow.

But when I enable GL driver:
-- when I start MPEG2 video using VLC program from accessories menu, the video works fine, running normally, as it should.
-- but when I start MPEG2 video using my java program, the VLCJ player window is shown for a second and then appears grey logon screen, saying to write username and password. If I write them in boxes and hit enter, my desktop is shown such the RPi is booted for the first time. And this is never ending story.

So the solution for smooth playing of video is GL driver enabled. But that logon screen is making me crazy.

Has anyone idea how to play video using hardware acceleration from my java program?

Thanks for your help.

Jan

User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: VLCJ and Hardware acceleration

Wed Jul 13, 2016 10:24 pm

If you get the login screen that very likely means that the X-server has crashed. The opengl driver is still very much "in development". What might be a better solution is to build a special version of VLC that takes advantage of the GPU in the Raspberry Pi without the unstable OpenGL driver for X.

viewtopic.php?f=66&t=59814&sid=af6d06ed ... 4f0c18be67

yann9
Posts: 3
Joined: Wed Jul 13, 2016 5:58 pm

Re: VLCJ and Hardware acceleration

Thu Jul 14, 2016 6:54 pm

Hi. Thanks for your reply. I will try it.

It is possible, that the X-server crashes only when using with my java program, but when playing video in VLC, everything works fine, without crashing?

Jan

yann9
Posts: 3
Joined: Wed Jul 13, 2016 5:58 pm

Re: VLCJ and Hardware acceleration

Mon Jul 25, 2016 7:42 am

Hi guys. I tried the solution that @topguy posted and VLC plays movie normally even with disabled GL driver. So this is OK.

But I have still problem with my Java media player. Movie played with "my" player is still freezing (playes a frame in 5 seconds).

Down is java code of my player. Has anyone idea, how to fix it, so the video will play smoothly?

Code: Select all


package player;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.discovery.NativeDiscovery;

public class Player {

    private final JFrame frame;
    private final EmbeddedMediaPlayerComponent mediaPlayerComponent;

    public static void main(final String[] args) {
        new NativeDiscovery().discover();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Player(args);
            }
        });
    }

    public Player(String[] args) {
        frame = new JFrame("My First Media Player");
        frame.setBounds(100, 100, 600, 400);
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                mediaPlayerComponent.release();
                System.exit(0);
            }
        });

        JPanel contentPane = new JPanel();
        contentPane.setLayout(new BorderLayout());

        mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
        contentPane.add(mediaPlayerComponent, BorderLayout.CENTER);

              
        Scanner in = new Scanner (System.in);
        
        
        pauseButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                mediaPlayerComponent.getMediaPlayer().pause();
            }
        });

        rewindButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                mediaPlayerComponent.getMediaPlayer().skip(-10000);
            }
        });

        skipButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                mediaPlayerComponent.getMediaPlayer().skip(1000);
            }
        });

        frame.setContentPane(contentPane);
        frame.setVisible(true);

        mediaPlayerComponent.getMediaPlayer().playMedia(//file URL);
        mediaPlayerComponent.getMediaPlayer().skip(1000);
        
        System.out.println("Insert number:");
        
        while (mediaPlayerComponent.getMediaPlayer().getTime() != mediaPlayerComponent.getMediaPlayer().getLength()) {
        	float i = in.nextFloat();
        	
        	mediaPlayerComponent.getMediaPlayer().setRate(i);
        }
    }
}


So, in my program I create a window for player and wait until user write a number in terminal, and than the movie is playing faster or slower, due to te inserted number.


Thanks for help.

Return to “Java”