简体   繁体   English

在 python 中使用日期列表来时间戳 / label mp4 视频

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

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.我有一个在 Google 地球引擎中创建的 MP4 视频文件 (Amundsen.mp4) - 延时摄影和每个图像的日期列表 (dates.txt) - 不是所有连续的日子。

I want to use this list of dates to timestamp each frame in the video in python.我想使用这个日期列表为 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.我还没有找到有关如何以这种方式处理视频的资源。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM