Frames to video conversion

3 Ansichten (letzte 30 Tage)
Lalit Patil
Lalit Patil am 5 Feb. 2013
Beantwortet: yanqi liu am 1 Feb. 2021
aviObject = avifile('Myvid1.avi')
for ctr = 441:500
iFrame = clock;
fname = ['IMG' num2str(ctr),'.PNG'];
I = imread(fname);
F = im2frame(I);
aviObject = addframe(aviObject,I);
elapsed = etime(clock, iFrame);
pause(5 - elapsed);
end
aviObject = close(aviObject);
This is my code to create video from frames.. It shows error..
??? Error using ==> im2frame
Indexed movie frame must have a non-empty colormap
Why..? My images are 600*800uint8 type..

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 5 Feb. 2013
[I, cmap] = imread(fname);
F = im2frame(I, cmap);
  3 Kommentare
Walter Roberson
Walter Roberson am 5 Feb. 2013
Before the loop:
cmap = gray(256);
Then in the loop,
I = imread(fname);
F = im2frame(I, cmap);
SETTE Houda
SETTE Houda am 5 Jan. 2021
@Lalit Patil how did you reserve this problem please ?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

yanqi liu
yanqi liu am 1 Feb. 2021
use video to images
function Video2Images(videoFilePath)
clc;
if nargin < 1
videoFilePath = 'traffic.avi';
end
nFrames = GetVideoImgList(videoFilePath);
function nFrames = GetVideoImgList(videoFilePath)
% 获取视频图像序列
% 输入参数:
% vidioFilePath——视频路径信息
% 输出参数:
% videoImgList——视频图像序列
xyloObj = VideoReader(videoFilePath);
nFrames = xyloObj.NumberOfFrames;
vidHeight = xyloObj.Height;
vidWidth = xyloObj.Width;
[pathstr, name, ext] = fileparts(videoFilePath);
video_imagesPath = fullfile(pwd, sprintf('%s_images', name));
if ~exist(video_imagesPath, 'dir')
mkdir(video_imagesPath);
end
files = dir(fullfile(video_imagesPath, '*.jpg'));
if length(files) == nFrames
return;
end
h = waitbar(0, '', 'Name', '获取视频图像序列...');
steps = nFrames;
for step = 1 : nFrames
temp = read(xyloObj, step);
temp_str = sprintf('%s\\%04d.jpg', video_imagesPath, step);
imwrite(temp, temp_str);
pause(0.01);
waitbar(step/steps, h, sprintf('已处理:%d%%', round(step/nFrames*100)));
end
close(h)
use images to video
function Images2Video(imgFilePath, filename_out)
if nargin < 2
imgFilePath = fullfile(pwd, 'traffic_images');
filename_out = fullfile(pwd, 'out.avi');
end
% 清理空间
clc;
% 起始帧
startnum = 1;
% 默认结束帧为jpg图像数目
endnum = size(ls(fullfile(imgFilePath, '*.jpg')), 1);
% 创建对象句柄
writerObj = VideoWriter(filename_out);
% 设置帧率
writerObj.FrameRate = 24;
% 开始打开
open(writerObj);
% 进度条
h = waitbar(0, '', 'Name', 'Write Video File...');
% 总帧数
steps = endnum - startnum;
for num = startnum : endnum
% 当前序号的名称
file = sprintf('%04d.jpg', num);
% 当前序号的位置
file = fullfile(imgFilePath, file);
% 读取
frame = imread(file);
% 转化为帧对象
frame = im2frame(frame);
% 写出
writeVideo(writerObj,frame);
% 刷新
pause(0.01);
% 进度
step = num - startnum;
% 显示进度条
waitbar(step/steps, h, sprintf('Process:%d%%', round(step/steps*100)));
end
% 关闭句柄
close(writerObj);
% 关闭进度条
close(h);

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by