Camera display mosaic freezing images

*nix specific usage questions
fearchannel
New Cone
New Cone
Posts: 4
Joined: 29 Oct 2019 13:39

Camera display mosaic freezing images

Postby fearchannel » 29 Oct 2019 13:46

I'm making a mosaic for viewing videos. I build a JFrame with some components, including Canvas. I place an instance of a MediaPlayer on each Canvas and play the video. But I'm having problems with frame loss, delayed display and even complete freezing of images. Is there anything that can be done to solve this problem?

Code:

Code: Select all

public class ViewerController { private List<EmbeddedMediaPlayer> playerList = new ArrayList<>(); private List<Canvas> canvasList = new ArrayList<>(); public ViewerController() { gerarTela(); } private void gerarTela() { String[] args = { "--rtsp-tcp", "--network-caching=1000", "--file-caching=300", "--clock-jitter=0", "--clock-synchro=0" }; JFrame janela = geraJframe(); var painelDaJanela = new JPanel(new GridLayout(0, 4, 5, 5)); var factory = new MediaPlayerFactory(args); for (int i = 0; i < 16; i++) { var containerDoVideo = new Canvas(); containerDoVideo.setBackground(Color.BLACK); JPanel painelDoContainer = new JPanel(); painelDoContainer.setBackground(new Color(31, 27, 36)); painelDoContainer.setLayout(new BorderLayout()); painelDoContainer.add(containerDoVideo, BorderLayout.CENTER); var player = factory.newEmbeddedMediaPlayer(); player.setVideoSurface(factory.newVideoSurface(containerDoVideo)); playerList.add(player); painelDaJanela.add(painelDoContainer); canvasList.add(containerDoVideo); } painelDaJanela.setBackground(new Color(31, 27, 36)); janela.add(painelDaJanela, BorderLayout.CENTER); janela.setResizable(true); janela.setExtendedState(JFrame.MAXIMIZED_BOTH); janela.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent windowEvent) { stop(); super.windowClosing(windowEvent); } }); janela.setVisible(true); } public void play(List<Camera> lista) { int limiteLista = lista.size(); for (int i = 0; i < 16; i++) { if (!(i < limiteLista)) { canvasList.get(i).setBackground(new Color(31, 27, 36)); } else { Camera camera = lista.get(i); playerList.get(i).playMedia(camera.getUrl_video()); } } } private void stop() { playerList.forEach(MediaPlayer::stop); } private JFrame geraJframe() { Toolkit tk = Toolkit.getDefaultToolkit(); Dimension d = tk.getScreenSize(); JFrame jFrame = new JFrame(); jFrame.setMinimumSize(new Dimension(d.width, d.height)); jFrame.setLayout(new BorderLayout()); jFrame.setIconImage(tk.getImage(getClass().getResource("/imgs/icon.png"))); jFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); return jFrame; } }
You can see my post at StackOverflow with images:
[url]https://stackoverflow.com/questions/58486575/images-being-frozen-delayed-using-vlcj-and-java-swing?noredirect=1#comment103446432_58486575[/url]

unidan
Developer
Developer
Posts: 1494
Joined: 25 Mar 2018 01:00

Re: Camera display mosaic freezing images

Postby unidan » 29 Oct 2019 18:08

Hi,

What is the size of the video you're trying to play ? you should probably adapt the size server side to avoid downloading many HD video and displaying them as really small video.

Otherwise, you'll need to monitor the performance metrics on your system (GPU, CPU, network access) and maybe you'll need a local cache (meaning, latency) if it is really at the limit and you can't downgrade the video size. If you don't have enough network throughput and can't change the amount of data using this bandwidth, and it's live, no cache system can prevent that and you'll probably have to change the whole design of your application.

fearchannel
New Cone
New Cone
Posts: 4
Joined: 29 Oct 2019 13:39

Re: Camera display mosaic freezing images

Postby fearchannel » 29 Oct 2019 21:11

Hi Unidan, thanks for the answer.

The video I'm trying to play is an RTSP stream (I suppose you're not talking about the dimensions of the video). GPU and CPU do not leave 40% of processing. I currently have 100mb internet, and I consume a maximum of 20mb when I'm playing 16 cameras simultaneously.

unidan
Developer
Developer
Posts: 1494
Joined: 25 Mar 2018 01:00

Re: Camera display mosaic freezing images

Postby unidan » 30 Oct 2019 10:27

(I suppose you're not talking about the dimensions of the video
Actually yes, it gives some good rule of thumb for this kind of application !

fearchannel
New Cone
New Cone
Posts: 4
Joined: 29 Oct 2019 13:39

Re: Camera display mosaic freezing images

Postby fearchannel » 30 Oct 2019 20:57

The video size is varied, but I scale it on a gridpane to fit my screen. Can have up to 16 cameras to fit any resolution.

Honestly i'm running out of hope, i'm in this problem for weeks and that's what is left to finish the project ...


Return to “VLC media player for Linux and friends Troubleshooting”

Who is online

Users browsing this forum: No registered users and 44 guests