10101111:license: MIT, see LICENSE for more details.
1212"""
13-
13+ import datetime
1414import sys
15+ import time
1516
1617import ffmpeg_streaming
1718from ffmpeg_streaming import Cloud
@@ -24,15 +25,8 @@ def download_progress(percentage, downloaded, total):
2425 sys .stdout .flush ()
2526
2627
27- def transcode_progress (percentage , ffmpeg ):
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 ("\r Transcoding...(%s%%)[%s%s]" % (percentage , '#' * percentage , '-' * (100 - percentage )))
31- sys .stdout .flush ()
32-
33-
34- def main ():
35- cloud = Cloud ()
28+ def cloud ():
29+ _cloud = Cloud ()
3630 download_options = {
3731 'url' : 'https://www.aminyazdanpanah.com/my_sweetie.mp4' ,
3832 'progress' : download_progress
@@ -49,8 +43,35 @@ def main():
4943 }
5044 }
5145
52- from_cloud = (cloud , download_options , None )
53- to_cloud = (cloud , upload_options )
46+ from_cloud = (_cloud , download_options , None )
47+ to_cloud = (_cloud , upload_options )
48+
49+ return from_cloud , to_cloud
50+
51+
52+ start_time = time .time ()
53+
54+
55+ def per_to_time_left (percentage ):
56+ if percentage != 0 :
57+ diff_time = time .time () - start_time
58+ seconds_left = 100 * diff_time / percentage - diff_time
59+ time_left = str (datetime .timedelta (seconds = int (seconds_left ))) + ' left'
60+ else :
61+ time_left = 'calculating...'
62+
63+ return time_left
64+
65+
66+ def transcode_progress (per , ffmpeg ):
67+ # You can update a field in your database or can log it to a file
68+ # You can also create a socket connection and show a progress bar to users
69+ sys .stdout .write ("\r Transcoding...(%s%%) %s [%s%s]" % (per , per_to_time_left (per ), '#' * per , '-' * (100 - per )))
70+ sys .stdout .flush ()
71+
72+
73+ def main ():
74+ from_cloud , to_cloud = cloud ()
5475
5576 (
5677 ffmpeg_streaming
0 commit comments