Adding watermark to video

2019-07-14 04:13发布

I am able to use the moviepy library to add a watermark to a section of video. However when I do this it is taking the watermarked segment, and creating a new file with it. I am trying to figure out if it is possible to simply splice in the edited part back into the original video, as moviepy is EXTREMELY slow writing to the disk, so the smaller the segment the better.

I was thinking maybe using shutil?

video = mp.VideoFileClip("C:\\Users\\admin\\Desktop\\Test\\demovideo.mp4").subclip(10,20)

logo = (mp.ImageClip("C:\\Users\\admin\\Desktop\\Watermark\\watermarkpic.png")
          .set_duration(20)
          .resize(height=20) # if you need to resize...
          .margin(right=8, bottom=8, opacity=0) # (optional) logo-border padding
          .set_pos(("right","bottom")))

final = mp.CompositeVideoClip([video, logo])
final.write_videofile("C:\\Users\\admin\\Desktop\\output\\demovideo(watermarked).mp4", audio = True, progress_bar = False)

Is there a way to copy the 10 second watermarked snippet back into the original video file? Or is there another library that allows me to do this?

1条回答
Rolldiameter
2楼-- · 2019-07-14 05:10

What is slow in your use case is the fact that Moviepy needs to decode and reencode each frame of the movie. If you want speed, I believe there are ways to ask FFMPEG to copy video segments without rencoding.

So you could use ffmpeg to cut the video into 3 subclips (before.mp4/fragment.mp4/after.mp4), only process fragment.mp4, then reconcatenate all clips together with ffmpeg.

The cutting into 3 clips using ffmpeg can be done from moviepy:

https://github.com/Zulko/moviepy/blob/master/moviepy/video/io/ffmpeg_tools.py#L27

However for concatenating everything together you may need to call ffmpeg directly.

查看更多
登录 后发表回答