| 200 | } |
| 201 | |
| 202 | async function analyzeSafeSearch(gcsUri) { |
| 203 | // [START video_analyze_explicit_content] |
| 204 | // Imports the Google Cloud Video Intelligence library |
| 205 | const video = require('@google-cloud/video-intelligence').v1; |
| 206 | |
| 207 | // Creates a client |
| 208 | const client = new video.VideoIntelligenceServiceClient(); |
| 209 | |
| 210 | /** |
| 211 | * TODO(developer): Uncomment the following line before running the sample. |
| 212 | */ |
| 213 | // const gcsUri = 'GCS URI of video to analyze, e.g. gs://my-bucket/my-video.mp4'; |
| 214 | |
| 215 | const request = { |
| 216 | inputUri: gcsUri, |
| 217 | features: ['EXPLICIT_CONTENT_DETECTION'], |
| 218 | }; |
| 219 | |
| 220 | // Human-readable likelihoods |
| 221 | const likelihoods = [ |
| 222 | 'UNKNOWN', |
| 223 | 'VERY_UNLIKELY', |
| 224 | 'UNLIKELY', |
| 225 | 'POSSIBLE', |
| 226 | 'LIKELY', |
| 227 | 'VERY_LIKELY', |
| 228 | ]; |
| 229 | |
| 230 | // Detects unsafe content |
| 231 | const [operation] = await client.annotateVideo(request); |
| 232 | console.log('Waiting for operation to complete...'); |
| 233 | const [operationResult] = await operation.promise(); |
| 234 | // Gets unsafe content |
| 235 | const explicitContentResults = |
| 236 | operationResult.annotationResults[0].explicitAnnotation; |
| 237 | console.log('Explicit annotation results:'); |
| 238 | explicitContentResults.frames.forEach(result => { |
| 239 | if (result.timeOffset === undefined) { |
| 240 | result.timeOffset = {}; |
| 241 | } |
| 242 | if (result.timeOffset.seconds === undefined) { |
| 243 | result.timeOffset.seconds = 0; |
| 244 | } |
| 245 | if (result.timeOffset.nanos === undefined) { |
| 246 | result.timeOffset.nanos = 0; |
| 247 | } |
| 248 | console.log( |
| 249 | `\tTime: ${result.timeOffset.seconds}` + |
| 250 | `.${(result.timeOffset.nanos / 1e6).toFixed(0)}s` |
| 251 | ); |
| 252 | console.log( |
| 253 | `\t\tPornography likelihood: ${likelihoods[result.pornographyLikelihood]}` |
| 254 | ); |
| 255 | }); |
| 256 | // [END video_analyze_explicit_content] |
| 257 | } |
| 258 | |
| 259 | async function analyzeVideoTranscription(gcsUri) { |