Use this API to retrieve media content from a Kinesis video stream. In the request, you identify the stream name or stream Amazon Resource Name (ARN), and the starting chunk. Kinesis Video Streams then returns a stream of chunks in order by fragment number.
You must first call the GetDataEndpoint API to get an endpoint. Then send the GetMedia requests to this endpoint using the --endpoint-url parameter.
When you put media data (fragments) on a stream, Kinesis Video Streams stores each incoming fragment and related metadata in what is called a "chunk." For more information, see PutMedia. The GetMedia API returns a stream of these chunks starting from the chunk that you specify in the request.
The following limits apply when using the GetMedia API:
-
A client can call GetMedia up to five times per second per stream.
-
Kinesis Video Streams sends media data at a rate of up to 25 megabytes per second (or 200 megabits per second) during a GetMedia session.
If an error is thrown after invoking a Kinesis Video Streams media API, in addition to the HTTP status code and the response body, it includes the following pieces of information:
-
x-amz-ErrorType HTTP header – contains a more specific error type in addition to what the HTTP status code provides.
-
x-amz-RequestId HTTP header – if you want to report an issue to AWS, the support team can better diagnose the problem if given the Request Id.
Both the HTTP status code and the ErrorType header can be utilized to make programmatic decisions about whether errors are retry-able and under what conditions, as well as provide information on what actions the client programmer might need to take in order to successfully try again.
For more information, see the Errors section at the bottom of this topic, as well as Common Errors.
Parameters:
-
stream_name
(Optional[StreamName], default:
None
)
–
The Kinesis video stream name from where you want to get the media content. If you don't specify the streamName, you must specify the streamARN.
-
stream_arn
(Optional[ResourceARN], default:
None
)
–
The ARN of the stream from where you want to get the media content. If you don't specify the streamARN, you must specify the streamName.
-
start_selector
(StartSelector)
–
Identifies the starting chunk to get from the specified stream.
Raises:
-
ClientLimitExceededException
–
Kinesis Video Streams has throttled the request because you have exceeded the limit of allowed client calls. Try making the call later.
-
ConnectionLimitExceededException
–
Kinesis Video Streams has throttled the request because you have exceeded the limit of allowed client connections.
-
InvalidArgumentException
–
The value for this input parameter is invalid.
-
InvalidEndpointException
–
Status Code: 400, Caller used wrong endpoint to write data to a stream. On receiving such an exception, the user must call GetDataEndpoint with AccessMode set to "READ" and use the endpoint Kinesis Video returns in the next GetMedia call.
-
NotAuthorizedException
–
Status Code: 403, The caller is not authorized to perform an operation on the given stream, or the token has expired.
-
ResourceNotFoundException
–
Status Code: 404, The stream with the given name does not exist.
-
UnknownServiceError
–
The service returned an error code this client does not model.
Source code in docs_src/capo_kinesis_video_media/_services/kinesis_video_media.py
| @contextmanager
def get_media(
self,
start_selector: "capo_kinesis_video_media.types.start_selector.StartSelector",
*,
config_overrides: Optional[KinesisVideoMediaClientConfig] = None,
stream_name: Optional[
"capo_kinesis_video_media.types.stream_name.StreamName"
] = None,
stream_arn: Optional[
"capo_kinesis_video_media.types.resource_arn.ResourceARN"
] = None,
) -> "Generator[capo_kinesis_video_media.types.get_media_output.GetMediaOutput]":
"""<p> Use this API to retrieve media content from a Kinesis video stream. In the request, you identify the stream name or stream Amazon Resource Name (ARN), and the starting chunk. Kinesis Video Streams then returns a stream of chunks in order by fragment number.</p> <note> <p>You must first call the <code>GetDataEndpoint</code> API to get an endpoint. Then send the <code>GetMedia</code> requests to this endpoint using the <a href="https://docs.aws.amazon.com/cli/latest/reference/">--endpoint-url parameter</a>. </p> </note> <p>When you put media data (fragments) on a stream, Kinesis Video Streams stores each incoming fragment and related metadata in what is called a "chunk." For more information, see <a href="https://docs.aws.amazon.com/kinesisvideostreams/latest/dg/API_dataplane_PutMedia.html">PutMedia</a>. The <code>GetMedia</code> API returns a stream of these chunks starting from the chunk that you specify in the request. </p> <p>The following limits apply when using the <code>GetMedia</code> API:</p> <ul> <li> <p>A client can call <code>GetMedia</code> up to five times per second per stream. </p> </li> <li> <p>Kinesis Video Streams sends media data at a rate of up to 25 megabytes per second (or 200 megabits per second) during a <code>GetMedia</code> session. </p> </li> </ul> <note> <p>If an error is thrown after invoking a Kinesis Video Streams media API, in addition to the HTTP status code and the response body, it includes the following pieces of information: </p> <ul> <li> <p> <code>x-amz-ErrorType</code> HTTP header – contains a more specific error type in addition to what the HTTP status code provides. </p> </li> <li> <p> <code>x-amz-RequestId</code> HTTP header – if you want to report an issue to AWS, the support team can better diagnose the problem if given the Request Id.</p> </li> </ul> <p>Both the HTTP status code and the ErrorType header can be utilized to make programmatic decisions about whether errors are retry-able and under what conditions, as well as provide information on what actions the client programmer might need to take in order to successfully try again.</p> <p>For more information, see the <b>Errors</b> section at the bottom of this topic, as well as <a href="https://docs.aws.amazon.com/kinesisvideostreams/latest/dg/CommonErrors.html">Common Errors</a>. </p> </note>
Args:
stream_name: <p>The Kinesis video stream name from where you want to get the media content. If you don't specify the <code>streamName</code>, you must specify the <code>streamARN</code>.</p>
stream_arn: <p>The ARN of the stream from where you want to get the media content. If you don't specify the <code>streamARN</code>, you must specify the <code>streamName</code>.</p>
start_selector: <p>Identifies the starting chunk to get from the specified stream. </p>
Raises:
capo_kinesis_video_media.errors.client_limit_exceeded_exception.ClientLimitExceededException: <p>Kinesis Video Streams has throttled the request because you have exceeded the limit of allowed client calls. Try making the call later.</p>
capo_kinesis_video_media.errors.connection_limit_exceeded_exception.ConnectionLimitExceededException: <p>Kinesis Video Streams has throttled the request because you have exceeded the limit of allowed client connections.</p>
capo_kinesis_video_media.errors.invalid_argument_exception.InvalidArgumentException: <p>The value for this input parameter is invalid.</p>
capo_kinesis_video_media.errors.invalid_endpoint_exception.InvalidEndpointException: <p> Status Code: 400, Caller used wrong endpoint to write data to a stream. On receiving such an exception, the user must call <code>GetDataEndpoint</code> with <code>AccessMode</code> set to "READ" and use the endpoint Kinesis Video returns in the next <code>GetMedia</code> call. </p>
capo_kinesis_video_media.errors.not_authorized_exception.NotAuthorizedException: <p>Status Code: 403, The caller is not authorized to perform an operation on the given stream, or the token has expired.</p>
capo_kinesis_video_media.errors.resource_not_found_exception.ResourceNotFoundException: <p>Status Code: 404, The stream with the given name does not exist.</p>
capo_kinesis_video_media.errors.UnknownServiceError: The service returned an error code this client does not model.
"""
def _handler(
req: "OperationRequest[capo_kinesis_video_media.types.get_media_input.GetMediaInput]",
) -> OperationResponse[
"capo_kinesis_video_media.types.get_media_output.GetMediaOutput"
]:
import capo_kinesis_video_media._operations.aws_acuity_inlet_service.get_media
output, http_response = (
capo_kinesis_video_media._operations.aws_acuity_inlet_service.get_media.get_media(
req.options, req.input
)
)
return OperationResponse(output=output, response=http_response)
def _redact_output(
output: "capo_kinesis_video_media.types.get_media_output.GetMediaOutput",
) -> dict[str, Any]:
import capo_kinesis_video_media.types.get_media_output
return capo_kinesis_video_media.types.get_media_output.redact_sensitive(
output
)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("GetMedia", redact_output=_redact_output)
)
input_: capo_kinesis_video_media.types.get_media_input.GetMediaInput = {
"start_selector": start_selector
}
if stream_name is not None:
input_["stream_name"] = stream_name
if stream_arn is not None:
input_["stream_arn"] = stream_arn
response = execute_pipeline(
OperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
try:
yield response.output
finally:
response.response.close()
|