Use list of dates to timestamp / label mp4 video in python

503 views Asked by At

I have an MP4 video file (Amundsen.mp4) that I created in Google Earth Engine - a timelapse, and a list of dates of each image (dates.txt) - not all consecutive days.

I want to use this list of dates to timestamp each frame in the video in python. Could someone please suggest how, or point me towards a tutorial that does this? I have not found resources on how to work with a video in this way.

1

There are 1 answers

0
Beardsley On BEST ANSWER

Thanks to the comments I succeeded. This was my successful code

from moviepy.editor import *
clip = VideoFileClip("myvideo.mp4")  

text_list = list3 # List of dates
clip_list = []

for text in text_list:
    try:
        txt_clip = TextClip(text, fontsize = 70, color = 'red').set_duration(1)
        clip_list.append(txt_clip)
    except UnicodeEncodeError: #Unsure if this part is necessary, took from elsewhere to address someone else's issue, but doesn't cause a problem
        txt_clip = TextClip("Issue with text", fontsize = 70, color = 'red').set_duration(1) 
        clip_list.append(txt_clip)
               
datevideo = concatenate(clip_list, method = "compose")
video2 = CompositeVideoClip([clip, datevideo])
#Write video
video2.write_videofile("videotest.mp4", fps = 1, codec = 'mpeg4')

# show video here embdeedded
#video2.ipython_display(width = 280)