How to read video file data from s3 and convert to mp4 using python?

  python, python-3.x

I have one bucket in which there are a number of videos and I want to convert their format to mp4 using python and for that, I had done code for fetching objects but it’s response is showing like below and I don’t know how I’ll get the name of that video file

{
    "RequestId":"33T5T33DDP1KWHEM",
    "HostId":"qQHGQVOpCBCGRRP5RMWQcmtOK2mJa42vvXzJMU1k5MIYiQheOHPnIQfqPuL7JkX+IsB7zwLa7sw=",
    "HTTPStatusCode":200,
    "HTTPHeaders":{
       "x-amz-id-2":"qQHGQVOpCBCGRRP5RMWQcmtOK2mJa42vvXzJMU1k5MIYiQheOHPnIQfqPuL7JkX+IsB7zwLa7sw=",
       "x-amz-request-id":"33T5T33DDP1KWHEM",
       "date":"Tue, 21 Sep 2021 06:59:06 GMT",
       "last-modified":"Tue, 21 Sep 2021 06:12:52 GMT",
       "etag":""911e20d3be5a7d700d3b1cc86c01325e"",
       "accept-ranges":"bytes",
       "content-type":"video/x-msvideo",
       "server":"AmazonS3",
       "content-length":"1480958"
    },
    "RetryAttempts":0
 },
 "AcceptRanges":"bytes",
 "LastModified":datetime.datetime(2021,9,21,6,12,52,
 "tzinfo=tzutc())",
 "ContentLength":1480958,
 "ETag":""911e20d3be5a7d700d3b1cc86c01325e"",
 "ContentType":"video/x-msvideo",
 "Metadata":{
    
 },
 "Body":<botocore.response.StreamingBody object at 0x7f78c5199ca0>
 }

For fetching objects of bucket code is as below

s3 = boto3.client('s3',
            region_name = S3_REGION,
            aws_access_key_id = S3_ACCESS_KEY_ID, 
            aws_secret_access_key = S3_ACCESS_SECRET_KEY)
        result = s3.list_objects(Bucket = bucket_name, Prefix='videos/')
        for o in result.get('Contents'):
            data = s3.get_object(Bucket=bucket_name, Key=o.get('Key'))

Now my query I’m getting body data Body:<botocore. response.StreamingBody object at 0x7f78c5199ca0> how can I read this data and convert that video format to another format using python ?

Source: Python-3x Questions

LEAVE A COMMENT