# Define function to start face search in video
def start_content_moderation(video_path, bucket_name):
response = rekognition_client.start_content_moderation(
Video={"S3Object": {"Bucket": bucket_name, "Name": video_path}}
)
return response["JobId"]
# Define function to get face search results
def get_content_moderation(job_id):
wait_for = 5
pagination_finished = False
next_token = ""
response = {
"ModerationLabels" : []
}
while not pagination_finished:
print(next_token)
moderation_res = rekognition_client.get_content_moderation(JobId=job_id, NextToken = next_token)
status = moderation_res["JobStatus"]
next_token = moderation_res.get("NextToken", "")
if status == "IN_PROGRESS":
time.sleep(wait_for)
elif status == "SUCCEEDED" :
print(moderation_res)
if (not next_token):
pagination_finished = True
response["ModerationLabels"].extend(moderation_res["ModerationLabels"])
return response
#Upload Target video to S3 Bucket
s3.create_bucket(Bucket=bucket_name)
s3.upload_file(video_output, bucket_name, video_output)
#Start Content Moderation using Rekognition API
job_id = start_content_moderation(video_output, bucket_name )
print(job_id)
moderation_res = get_content_moderation(job_id)
print(moderation_res)