我有一些目录,每个目录都有几个短(约 10 秒).avi
视频。有谁知道如何将特定目录中的所有视频按字母顺序连接起来形成一个视频?
我会尝试使用 VLC,但我必须对一千多个不同的目录执行此操作。我没有意识到这会如此困难,但在 Google 上找不到任何东西。
更多细节:
对于我想要对其执行此操作的每个目录,所有视频都保证为:
.avi
、MJPG
、20fps
、640x480 分辨率
、无音频
、长度小于 1 秒到 15 秒之间
我希望播放单个视频文件,就像我连续播放各个视频文件一样。
如果我遗漏了任何其他细节,请告诉我。
合并的视频旨在全部放入同一目录中,并提供给其他人使用 Matlab 执行他们自己的视频处理。他们将通过互相关或机器学习来尝试识别视频中的特定对象。
最佳答案
您可以结合使用 VideoReader
和 VideoWriter
(有关更多示例,请参阅 doc)。按字母顺序迭代视频文件并将它们“流”到一个新文件中。
我拼凑了一些(未经测试的)代码。但我不知道这有多快:
cd(VIDEO_DIRECTORY);
tmp = dir('*.avi'); % all .avi video clips
videoList = {tmp.name}'; % sort this list if necessary! sort(videoList) might work
% create output in seperate folder (to avoid accidentally using it as input)
mkdir('output');
outputVideo = VideoWriter(fullfile(workingDir,'output/mergedVideo.avi'));
% if all clips are from the same source/have the same specifications
% just initialize with the settings of the first video in videoList
inputVideo_init = VideoReader(videoList{1}); % first video
outputVideo.FrameRate = inputVideo_init.FrameRate;
open(outputVideo) % >> open stream
% iterate over all videos you want to merge (e.g. in videoList)
for i = 1:length(videoList)
% select i-th clip (assumes they are in order in this list!)
inputVideo = VideoReader(videoList{i});
% -- stream your inputVideo into an outputVideo
while hasFrame(inputVideo)
writeVideo(outputVideo, readFrame(inputVideo));
end
end
close(outputVideo) % << close after having iterated through all videos
关于MATLAB:合并目录中的所有视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43301904/