【发布时间】:2019-09-20 23:39:50
【问题描述】:
我正在尝试读取视频文件并将帧存储为一系列图像。我正在使用 VideoReader,但由于某种原因我遇到了麻烦。我想存储两个以不同方式编码的视频的帧,并逐帧测量两者之间的结构相似性和 PSNR。
基本上我有三个视频文件,一个原始文件(读起来很好),一个使用 ffmpeg 用 VP9 压缩,一个使用 ffmpeg 用 H.624 压缩。原始视频最初只是使用 VirtualDub 将一组帧合并成一个 .avi 视频。压缩视频也是 .avi 容器。
VP9 视频看起来工作正常,但是当我使用 imshow() 打开图像时,它们似乎只是纯绿色。该视频在 VLC 上打开正常,所以我不确定问题是什么。
H.264 视频根本无法读取。当它尝试进入“while hasFrame()”循环时,它会跳过它,这会导致认为 Matlab 认为视频帧不存在?同样,该视频在 VLC 中打开良好,三个视频看起来几乎相同。
有人知道为什么会这样吗?是和matlab解码视频的方式还是ffmpeg设置的一些参数有关?
Console output for ffmpeg - VP9
Console output for ffmpeg - H264
主文件:
test_vid = 'vp9.avi';
images = readVideos(test_vid);
for i=1:length(images)
% Convert from cells to matrices
image1 = cell2mat(images(1,i));
image2 = cell2mat(images(2,i));
% Do stuff with the images here
subplot(1,2,1);
imshow(image1);
subplot(1,2,2);
imshow(image2);
end
ReadVideos():
function images = readVideos(test_video)
% Video directories
test_video_dir = strcat('src/', test_video);
v_original = VideoReader('src/input.avi');
v_test = VideoReader(test_video_dir);
% Read original video
i = 1;
v_original.CurrentTime = 5;
while hasFrame(v_original)
frame = readFrame(v_original);
originalImages{i} = frame;
i = i + 1;
end
% Read test video
i = 1;
v_test.CurrentTime = 5;
while hasFrame(v_test)
frame = readFrame(v_test);
testImages{i} = frame;
i = i + 1;
end
images = cat(1, originalImages, testImages);
end
顺便说一句,Matlab 是完成这项任务的最佳选择,还是有专门的软件可以做到这一点?
【问题讨论】:
标签: matlab image-processing ffmpeg video-processing codec