or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

features-config.mdindex.mdresults-data-types.mdstreaming-analysis.mdvideo-analysis.md

video-analysis.mddocs/

0

# Video Analysis

1

2

Core client functionality for analyzing videos with Google's AI capabilities. The Video Intelligence API provides both synchronous and asynchronous clients for processing videos with various machine learning features.

3

4

## Capabilities

5

6

### VideoIntelligenceServiceClient

7

8

Primary synchronous client for video analysis operations. All video analysis operations are long-running and return Operation objects that must be polled for completion.

9

10

```python { .api }

11

class VideoIntelligenceServiceClient:

12

"""

13

Synchronous client for Video Intelligence Service.

14

15

Service that implements the Video Intelligence API.

16

"""

17

18

def __init__(

19

self,

20

*,

21

credentials: Optional[ga_credentials.Credentials] = None,

22

transport: Optional[Union[str, VideoIntelligenceServiceTransport]] = None,

23

client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,

24

client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,

25

):

26

"""

27

Instantiate the video intelligence service client.

28

29

Parameters:

30

- credentials: The authorization credentials to attach to requests

31

- transport: The transport to use for communicating with the service

32

- client_options: Optional client options

33

- client_info: The client info used to send a user-agent string

34

"""

35

36

def annotate_video(

37

self,

38

request: Optional[Union[AnnotateVideoRequest, dict]] = None,

39

*,

40

input_uri: Optional[str] = None,

41

features: Optional[MutableSequence[Feature]] = None,

42

retry: OptionalRetry = gapic_v1.method.DEFAULT,

43

timeout: Union[float, object] = gapic_v1.method.DEFAULT,

44

metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),

45

) -> operation.Operation:

46

"""

47

Performs asynchronous video annotation. Progress and results can be

48

retrieved through the google.longrunning.Operations interface.

49

50

Parameters:

51

- request: The request object or dict

52

- input_uri: Input video location (Google Cloud Storage URI)

53

- features: Requested video annotation features

54

- retry: Designation of what errors, if any, should be retried

55

- timeout: The timeout for this request

56

- metadata: Strings which should be sent along with the request as metadata

57

58

Returns:

59

Operation object representing the long-running operation.

60

Operation.metadata contains AnnotateVideoProgress (progress).

61

Operation.response contains AnnotateVideoResponse (results).

62

"""

63

64

@classmethod

65

def from_service_account_file(

66

cls, filename: str, *args, **kwargs

67

) -> VideoIntelligenceServiceClient:

68

"""

69

Creates an instance of this client using the provided credentials file.

70

71

Parameters:

72

- filename: The path to the service account private key json file

73

74

Returns:

75

VideoIntelligenceServiceClient: The constructed client

76

"""

77

78

@classmethod

79

def from_service_account_info(

80

cls, info: dict, *args, **kwargs

81

) -> VideoIntelligenceServiceClient:

82

"""

83

Creates an instance of this client using the provided credentials info.

84

85

Parameters:

86

- info: The service account private key info in dict format

87

88

Returns:

89

VideoIntelligenceServiceClient: The constructed client

90

"""

91

92

@property

93

def transport(self) -> VideoIntelligenceServiceTransport:

94

"""Returns the transport used by the client instance."""

95

```

96

97

### VideoIntelligenceServiceAsyncClient

98

99

Asynchronous version of the video intelligence client for non-blocking operations. Provides the same functionality as the synchronous client but with async/await support.

100

101

```python { .api }

102

class VideoIntelligenceServiceAsyncClient:

103

"""

104

Asynchronous client for Video Intelligence Service.

105

106

Service that implements the Video Intelligence API.

107

"""

108

109

def __init__(

110

self,

111

*,

112

credentials: Optional[ga_credentials.Credentials] = None,

113

transport: Optional[Union[str, VideoIntelligenceServiceAsyncTransport]] = None,

114

client_options: Optional[client_options_lib.ClientOptions] = None,

115

client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,

116

):

117

"""

118

Instantiate the async video intelligence service client.

119

120

Parameters:

121

- credentials: The authorization credentials to attach to requests

122

- transport: The transport to use for communicating with the service

123

- client_options: Optional client options

124

- client_info: The client info used to send a user-agent string

125

"""

126

127

async def annotate_video(

128

self,

129

request: Optional[Union[AnnotateVideoRequest, dict]] = None,

130

*,

131

input_uri: Optional[str] = None,

132

features: Optional[MutableSequence[Feature]] = None,

133

retry: OptionalRetry = gapic_v1.method.DEFAULT,

134

timeout: Union[float, object] = gapic_v1.method.DEFAULT,

135

metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),

136

) -> operation_async.AsyncOperation:

137

"""

138

Performs asynchronous video annotation.

139

140

Parameters:

141

- request: The request object or dict

142

- input_uri: Input video location (Google Cloud Storage URI)

143

- features: Requested video annotation features

144

- retry: Designation of what errors, if any, should be retried

145

- timeout: The timeout for this request

146

- metadata: Strings which should be sent along with the request as metadata

147

148

Returns:

149

AsyncOperation object representing the long-running operation.

150

"""

151

152

@classmethod

153

def from_service_account_file(

154

cls, filename: str, *args, **kwargs

155

) -> VideoIntelligenceServiceAsyncClient:

156

"""

157

Creates an instance of this client using the provided credentials file.

158

159

Parameters:

160

- filename: The path to the service account private key json file

161

162

Returns:

163

VideoIntelligenceServiceAsyncClient: The constructed async client

164

"""

165

166

@classmethod

167

def from_service_account_info(

168

cls, info: dict, *args, **kwargs

169

) -> VideoIntelligenceServiceAsyncClient:

170

"""

171

Creates an instance of this client using the provided credentials info.

172

173

Parameters:

174

- info: The service account private key info in dict format

175

176

Returns:

177

VideoIntelligenceServiceAsyncClient: The constructed async client

178

"""

179

```

180

181

### Usage Examples

182

183

#### Basic Video Analysis

184

185

```python

186

from google.cloud import videointelligence

187

188

# Create client

189

client = videointelligence.VideoIntelligenceServiceClient()

190

191

# Analyze video with multiple features

192

features = [

193

videointelligence.Feature.LABEL_DETECTION,

194

videointelligence.Feature.SHOT_CHANGE_DETECTION,

195

videointelligence.Feature.EXPLICIT_CONTENT_DETECTION

196

]

197

198

operation = client.annotate_video(

199

request={

200

"features": features,

201

"input_uri": "gs://your-bucket/your-video.mp4",

202

}

203

)

204

205

# Wait for completion and get results

206

result = operation.result(timeout=600)

207

```

208

209

#### Async Video Analysis

210

211

```python

212

import asyncio

213

from google.cloud import videointelligence

214

215

async def analyze_video():

216

# Create async client

217

client = videointelligence.VideoIntelligenceServiceAsyncClient()

218

219

# Analyze video

220

operation = await client.annotate_video(

221

request={

222

"features": [videointelligence.Feature.FACE_DETECTION],

223

"input_uri": "gs://your-bucket/your-video.mp4",

224

}

225

)

226

227

# Wait for completion

228

result = await operation.result(timeout=600)

229

return result

230

231

# Run async analysis

232

result = asyncio.run(analyze_video())

233

```

234

235

#### Service Account Authentication

236

237

```python

238

from google.cloud import videointelligence

239

240

# Using service account file

241

client = videointelligence.VideoIntelligenceServiceClient.from_service_account_file(

242

"path/to/service-account-key.json"

243

)

244

245

# Using service account info dict

246

service_account_info = {

247

"type": "service_account",

248

"project_id": "your-project-id",

249

# ... other service account fields

250

}

251

client = videointelligence.VideoIntelligenceServiceClient.from_service_account_info(

252

service_account_info

253

)

254

```

255

256

### Path Helper Methods

257

258

The client provides utility methods for constructing common resource paths:

259

260

```python { .api }

261

# Static methods for path construction

262

@staticmethod

263

def common_billing_account_path(billing_account: str) -> str:

264

"""Return a fully-qualified billing_account string."""

265

266

@staticmethod

267

def common_folder_path(folder: str) -> str:

268

"""Return a fully-qualified folder string."""

269

270

@staticmethod

271

def common_organization_path(organization: str) -> str:

272

"""Return a fully-qualified organization string."""

273

274

@staticmethod

275

def common_project_path(project: str) -> str:

276

"""Return a fully-qualified project string."""

277

278

@staticmethod

279

def common_location_path(project: str, location: str) -> str:

280

"""Return a fully-qualified location string."""

281

```

282

283

### Transport Options

284

285

The client supports multiple transport protocols:

286

287

- **gRPC** (default): High-performance binary protocol

288

- **gRPC AsyncIO**: Asynchronous gRPC support

289

- **REST**: HTTP/1.1 REST API for environments where gRPC is not available

290

291

Transport can be specified during client initialization:

292

293

```python

294

# Using specific transport

295

client = videointelligence.VideoIntelligenceServiceClient(

296

transport="rest" # or "grpc", "grpc_asyncio"

297

)

298

```