I use opencv to read a frame from a video file, edit it, then write it to a new video file. In this way I can process large videos without the need to have the whole video in memory.
Something like this for each frame of the video -
success, img = vidObj.read()
img = processImg(img)
vidWriter.write(img)
The problem is this doesn't save the audio. I tried using moviePy to add in the audio after but it is extremely slow since it has to make a whole new video.
def addAudio(audioSource, videoSource, savePath):
source_audio = AudioFileClip(audioSource)
target_video = VideoFileClip(videoSource)
target_video = target_video.set_audio(source_audio)
target_video.write_videofile(savePath, audio_codec='aac')
Is there a way to write the video frame by frame the way I can with opencv but include the audio too? Or just a way to edit the frames without having to have them all loaded into RAM?