randomly picking a fram from a video in matlab

1 次查看(过去 30 天)
my problem is that i want to randomly pick a frame from a video , using mmreader , and also i am getting the last frame of the video so that i can set limit, so that when using rand function the number can be picked from 1 to the last frame number,the code is;
readerobj = mmreader(myvideoname);
last_Frame_number = read(readerobj, inf);
end_frame=readerobj.NumberOfFrames;
random_frame=randi([1,end_frame]);
can someone tell a better solution because this take alot of time because every video has a varying size , and i want to make it more efficient.
  3 个评论
KT
KT 2012-4-25
and longer the video size more time it takes as it needs to fetch the last frame number

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2012-4-25
For videos that are not variable-frame-rate, the NumberOfFrames property will be set when the object is created. If you are not getting a warning when you create the object (before you even do anything to it) then the NumberOfFrames will reflect the total number in the file.
  10 个评论
Walter Roberson
Walter Roberson 2012-4-26
Show your current code, and indicate which line it runs out of memory on.
KT
KT 2012-4-26
readerobj = mmreader('myvideo.mpg');
last_Frame = read(readerobj, inf);
last_Frame_number=readerobj.NumberOfFrames;
frame_rand=randi([1,last_Frame_number]);
vidFrames = read(readerobj,frame_rand);
this is my code, it takes alot of time, and if i run on loop like for 5 times, it gives timeout error.

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by