All Products
Search
Document Center

Media fingerprinting

Last Updated: Jan 04, 2021

This topic provides examples on how to use the API operations of the media fingerprinting module. The API operations are encapsulated in ApsaraVideo VOD SDK for .NET. You can call the API operations to submit media fingerprinting jobs, query media fingerprinting jobs, and query media fingerprinting results.

Initialize a client

Before you can use the SDK, initialize a client. For more information, see Initialization.

Submit a media fingerprinting job

You can call the SubmitAIJob operation to submit a media fingerprinting job.

For more information about the request and response parameters of this operation, see SubmitAIJob. Example:

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.SubmitAIJob
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // Create a request.
                SubmitAIJobRequest request = new SubmitAIJobRequest();
                // Specify the video ID.
                request.MediaId = "3eb19a4585bc475e995bdd7894****";
                // Specify the AI type. Set the value to AIMediaDNA.
                request.Types = "AIMediaDNA";
                // Initialize a client.
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // Initiate the request and display the response.
                SubmitAIJobResponse response = client.GetAcsResponse(request);
                // List the request ID.
                Console.WriteLine("RequestId = " + response.RequestId);
                if (response.AIJobList ! = null && response.AIJobList.Count > 0) 
                {
                    foreach (var job in response.AIJobList) 
                    {
                        // The video ID.
                        Console.WriteLine("MediaId = " + job.MediaId);
                        // The job ID.
                        Console.WriteLine("JobId = " + job.JobId);
                        // The AI type.
                        Console.WriteLine("Type = " + job.Type);
                    }
                }
            }
            catch (ServerException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }
    }
}

Query media fingerprinting jobs

You can call the ListAIJob operation to query media fingerprinting jobs.

For more information about the request and response parameters of this operation, see ListAIJob. Example:

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.ListAIJob
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // Create a request.
                ListAIJobRequest request = new ListAIJobRequest();
                // Specify the video IDs.
                request.JobIds = "979d4d7a36ae41b1a945a258****,3eb19a4585bc475e995bddea58****";
                // Initialize a client.
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // Initiate the request and display the response.
                ListAIJobResponse response = client.GetAcsResponse(request);
                // List the request ID.
                Console.WriteLine("RequestId = " + response.RequestId);
                // List details about jobs.
                if (response.AIJobList ! = null && response.AIJobList.Count > 0)
                {
                    foreach (var job in response.AIJobList)
                    {
                        // The video ID.
                        Console.WriteLine("MediaId = " + job.MediaId);
                        // The job ID.
                        Console.WriteLine("JobId = " + job.JobId);
                        // The AI type.
                        Console.WriteLine("Type = " + job.Type);
                        // The job status.
                        Console.WriteLine("Status = " + job.Status);
                        // The job result.
                        Console.WriteLine("Data = " + job.Data);
                    }
                }
                // List the IDs of jobs that do not exist.
                if (response.NonExistAIJobIds ! = null && response.NonExistAIJobIds.Count > 0)
                {
                    foreach(jobId in response.NonExistAIJobIds) 
                    {
                        // The job ID.
                        Console.WriteLine("JobId = " + jobId);
                    }
                }
            }
            catch (ServerException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }
    }
}

Query media fingerprinting results

You can call the GetMediaDNAResult operation to query media fingerprinting results.

For more information about the request and response parameters of this operation, see GetMediaDNAResult. Example:

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace GetMediaDNAResult
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // Create a request.
                GetMediaDNAResultRequest request = new GetMediaDNAResultRequest();
                // Specify the video ID.
                request.MediaId = "3eb19a4585bc475e995bdd62eaee0****";
                // Initialize a client.
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // Initiate the request and display the response.
                GetMediaDNAResultResponse response = client.GetAcsResponse(request);
                // List the request ID.
                Console.WriteLine("RequestId = " + response.RequestId);
                if (response.DNAResult ! = null)
                {
                    // List media fingerprinting results.
                    Console.WriteLine("DNAResult = " + response.DNAResult.ToString());
                }
            }
            catch (ServerException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }
    }
}