A tool just for your playback needs – implay

Until now, we have demonstrated ways to display videos in MATLAB that are quite useful for adding processing steps in the loop, but are somewhat difficult in comparison to standard video-playing software. However, MATLAB also provides a tool aimed at those that do not want to get their hands dirty with frame-by-frame processing. Its name is implay and it has a pretty straightforward usage. It can be used in three different ways; as a standalone GUI-based video player, as a function that plays back a given image sequence stored in a matrix and as a function that loads and plays a video given its filename. Let's see how these work.

Using the GUI of implay

This is the most common way to use this tool. It is invoked by typing in its name:

>> implay

This opens the following window:

Using the GUI of implay

This GUI gives you the following choices:

  • To open up a new player (clicking on the first icon from the left)
  • Printing your frames (using the second icon from the left)
  • Opening a video file (using the third icon from the left)
  • Opening an image sequence from a matrix in the workspace (fourth icon)
  • Exporting the current frame to imtool for processing (fifth icon)
  • Inspecting information about the open video (sixth icon)
  • Inspecting pixel values by placing a crosshair cursor inside the frame, like we did in the imtool (seventh icon)
  • Zooming in/out (eighth/ninth icon)
  • Dragging image to pan (tenth icon)
  • Resizing the frame to fit the window (eleventh icon)
  • Resizing the frame to a given ratio (textbox at the top right corner)

When we load a video, a second toolbar opens up beneath the first one:

Using the GUI of implay

This second toolbar will probably look familiar to anyone that has used video players of any kind. Its functionalities are:

  • Go to first frame (first icon)
  • Jump 10 frames back (second icon)
  • Step back one frame (third icon)
  • Stop video (fourth icon)
  • Play video (fifth icon)
  • Step forward one frame (sixth icon)
  • Jump 10 frames forward (seventh icon)
  • Go to last frame (eighth icon)
  • Jump to a frame of your choice (ninth icon)
  • Repeat on/off (tenth icon)
  • Forward/backward playback (eleventh icon)

All these functionalities give the everyday users of MATLAB a handy tool to playback their videos. Let's see how they can be combined with what we have already shown.

Using implay to play a video file

Instead of clicking on the third icon of the GUI, we can call implay with the filename of the video we want to play as input:

>> implay('singleball.avi'),

We can also use a different frame rate:

>> implay('singleball.avi',20);

Using implay to play an image sequence

Combining it with a function such as imread and a loop that goes through all the filenames of images in a directory, we can also playback an image sequence such as the driving scene presented in an earlier example:

>> cd ('E:Videosseq'),       % Change working directory
>> contents = dir('*.jpeg'),   % Get names of jpeg images 
>> for i = 1:length(contents)  % Loop through all images
images(:,:,:,i) = imread(contents(i).name); % Import and save them
end
>> implay(images,15); % Play back the video sequence at 15 fps
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset