Reputation: 138
I had implemented the FFmpeg function to convert video format using python but I need to save its output directly to the s3 bucket from where it takes as input but I don't have any idea about it. Below is my code for converting video format
s3 = boto3.client('s3',
region_name = S3_REGION,
aws_access_key_id = S3_ACCESS_KEY_ID,
aws_secret_access_key = S3_ACCESS_SECRET_KEY)
os.popen("ffmpeg -i '{input}' -ac 2 -b:v 2000k -c:a aac -c:v libx264 -b:a 160k -vprofile high -bf 0 -strict experimental -f mp4 '{output}.mp4'".format(input = avi_file_path, output = output_name))
Can anyone suggest me how can I resolve this issue ?
Upvotes: 0
Views: 1285
Reputation: 2765
You could pipe the the output of ffmpeg to AWS Cli copy command. Something like this (not tested):
ffmpeg -i '{input}' -ac 2 -b:v 2000k -c:a aac -c:v libx264 -b:a 160k -vprofile high -bf 0 -strict experimental -f mp4 pipe:1 | aws s3 cp - s3://test-bucket/youroutput.mp4
EDIT
Due to the nature of the mp4 this won't work, mp4 need to be seekable and a stream is not seekable. One way could be to add -movflags frag_keyframe+empty_moov
to the command, this will create a fragmented mp4, which is a kind of different format with limited (with respect to the normal mp4) playback capability.
Alternatively I suggest if you can to create the file locally and later upload to S3.
Upvotes: 2