Skip to content

Commit 8808326

Browse files
clouds
1 parent b5be382 commit 8808326

20 files changed

Lines changed: 301 additions & 232 deletions

examples/_example.mp4

-290 KB
Binary file not shown.

examples/dash-from_url.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

examples/dash.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

examples/dash/dash-from_url.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import argparse
2+
import sys
3+
import ffmpeg_streaming
4+
5+
from ffmpeg_streaming.from_clouds import from_url
6+
7+
8+
def download_progress(percentage, downloaded, total):
9+
# You can update a field in your database
10+
# You can also create a socket connection and show a progress bar to users
11+
sys.stdout.write("\rDownloading...(%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage)))
12+
sys.stdout.flush()
13+
14+
15+
def transcode_progress(percentage, ffmpeg, media):
16+
# You can update a field in your database
17+
# You can also create a socket connection and show a progress bar to users
18+
sys.stdout.write("\rTranscoding...(%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage)))
19+
sys.stdout.flush()
20+
21+
22+
def main():
23+
parser = argparse.ArgumentParser()
24+
25+
parser.add_argument('-url', '--url', required=True, help='The URL to the video file.')
26+
parser.add_argument('-o', '--output', required=True, help='The output to write files.')
27+
28+
args = parser.parse_args()
29+
30+
(
31+
ffmpeg_streaming
32+
.dash(from_url(args.url, progress=download_progress), adaption='"id=0,streams=v id=1,streams=a"')
33+
.format('libx265')
34+
.auto_rep()
35+
.package(args.output, transcode_progress)
36+
)
37+
38+
39+
if __name__ == "__main__":
40+
sys.exit(main())

examples/dash/dash.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import argparse
2+
import sys
3+
import ffmpeg_streaming
4+
5+
6+
def transcode_progress(percentage, ffmpeg, media):
7+
# You can update a field in your database
8+
# You can also create a socket connection and show a progress bar to users
9+
sys.stdout.write("\rTranscoding...(%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage)))
10+
sys.stdout.flush()
11+
12+
13+
def main():
14+
parser = argparse.ArgumentParser()
15+
16+
parser.add_argument('-i', '--input', required=True, help='The path to the video file (required).')
17+
parser.add_argument('-o', '--output', default=None, help='The output to write files.')
18+
19+
args = parser.parse_args()
20+
21+
(
22+
ffmpeg_streaming
23+
.dash(args.input, adaption='"id=0,streams=v id=1,streams=a"')
24+
.format('libx265')
25+
.auto_rep()
26+
.package(args.output, transcode_progress)
27+
)
28+
29+
30+
if __name__ == "__main__":
31+
sys.exit(main())
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
import os
1+
import argparse
22
import sys
33
import ffmpeg_streaming
4+
45
from ffmpeg_streaming import Representation
56

67

7-
def progress(percentage, ffmpeg, media):
8+
def transcode_progress(percentage, ffmpeg, media):
89
# You can update a field in your database
910
# You can also create a socket connection and show a progress bar to users
10-
sys.stdout.write("\r Transcoding... (%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage)))
11+
sys.stdout.write("\rTranscoding...(%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage)))
1112
sys.stdout.flush()
1213

1314

14-
def create_dash_files(_input, _output, __progress=None):
15+
def main():
16+
parser = argparse.ArgumentParser()
17+
18+
parser.add_argument('-i', '--input', required=True, help='The path to the video file (required).')
19+
parser.add_argument('-o', '--output', default=None, help='The output to write files.')
20+
21+
args = parser.parse_args()
22+
1523
rep1 = Representation(width=256, height=144, kilo_bitrate=200, audio_k_bitrate=64)
1624
rep2 = Representation(width=854, height=480, kilo_bitrate=500, audio_k_bitrate=128)
1725
rep3 = Representation(width=1080, height=720, kilo_bitrate=1000, audio_k_bitrate=320)
1826

1927
(
2028
ffmpeg_streaming
21-
.dash(_input, adaption='"id=0,streams=v id=1,streams=a"')
29+
.dash(args.input, adaption='"id=0,streams=v id=1,streams=a"')
2230
.format('libx265')
2331
.add_rep(rep1, rep2, rep3)
24-
.package(_output, __progress)
32+
.package(args.output, transcode_progress)
2533
)
2634

2735

2836
if __name__ == "__main__":
29-
name = os.path.basename(__file__).split('.')[0]
30-
current_dir = os.path.dirname(os.path.abspath(__file__))
31-
32-
_input = os.path.join(current_dir, '_example.mp4')
33-
_output = os.path.join(current_dir, name, 'output')
34-
35-
_progress = progress
36-
37-
create_dash_files(_input, _output, _progress)
37+
sys.exit(main())

examples/hls-from_url.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

examples/hls.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

examples/hls/hls-from_url.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import argparse
2+
import sys
3+
import ffmpeg_streaming
4+
5+
from ffmpeg_streaming.from_clouds import from_url
6+
7+
8+
def download_progress(percentage, downloaded, total):
9+
# You can update a field in your database
10+
# You can also create a socket connection and show a progress bar to users
11+
sys.stdout.write("\rDownloading...(%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage)))
12+
sys.stdout.flush()
13+
14+
15+
def transcode_progress(percentage, ffmpeg, media):
16+
# You can update a field in your database
17+
# You can also create a socket connection and show a progress bar to users
18+
sys.stdout.write("\rTranscoding...(%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage)))
19+
sys.stdout.flush()
20+
21+
22+
def main():
23+
parser = argparse.ArgumentParser()
24+
25+
parser.add_argument('-url', '--url', required=True, help='The URL to the video file.')
26+
parser.add_argument('-o', '--output', required=True, help='The output to write files.')
27+
28+
args = parser.parse_args()
29+
30+
(
31+
ffmpeg_streaming
32+
.hls(from_url(args.url, progress=download_progress), hls_time=20)
33+
.format('libx264')
34+
.auto_rep()
35+
.package(args.output, progress=transcode_progress)
36+
)
37+
38+
39+
if __name__ == "__main__":
40+
sys.exit(main())

examples/hls/hls.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import argparse
2+
import sys
3+
import ffmpeg_streaming
4+
5+
6+
def transcode_progress(percentage, ffmpeg, media):
7+
# You can update a field in your database
8+
# You can also create a socket connection and show a progress bar to users
9+
sys.stdout.write("\rTranscoding...(%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage)))
10+
sys.stdout.flush()
11+
12+
13+
def main():
14+
parser = argparse.ArgumentParser()
15+
16+
parser.add_argument('-i', '--input', required=True, help='The path to the video file (required).')
17+
parser.add_argument('-o', '--output', default=None, help='The output to write files.')
18+
19+
args = parser.parse_args()
20+
21+
(
22+
ffmpeg_streaming
23+
.hls(args.input, hls_time=20)
24+
.format('libx264')
25+
.auto_rep()
26+
.package(args.output, transcode_progress)
27+
)
28+
29+
30+
if __name__ == "__main__":
31+
sys.exit(main())

0 commit comments

Comments
 (0)