MATLAB:合并目录中的所有视频

标签 matlab video concatenation avi

我有一些目录,每个目录都有几个短(约 10 秒).avi 视频。有谁知道如何将特定目录中的所有视频按字母顺序连接起来形成一个视频?

我会尝试使用 VLC,但我必须对一千多个不同的目录执行此操作。我没有意识到这会如此困难,但在 Google 上找不到任何东西。

更多细节: 对于我想要对其执行此操作的每个目录,所有视频都保证为: .aviMJPG20fps640x480 分辨率无音频长度小于 1 秒到 15 秒之间 我希望播放单个视频文件,就像我连续播放各个视频文件一样。 如果我遗漏了任何其他细节,请告诉我。

合并的视频旨在全部放入同一目录中,并提供给其他人使用 Matlab 执行他们自己的视频处理。他们将通过互相关或机器学习来尝试识别视频中的特定对象。

最佳答案

您可以结合使用 VideoReaderVideoWriter(有关更多示例,请参阅 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/

相关文章:

matlab - 处理过的图像中的伪影

闪光灯:提高相机的数据速率/质量

php - 如何连接PHP变量名?

python - 匹配元组中的字符串 - python

matlab - 将图形分别分组到窗口和选项卡中

matlab - 在Matlab上绘制正弦波的问题

image - 在 MATLAB 中绘制极 map 像

html - 在回退到 <Object> 中嵌入的 IE8 时调整 <Video> 的大小,视频被裁剪

video - 将 H.264 媒体文件转换为 mp4

C 在 while 循环中连接字符串