Skip to content

Commit 6902a2d

Browse files
add logging to examples and update readme
1 parent 2b26cee commit 6902a2d

12 files changed

Lines changed: 85 additions & 26 deletions

File tree

README.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@ video = (google_cloud, download_options, None)
5858

5959

6060
### DASH
61-
**[Dynamic Adaptive Streaming over HTTP (DASH)](https://dashif.org/)**, also known as MPEG-DASH, is an adaptive bitrate streaming technique that enables high quality streaming of media content over the Internet delivered from conventional HTTP web servers.
61+
**[Dynamic Adaptive Streaming over HTTP (DASH)](https://dashif.org/)**, also known as MPEG-DASH, is an adaptive bitrate streaming technique that enables high quality streaming of media content over the Internet delivered from conventional HTTP web servers. [Learn more](https://en.wikipedia.org/wiki/Dynamic_Adaptive_Streaming_over_HTTP)
6262

63-
Similar to Apple's HTTP Live Streaming (HLS) solution, MPEG-DASH works by breaking the content into a sequence of small HTTP-based file segments, each segment containing a short interval of playback time of content that is potentially many hours in duration, such as a movie or the live broadcast of a sports event. The content is made available at a variety of different bit rates, i.e., alternative segments encoded at different bit rates covering aligned short intervals of playback time. While the content is being played back by an MPEG-DASH client, the client uses a bit rate adaptation (ABR) algorithm to automatically select the segment with the highest bit rate possible that can be downloaded in time for playback without causing stalls or re-buffering events in the playback. The current MPEG-DASH reference client dash.js offers both buffer-based (BOLA) and hybrid (DYNAMIC) bit rate adaptation algorithms. Thus, an MPEG-DASH client can seamlessly adapt to changing network conditions and provide high quality playback with fewer stalls or re-buffering events. [Learn more](https://en.wikipedia.org/wiki/Dynamic_Adaptive_Streaming_over_HTTP)
6463

65-
Create DASH Files:
64+
Create DASH files:
6665
```python
6766
import ffmpeg_streaming
6867

@@ -74,7 +73,7 @@ import ffmpeg_streaming
7473
.package('/var/www/media/videos/dash/dash-stream.mpd')
7574
)
7675
```
77-
You can also create representations manually:
76+
Generate representations manually:
7877
```python
7978
import ffmpeg_streaming
8079
from ffmpeg_streaming import Representation
@@ -85,7 +84,7 @@ r_360p = Representation(width=640, height=360, kilo_bitrate=276)
8584
r_480p = Representation(width=854, height=480, kilo_bitrate=750)
8685
r_720p = Representation(width=1280, height=720, kilo_bitrate=2048)
8786
r_1080p = Representation(width=1920, height=1080, kilo_bitrate=4096)
88-
r_2k = Representation(width=2560, height=1440, kilo_bitrate=6144)
87+
r_2k = Representation(width=2560, height=1440, kilo_bitrate=6144)
8988
r_4k = Representation(width=3840, height=2160, kilo_bitrate=17408)
9089

9190
(
@@ -97,16 +96,12 @@ r_4k = Representation(width=3840, height=2160, kilo_bitrate=17408)
9796
)
9897

9998
```
100-
See **[DASH examples](https://github.com/aminyazdanpanah/python-ffmpeg-video-streaming/tree/master/examples/dash)** for more information.
101-
102-
See also **[DASH options](https://ffmpeg.org/ffmpeg-formats.html#dash-2)** for more information about options.
99+
See **[DASH examples](https://github.com/aminyazdanpanah/python-ffmpeg-video-streaming/tree/master/examples/dash)** and **[DASH options](https://ffmpeg.org/ffmpeg-formats.html#dash-2)** for more information.
103100

104101
### HLS
105-
**[HTTP Live Streaming (also known as HLS)](https://developer.apple.com/streaming/)** is an HTTP-based adaptive bitrate streaming communications protocol implemented by Apple Inc. as part of its QuickTime, Safari, OS X, and iOS software. Client implementations are also available in Microsoft Edge, Firefox and some versions of Google Chrome. Support is widespread in streaming media servers.
102+
**[HTTP Live Streaming (also known as HLS)](https://developer.apple.com/streaming/)** is an HTTP-based adaptive bitrate streaming communications protocol implemented by Apple Inc. as part of its QuickTime, Safari, OS X, and iOS software. Client implementations are also available in Microsoft Edge, Firefox and some versions of Google Chrome. Support is widespread in streaming media servers. [Learn more](https://en.wikipedia.org/wiki/HTTP_Live_Streaming)
106103

107-
HLS resembles MPEG-DASH in that it works by breaking the overall stream into a sequence of small HTTP-based file downloads, each download loading one short chunk of an overall potentially unbounded transport stream. A list of available streams, encoded at different bit rates, is sent to the client using an extended M3U playlist. [Learn more](https://en.wikipedia.org/wiki/HTTP_Live_Streaming)
108-
109-
Create HLS files based on original video(auto generate qualities).
104+
Create HLS files:
110105
```python
111106
import ffmpeg_streaming
112107

@@ -119,7 +114,7 @@ import ffmpeg_streaming
119114
)
120115
```
121116

122-
You can also create representations manually:
117+
Generate representations manually:
123118
```python
124119
import ffmpeg_streaming
125120
from ffmpeg_streaming import Representation
@@ -144,14 +139,15 @@ The encryption process requires some kind of secret (key) together with an encry
144139
You must specify a path to save a random key to your local machine and also a URL(or a path) to access the key on your website(the key you will save must be accessible from your website). You must pass both these parameters to the `encryption` method:
145140

146141
```python
142+
import ffmpeg_streaming
143+
147144
#A path you want to save a random key to your server
148145
save_to = '/home/public_html/PATH_TO_KEY_DIRECTORY/random_key.key'
149146

150147
#A URL (or a path) to access the key on your website
151148
url = 'https://www.aminyazdanpanah.com/PATH_TO_KEY_DIRECTORY/random_key.key'
152149
# or url = '/PATH_TO_KEY_DIRECTORY/random_key.key'
153150

154-
import ffmpeg_streaming
155151
(
156152
ffmpeg_streaming
157153
.hls(video, hls_time=10, hls_allow_cache=1)
@@ -162,19 +158,26 @@ import ffmpeg_streaming
162158
)
163159
```
164160
**NOTE:** It is very important to protect your key on your website using a token or a session/cookie(****It is highly recommended****).
165-
See **[HLS examples](https://github.com/aminyazdanpanah/python-ffmpeg-video-streaming/tree/master/examples/hls)** for more information.
166161

167-
See also **[HLS options](https://ffmpeg.org/ffmpeg-formats.html#hls-2)** for more information about options.
162+
See **[HLS examples](https://github.com/aminyazdanpanah/python-ffmpeg-video-streaming/tree/master/examples/hls)** and **[HLS options](https://ffmpeg.org/ffmpeg-formats.html#hls-2)** for more information.
168163

169164
### Progress
170-
You can get realtime information about transcoding by passing callable methods to the `package`:
165+
You can get realtime information about transcoding by passing a callable method to the `package` method:
171166
```python
172167
import sys
168+
import time
169+
import logging
170+
173171
import ffmpeg_streaming
174172

173+
174+
start_time = time.time()
175+
logging.basicConfig(filename='Transcoding-' + str(start_time) + '.log', level=logging.DEBUG)
176+
175177
def progress(percentage, ffmpeg):
176178
# You can update a field in your database
177179
# You can also create a socket connection and show a progress bar to users
180+
logging.debug(ffmpeg)
178181
sys.stdout.write("\rTranscoding...(%s%%)[%s%s]" % (percentage, '#' * percentage, '-' * (100 - percentage)))
179182
sys.stdout.flush()
180183

@@ -187,11 +190,11 @@ def progress(percentage, ffmpeg):
187190
.package('/var/www/media/videos/hls/hls-stream.m3u8', progress=progress)
188191
)
189192
```
190-
Output of the progress:
193+
Output from a terminal:
191194
![transcoding](https://github.com/aminyazdanpanah/aminyazdanpanah.github.io/blob/master/video-streaming/transcoding.gif?raw=true "transcoding" )
192195

193196
### Saving Files
194-
There are several options to save your files.
197+
There are two ways to save your files.
195198

196199
#### 1. To a Local Path
197200
You can pass a local path to the `package` method. If there was no directory in the path, then the package auto makes the directory.
@@ -214,10 +217,10 @@ It can also be null. The default path to save files is the input path.
214217
.package(progress=progress)
215218
)
216219
```
217-
**NOTE:** If you open a file from cloud and did not pass a path to save a file, you will have to pass a local path to the `package` method.
220+
**NOTE:** If you open a file from a cloud and do not pass a path to save the file to your local machine, you will have to pass a local path to the `package` method.
218221

219222
#### 2. To Clouds
220-
You can save your files to clouds by passing a array of cloud configuration to the `package` method.
223+
You can save your files to a cloud by passing an array of cloud configuration to the `package` method.
221224

222225
In **[this page](https://video.aminyazdanpanah.com/python/start/clouds?r=save)**, you will find some examples of saving files to **[Amazon S3](https://aws.amazon.com/s3)**, **[Google Cloud Storage](https://console.cloud.google.com/storage)**, **[Microsoft Azure Storage](https://azure.microsoft.com/en-us/features/storage-explorer/)**, and a custom cloud.
223226

@@ -231,7 +234,7 @@ In **[this page](https://video.aminyazdanpanah.com/python/start/clouds?r=save)**
231234
progress=progress)
232235
)
233236
```
234-
A path can also be passed to save a copy of files on your local machine.
237+
A path can also be passed to save a copy of files to your local machine.
235238
```python
236239
(
237240
ffmpeg_streaming
@@ -243,13 +246,11 @@ A path can also be passed to save a copy of files on your local machine.
243246
)
244247
```
245248

246-
247-
**NOTE:** You can open a file from your local machine(or a cloud) and save files to a local path or a cloud(or multiple clouds) or both.
248-
249+
**Schema:** The relation is `one-to-many`.
249250
<p align="center"><img src="https://github.com/aminyazdanpanah/aminyazdanpanah.github.io/blob/master/video-streaming/video-streaming.gif?raw=true" width="100%"></p>
250251

251252
### Probe
252-
You can extract the metadata of video file using the following code:
253+
You can extract the metadata of the video file using the following code:
253254
```python
254255
from ffmpeg_streaming import FFProbe
255256

examples/clouds/aws_cloud.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import argparse
1515
import datetime
16+
import logging
1617
import sys
1718
import tempfile
1819
import time
@@ -78,6 +79,7 @@ def aws_cloud(bucket_name, key):
7879

7980

8081
start_time = time.time()
82+
logging.basicConfig(filename='Transcoding-' + str(start_time) + '.log', level=logging.DEBUG)
8183

8284

8385
def per_to_time_left(percentage):
@@ -94,6 +96,7 @@ def per_to_time_left(percentage):
9496
def transcode_progress(per, ffmpeg):
9597
# You can update a field in your database or can log it to a file
9698
# You can also create a socket connection and show a progress bar to users
99+
logging.debug(ffmpeg)
97100
sys.stdout.write("\rTranscoding...(%s%%) %s [%s%s]" % (per, per_to_time_left(per), '#' * per, '-' * (100 - per)))
98101
sys.stdout.flush()
99102

examples/clouds/azure_cloud.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import argparse
1515
import datetime
16+
import logging
1617
import sys
1718
import tempfile
1819
import time
@@ -67,6 +68,7 @@ def azure_cloud(container, blob):
6768

6869

6970
start_time = time.time()
71+
logging.basicConfig(filename='Transcoding-' + str(start_time) + '.log', level=logging.DEBUG)
7072

7173

7274
def per_to_time_left(percentage):
@@ -83,6 +85,7 @@ def per_to_time_left(percentage):
8385
def transcode_progress(per, ffmpeg):
8486
# You can update a field in your database or can log it to a file
8587
# You can also create a socket connection and show a progress bar to users
88+
logging.debug(ffmpeg)
8689
sys.stdout.write("\rTranscoding...(%s%%) %s [%s%s]" % (per, per_to_time_left(per), '#' * per, '-' * (100 - per)))
8790
sys.stdout.flush()
8891

examples/clouds/cloud.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
:license: MIT, see LICENSE for more details.
1212
"""
1313
import datetime
14+
import logging
1415
import socket
1516
import sys
1617
import tempfile
@@ -110,6 +111,7 @@ def cloud():
110111

111112

112113
start_time = time.time()
114+
logging.basicConfig(filename='Transcoding-' + str(start_time) + '.log', level=logging.DEBUG)
113115

114116

115117
def per_to_time_left(percentage):
@@ -126,6 +128,7 @@ def per_to_time_left(percentage):
126128
def transcode_progress(per, ffmpeg):
127129
# You can update a field in your database or can log it to a file
128130
# You can also create a socket connection and show a progress bar to users
131+
logging.debug(ffmpeg)
129132
sys.stdout.write("\rTranscoding...(%s%%) %s [%s%s]" % (per, per_to_time_left(per), '#' * per, '-' * (100 - per)))
130133
sys.stdout.flush()
131134

examples/clouds/custom_cloud.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
:license: MIT, see LICENSE for more details.
1212
"""
1313
import datetime
14+
import logging
1415
import sys
1516
import time
1617

@@ -46,6 +47,7 @@ def custom_cloud():
4647

4748

4849
start_time = time.time()
50+
logging.basicConfig(filename='Transcoding-' + str(start_time) + '.log', level=logging.DEBUG)
4951

5052

5153
def per_to_time_left(percentage):
@@ -62,6 +64,7 @@ def per_to_time_left(percentage):
6264
def transcode_progress(per, ffmpeg):
6365
# You can update a field in your database or can log it to a file
6466
# You can also create a socket connection and show a progress bar to users
67+
logging.debug(ffmpeg)
6568
sys.stdout.write("\rTranscoding...(%s%%) %s [%s%s]" % (per, per_to_time_left(per), '#' * per, '-' * (100 - per)))
6669
sys.stdout.flush()
6770

examples/clouds/google_cloud.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import argparse
1515
import datetime
16+
import logging
1617
import sys
1718
import tempfile
1819
import time
@@ -70,6 +71,7 @@ def google_cloud(bucket_name, object_name):
7071

7172

7273
start_time = time.time()
74+
logging.basicConfig(filename='Transcoding-' + str(start_time) + '.log', level=logging.DEBUG)
7375

7476

7577
def per_to_time_left(percentage):
@@ -86,6 +88,7 @@ def per_to_time_left(percentage):
8688
def transcode_progress(per, ffmpeg):
8789
# You can update a field in your database or can log it to a file
8890
# You can also create a socket connection and show a progress bar to users
91+
logging.debug(ffmpeg)
8992
sys.stdout.write("\rTranscoding...(%s%%) %s [%s%s]" % (per, per_to_time_left(per), '#' * per, '-' * (100 - per)))
9093
sys.stdout.flush()
9194

examples/clouds/multiple_clouds.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
:license: MIT, see LICENSE for more details.
1212
"""
1313
import datetime
14+
import logging
1415
import sys
1516
import time
1617

@@ -21,6 +22,7 @@
2122

2223

2324
start_time = time.time()
25+
logging.basicConfig(filename='Transcoding-' + str(start_time) + '.log', level=logging.DEBUG)
2426

2527

2628
def per_to_time_left(percentage):
@@ -37,6 +39,7 @@ def per_to_time_left(percentage):
3739
def transcode_progress(per, ffmpeg):
3840
# You can update a field in your database or can log it to a file
3941
# You can also create a socket connection and show a progress bar to users
42+
logging.debug(ffmpeg)
4043
sys.stdout.write("\rTranscoding...(%s%%) %s [%s%s]" % (per, per_to_time_left(per), '#' * per, '-' * (100 - per)))
4144
sys.stdout.flush()
4245

examples/dash/dash.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
import datetime
1616
import sys
1717
import time
18+
import logging
1819

1920
import ffmpeg_streaming
2021

2122

2223
start_time = time.time()
24+
logging.basicConfig(filename='Transcoding-' + str(start_time) + '.log', level=logging.DEBUG)
2325

2426

2527
def per_to_time_left(percentage):
@@ -36,6 +38,7 @@ def per_to_time_left(percentage):
3638
def transcode_progress(per, ffmpeg):
3739
# You can update a field in your database or can log it to a file
3840
# You can also create a socket connection and show a progress bar to users
41+
logging.debug(ffmpeg)
3942
sys.stdout.write("\rTranscoding...(%s%%) %s [%s%s]" % (per, per_to_time_left(per), '#' * per, '-' * (100 - per)))
4043
sys.stdout.flush()
4144

@@ -48,6 +51,9 @@ def main():
4851

4952
args = parser.parse_args()
5053

54+
logging.debug("input: " + args.input
55+
+ ", output: " + str(args.output)
56+
+ ", datetime: " + str(datetime.datetime.now()))
5157
(
5258
ffmpeg_streaming
5359
.dash(args.input, adaption='"id=0,streams=v id=1,streams=a"')

examples/dash/dash_manual.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515
import datetime
1616
import sys
1717
import time
18+
import logging
1819

1920
import ffmpeg_streaming
2021

2122
from ffmpeg_streaming import Representation
2223

24+
start_time = time.time()
25+
logging.basicConfig(filename='Transcoding-' + str(start_time) + '.log', level=logging.DEBUG)
26+
2327

2428
start_time = time.time()
2529

@@ -38,6 +42,7 @@ def per_to_time_left(percentage):
3842
def transcode_progress(per, ffmpeg):
3943
# You can update a field in your database or can log it to a file
4044
# You can also create a socket connection and show a progress bar to users
45+
logging.debug(ffmpeg)
4146
sys.stdout.write("\rTranscoding...(%s%%) %s [%s%s]" % (per, per_to_time_left(per), '#' * per, '-' * (100 - per)))
4247
sys.stdout.flush()
4348

@@ -50,6 +55,10 @@ def main():
5055

5156
args = parser.parse_args()
5257

58+
logging.debug("input: " + args.input
59+
+ ", output: " + str(args.output)
60+
+ ", datetime: " + str(datetime.datetime.now()))
61+
5362
rep1 = Representation(width=256, height=144, kilo_bitrate=200, audio_k_bitrate=64)
5463
rep2 = Representation(width=854, height=480, kilo_bitrate=500, audio_k_bitrate=128)
5564
rep3 = Representation(width=1080, height=720, kilo_bitrate=1000, audio_k_bitrate=320)

0 commit comments

Comments
 (0)