Anmerkungen zu Videos an Speicher streamen
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Mit der Video Intelligence API können Sie einen Cloud Storage-Bucket angeben, der die Ergebnisse Ihrer Streaming Video-Annotation enthält.
Im folgenden Codebeispiel wird veranschaulicht, wie Sie Ihre Anfrage für Videoanmerkungen konfigurieren, damit das Ergebnis in Cloud Storage gespeichert wird.
importcom.google.api.gax.rpc.BidiStream;importcom.google.cloud.videointelligence.v1p3beta1.StreamingAnnotateVideoRequest;importcom.google.cloud.videointelligence.v1p3beta1.StreamingAnnotateVideoResponse;importcom.google.cloud.videointelligence.v1p3beta1.StreamingFeature;importcom.google.cloud.videointelligence.v1p3beta1.StreamingLabelDetectionConfig;importcom.google.cloud.videointelligence.v1p3beta1.StreamingStorageConfig;importcom.google.cloud.videointelligence.v1p3beta1.StreamingVideoConfig;importcom.google.cloud.videointelligence.v1p3beta1.StreamingVideoIntelligenceServiceClient;importcom.google.protobuf.ByteString;importio.grpc.StatusRuntimeException;importjava.io.IOException;importjava.nio.file.Files;importjava.nio.file.Path;importjava.nio.file.Paths;importjava.util.Arrays;importjava.util.concurrent.TimeoutException;publicclassStreamingAnnotationToStorage{// Perform streaming video detection for explicit contentstaticvoidstreamingAnnotationToStorage(StringfilePath,StringgcsUri)throwsIOException,TimeoutException,StatusRuntimeException{// String filePath = "path_to_your_video_file";// String gcsUri = "gs://BUCKET_ID";try(StreamingVideoIntelligenceServiceClientclient=StreamingVideoIntelligenceServiceClient.create()){Pathpath=Paths.get(filePath);byte[]data=Files.readAllBytes(path);// Set the chunk size to 5MB (recommended less than 10MB).intchunkSize=5*1024*1024;intnumChunks=(int)Math.ceil((double)data.length/chunkSize);StreamingStorageConfigstreamingStorageConfig=StreamingStorageConfig.newBuilder().setEnableStorageAnnotationResult(true).setAnnotationResultStorageDirectory(gcsUri).build();StreamingLabelDetectionConfiglabelConfig=StreamingLabelDetectionConfig.newBuilder().setStationaryCamera(false).build();StreamingVideoConfigstreamingVideoConfig=StreamingVideoConfig.newBuilder().setFeature(StreamingFeature.STREAMING_LABEL_DETECTION).setLabelDetectionConfig(labelConfig).setStorageConfig(streamingStorageConfig).build();BidiStream<StreamingAnnotateVideoRequest,StreamingAnnotateVideoResponse>call=client.streamingAnnotateVideoCallable().call();// The first request must **only** contain the audio configuration:call.send(StreamingAnnotateVideoRequest.newBuilder().setVideoConfig(streamingVideoConfig).build());// Subsequent requests must **only** contain the audio data.// Send the requests in chunksfor(inti=0;i < numChunks;i++){call.send(StreamingAnnotateVideoRequest.newBuilder().setInputContent(ByteString.copyFrom(Arrays.copyOfRange(data,i*chunkSize,i*chunkSize+chunkSize))).build());}// Tell the service you are done sending datacall.closeSend();for(StreamingAnnotateVideoResponseresponse:call){System.out.format("Storage Uri: %s\n",response.getAnnotationResultsUri());}}}}
/** * TODO(developer): Uncomment these variables before running the sample. */// const path = 'Local file to analyze, e.g. ./my-file.mp4';// const outputUri = 'Path to output, e.g. gs://path_to_output';const{StreamingVideoIntelligenceServiceClient}=require('@google-cloud/video-intelligence').v1p3beta1;constfs=require('fs');// Instantiates a clientconstclient=newStreamingVideoIntelligenceServiceClient();// Streaming configurationconstconfigRequest={videoConfig:{feature:'STREAMING_LABEL_DETECTION',storageConfig:{enableStorageAnnotationResult:true,annotationResultStorageDirectory:outputUri,},},};constreadStream=fs.createReadStream(path,{highWaterMark:5*1024*1024,//chunk size set to 5MB (recommended less than 10MB)encoding:'base64',});//Load file contentconstchunks=[];readStream.on('data',chunk=>{constrequest={inputContent:chunk.toString(),};chunks.push(request);}).on('close',()=>{// configRequest should be the first in the stream of requestsstream.write(configRequest);for(leti=0;i < chunks.length;i++){stream.write(chunks[i]);}stream.end();});conststream=client.streamingAnnotateVideo().on('data',response=>{//Gets annotations for videoconsole.log(`The annotation is stored at: ${response.annotationResultsUri} `);});
fromgoogle.cloudimportvideointelligence_v1p3beta1asvideointelligence# path = 'path_to_file'# output_uri = 'gs://path_to_output'client=videointelligence.StreamingVideoIntelligenceServiceClient()# Set streaming config specifying the output_uri.# The output_uri is the prefix of the actual output files.storage_config=videointelligence.StreamingStorageConfig(enable_storage_annotation_result=True,annotation_result_storage_directory=output_uri,)# Here we use label detection as an example.# All features support output to GCS.config=videointelligence.StreamingVideoConfig(feature=(videointelligence.StreamingFeature.STREAMING_LABEL_DETECTION),storage_config=storage_config,)# config_request should be the first in the stream of requests.config_request=videointelligence.StreamingAnnotateVideoRequest(video_config=config)# Set the chunk size to 5MB (recommended less than 10MB).chunk_size=5*1024*1024# Load file content.stream=[]withio.open(path,"rb")asvideo_file:whileTrue:data=video_file.read(chunk_size)ifnotdata:breakstream.append(data)defstream_generator():yieldconfig_requestforchunkinstream:yieldvideointelligence.StreamingAnnotateVideoRequest(input_content=chunk)requests=stream_generator()# streaming_annotate_video returns a generator.# The default timeout is about 300 seconds.# To process longer videos it should be set to# larger than the length (in seconds) of the stream.responses=client.streaming_annotate_video(requests,timeout=600)forresponseinresponses:# Check for errors.ifresponse.error.message:print(response.error.message)breakprint("Storage URI: {}".format(response.annotation_results_uri))
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2026-06-19 (UTC)."],[],[]]