Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kokeiro001/ecb65172a36d678f0231a1ee7ad23b25 to your computer and use it in GitHub Desktop.
Save kokeiro001/ecb65172a36d678f0231a1ee7ad23b25 to your computer and use it in GitHub Desktop.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Cloud.VideoIntelligence.V1Beta1" Version="1.0.0-alpha03" />
</ItemGroup>
</Project>
using System;
using System.Linq;
using System.Threading.Tasks;
using Google.Cloud.VideoIntelligence.V1Beta1;
namespace GoogleCloudVideoIntelligenceSandbox.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
MainAsync().GetAwaiter().GetResult();
}
static async Task AnalizeLablesAsync(string inputUri, string outputUri)
{
AnnotateVideoRequest request = new AnnotateVideoRequest()
{
Features = { Feature.LabelDetection },
InputUri = inputUri,
OutputUri = outputUri,
LocationId = @"asia-east1",
};
var videoClient = VideoIntelligenceServiceClient.Create();
var operation = await videoClient.AnnotateVideoAsync(request);
var resultOperation = await operation.PollUntilCompletedAsync();
var result = resultOperation.Result.AnnotationResults.First();
foreach (var label in result.LabelAnnotations)
{
Console.WriteLine($"Label description: {label.Description}");
Console.WriteLine($"Locations:");
foreach (var item in label.Locations.Select((location, index) => new { location = location, index = index }))
{
Console.WriteLine($"\t{item.index}: {item.location.Segment.StartTimeOffset} to {item.location.Segment.EndTimeOffset}");
}
}
}
static async Task MainAsync()
{
var inputVideoUri = $"gs://yourInputVideoFile.avi";
var outputResultJson = $"gs://yourOutputResultJson.json";
await AnalizeLablesAsync(inputVideoUri, outputResultJson);
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment