Moviepy: Save to Amazon S3

Created on 29 Jan 2014  路  12Comments  路  Source: Zulko/moviepy

Hi,

I want to save my final video to Amazon S3 (or other network storage), but with current to_videofile I cannot.

Code from example:

# write the result to a file in any format
final_clip.to_videofile("myHolidays_edited.avi",fps=25, codec='mpeg4')

Can you use buffer instead of filename? Or other suggestions how can I do it.

enhancement won't-fix

Most helpful comment

While I think folding in native S3 support is not necessary, it would be good to have examples of how MoviePy works without writing to disk (is that possible)? I want to perform my conversions in the context of the request and in memory before uploading the result to S3 (from memory).

All 12 comments

I am not familiar with Amazon S3. Could you give (a lot) more details on what you are trying to do ? Like, cannot you write to a file and then upload to Amazon ?

It is an interesting question (writing the output to a buffer), could be useful for web streaming too, but I am not sure how easy it will be, I will see.

For example, I want to store my videos on a remote host

  • with filename I need to save it to a temp file, upload and delete the temp file
  • with buffer I need to upload a buffer.

I use django-storages (Amazon S3: https://github.com/iserko/django-storages/blob/master/storages/backends/s3.py) and with image files I can:

from django.core.files.storage import default_storage as s3_storage

my_file = s3_storage.open(image_file.name, 'rw')  # download a file
img = Image.open(my_file)
img.save(my_file, 'JPEG', quality=80)
my_file.close()  # upload a file

s3cmd is a great library for doing command line saves to s3, perhaps you could pipe the output from moviepy into s3cmd?

There is also the python AWS interface boto.

Hi @Zulko ,
I have similar situation as well.
I want to edit a video (mp4) with Moviepy. Need to add 3 images and edit it's audio as well and Finally I want to show it on a web Page.
So, is there any possibility ?

Also, I have one more question Please.
My video is bit long (8 minutes) and when I call write_videofile method to save edited video. It takes very very long. Can you please suggest me to improve it's performance ?

I shall be thankful

Thanks
Harpreet Gill

I think we should keep this functionality out of the package, since it can be easily achieved on your own with boto.
Thoughts? @Zulko @earney @Gloin1313

Closing this. You can achieve a similar upload to s3 using boto3 s3 (pip install boto3) something like:

from boto3.s3.transfer import S3Transfer
import boto3

... video/audio manipulations via moviepy ...

# Define the S3 client with access and secret keys, if necessary.
client = boto3.client('s3', aws_access_key_id=access_key,aws_secret_access_key=secret_key)
# Define the S3Transfer instance.
transfer = S3Transfer(client)
# Upload the file to S3
transfer.upload_file(final_clip_path, aws_bucket, file_path_in_bucket)

Thank you!

While I think folding in native S3 support is not necessary, it would be good to have examples of how MoviePy works without writing to disk (is that possible)? I want to perform my conversions in the context of the request and in memory before uploading the result to S3 (from memory).

Hi @Zulko ,
I have similar situation as well.
I want to edit a video (mp4) with Moviepy. Need to add 3 images and edit it's audio as well and Finally I want to show it on a web Page.
So, is there any possibility ?

Also, I have one more question Please.
My video is bit long (8 minutes) and when I call write_videofile method to save edited video. It takes very very long. Can you please suggest me to improve it's performance ?

I shall be thankful

Thanks
Harpreet Gill

Did you pull this out ? were you able to show video in webpage ?

how to directly write video on s3

Closing this. You can achieve a similar upload to s3 using boto3 s3 (pip install boto3) something like:

from boto3.s3.transfer import S3Transfer
import boto3

... video/audio manipulations via moviepy ...

# Define the S3 client with access and secret keys, if necessary.
client = boto3.client('s3', aws_access_key_id=access_key,aws_secret_access_key=secret_key)
# Define the S3Transfer instance.
transfer = S3Transfer(client)
# Upload the file to S3
transfer.upload_file(final_clip_path, aws_bucket, file_path_in_bucket)

Thank you!

in this solution
I think you try to tell first write video on website storage and later upload on AWS
any other solution
like directly write on aws s3
or
first, upload video in s3 bucket
after that rewrite video
if you have any idea please tell me

Closing this. You can achieve a similar upload to s3 using boto3 s3 (pip install boto3) something like:

from boto3.s3.transfer import S3Transfer
import boto3

... video/audio manipulations via moviepy ...

# Define the S3 client with access and secret keys, if necessary.
client = boto3.client('s3', aws_access_key_id=access_key,aws_secret_access_key=secret_key)
# Define the S3Transfer instance.
transfer = S3Transfer(client)
# Upload the file to S3
transfer.upload_file(final_clip_path, aws_bucket, file_path_in_bucket)

Thank you!

in this solution
I think you try to tell first write video on website storage and later upload on AWS
any other solution
like directly write on aws s3
or
first, upload video in s3 bucket
after that rewrite video
if you have any idea please tell me

I think direct writing on S3 using multipart upload is a good solution. It will upload quickly and the process will be fast. As of now we are saving the output video on a local file and then that file is uploaded to S3 which takes time (1. video rendering 2. uploading 3. Deleting the video) and then respond to the client.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PyB1l picture PyB1l  路  3Comments

bilel picture bilel  路  4Comments

cquintini picture cquintini  路  4Comments

Deng-deng-deng-deng picture Deng-deng-deng-deng  路  3Comments

buddhashrestha picture buddhashrestha  路  3Comments