File size: 2,099 Bytes
599e594
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from google.cloud import videointelligence
import io
import os

def analyze_video(video_path):
    # Initialize the Video Intelligence client
    client = videointelligence.VideoIntelligenceServiceClient()

    # Open the video file
    with io.open(video_path, "rb") as file:
        input_content = file.read()

    # Configure the request (Label detection and Text detection)
    features = [videointelligence.Feature.LABEL_DETECTION, videointelligence.Feature.TEXT_DETECTION]
    
    # Make the request to the Video Intelligence API
    operation = client.annotate_video(request={"features": features, "input_content": input_content})
    
    print("\nProcessing video for label detection and text detection...")
    
    # Wait for the operation to complete
    result = operation.result(timeout=600)

    # Process the results
    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")

    # Text detection
    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'
    # Example usage (replace with your video file path)
    video_path = "temp_video.mp4"
    analyze_video(video_path)