|
|
from google.cloud import videointelligence |
|
|
import io |
|
|
import os |
|
|
|
|
|
def analyze_video(video_path): |
|
|
|
|
|
client = videointelligence.VideoIntelligenceServiceClient() |
|
|
|
|
|
|
|
|
with io.open(video_path, "rb") as file: |
|
|
input_content = file.read() |
|
|
|
|
|
|
|
|
features = [videointelligence.Feature.LABEL_DETECTION, videointelligence.Feature.TEXT_DETECTION] |
|
|
|
|
|
|
|
|
operation = client.annotate_video(request={"features": features, "input_content": input_content}) |
|
|
|
|
|
print("\nProcessing video for label detection and text detection...") |
|
|
|
|
|
|
|
|
result = operation.result(timeout=600) |
|
|
|
|
|
|
|
|
print("\nLabel annotations:") |
|
|
for i, annotation in enumerate(result.annotation_results[0].segment_label_annotations): |
|
|
print(f"Label {i+1}: {annotation.entity.description}") |
|
|
for segment in annotation.segments: |
|
|
print(f"\tStart time: {segment.segment.start_time_offset.seconds} seconds") |
|
|
print(f"\tEnd time: {segment.segment.end_time_offset.seconds} seconds") |
|
|
|
|
|
|
|
|
print("\nText Detection:") |
|
|
for i, text_annotation in enumerate(result.annotation_results[0].text_annotations): |
|
|
print(f"Detected Text {i+1}: {text_annotation.text}") |
|
|
for segment in text_annotation.segments: |
|
|
start_time = segment.segment.start_time_offset.seconds + segment.segment.start_time_offset.microseconds / 1e6 |
|
|
end_time = segment.segment.end_time_offset.seconds + segment.segment.end_time_offset.microseconds / 1e6 |
|
|
print(f"\tAppears from {start_time:.2f} to {end_time:.2f} seconds") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '/home/vladp/Projects/meetingUnderstanding/meetingunderstandingproject-221fb498c363.json' |
|
|
|
|
|
video_path = "temp_video.mp4" |
|
|
analyze_video(video_path) |
|
|
|