Append a progress bar to a video or image sequence and show frame reordering

Alec Jacobson

December 19, 2013

weblog/

For a project we're reordering the frames of a video. Here's how to append a progress bar that visualizes where the frames are coming from in the original video.

Load in a video, here I use a video object:

video = VideoReader('rhinos.avi');

Let's define a vector of indices I to be a remapping of the video frames so that frame f of the new video will be frame I(f) of the original video. We'll use the original ordering

I = 1:video.NumberOfFrames;

or a random ordering:

I = randperm(video.NumberOfFrames);

Then append a progress bar and store the composite as an Height-by-Width-by-3-by-NumberOfFrames image sequence matrix S:

bar_w = video.Width;
bar_h = 20;
S = zeros(video.Height+bar_h,video.Width,3,video.NumberOfFrames);
for f = 1:video.NumberOfFrames
  S(1:video.Height,:,:,f) = read(video,f);
  col_If = round((I(f)-1)/(video.NumberOfFrames-1) * (bar_w-1)) + 1;
  col_f = round((f-1)/(video.NumberOfFrames-1) * (bar_w-1)) + 1;
  S(video.Height+(1:bar_h),1:col_f,:,f) = 0.2;
  S(video.Height+(1:bar_h),col_If,1,f) = 1;
end

Here's what the result looks like for the original ordering:

original rhino ordering with progress bar

And with the random ordering:

remapped rhino ordering with progress bar

Note: This assumes that the remapped video and the original video are the same length.