Skip to content

Commit 8c17a52

Browse files
- add clouds
- bug fixes and other minor improvements
1 parent b91b278 commit 8c17a52

30 files changed

Lines changed: 903 additions & 139 deletions

.appveyor.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@ clone_folder: c:\projects\project-code
88
cache:
99
- c:\ProgramData\chocolatey\bin -> .appveyor.yml
1010
- c:\ProgramData\chocolatey\lib -> .appveyor.yml
11-
- c:\ProgramData\ComposerSetup -> .appveyor.yml
12-
- c:\tools\php -> .appveyor.yml
1311

1412
environment:
1513
global:
16-
COMPOSER_NO_INTERACTION: 1
17-
ANSICON: 121x90 (121x90) # Console colors
18-
1914
ffmpeg_download: https://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20190225-f948082-win64-static.zip
2015

2116
matrix:

.github/lock.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
# Configuration for Lock Threads - https://github.com/dessant/lock-threads
3+
4+
# Number of days of inactivity before a closed issue or pull request is locked
5+
daysUntilLock: 30
6+
7+
# Skip issues and pull requests created before a given timestamp. Timestamp must
8+
# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable
9+
skipCreatedBefore: false
10+
11+
# Issues and pull requests with these labels will be ignored. Set to `[]` to disable
12+
exemptLabels: []
13+
14+
# Label to add before locking, such as `outdated`. Set to `false` to disable
15+
lockLabel: false
16+
17+
# Comment to post before locking. Set to `false` to disable
18+
lockComment: false
19+
20+
# Assign `resolved` as the reason for locking. Set to `false` to disable
21+
setLockReason: false
22+
23+
# Limit to only `issues` or `pulls`
24+
# only: issues
25+
26+
# Optionally, specify configuration settings just for `issues` or `pulls`
27+
# issues:
28+
# exemptLabels:
29+
# - help-wanted
30+
# lockLabel: outdated
31+
32+
# pulls:
33+
# daysUntilLock: 30
34+
35+
# Repository to extend settings from
36+
# _extends: repo

examples/clouds/aws_cloud.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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())

examples/clouds/azure_cloud.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
examples.clouds.azure_clod
3+
~~~~~~~~~~~~
4+
5+
Open a file from a Microsoft Azure cloud and save hls 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 MicrosoftAzure
19+
20+
21+
def azure_cloud(container, blob):
22+
cloud = MicrosoftAzure(account_name='account_name', account_key='account_key')
23+
24+
download_options = {
25+
'container': container,
26+
'blob': blob
27+
}
28+
upload_options = {
29+
'container': container,
30+
}
31+
32+
from_azure_cloud = (cloud, download_options, None)
33+
to_azure_cloud = (cloud, upload_options)
34+
35+
return from_azure_cloud, to_azure_cloud
36+
37+
38+
def transcode_progress(percentage, ffmpeg, media):
39+
# You can update a field in your database
40+
# You can also create a socket connection and show a progress bar to users
41+
sys.stdout.write("\rTranscoding...(%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage)))
42+
sys.stdout.flush()
43+
44+
45+
def main():
46+
parser = argparse.ArgumentParser()
47+
48+
parser.add_argument('-c', '--container', required=True, help='Bucket name (required).')
49+
parser.add_argument('-b', '--blob', required=True, help='Key name (required)')
50+
51+
args = parser.parse_args()
52+
53+
from_azure_cloud, to_azure_cloud = azure_cloud(args.container, args.blob)
54+
55+
(
56+
ffmpeg_streaming
57+
.hls(from_azure_cloud)
58+
.format('libx264')
59+
.auto_rep()
60+
.package(clouds=to_azure_cloud, progress=transcode_progress)
61+
)
62+
63+
64+
if __name__ == "__main__":
65+
sys.exit(main())

examples/clouds/cloud.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
examples.clouds.cloud
3+
~~~~~~~~~~~~
4+
5+
Open a file from a 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 sys
15+
16+
import ffmpeg_streaming
17+
from ffmpeg_streaming import Cloud
18+
19+
20+
def download_progress(percentage, downloaded, total):
21+
# You can update a field in your database
22+
# You can also create a socket connection and show a progress bar to users
23+
sys.stdout.write("\rDownloading...(%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage)))
24+
sys.stdout.flush()
25+
26+
27+
def transcode_progress(percentage, ffmpeg, media):
28+
# You can update a field in your database
29+
# You can also create a socket connection and show a progress bar to users
30+
sys.stdout.write("\rTranscoding...(%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage)))
31+
sys.stdout.flush()
32+
33+
34+
def main():
35+
cloud = Cloud()
36+
download_options = {
37+
'url': 'https://www.aminyazdanpanah.com/my_sweetie.mp4',
38+
'progress': download_progress
39+
}
40+
upload_options = {
41+
'url': 'https://localhost:8000/api/upload',
42+
'method': 'post',
43+
'auth': ('username', 'password'),
44+
'headers': {
45+
'User-Agent': 'Mozilla/5.0 (compatible; AminYazdanpanahBot/1.0; +http://aminyazdanpanah.com/bots)',
46+
'Accept': 'application/json',
47+
'Authorization': 'Bearer ACCESS_TOKEN'
48+
}
49+
}
50+
51+
from_cloud = (cloud, download_options, None)
52+
to_cloud = (cloud, upload_options)
53+
54+
(
55+
ffmpeg_streaming
56+
.dash(from_cloud, adaption='"id=0,streams=v id=1,streams=a"')
57+
.format('libx265')
58+
.auto_rep()
59+
.package('/var/www/media/stream.mpd', to_cloud, transcode_progress)
60+
)
61+
62+
63+
if __name__ == "__main__":
64+
sys.exit(main())

examples/clouds/custom_cloud.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
examples.clouds.cloud
3+
~~~~~~~~~~~~
4+
5+
Open a file from a custom 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 sys
15+
16+
import ffmpeg_streaming
17+
from ffmpeg_streaming import Clouds
18+
19+
20+
class CustomCloud(Clouds):
21+
22+
def upload_directory(self, directory, **options):
23+
# @TODO: upload a directory to a cloud
24+
pass
25+
26+
def download(self, filename=None, **options):
27+
# @TODO: download a file to a local path
28+
pass
29+
30+
31+
def custom_cloud():
32+
33+
cloud = CustomCloud()
34+
download_options = {
35+
'YOUR_OPTIONS': 'my_sweetie.mp4',
36+
}
37+
upload_options = {
38+
'YOUR_OPTIONS': 'my_sweetie.mp4',
39+
}
40+
41+
from_custom_cloud = (cloud, download_options, None)
42+
to_custom_cloud = (cloud, upload_options)
43+
44+
return from_custom_cloud, to_custom_cloud
45+
46+
47+
def transcode_progress(percentage, ffmpeg, media):
48+
# You can update a field in your database
49+
# You can also create a socket connection and show a progress bar to users
50+
sys.stdout.write("\rTranscoding...(%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage)))
51+
sys.stdout.flush()
52+
53+
54+
def main():
55+
from_custom_cloud, to_custom_cloud = custom_cloud()
56+
57+
(
58+
ffmpeg_streaming
59+
.dash(from_custom_cloud, adaption='"id=0,streams=v id=1,streams=a"')
60+
.format('libx265')
61+
.auto_rep()
62+
.package(clouds=to_custom_cloud, progress=transcode_progress)
63+
)
64+
65+
66+
if __name__ == "__main__":
67+
sys.exit(main())

examples/clouds/google_cloud.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
examples.clouds.google_cloud
3+
~~~~~~~~~~~~
4+
5+
Open a file from a google cloud and save hls 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 GoogleCloudStorage
19+
20+
21+
def google_cloud(bucket_name, object_name):
22+
cloud = GoogleCloudStorage(bucket_name)
23+
download_options = {
24+
'object_name': object_name,
25+
}
26+
upload_options = {
27+
'encryption': 'SOME_BASE64_ENCRYPTION',
28+
}
29+
30+
from_google_cloud = (cloud, download_options, None)
31+
to_google_cloud = (cloud, upload_options)
32+
33+
return from_google_cloud, to_google_cloud
34+
35+
36+
def transcode_progress(percentage, ffmpeg, media):
37+
# You can update a field in your database
38+
# You can also create a socket connection and show a progress bar to users
39+
sys.stdout.write("\rTranscoding...(%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage)))
40+
sys.stdout.flush()
41+
42+
43+
def main():
44+
parser = argparse.ArgumentParser()
45+
46+
parser.add_argument('-b', '--bucket_name', required=True, help='Bucket name (required).')
47+
parser.add_argument('-o', '--object_name', required=True, help='object name (required).')
48+
49+
args = parser.parse_args()
50+
51+
from_google_cloud, to_google_cloud = google_cloud(args.bucket_name, args.object_name)
52+
53+
(
54+
ffmpeg_streaming
55+
.hls(from_google_cloud)
56+
.format('libx264')
57+
.auto_rep()
58+
.package('/var/www/media/stream.mpd', to_google_cloud, transcode_progress)
59+
)
60+
61+
62+
if __name__ == "__main__":
63+
sys.exit(main())

0 commit comments

Comments
 (0)