|
| 1 | +""" |
| 2 | +examples.clouds.aws_cloud |
| 3 | +~~~~~~~~~~~~ |
| 4 | +
|
| 5 | +Open a file from a Amazon S3 cloud and save dash files to it |
| 6 | +
|
| 7 | +
|
| 8 | +:copyright: (c) 2019 by Amin Yazdanpanah. |
| 9 | +:website: https://www.aminyazdanpanah.com |
| 10 | + |
| 11 | +:license: MIT, see LICENSE for more details. |
| 12 | +""" |
| 13 | + |
| 14 | +import argparse |
| 15 | +import sys |
| 16 | + |
| 17 | +import ffmpeg_streaming |
| 18 | +from ffmpeg_streaming import AWS |
| 19 | + |
| 20 | + |
| 21 | +def aws_cloud(bucket_name, key): |
| 22 | + cloud = AWS(aws_access_key_id='YOUR_KEY_ID', aws_secret_access_key='YOUR_KEY_SECRET') |
| 23 | + download_options = { |
| 24 | + 'bucket_name': bucket_name, |
| 25 | + 'key': key, |
| 26 | + } |
| 27 | + upload_options = { |
| 28 | + 'bucket_name': bucket_name, |
| 29 | + } |
| 30 | + |
| 31 | + from_aws_cloud = (cloud, download_options, None) |
| 32 | + to_aws_cloud = (cloud, upload_options) |
| 33 | + |
| 34 | + return from_aws_cloud, to_aws_cloud |
| 35 | + |
| 36 | + |
| 37 | +def transcode_progress(percentage, ffmpeg, media): |
| 38 | + # You can update a field in your database |
| 39 | + # You can also create a socket connection and show a progress bar to users |
| 40 | + sys.stdout.write("\rTranscoding...(%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage))) |
| 41 | + sys.stdout.flush() |
| 42 | + |
| 43 | + |
| 44 | +def main(): |
| 45 | + parser = argparse.ArgumentParser() |
| 46 | + |
| 47 | + parser.add_argument('-b', '--bucket_name', required=True, help='Bucket name (required).') |
| 48 | + parser.add_argument('-k', '--key', required=True, help='Key name (required)') |
| 49 | + |
| 50 | + args = parser.parse_args() |
| 51 | + |
| 52 | + from_aws_cloud, to_aws_cloud = aws_cloud(args.bucket_name, args.key) |
| 53 | + |
| 54 | + ( |
| 55 | + ffmpeg_streaming |
| 56 | + .dash(from_aws_cloud, adaption='"id=0,streams=v id=1,streams=a"') |
| 57 | + .format('libx265') |
| 58 | + .auto_rep() |
| 59 | + .package('/var/www/media/stream.mpd', to_aws_cloud, transcode_progress) |
| 60 | + ) |
| 61 | + |
| 62 | + |
| 63 | +if __name__ == "__main__": |
| 64 | + sys.exit(main()) |
0 commit comments