זיהוי תוכן בוטה בסרטונים

זיהוי תוכן בוטה מזהה תוכן למבוגרים בלבד בסרטונים. תוכן למבוגרים בלבד בדרך כלל לא מתאים לאנשים מתחת לגיל 18, והוא כולל, בין היתר, עירום, פעילויות מיניות ופורנוגרפיה. המערכת מזהה תוכן כזה גם בסרטים מצוירים או באנימה.

התשובה כוללת ערך סבירות מקובץ, מ-VERY_UNLIKELY עד VERY_LIKELY.

כשהתכונה "זיהוי תוכן בוטה" בודקת סרטון, היא עושה את זה פריים אחרי פריים ומתייחסת רק לתוכן החזותי. רכיב האודיו של הסרטון לא משמש להערכת רמת התוכן הבוטה.

הדוגמה הבאה ממחישה איך לבצע ניתוח וידאו של תכונות Explicit Content Detection בקובץ שנמצא ב-Cloud Storage.

REST

שליחת בקשה להערת וידאו

כך שולחים בקשת POST ל-method‏ videos:annotate. בדוגמה הזו משתמשים ב-Google Cloud CLI כדי ליצור אסימון גישה. במדריך למתחילים של Video Intelligence API מוסבר איך מתקינים את ה-CLI של gcloud.

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫INPUT_URI: קטגוריה של Cloud Storage שמכילה את הקובץ שרוצים להוסיף לו הערות, כולל שם הקובץ. חייב להתחיל ב-gs://.
    לדוגמה: "inputUri": "gs://cloud-videointelligence-demo/assistant.mp4",
  • ‫PROJECT_NUMBER: המזהה המספרי של הפרויקט ב- Google Cloud

ה-method של ה-HTTP וכתובת ה-URL:

POST https://videointelligence.googleapis.com/v1/videos:annotate

תוכן בקשת JSON:

{
  "inputUri": "INPUT_URI",
  "features": ["EXPLICIT_CONTENT_DETECTION"]
}

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID"
}

אם התגובה מצליחה, ה-Video Intelligence API מחזיר את הערך name של הפעולה. למעלה מוצגת דוגמה לתגובה כזו, שבה:

  • ‫PROJECT_NUMBER: מספר הפרויקט.
  • ‫LOCATION_ID: האזור ב-Cloud שבו תתבצע ההערה. אזורי הענן הנתמכים הם: us-east1, us-west1, europe-west1, asia-east1. אם לא מציינים אזור, הוא נקבע לפי המיקום של קובץ הווידאו.
  • ‫OPERATION_ID: המזהה של הפעולה הממושכת שנוצרה בשביל הבקשה, שמופיע בתשובה כשמתחילים את הפעולה, לדוגמה 12345...

קבלת תוצאות של הערות

כדי לאחזר את תוצאת הפעולה, שולחים בקשת GET באמצעות שם הפעולה שהוחזר מהקריאה ל-videos:annotate, כמו בדוגמה הבאה.

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • ‫OPERATION_NAME: שם הפעולה שמוחזר על ידי Video Intelligence API. הפורמט של שם הפעולה הוא projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID
  • ‫PROJECT_NUMBER: המזהה המספרי של הפרויקט ב- Google Cloud

ה-method של ה-HTTP וכתובת ה-URL:

GET https://videointelligence.googleapis.com/v1/OPERATION_NAME

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoProgress",
    "annotationProgress": [
     {
      "inputUri": "/demomaker/gbikes_dinosaur.mp4",
      "progressPercent": 100,
      "startTime": "2020-03-26T00:16:35.112404Z",
      "updateTime": "2020-03-26T00:16:55.937889Z"
     }
    ]
   },
   "done": true,
   "response": {
    "@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoResponse",
    "annotationResults": [
     {
      "inputUri": "/demomaker/gbikes_dinosaur.mp4",
      "explicitAnnotation": {
       "frames": [
        {
         "timeOffset": "0.056149s",
         "pornographyLikelihood": "VERY_UNLIKELY"
        },
        {
         "timeOffset": "1.166841s",
         "pornographyLikelihood": "VERY_UNLIKELY"
        },
            ...
        {
         "timeOffset": "41.678209s",
         "pornographyLikelihood": "VERY_UNLIKELY"
        },
        {
         "timeOffset": "42.596413s",
         "pornographyLikelihood": "VERY_UNLIKELY"
        }
       ]
      }
     }
    ]
   }
  }
ההערות של זיהוי השוטים מוחזרות כרשימה של shotAnnotations. הערה: השדה done מוחזר רק כשהערך שלו הוא True. הוא לא נכלל בתשובות לפעולות שלא הושלמו.

הורדת תוצאות ההערות

מעתיקים את ההערה מקטגוריית המקור לקטגוריית היעד: (ראו העתקת קבצים ואובייקטים)

gcloud storage cp gcs_uri gs://my-bucket

הערה: אם המשתמש מספק את ה-URI של הפלט ב-GCS, ההערה נשמרת ב-URI הזה.

Go


func explicitContentURI(w io.Writer, file string) error {
	ctx := context.Background()
	client, err := video.NewClient(ctx)
	if err != nil {
		return err
	}
	defer client.Close()

	op, err := client.AnnotateVideo(ctx, &videopb.AnnotateVideoRequest{
		Features: []videopb.Feature{
			videopb.Feature_EXPLICIT_CONTENT_DETECTION,
		},
		InputUri: file,
	})
	if err != nil {
		return err
	}
	resp, err := op.Wait(ctx)
	if err != nil {
		return err
	}

	// A single video was processed. Get the first result.
	result := resp.AnnotationResults[0].ExplicitAnnotation

	for _, frame := range result.Frames {
		offset, _ := ptypes.Duration(frame.TimeOffset)
		fmt.Fprintf(w, "%s - %s\n", offset, frame.PornographyLikelihood.String())
	}

	return nil
}

Java

כדי לבצע אימות ב-Video Intelligence, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

// Instantiate a com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient
try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
  // Create an operation that will contain the response when the operation completes.
  AnnotateVideoRequest request =
      AnnotateVideoRequest.newBuilder()
          .setInputUri(gcsUri)
          .addFeatures(Feature.EXPLICIT_CONTENT_DETECTION)
          .build();

  OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response =
      client.annotateVideoAsync(request);

  System.out.println("Waiting for operation to complete...");
  // Print detected annotations and their positions in the analyzed video.
  for (VideoAnnotationResults result : response.get().getAnnotationResultsList()) {
    for (ExplicitContentFrame frame : result.getExplicitAnnotation().getFramesList()) {
      double frameTime =
          frame.getTimeOffset().getSeconds() + frame.getTimeOffset().getNanos() / 1e9;
      System.out.printf("Location: %.3fs\n", frameTime);
      System.out.println("Adult: " + frame.getPornographyLikelihood());
    }
  }

Node.js

כדי לבצע אימות ב-Video Intelligence, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

// Imports the Google Cloud Video Intelligence library
const video = require('@google-cloud/video-intelligence').v1;

// Creates a client
const client = new video.VideoIntelligenceServiceClient();

/**
 * TODO(developer): Uncomment the following line before running the sample.
 */
// const gcsUri = 'GCS URI of video to analyze, e.g. gs://my-bucket/my-video.mp4';

const request = {
  inputUri: gcsUri,
  features: ['EXPLICIT_CONTENT_DETECTION'],
};

// Human-readable likelihoods
const likelihoods = [
  'UNKNOWN',
  'VERY_UNLIKELY',
  'UNLIKELY',
  'POSSIBLE',
  'LIKELY',
  'VERY_LIKELY',
];

// Detects unsafe content
const [operation] = await client.annotateVideo(request);
console.log('Waiting for operation to complete...');
const [operationResult] = await operation.promise();
// Gets unsafe content
const explicitContentResults =
  operationResult.annotationResults[0].explicitAnnotation;
console.log('Explicit annotation results:');
explicitContentResults.frames.forEach(result => {
  if (result.timeOffset === undefined) {
    result.timeOffset = {};
  }
  if (result.timeOffset.seconds === undefined) {
    result.timeOffset.seconds = 0;
  }
  if (result.timeOffset.nanos === undefined) {
    result.timeOffset.nanos = 0;
  }
  console.log(
    `\tTime: ${result.timeOffset.seconds}` +
      `.${(result.timeOffset.nanos / 1e6).toFixed(0)}s`
  );
  console.log(
    `\t\tPornography likelihood: ${likelihoods[result.pornographyLikelihood]}`
  );
});

Python

מידע נוסף על התקנה ושימוש בספריית הלקוח של Cloud Video Intelligence API ל-Python זמין במאמר ספריות הלקוח של Cloud Video Intelligence API.
"""Detects explicit content from the GCS path to a video."""
video_client = videointelligence.VideoIntelligenceServiceClient()
features = [videointelligence.Feature.EXPLICIT_CONTENT_DETECTION]

operation = video_client.annotate_video(
    request={"features": features, "input_uri": path}
)
print("\nProcessing video for explicit content annotations:")

result = operation.result(timeout=90)
print("\nFinished processing.")

# Retrieve first result because a single video was processed
for frame in result.annotation_results[0].explicit_annotation.frames:
    likelihood = videointelligence.Likelihood(frame.pornography_likelihood)
    frame_time = frame.time_offset.seconds + frame.time_offset.microseconds / 1e6
    print("Time: {}s".format(frame_time))
    print("\tpornography: {}".format(likelihood.name))

שפות נוספות

‫C#‎: פעלו לפי הוראות ההגדרה של C# ‎ בדף ספריות הלקוח, ואז עיינו ב מאמרי העזרה של Video Intelligence ל-‎ .NET.

‫PHP: פועלים לפי הוראות ההגדרה של PHP בדף ספריות הלקוח, ואז עוברים אל מאמרי העזרה של Video Intelligence ל-PHP.

‫Ruby: פועלים לפי הוראות ההגדרה של Ruby בדף ספריות הלקוח, ואז עוברים אל מאמרי העזרה של Video Intelligence ל-Ruby.