You are on page 1of 8

Construct an mmreader object for the example movie file xylophone.

mpg and view its


properties:
xyloObj = mmreader('xylophone.mpg', 'Tag', 'My reader object');
get(xyloObj)
Read and play back the movie file xylophone.mpg:
xyloObj = mmreader('xylophone.mpg');

nFrames = xyloObj.NumberOfFrames;
vidHeight = xyloObj.Height;
vidWidth = xyloObj.Width;

% Preallocate movie structure.


mov(1:nFrames) = ...
struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),...
'colormap', []);

% Read one frame at a time.


for k = 1 : nFrames
mov(k).cdata = read(xyloObj, k);
end

% Size a figure based on the video's width and height.


hf = figure;
set(hf, 'position', [150 150 vidWidth vidHeight])

% Play back the movie once at the video's frame rate.


movie(hf, mov, 1, xyloObj.FrameRate);

===================================================

xyloObj = mmreader('xylophone.mpg');
nFrames = xyloObj.NumberOfFrames;
vidHeight = xyloObj.Height;
vidWidth = xyloObj.Width;
%// Preallocate movie structure.
mov(1:nFrames) = struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),
...
'colormap', []);
%// Read one frame at a time.
for k = 1 : nFrames
mov(k).cdata = read(xyloObj, k);
end
%// Size a figure based on the video's width and height.
hf = figure;
set(hf, 'position', [150 150 vidWidth vidHeight])
%// Play back the movie once at the video's frame rate.
movie(hf, mov, 1, xyloObj.FrameRate);
==================================================
mmreader('C:\Users\Public\Videos\Sample Videos\Wildlife.wmv')

==========================================================
filename = 'god.avi';%video file encoded with DivX 5.0
avi_obj=mmreader(filename);
no_frame=get(avi_obj,'NumberOfFrames');
figure
for i=1:no_frame
img=read(avi_obj,i);
imshow(img),title(sprintf('Frame %d',i));

drawnow; pause(0.5);
end

==================================================
================================
filename = 'seq3.avi';
avi_obj=aviread(filename);
no_frame=size(avi_obj,2);
figure
for i=721:no_frame
img=avi_obj(i).cdata;
imshow(img),title(sprintf('Frame %d',i));
drawnow; pause(0.5);
end

==================================================
==================================
function [ frame ] = readFrames( vid )
readerobj = mmreader(vid);
vidFrames = read(readerobj);
numFrames = get(readerobj, numberOfFrames);
for k = 1 : numFrames
mov(k).cdata = vidFrames(:,:,:,k);
mov(k).colormap = [];
%imshow(mov(k).cdata);
imagename=strcat(int2str(k), .jpeg);
imwrite(mov(k).cdata, strcat(vasanth,imagename));
%extractComponents(mov(k).cdata);
end

Matlab is to be utilized for data extraction,data analysis and data processing,it is further
utilized for some statistical task to analyze the behavior of the system by plotting.it is
used to generate stimulus for verification of the system

MATLAB is a commercial software package written by The MathWorks, Inc. Quoting from
their web page: "Numeric computation,
technical graphics and visualization, and an intuitive programming language for
applications in engineering and science."
MATLAB is a complete environment for high-level programming, as well as interactive
data analysis. MATLAB excels at numerical
computations, especially when dealing with vectors or matrices of data. Symbolic math is
available through an add-on toolbox
that uses a Maple kernel.

How Does 2D To 3D Conversion Work?


When a movie gets converted from 2D to 3D it can spend months in post
production getting tweaked and redone in 3D for the theaters. As you can expect,
most comsumers aren't going to wait that long for their TV to convert 2D to 3D so
in a 3D TV this conversion must be done real time. How does a television convert
a 2D image into a 3D image? It's a very complex problem that we will attempt to
simplify in this article.
Generating 3D from a 2D image in real time requires more processing power
than it does to just display 2D or 3D directly from a source so more powerful

processing hardware is the first requirement for the conversion. Software then
analyzes the content's color and motion and even uses edges to define objects in
the picture. It can decide what parts of the image are in the background by
noticing how objects occlude, or cover, each other in the picture. In fact, the more
motion there is in a picture the easier it is for the software to determine what
objects on screen are in the foreground and which are in the background. The
more color or contrast difference there is between the foreground and the
background also helps the software to determine the depth of objects in the
picture.
After analyzing all of the above
information the software creates a
depth map of the picture and from
that creates two versions of the
frame with the 3D information
embedded into them, perspectives
of objects are slightly tweaked to
give the appearance that each eye is seeing the object from different angles
which creates the 3D effect. What is really amazing is that in the time it took you
read to this point a 3D TV would have completed this process about 1800 times
and rendered 3600 frames of 3D content.

How Does It Look?


Recently, we have reviewed 3D TVs with 2D to 3D conversion from almost every
manufacturer. It seems to be a requisite capability these days for any TV
manufacturer serious about producing 3D TVs. Though the technology is difficult
to accomplish, it shows. I havent seen any 2D to 3D conversion out there where I
thought, "Wow, that looks good." Not a single one. And the private displays in
which I have participated are showing the best possible presentation of the
technology. The 3D depth perception impact is greatly reduced and muted from
the normal active 3D picture presentation. The picture quality is somewhat grainy
normally with lots of picture artifacts. The active shutter glasses are always

required, based on what I have seen thus far. So I have to ask, what's the point
of having a subdued 3D effect? This is certainly not a feature upon which I will
critically evaluate which 3D TV to
purchase.

What 3D TVs
Have It?
Samsung currently has this
capability in all sizes of the C8000
and C7000 series plasmas and the
C9000, C8000 and C7000 series LED TVs. The C750 series of LCD televisions
also has 2D to 3D conversion. For 2011 the D9500, D7900, D8000, D7000 and
D6400 lines of LED TVs will have it as will the D8000 and D6500 plasmas. See
Samsung 3D TVs
Current Sony models featuring this technology are the LX900 and HX909 LED
backlit LCD TVs. In 2011 the HX929 and HX820 will feature this technology. See
Sony 3D TVs
LG, Toshiba, Panasonic and others will be featuring 2D to 3D converison on 2011
models but do not have it in any available models at press time.
[video, audio] = mmread(filename, frames, time, disableVideo, disableAudio, matlabCommand, trySeeking, useFFGRAB)

mmread reads virtually any media file. It now uses AVbin and FFmpeg to capture the data, this includes URLs. The code supports all major OSs and arc
Matlab runs on.
INPUT
filename input file to read (mpg, avi, wmv, asf, wav, mp3, gif, ...) frames specifies which video frames to capture, default [] for all or to specify time

time [startTime stopTime], default [] for all disableVideo disables ALL video capturing, to save memory or time disableAudio disables ALL audio capturing
or time

matlabCommand Do not return the video structure, but call the function specified by matlabCommand. The function definition must match that of proces
processFrame.m for more information.

trySeeking [true] setting this to false makes the code slower but more precise. If the first several frames are distorted or timing information isn't accurate

useFFGRAB [true] Use the new version of mmread, which uses ffmpeg. However, if an audio or video stream can't be read AND you are running Windo
false (old version).
OUTPUT

video is a struct with the following fields:


width width of the video frames
height height of the video frames
rate the frame rate of the video, if it can't be determined it will be 1.

nrFramesTotal the total number of frames in the movie regardless of how many were captured. Unfortunately, this can not always be determined. If it is

an estimate based upon the duration and rate (normally accurate to within .1%). It can be 0, in which case it could not be determined at all. If it is a poss
should always be accurate.
totalDuration the total length of the video in seconds.
frames a struct array with the following fields:
cdata [height X width X 3] uint8 matricies
colormap always empty
times the corresponding time stamps for the frames (in msec)
skippedFrames some codecs (not mmread) will skip duplicate frames (i.e. identical to the previous) in fixed frame rate movies to save space and time.
frames can be detected by looking for jumps in the "times" field. This field will be true when frames are skipped.
audio is a struct with the following fields:
nrChannels the number of channels in the audio stream (1 or 2)
rate sampling rate of the audio, ex. 44100. If it can't be determined then it will be 1.
bits bit depth of the samples (8 or 16)

data the real data of the whole audio stream. This can be played using wavplay. If time ranges are specified, the length of the data may not correspond

This normally happens with movies. The issue is that the start of the audio stream is generally counted at the END of the first frame. So, time is shifted b
nrFramesTotal Audio comes in packets or frames when captured, the division of the audio into frames may or may not make sense.
totalDuration the total length of the audio in seconds.
frames cell array of uint8s. Probably not of great use.
times the corresponding time stamps for the frames (in milliseconds)
If there is no video or audio stream the corresponding structure will be empty.

Specifying frames does not effect audio capturing. If you want only a subsection of the audio use the 3rd parameter "time". Specifying time effects both a

Time is specified in seconds (subsecond resolution is supported with fractional numbers ex. 1.125), starting at 0. Time is defined as startTime (inclusive)
(exclusive), or using set notation [startTime stopTime).
If there are multiple video or audio streams, then the structure will be of length > 1. For example: audio(1).data and audio(2).data.
EXAMPLES
[video, audio] = mmread('chimes.wav'); % read whole wav file
wavplay(audio.data,audio.rate);
video = mmread('mymovie.mpg'); % read whole movie
movie(video.frames);
video = mmread('mymovie.mpg',1:10); %get only the first 10 frames
video = mmread('mymovie.mpg',[],[0 3.5]); %read the first 3.5 seconds of the video
[video, audio] = mmread('chimes.wav',[],[0 0.25]); %read the first 0.25 seconds of the wav
[video, audio] = mmread('chimes.wav',[],[0.25 0.5]); %read 0.25 to 0.5 seconds of the wav, there is no overlap with the previous example.
read a movie directly from a URL
video = mmread('http://www.nature.com/neuro/journal/v9/n4/extref/nn1660-S8.avi');

video = mmread('mymovie.mpg',[],[],false,true); %read all frames, disable audio


mmread('mymovie.mpg',[],[],false,false,'processFrame'); %Use inline processing for all frames in a movie using the function processFrame.m

Acknowledgements

Mpgread inspired this file.

This file inspired Mmcount.M, Automated Phenotyping Of Mouse Behavior, Mmpl


and Motion Detection.

You might also like