5

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

I need to write a specialised video annotation software in MATLAB which has to be capable to play multiple videos (at least 2) simultaneously on a GUI. The video files are XVID-encoded. Up to now, I basically just adjusted the mathworks.com example for video playback (xylophon.avi, see movie() description).

I am familiar with the mmreader, VideoReader, movie and implay functions but still I am facing two issues:

  1. Even if I read in only a small number of frames (like in the xylophon.avi example), my progam soon exceeds available memory. Also, it takes quite long to read in even relatively few frames (say 100).

  2. The movie() function is sycnhronous, so the second video does not start until the first video completed. How can I call two movie()-functions concurrently? Or is there another way to show two (or more) videos simultaneously?

Any suggestions? Thanks!

Erich
  • 51
  • 1
  • 4

3 Answers3

2

First of all MATLAB is not multithreaded. Doing two things in parallel will be difficult. Try to breakout to Java. Matlab uses JIDE as their graphical front-end which is built on Swing. Use MATLAB Builder JA in order to compile your MATLAB code to Java, or add your own 'Panels' to the IDE as shown in this question.

Community
  • 1
  • 1
zellus
  • 9,617
  • 5
  • 39
  • 56
  • I was thinking about whether I can accomplish Multithreading with the Parallel Toolbox. However, I concluded to implement this Tool in another language. Thanks anyway! – Erich Oct 18 '11 at 14:03
1

You could display the videos in two different windows and start the playback simultaneously by giving the videos a handle and calling its undocumented play function. This removes any struggle you might have with videos of unequal length as well.

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)
ppr
  • 11
  • 1
0

In principle, you can display each video frame as an image and alternate updating each video, but getting it to play at exactly the right frame rate might be difficult.

Try something like the following. This probably won't work as-is, but you should be able to 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
Nzbuu
  • 5,241
  • 1
  • 29
  • 51