orangecube
orangecube

Reputation: 27

How to combine/concatenate videos stored in AWS S3 bucket based on title of the file name

I am using a service that allows me to record videos that get automatically pushed to a folder (submissions) in an S3 bucket. There are multiple videos however they need to be grouped together and concatenated so the output is one video per group.

So, basically, any tips on how I can take videos based on the title and stitch them together?

Example:

Submissions folder will have:

a-100-2.mp4
a-200-6.mp4
b-123-5.mp4

Expected output in processed folder:

a.mp4     - (both 'a' videos get stitched together)
b.mp4     - (only 'b' gets sent over since there is only one video.)

Thanks in advance!

Edit: Some additional and detailed information below if it helps.

The files will be labeled with: {name}-{location}-{video_token}-{stream_token}.mp4

Need help creating a script or process that will concatenate the videos using the procedure outlined below:

Processing rules (back end):

  1. Check if videos have same {video_token} in ‘submissions folder’. If so, keep the newest one and delete old ones.

  2. Take all videos in ‘submissions folder’ with same {name} and {location} in title and concatenate the videos. Save output video to a new folder in the bucket labeled as the {location} for the folder name. Output file name: {name}-{location}-{year}.{mp4}.

EXAMPLE:

Submissions folder: joey-toronto-001-354.mp4

joey-toronto-001-241.mp4 - this will be deleted

joey-toronto-103-452.mp4

alex-montreal-352-232.mp4

alex-montreal-452-223.mp4

Resulting output:

Toronto folder:

Joey-toronto-2020.mp4

Montreal folder:

Alex-montreal-2020.mp4

Upvotes: 2

Views: 3690

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269520

You can use Clip Stitching - Amazon Elastic Transcoder.

The Amazon Elastic Transcoder allows you to specify multiple input files from S3 (and even time ranges within those files) and output them to a single video file. It's just a matter of providing a list of input sources.

I used that for: Automated video editing with YOU as the star! | AWS Machine Learning Blog

There is some sample code on that page that calls Elastic Transcoder:

'''
The inputs array now looks like:
[
  {'Key': 'trainers.mp4', 'TimeSpan': {'StartTime': '99.8', 'Duration': '1.68'}},
  {'Key': 'trainers.mp4', 'TimeSpan': {'StartTime': '127.52', 'Duration': '4.24'}},
  ...
]
'''

# Call Amazon Elastic Transcoder to stitch together a new video
client = boto3.client('elastictranscoder', region_name = 'ap-southeast-2')

job = client.create_job(
  PipelineId = '...',
  Inputs=inputs,
  Output={'Key': person_to_find + '.mp4', 'PresetId': '...'}
)

It might also be possible with AWS Elemental MediaConvert.

Upvotes: 3

Related Questions