Play multiple videos at once with MATLAB

I searched the internet and stack overflow, but could not find a solution or even useful hints to my problem.

I need to write specialized video software in MATLAB, which should simultaneously play several videos (at least 2) in a graphical interface. Video files are encoded in XVID format. So far, I basically just adjusted the mathworks.com example for playing videos (xylophon.avi, see Movie Description ()).

I am familiar with the functions mmreader, VideoReader, movie and implay, but still I ran into two problems:

  • Even if I read only a small number of frames (for example, in the xylophon.avi example), my program will soon exceed the available memory. In addition, reading takes a lot of time (at least 100).

  • The movie () function is synchronous, so the second video does not start until the completion of the first video. How can I call two movie () functions at the same time? Or is there another way to show two (or more) videos at the same time?

Any suggestions? Thanks!

+4
source share
3 answers

First of all, MATLAB is not multithreaded. Doing two things in parallel will be difficult. Try switching to Java. Matlab uses JIDE as a graphical interface that is built on Swing. Use MATLAB Builder JA to compile your MATLAB code in Java or add your own “panels” to the IDE, as shown in this question .

+2
source

You can display video in two different windows and simultaneously start playback by providing a video handle and calling up your undocumented playback function. This fixes any possible problem with unequal video lengths.

handle1 = implay('file1.mp4'); handle2 = implay('file2.mp4'); handle1.Parent.Position = [100 100 640 480]; handle2.Parent.Position = [740 100 640 480]; play(handle1.DataSource.Controls) play(handle2.DataSource.Controls) 
+1
source

In principle, you can display each video frame as an image and update each video one at a time, but it can be difficult to get it to play with exactly the same frame rate.

Try the following: It probably won’t work as it is, but you can update it.

 v1 = VideoReader(firstVideo) v2 = VideoReader(secondVideo) i1 = 0; i2 = 0; while i1 < v1.NumberOfFrames && i2 < v2.NumberOfFrames if i1 < v1.NumberOfFrames i1 = i1+1; subplot(1,2,1) image(v1.read(i1)) end if i2 < v2.NumberOfFrames i2 = i2+1; subplot(1,2,2) image(v2.read(i2)) end drawnow end 
0
source

All Articles