Hands-On Analysis of Long Videos and Very Large Audio Files: Fast Hosting and Semantic Search with the File API
How do you hand a multi-gigabyte video to a large model? This step-by-step guide shows the full workflow for using the official Files API to upload and host very large audio and video files, pinpoint video timestamps in seconds, and distill long content.
1. Never Embed Very Large Files as Base64
If a multimedia file larger than 20 MB is converted to a Base64 string and embedded in the request body, it will make the HTTP request body extremely bloated and may even trigger a gateway timeout.
The official Files API is provided for temporary cloud storage.
2. Hands-On: Upload and Analyze a Long Video
video_file = genai.upload_file(path="lecture_recording.mp4")
while video_file.state.name == "PROCESSING":
time.sleep(5)
video_file = genai.get_file(video_file.name)
response = model.generate_content([
"Please summarize the core points of the entire video presentation, and mark the corresponding video timestamps where key theories are introduced.",
video_file
])
print(response.text)
Using the powerful indexing capabilities of Google's cloud servers, a complex video several hours long can be thoroughly interpreted in tens of seconds.