フィルターのクリア

How to save video from frame

5 ビュー (過去 30 日間)
Marco Rossi
Marco Rossi 2017 年 2 月 1 日
回答済み: T.Nikhil kumar 2024 年 4 月 8 日
Hi all, how can I save the video in this function? I want to save the video resized as another video (vid_resize.mp4).
vidobj = vision.VideoFileReader('video.mp4')
viewer = vision.DeployableVideoPlayer;
while (1)
A = step(vidobj);
viewframe = imresize(A,0.5);
step(viewer, viewframe);
end
release(vidobj);
release(viewer);

回答 (1 件)

T.Nikhil kumar
T.Nikhil kumar 2024 年 4 月 8 日
Hello Marco,
It appears that you want to save the resized frames of a video (video.mp4) into another video (vid_resize.mp4).
I would suggest you to use the ‘VideoWriter’ object in MATLAB. This object allows you to write video files. You can create a ‘VideoWriter’ object, specify the desired output file name, and then write each frame to it after resizing:
  1. Create a ‘VideoWriter’ object and specify the file name and format. Open the object for writing.
  2. Loop through the frames of existing video, resize them and write them to the new file. Close the object after writing.
Please refer to the modified code snippet below for your requirement:
vidobj = vision.VideoFileReader('video.mp4');
viewer = vision.DeployableVideoPlayer;
% Create a VideoWriter object to write the resized video
outputVideo = VideoWriter('vid_resize.mp4', 'MPEG-4');
open(outputVideo);
% Write a loop to resize and write video frames
while ~isDone(vidobj)
A = step(vidobj);
viewframe = imresize(A, 0.5);
step(viewer, viewframe);
writeVideo(outputVideo, viewframe); % Write the frame to the output video
end
release(vidobj);
release(viewer);
close(outputVideo); % Close the VideoWriter object
I also would like to point out that you can use a finite loop instead of infinite loop for the frames of the video. I have used ‘isDone’ function of ‘VideoFileReader’ object which denoted the end of the file. This ensures that the loop exits when all frames have been processed.
Refer to the following documentation for understanding more about the MATLAB objects and functions used above:
Hope this helps you with your work!

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by