Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Wenn Sie ein Video an die Video Intelligence API übergeben, können Sie dazu entweder einen Cloud Storage-URI verwenden oder Videodaten direkt in das Feld content der Anfrage einbetten. Diese muss Base64-codiert sein.
Befehlszeile verwenden
Innerhalb einer gRPC-Anfrage können Sie die Binärdaten einfach direkt ausschreiben. Bei einer REST-Anfrage müssen Sie jedoch JSON verwenden. JSON ist ein Textformat, das Binärdaten nicht direkt unterstützt, weshalb diese mit der base64-Codierung in Text umgewandelt werden müssen.
Die meisten Entwicklungsumgebungen enthalten ein natives base64-Dienstprogramm, um ein Binärbild als ASCII-Textdaten zu codieren. So codieren Sie eine Datei:
Linux
Codieren Sie die Datei mithilfe des base64-Befehlszeilentools und achten Sie darauf, Zeilenumbrüche mithilfe des Flags -w 0 zu verhindern:
base64 INPUT_FILE -w 0 > OUTPUT_FILE
macOS
Codieren Sie die Datei mit dem base64-Befehlszeilentool:
Binäre Daten mit Texteditoren in Anfragen einzubetten, ist weder wünschenswert noch praktisch. In der Praxis betten Sie base64-codierte Dateien in den Clientcode ein. Alle unterstützten Programmiersprachen haben integrierte Mechanismen für die base64-codierte Inhalte:
Python
So codieren Sie Videodateien mit Base64 in Python:
# Import the base64 encoding library.importbase64# Pass the video data to an encoding function.defencode_video(video):video_content=video.read()returnbase64.b64encode(video_content)
Node.js
So codieren Sie Videodateien mit Base64 unter Node.js:
// Read the file into memory.varfs=require('fs');varvideoFile=fs.readFileSync('/path/to/file');// Convert the video data to a Buffer and base64 encode it.varencoded=newBuffer(videoFile).toString('base64');
Java
In Java können Sie die Base64-Codierung von Bilddateien so durchführen:
// Import the Base64 encoding library.importorg.apache.commons.codec.binary.Base64;// Encode the video.byte[]videoData=Base64.encodeBase64(videoFile.getBytes());
[[["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: 2025-09-03 (UTC)."],[],[],null,["# Base64 Encoding\n\nWhen passing video to the Video Intelligence API, you can either pass a\nCloud Storage URI, or you can embed video data directly within the request's\n`content` field, which must be base64 encoded.\n\nUsing the command line\n----------------------\n\nWithin a gRPC request, you can simply write binary data out directly;\nhowever, JSON is used when making a REST request. JSON\nis a text format that does not directly support binary data, so you will need to\nconvert such binary data into text using\n[Base64](https://en.wikipedia.org/wiki/Base64) encoding.\n\nMost development environments contain a native `base64` utility to\nencode a binary into ASCII text data. To encode a file: \n\n### Linux\n\nEncode the file using the `base64` command line tool, making sure to\nprevent line-wrapping by using the `-w 0` flag: \n\n```\nbase64 INPUT_FILE -w 0 \u003e OUTPUT_FILE\n```\n\n### macOS\n\nEncode the file using the `base64` command line tool: \n\n```\nbase64 -i INPUT_FILE -o OUTPUT_FILE\n```\n\n### Windows\n\nEncode the file using the `Base64.exe` tool:\n\n\n```\ncertutil -encodehex SOURCE_VIDEO_FILE \u003e DEST_TEXT_FILE 0x40000001\n```\n\n\u003cbr /\u003e\n\n### PowerShell\n\nEncode the file using the `Convert.ToBase64String` method: \n\n```\n[Convert]::ToBase64String([IO.File]::ReadAllBytes(\"./INPUT_FILE\")) \u003e OUTPUT_FILE\n```\n\nCreate a JSON request file, inlining the base64-encoded data: \n\n### JSON\n\n\n```json\n{\n \"requests\":[\n {\n \"image\":{\n \"content\": \"ZkxhQwAAACIQABAAAAUJABtAA+gA8AB+W8FZndQvQAyjv...\"\n },\n \"features\": [\n {\n \"type\":\"LABEL_DETECTION\",\n \"maxResults\":1\n }\n ]\n }\n ]\n}\n```\n\n\u003cbr /\u003e\n\nUsing client libraries\n----------------------\n\nEmbedding binary data into requests through text editors is neither\ndesirable or practical. In practice, you will be embedding base64 encoded files\nwithin client code. All supported programming languages have built-in mechanisms\nfor base64 encoding content.\n\n\n### Python\n\nIn Python, base64 encode video files as follows: \n\n # Import the base64 encoding library.\n import base64\n\n # Pass the video data to an encoding function.\n def encode_video(video):\n video_content = video.read()\n return base64.b64encode(video_content)\n\n### Node.js\n\nIn Node.js, base64 encode video files as follows: \n\n // Read the file into memory.\n var fs = require('fs');\n var videoFile = fs.readFileSync('/path/to/file');\n\n // Convert the video data to a Buffer and base64 encode it.\n var encoded = new Buffer(videoFile).toString('base64');\n\n### Java\n\nIn Java, you can base64 encode image files as follows: \n\n // Import the Base64 encoding library.\n import org.apache.commons.codec.binary.Base64;\n\n // Encode the video.\n byte[] videoData = Base64.encodeBase64(videoFile.getBytes());\n\n\u003cbr /\u003e"]]