How can I decrease the frame rate of a video?

85 ビュー (過去 30 日間)
Janely Medina
Janely Medina 2021 年 10 月 22 日
コメント済み: Janely Medina 2021 年 10 月 25 日
I'm displaying a video, but it's automatically speeding it up. The default frame rate is 30, How can I decrease the frame rate? If this is not possible, what are ways to go around it? I've tried slowing down the input video itself before loading it with no luck.
Here is the code:
%% Play a Video File
% Read video from a file and set up player object.
videoReader = VideoReader('testing.mov')
videoPlayer = vision.VideoPlayer('Name','Testing');
% Play video. Every iteration reads another frame.
while hasFrame(videoReader)
frame = readFrame(videoReader);
step(videoPlayer,frame);
end
% Close the video player.
release(videoPlayer);

採用された回答

Dave B
Dave B 2021 年 10 月 23 日
Each iteration is going as fast as MATLAB can, you can slow it down with pause:
videoReader = VideoReader('viplanedeparture.mp4');
videoPlayer = vision.VideoPlayer;
while hasFrame(videoReader)
frame = readFrame(videoReader);
step(videoPlayer,frame);
pause(0.1) % pause for 100ms between frames
end
Playing at a precise framerate is a little tricky. You could approximate 30fps by:
pause(1/30) % pause for 1/30th of a second, so 30fps
But that's not exact, because there's some time neaded for readFrame and step. It looked to me like on my computer those are pretty fast, but your mileage may vary. An idea to get a little bit closer (if it's important to you):
while hasFrame(videoReader)
tic
frame = readFrame(videoReader);
step(videoPlayer,frame);
pause(1/30 - toc)
end
  1 件のコメント
Janely Medina
Janely Medina 2021 年 10 月 25 日
The pause function worked perfectly. I paused for 50ms and it plays very closely to the actual speed of the video, TYSM!!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 10 月 23 日
You could write a new video with the same frames but specify a different frame rate property.
I'm attaching a demo of how to create a new movie from an existing one but I don't change the frame rate so you'd have to add that line of code.

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by