Skip to content

Commit

Permalink
feat(client-kinesis-video-archived-media): Add support for GetImages …
Browse files Browse the repository at this point in the history
…API for retrieving images from a video stream
  • Loading branch information
awstools committed May 3, 2022
1 parent d3b2e8c commit a775394
Show file tree
Hide file tree
Showing 7 changed files with 745 additions and 19 deletions.
Expand Up @@ -11,6 +11,7 @@ import {
GetHLSStreamingSessionURLCommandInput,
GetHLSStreamingSessionURLCommandOutput,
} from "./commands/GetHLSStreamingSessionURLCommand";
import { GetImagesCommand, GetImagesCommandInput, GetImagesCommandOutput } from "./commands/GetImagesCommand";
import {
GetMediaForFragmentListCommand,
GetMediaForFragmentListCommandInput,
Expand Down Expand Up @@ -482,6 +483,32 @@ export class KinesisVideoArchivedMedia extends KinesisVideoArchivedMediaClient {
}
}

/**
* <p>Retrieves a list of Images corresponding to each timestamp for a given time range, sampling interval, and image format configuration.</p>
*/
public getImages(args: GetImagesCommandInput, options?: __HttpHandlerOptions): Promise<GetImagesCommandOutput>;
public getImages(args: GetImagesCommandInput, cb: (err: any, data?: GetImagesCommandOutput) => void): void;
public getImages(
args: GetImagesCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: GetImagesCommandOutput) => void
): void;
public getImages(
args: GetImagesCommandInput,
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: GetImagesCommandOutput) => void),
cb?: (err: any, data?: GetImagesCommandOutput) => void
): Promise<GetImagesCommandOutput> | void {
const command = new GetImagesCommand(args);
if (typeof optionsOrCb === "function") {
this.send(command, optionsOrCb);
} else if (typeof cb === "function") {
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
this.send(command, optionsOrCb || {}, cb);
} else {
return this.send(command, optionsOrCb);
}
}

/**
* <p>Gets media for a list of fragments (specified by fragment number) from the archived
* data in an Amazon Kinesis video stream.</p>
Expand Down
Expand Up @@ -60,6 +60,7 @@ import {
GetHLSStreamingSessionURLCommandInput,
GetHLSStreamingSessionURLCommandOutput,
} from "./commands/GetHLSStreamingSessionURLCommand";
import { GetImagesCommandInput, GetImagesCommandOutput } from "./commands/GetImagesCommand";
import {
GetMediaForFragmentListCommandInput,
GetMediaForFragmentListCommandOutput,
Expand All @@ -71,13 +72,15 @@ export type ServiceInputTypes =
| GetClipCommandInput
| GetDASHStreamingSessionURLCommandInput
| GetHLSStreamingSessionURLCommandInput
| GetImagesCommandInput
| GetMediaForFragmentListCommandInput
| ListFragmentsCommandInput;

export type ServiceOutputTypes =
| GetClipCommandOutput
| GetDASHStreamingSessionURLCommandOutput
| GetHLSStreamingSessionURLCommandOutput
| GetImagesCommandOutput
| GetMediaForFragmentListCommandOutput
| ListFragmentsCommandOutput;

Expand Down
@@ -0,0 +1,99 @@
import { getSerdePlugin } from "@aws-sdk/middleware-serde";
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http";
import { Command as $Command } from "@aws-sdk/smithy-client";
import {
FinalizeHandlerArguments,
Handler,
HandlerExecutionContext,
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

import {
KinesisVideoArchivedMediaClientResolvedConfig,
ServiceInputTypes,
ServiceOutputTypes,
} from "../KinesisVideoArchivedMediaClient";
import { GetImagesInput, GetImagesOutput } from "../models/models_0";
import {
deserializeAws_restJson1GetImagesCommand,
serializeAws_restJson1GetImagesCommand,
} from "../protocols/Aws_restJson1";

export interface GetImagesCommandInput extends GetImagesInput {}
export interface GetImagesCommandOutput extends GetImagesOutput, __MetadataBearer {}

/**
* <p>Retrieves a list of Images corresponding to each timestamp for a given time range, sampling interval, and image format configuration.</p>
* @example
* Use a bare-bones client and the command you need to make an API call.
* ```javascript
* import { KinesisVideoArchivedMediaClient, GetImagesCommand } from "@aws-sdk/client-kinesis-video-archived-media"; // ES Modules import
* // const { KinesisVideoArchivedMediaClient, GetImagesCommand } = require("@aws-sdk/client-kinesis-video-archived-media"); // CommonJS import
* const client = new KinesisVideoArchivedMediaClient(config);
* const command = new GetImagesCommand(input);
* const response = await client.send(command);
* ```
*
* @see {@link GetImagesCommandInput} for command's `input` shape.
* @see {@link GetImagesCommandOutput} for command's `response` shape.
* @see {@link KinesisVideoArchivedMediaClientResolvedConfig | config} for KinesisVideoArchivedMediaClient's `config` shape.
*
*/
export class GetImagesCommand extends $Command<
GetImagesCommandInput,
GetImagesCommandOutput,
KinesisVideoArchivedMediaClientResolvedConfig
> {
// Start section: command_properties
// End section: command_properties

constructor(readonly input: GetImagesCommandInput) {
// Start section: command_constructor
super();
// End section: command_constructor
}

/**
* @internal
*/
resolveMiddleware(
clientStack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>,
configuration: KinesisVideoArchivedMediaClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<GetImagesCommandInput, GetImagesCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));

const stack = clientStack.concat(this.middlewareStack);

const { logger } = configuration;
const clientName = "KinesisVideoArchivedMediaClient";
const commandName = "GetImagesCommand";
const handlerExecutionContext: HandlerExecutionContext = {
logger,
clientName,
commandName,
inputFilterSensitiveLog: GetImagesInput.filterSensitiveLog,
outputFilterSensitiveLog: GetImagesOutput.filterSensitiveLog,
};
const { requestHandler } = configuration;
return stack.resolve(
(request: FinalizeHandlerArguments<any>) =>
requestHandler.handle(request.request as __HttpRequest, options || {}),
handlerExecutionContext
);
}

private serialize(input: GetImagesCommandInput, context: __SerdeContext): Promise<__HttpRequest> {
return serializeAws_restJson1GetImagesCommand(input, context);
}

private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<GetImagesCommandOutput> {
return deserializeAws_restJson1GetImagesCommand(output, context);
}

// Start section: command_body_extra
// End section: command_body_extra
}
@@ -1,5 +1,6 @@
export * from "./GetClipCommand";
export * from "./GetDASHStreamingSessionURLCommand";
export * from "./GetHLSStreamingSessionURLCommand";
export * from "./GetImagesCommand";
export * from "./GetMediaForFragmentListCommand";
export * from "./ListFragmentsCommand";
166 changes: 166 additions & 0 deletions clients/client-kinesis-video-archived-media/src/models/models_0.ts
Expand Up @@ -970,6 +970,172 @@ export namespace GetHLSStreamingSessionURLOutput {
});
}

export enum Format {
JPEG = "JPEG",
PNG = "PNG",
}

export enum FormatConfigKey {
JPEGQuality = "JPEGQuality",
}

export enum ImageSelectorType {
PRODUCER_TIMESTAMP = "PRODUCER_TIMESTAMP",
SERVER_TIMESTAMP = "SERVER_TIMESTAMP",
}

export interface GetImagesInput {
/**
* <p>The name of the stream from which to retrieve the images. You must specify either the <code>StreamName</code> or the <code>StreamARN</code>.</p>
*/
StreamName?: string;

/**
* <p>The Amazon Resource Name (ARN) of the stream from which to retrieve the images. You must specify either the <code>StreamName</code> or the <code>StreamARN</code>.</p>
*/
StreamARN?: string;

/**
* <p>The origin of the Server or Producer timestamps to use to generate the images.</p>
*/
ImageSelectorType: ImageSelectorType | string | undefined;

/**
* <p>The starting point from which the images should be generated. This <code>StartTimestamp</code> must be within an inclusive range of timestamps for an image to be returned.</p>
*/
StartTimestamp: Date | undefined;

/**
* <p>The end timestamp for the range of images to be generated.</p>
*/
EndTimestamp: Date | undefined;

/**
* <p>The time interval in milliseconds (ms) at which the images need to be generated from the stream. The minimum value that can be provided is 3000 ms. If the timestamp range is less than the sampling interval, the Image from the <code>startTimestamp</code> will be returned if available.
* </p>
* <note>
* <p>The minimum value of 3000 ms is a soft limit. If needed, a lower sampling frequency can be requested.</p>
* </note>
*/
SamplingInterval: number | undefined;

/**
* <p>The format that will be used to encode the image.</p>
*/
Format: Format | string | undefined;

/**
* <p>The list of a key-value pair structure that contains extra parameters that can be applied when the image is generated. The <code>FormatConfig</code> key is the <code>JPEGQuality</code>, which indicates the JPEG quality key to be used to generate the image.
* The <code>FormatConfig</code> value accepts ints from 1 to 100. If the value is 1, the image will be generated with less quality and the best compression.
* If the value is 100, the image will be generated with the best quality and less compression. If no value is provided, the default value of the <code>JPEGQuality</code> key will be set to 80.</p>
*/
FormatConfig?: { [key: string]: string };

/**
* <p>The width of the output image that is used in conjunction with the <code>HeightPixels</code> parameter. When both <code>WidthPixels</code> and <code>HeightPixels</code> parameters are provided,
* the image will be stretched to fit the specified aspect ratio. If only the <code>WidthPixels</code> parameter is provided or if only the <code>HeightPixels</code> is provided, a <code>ValidationException</code> will be thrown.
* If neither parameter is provided, the original image size from the stream will be returned.</p>
*/
WidthPixels?: number;

/**
* <p>The height of the output image that is used in conjunction with the <code>WidthPixels</code> parameter. When both <code>HeightPixels</code> and <code>WidthPixels</code> parameters are provided, the image will be stretched to fit the
* specified aspect ratio. If only the <code>HeightPixels</code> parameter is provided, its original aspect ratio will be used to calculate the <code>WidthPixels</code> ratio. If neither parameter is provided,
* the original image size will be returned.</p>
*/
HeightPixels?: number;

/**
* <p>The maximum number of images to be returned by the API. </p>
* <note>
* <p>The default limit is 100 images per API response. The additional results will be paginated. </p>
* </note>
*/
MaxResults?: number;

/**
* <p>A token that specifies where to start paginating the next set of Images. This is the <code>GetImages:NextToken</code> from a previously truncated response.</p>
*/
NextToken?: string;
}

export namespace GetImagesInput {
/**
* @internal
*/
export const filterSensitiveLog = (obj: GetImagesInput): any => ({
...obj,
});
}

export enum ImageError {
MEDIA_ERROR = "MEDIA_ERROR",
NO_MEDIA = "NO_MEDIA",
}

/**
* <p>A structure that contains the <code>Timestamp</code>, <code>Error</code>, and <code>ImageContent</code>.</p>
*/
export interface Image {
/**
* <p>An attribute of the <code>Image</code> object that is used to extract an image from the video stream. This field is used to manage gaps on images or to better understand the pagination
* window.</p>
*/
TimeStamp?: Date;

/**
* <p>The error message shown when the image for the provided timestamp was not extracted due to a non-tryable error. An error will be returned if: </p>
* <ul>
* <li>
* <p>There is no media that exists for the specified <code>Timestamp</code>.</p>
* </li>
* </ul>
* <ul>
* <li>
* <p>The media for the specified time does not allow an image to be extracted. In this case the media is audio only, or the incorrect
* media has been ingested.</p>
* </li>
* </ul>
*/
Error?: ImageError | string;

/**
* <p>An attribute of the <code>Image</code> object that is Base64 encoded.</p>
*/
ImageContent?: string;
}

export namespace Image {
/**
* @internal
*/
export const filterSensitiveLog = (obj: Image): any => ({
...obj,
});
}

export interface GetImagesOutput {
/**
* <p>The list of images generated from the video stream. If there is no media available for the given timestamp, the <code>NO_MEDIA</code> error will be listed in the output.
* If an error occurs while the image is being generated, the <code>MEDIA_ERROR</code> will be listed in the output as the cause of the missing image. </p>
*/
Images?: Image[];

/**
* <p>The encrypted token that was used in the request to get more images.</p>
*/
NextToken?: string;
}

export namespace GetImagesOutput {
/**
* @internal
*/
export const filterSensitiveLog = (obj: GetImagesOutput): any => ({
...obj,
});
}

export interface GetMediaForFragmentListInput {
/**
* <p>The name of the stream from which to retrieve fragment media. Specify either this parameter or the <code>StreamARN</code> parameter.</p>
Expand Down

0 comments on commit a775394

Please sign in to comment.