Downsample and Upsample videos in matlab

I am working with videos in matlab and the code is taking so much time to give me results, that's why i thought downsampling and upsmaling the video could be the best solution, can anyone help me with that.

댓글 수: 1

Star Strider
Star Strider 2022년 7월 16일
What do you intend by ‘upsampling’ and ‘downsampling’?

댓글을 달려면 로그인하십시오.

답변 (2개)

KSSV
KSSV 2022년 7월 16일

0 개 추천

Read video frame by frame, and use imresize on each frame.

댓글 수: 10

Thanks for the answer but even with resizing the frame to this scale the process still takes so long.
imresize(im, [300 300])
KSSV
KSSV 2022년 7월 16일
What do you mean by so long quantitatively?
Ala baccar
Ala baccar 2022년 7월 16일
I mean when i tried to run my code on a one minute video it took almost a half an hour to give the result, which is too long.
KSSV
KSSV 2022년 7월 16일
Show us your code....
Ala baccar
Ala baccar 2022년 7월 16일
편집: Ala baccar 2022년 7월 16일
v1 = VideoReader('C:\Users\alaba\Desktop\skeleton\compressed.mp4');
set(gca,'xtick',[],'ytick',[])
set(gca,'LooseInset',get(gca,'TightInset'))
i1 = 0;
i2 = 0;
i3 = 0;
i4 = 0;
%matlab.video.read.UseHardwareAcceleration('on');
while i1 < v1.NumberOfFrames && i2 < v1.NumberOfFrames && i3< v1.NumberOfFrames && i4 < v1.NumberOfFrames
if i1 < v1.NumberOfFrames
i1 = i1+1;
im = v1.read(i1);
im = imresize(im, [300 300]);
im = imrotate(im,90);
iim1 = image(im,'XData',[0 0],'YData',[height1/2 - 300/2 height1/2 - 300/2]);
end
if i2 < v1.NumberOfFrames
i2 = i2+1;
im = v2.read(i2);
im = imresize(im, [300 300]);
iim2 = image(im,'XData',[width1/2-300/2 width1/2-300/2],'YData',[0 0]);
end
if i3 < v1.NumberOfFrames
i3 = i3+1;
im = v3.read(i1);
im = imresize(im, [300 300]);
im = imrotate(im,-90);
iim3 = image(im,'XData',[width1-300 width1-300],'YData',[height1/2 - 300/2 height1/2 - 300/2]);
end
if i4 < v1.NumberOfFrames
i4 = i4+1;
im = v4.read(i4);
im = imresize(im, [300 300]);
im = imrotate(im,180);
iim4 = image(im,'XData',[width1/2-300/2 width1/2-300/2],'YData',[height1 - 300 height1 - 300]);
end
%frame=im2frame(gcf);
frame=getframe(gcf);
writeVideo(writerObj,frame);
drawnow
end
close(writerObj)
Well this is the useful part
Image Analyst
Image Analyst 2022년 7월 16일
What are i1, i2, i3, and i4 for? Why are you doing something 4 times? Is there any difference?
And did you even try my code that I uploaded below for you? It uses imresize just like @KSSV but it's a full demo - you just have to change the name of the video and the desired output size of the frames. If you want me to just butt out, that's fine too.
Ala baccar
Ala baccar 2022년 7월 16일
Of course sir i tried your code but i am still stack with this error saying Error using movie_resize (line 44)
Cannot create file C:\Program Files\Polyspace\R2021a\bin\win64\NewRhinos.avi. Permission Denied. That's why i haven't given you my feedback yet
And for the code i am trying to generate a video from an original video given as input which have the following from
Image Analyst
Image Analyst 2022년 7월 16일
Windows does not let you create any files under "C:\Program Files". Choose another location.
Even when i changed the path out from "C:\Program Files" it gave me this eror Unable to find file. Ensure file exists and path is valid.
% Create a VideoWriter object to write the video out to a new, different file.
outputFullFileName = fullfile(pwd, 'C:\resize\NewRhinos.avi');
outputVideoWriterObject = VideoWriter(outputFullFileName);
When using VideoWriter, it creates a new file. So all you need to do is to make sure the folder exists:
You can't append c:\resize onto your current folder because then you'd have two drive letters and two colons in the filename. Just leave off the colon off
outputFullFileName = fullfile(pwd, 'C:\resize\NewRhinos.avi')
to see.
>> fullfile(pwd, 'C:\resize\NewRhinos.avi')
ans =
'C:\Users\alabaccar\Documents\MATLAB\work\Tests\C:\resize\NewRhinos.avi'
See - that's not a proper filename.
So do this:
% Create a VideoWriter object to write the video out to a new, different file.
outputFolder = 'C:\resize';
outputFullFileName = fullfile(outputFolder, 'NewRhinos.avi');
fprintf('Creating new output file : "%s".\n', outputFullFileName)
outputVideoWriterObject = VideoWriter(outputFullFileName);

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2022년 7월 16일

0 개 추천

I already have a demo for resizing a video. See attached.

댓글 수: 1

Image Analyst
Image Analyst 2022년 7월 16일
If you say that it takes too long, how long does it take and what is the maximum time you will allow? Perhaps you can use parfor and the Parallel Processing Toolbox, and a faster computer, to speed it up.

댓글을 달려면 로그인하십시오.

질문:

2022년 7월 16일

댓글:

2022년 7월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by