映像と音声137(TimeLaps時間表示)

TimeLapsVideoに時間経過の字幕を作成するPythonのAPP

CMDで
py -m pip install opencv-python-headless pillow
の実行が必要

import cv2
import numpy as np
from PIL import Image, ImageDraw, ImageFont
from datetime import datetime, timedelta

# ビデオの設定
frame_width = 1920
frame_height = 1080
fps = 24
duration = 24  # 秒

fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_out = cv2.VideoWriter('output.mp4', fourcc, fps, (frame_width, frame_height))

# フォントとサイズの設定
font_size = 36
font = ImageFont.truetype("arial.ttf", font_size)

# 開始時刻を入力から受け取る
start_time_input = input("開始時刻 (HH:MM): ")
start_time = datetime.strptime(start_time_input, "%H:%M")
current_time = start_time

# メインのビデオ生成ループ
for _ in range(fps * duration):
    # フレームの生成
    frame = np.zeros((frame_height, frame_width, 3), dtype=np.uint8)
    
    # 時間の更新
    current_time += timedelta(seconds=1)
    
    # フレームに時間を描画
    frame_pil = Image.fromarray(frame)
    draw = ImageDraw.Draw(frame_pil)
    time_str = current_time.strftime("%H:%M:%S")
    draw.text((frame_width - 150, frame_height - 50), time_str, font=font, fill=(255, 255, 255))
    frame = np.array(frame_pil)
    
    # ビデオにフレームを追加
    video_out.write(frame)

# ビデオのクリーンアップ
video_out.release()
cv2.destroyAllWindows()





わかお かずまさ

VegaSystems


📷📷📷📷📷📷
#LAN_PRO
#Bloguru
#VegaSystems
#photograph
#kuma

People Who Wowed This Post

×
  • If you are a bloguru member, please login.
    Login
  • If you are not a bloguru member, you may request a free account here:
    Request Account
This user only allows bloguru members to make comments.
If you are a bloguru member, please login.
Login
If you are not a bloguru member, you may request a free account here:
Request Account