How to make number of frames equal of several videos having different length and having different number of frames?

2 ビュー (過去 30 日間)
I have several videos of different lengths. Correspondilgy, every video has got different number of frames. I want to make every video equal in terms of number of frames. For eg. I have five videos having 21, 28, 8, 104 and 62 frames respectively. I want to make number of frames 32 for every video. Is there any solution for this problem?
  4 件のコメント
NAVNEET NAYAN
NAVNEET NAYAN 2020 年 10 月 21 日
編集済み: NAVNEET NAYAN 2020 年 10 月 21 日
@Ameer Hamza... I want to keep the number of frames equal. Their duration may vary.
In case, I am not able to clear my problem, feel free to comment
NAVNEET NAYAN
NAVNEET NAYAN 2020 年 10 月 21 日
@KSSV... Ok I will read the interp1 and interpn.

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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 21 日
This shows how to write the video with fixed number of frames
num_frames = 32; % number of frames in out.mp4
TotalTime = 2; % out.mp4 will be 2 seconds
v = VideoReader('xylophone.mp4');
frames = read(v, [1 inf]);
frames = permute(frames, [4 1 2 3]);
frames_out = uint8(interp1(linspace(0,1,size(frames,1)), double(frames), linspace(0,1,num_frames)));
frames_out = permute(frames_out, [2 3 4 1]);
V = VideoWriter('out.mp4', 'MPEG-4');
V.FrameRate = 32/TotalTime;
open(V);
writeVideo(V, frames_out);
close(V);

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by