Reputation: 103
I am trying to overlay an image on a base video. This is currently the code I have:
clip = VideoFileClip("base_video.mp4")
cat = (ImageClip("title.png")
.set_start(0) #which second to start displaying image
.set_duration(4) #how long to display image
.set_position(("center", "center")))
clip = CompositeVideoClip([clip, cat])
clip.write_videofile("asdf.avi",fps=24, codec='rawvideo')
I found this code on reddit and it seems to work but it converts the mp4 file to an avi file (I tried changing the ".avi" to ".mp4" and it doesn't work). Was wondering if there was another way to do so while keeping the mp4 file type.
Thank you so much in advance!
Upvotes: 0
Views: 8774
Reputation: 80
There are different codecs for different formats. You can find them here. If you don't set codec argument in write_videofile
method, it detects it automatically and uses the corresponding codec.
'libx264' (default codec for file extension .mp4) makes well-compressed videos (quality tunable using ‘bitrate’).
'mpeg4' (other codec for extension .mp4) can be an alternative to 'libx264', and produces higher quality videos by default.
'rawvideo' (use file extension .avi) will produce a video of perfect quality, of possibly very huge size.
png (use file extension .avi) will produce a video of perfect quality, of smaller size than with rawvideo.
'libvorbis' (use file extension .ogv) is a nice video format, which is completely free/ open source. However not everyone has the codecs installed by default on their machine.
'libvpx' (use file extension .webm) is tiny a video format well indicated for web videos (with HTML5). Open-source.
Upvotes: 1
Reputation: 103
nvm i figured it out
video = VideoFileClip("base_video.mp4")
title = ImageClip("title.png").set_start(3).set_duration(7).set_pos(("center","center"))
#.resize(height=50) # if you need to resize...
final = CompositeVideoClip([video, title])
final.write_videofile("test.mp4")
Upvotes: 8