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

4 visualizzazioni (ultimi 30 giorni)
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?

Risposte (1)

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

Community Treasure Hunt

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

Start Hunting!

Translated by