ChatGPT Vision API – Video

parmarjatin4911@gmail.com - Jan 28 - - Dev Community

ChatGPT Vision API – Video

import openai
client = openai.OpenAI()
import cv2
import base64

video = cv2.VideoCapture("video.mp4")

base64Frames = []
while video.isOpened():
success, frame = video.read()
if not success:
break
_, buffer = cv2.imencode(".jpg", frame)
base64Frames.append(base64.b64encode(buffer).decode("utf-8"))

video.release()

response = client.chat.completions.create(
model="gpt-4-vision-preview",
messages=[{"role": "user", "content": [{"image": frame} for frame in base64Frames[0:5]]}]
)
print(response.choices[0].message.content)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player