Skip to content
Related Articles

Related Articles

Improve Article

Reverse Video in Matlab

  • Last Updated : 08 Apr, 2019

MATLAB provides algorithms and tools to process, analyze and interact with videos.
VideoReader lets you import videos into MATLAB. This function supports formats such as AVI, MPEG as well as platform specific formats for Windows, MAC and Linux.

Video:
A video is a set of images known as frames. It contains four dimensions i.e. 1st dimension is for the rows, the 2nd one is for the columns, 3rd is for the RGB channel representation and the other dimension also gets added called time or frame number.

VideoReader:
Using a VideoReader object to read files containing video data. The object contains information about the video file and enables to read data from the video.

v = VideoReader(filename)

VideoWriter:
Using a VideoWriter object to create a video file. The object contains information about the video and the properties that control the output video. We can create a VideoWriter object using the VideoWriter function, specify its properties, and then write the video using object functions.

v = VideoWriter(filename)

Framerate:
Frame rate is defined as the number of frames per second or fps. It is the frequency (rate) at which consecutive images called frames to appear on a display.
To Reverse the video we reverse the frame rate.



Approach:

  • Load the video into a variable obj by using VideoReader.
  • Create new variable and read the video present in the object(here obj).
  • The rgb channels remains as it is.The frames are reversed and stored in new variable(here vid2).
  • Use a new variable obj2 to create a new copy of this video which is appearing in reverse mode by using
    VideoWriter()
  • open obj2.
  • Write all the reverse frames in obj2 using writeVideo()
  • Close obj2.

Below is the implementation:




% load the video. 
obj=VideoReader('flower.mp4');
  
% Contains the video present in obj 
vid=read(obj);
  
% rgb remains as it is
% frames are reversed 
vid2=vid(:, :, :, end:-1:1);
  
% Write in new variable 
obj2=VideoWriter('reverse.mp4');
  
open(obj2);
  
% write the frames in obj2.          
obj2.writeVideo(vid2);
  
close(obj2);

To get the link to input video, click here

OUTPUT:

My Personal Notes arrow_drop_up
Recommended Articles
Page :