필터 지우기
필터 지우기

how to merge 2 videos into 1 video without losing FPS?

조회 수: 11 (최근 30일)
muhammad choudhry
muhammad choudhry 2021년 8월 31일
답변: yanqi liu 2021년 9월 27일
Hi,
I have 2 x 10 mins videos, both with the 59.94 FPS. Since the videos holding the same experimental phenomena in 2 videos. I want to merge them two videos without losing any frame, (I achieve this by using the window 10 but losing my frame rate means losing data). I also have tried the code below but what this code is doing putting both videos side by side this is not what I am after. I am looking to merge 2 videos into 1. If anyone can help that be great!
Code:
close all; clear all; clc;
vid1 = VideoReader('test.avi');
vid2 = VideoReader('test1.avi');
videoPlayer = vision.VideoPlayer;
% new video
outputVideo = VideoWriter('finaltest.avi');
outputVideo.FrameRate = vid1.FrameRate;
open(outputVideo);
img1 = readFrame(vid1);
[rows1, columns1, numColors1] = size(img1);
img2 = readFrame(vid2);
[rows2, columns2, numColors2] = size(img1);
img2 = imresize(img2, [rows1, rows2]);
imgt = horzcat(img1, img2);
while hasFrame(vid1) && hasFrame(vid2)
img1 = readFrame(vid1);
[rows1, columns1, numColors1] = size(img1);
img2 = readFrame(vid2);
[rows2, columns2, numColors2] = size(img1);
img2 = imresize(img2, [rows1, rows2]);
imgt = horzcat(img1, img2);
% play video
step(videoPlayer, imgt);
% record new video
writeVideo(outputVideo, imgt);
end
release(videoPlayer);
close(outputVideo);

채택된 답변

yanqi liu
yanqi liu 2021년 9월 27일
sir, may be use the follows code to ref
clc
close all
clear all
vid1 = VideoReader('xylophone.mp4');
vid2 = VideoReader('traffic.avi');
% new video
outputVideo = VideoWriter('finaltest.avi');
outputVideo.FrameRate = vid1.FrameRate;
open(outputVideo);
sz1 = [vid1.Height vid1.Width];
sz2 = [vid2.Height vid2.Width];
while hasFrame(vid1)
img = readFrame(vid1);
writeVideo(outputVideo, img);
end
while hasFrame(vid2)
img = readFrame(vid2);
if ~isequal(sz1,sz2)
img=imresize(img,sz1,'bilinear');
end
writeVideo(outputVideo, img);
end
close(outputVideo);
% display new video
vidObj = VideoReader('finaltest.avi');
while(hasFrame(vidObj))
frame = readFrame(vidObj);
imshow(frame);
title(sprintf('Current Time = %.3f sec', vidObj.CurrentTime));
pause(2/vidObj.FrameRate);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by