Make video from images
古いコメントを表示
Hello !
I have about 500 pics and i'd like to make a video with. Also, i have a vector with the time each image should appear. (Img10 at tome(10))
Is it possible ?
Thank you so much, Loic.
2 件のコメント
Matthew Eicholtz
2016 年 4 月 27 日
Yes, this should be possible. Is the frame rate constant?
Riva
2025 年 4 月 2 日
Eu também tenho interesse nesse algoritmo.. A taxa pode ser constante sim.
採用された回答
その他の回答 (5 件)
Matthew Eicholtz
2016 年 4 月 27 日
Here is some basic code structure to get you started:
video = VideoWriter('yourvideo.avi'); %create the video object
open(video); %open the file for writing
for ii=1:N %where N is the number of images
I = imread('the ith image.jpg'); %read the next image
writeVideo(video,I); %write the image to file
end
close(video); %close the file
Now, this assumes constant frame rate (which can be set using the video.FrameRate property). I am not aware of any built-in functionality for handling variable frame rate. But, in theory, you could hack it by repeating image frames.
For example, if your frame rate is 1 frame per second, and the time vector is something like:
t = [0 2 3 7 ...]; %times for the 1st image, 2nd image, and so forth
Then, you will want to call 'writeVideo(video,I)' 2 times for image 1, 1 time for image 2, 4 times for image 3, etc. This will be challenging if your times are not multiples of your frame rate, so watch out for that.
6 件のコメント
Shafi Ullah
2020 年 1 月 5 日
I need a code for making video from image. The following code is not working...
Image Analyst
2020 年 1 月 5 日
Did you look at my latest comment. That code works. Why don't you try it?
Spandana M
2020 年 7 月 20 日
Your file is too big Image Analyst....I know maybe its very detailed and would be very efficient,but I have no time to through whole of it and undertstans and then apply T.T
Image Analyst
2020 年 7 月 24 日
madamebig, thanks, I've fixed the link, but I'm also attaching more video creating demos here.
Nidhish Jain
2021 年 3 月 4 日
@Matthew Eicholtz I followed your code and I got the avi file. But the video is all black. I don't know what is happening. I can see the images in the video but somehow they are all filtered to black. Please let me know if you know anything about this.
Image Analyst
2021 年 3 月 4 日
Try my code instead. If that still doesn't work, then start a new question and attach 5 of your images.
Pascal Stirtzel
2020 年 1 月 30 日
1 投票
Perfect, thank you very much
Vikas Arora
2022 年 9 月 11 日
編集済み: Image Analyst
2022 年 9 月 11 日
% If your image file starts with image_1.png, image_2.png and so on ...
% and live in the current folder.
folder = pwd; % Or wherever you want.
video = VideoWriter('yourvideo.avi'); % Create the video object.
open(video); % Open the file for writing
N=601; % Where N is the separate number of PNG image files.
for k = 1 : N
I = imread(fullfile(folder, sprintf('image_%g.png', k))); % Read the next image from disk.
writeVideo(video,I); % Write the image to file.
end
close(video);
3 件のコメント
atharva aalok
2022 年 9 月 15 日
The file appears but when I play it says:
"This item is in a format we don't support."
S Ch
2022 年 10 月 27 日
@atharva aalok Read it using Windows Media.
Image Analyst
2022 年 10 月 28 日
@atharva aalok try a different file extension, like .mp4 or .mpg or .wmv.
AMIT SURYAVANSHI
2024 年 1 月 15 日
0 投票
% Example data
imageFolder = 'path_to_your_images'; % Replace with the actual path to your image folder
imageFiles = dir(fullfile(imageFolder, '*.jpg')); % Change the extension based on your image format
numImages = length(imageFiles);
% Vector with time each image should appear (in seconds)
timeVector = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; % Adjust the timings as needed
% Create a VideoWriter object
outputVideo = VideoWriter('outputVideo.mp4', 'MPEG-4');
outputVideo.FrameRate = 1; % Adjust the frame rate as needed
open(outputVideo);
% Loop through each image and write it to the video
for i = 1:numImages
% Read the current image
currentImage = imread(fullfile(imageFolder, imageFiles(i).name));
% Write the current image to the video
writeVideo(outputVideo, currentImage);
% Pause for the specified time
pause(timeVector(i));
end
% Close the video file
close(outputVideo);
MathWorks Computer Vision Toolbox Team
2024 年 11 月 26 日
0 投票
Please consider the MATLAB example 'Convert Between Images Sequences and Video' as an answer to this question.
カテゴリ
ヘルプ センター および File Exchange で Video Formats and Interfaces についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





