How can I create a video from a folder of images and add audio?

조회 수: 5 (최근 30일)
abcd efgh
abcd efgh 2018년 3월 11일
답변: Walter Roberson 2018년 3월 11일
I took each frame from a video in color and modified the images and saved them in a folder, but now I want to combine these images from my folder into a new video with the same framerate as the original video and add the sound back in. How can I do that? I was successfully able to write these images into a new video without sound using the below code:
v = VideoReader('sample.mp4'); % Read the original video
shuttleVideo=v;
info = get(v);
framerate = v.FrameRate;
%%image processing was done here
writerObj = VideoWriter('YourAVI.avi'); % new video
writerObj.FrameRate = framerate;
open(writerObj);
for K = 1 : i
filename = sprintf('a%04d.tif', K);
thisimage = imread(filename);
writeVideo(writerObj, thisimage);
end
close(writerObj);
However, how can I do this while keeping my audio? From looking at other codes online, it seems I'm supposed to use the vision.VideoFileWriter function instead so that I can write both video and audio into a file, but I'm confused on how this function works?

답변 (1개)

Walter Roberson
Walter Roberson 2018년 3월 11일
Use vision.VideoFileWriter() . When you use the step() method, you pass in the audio as the parameter after the video information.

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by