Passed
Push — master ( 671d58...c8c24d )
by Amin
03:46
created

stream_to_file   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 2

2 Functions

Rating   Name   Duplication   Size   Complexity  
A main() 0 13 1
A progress() 0 2 1
1
"""
2
examples.conversion.stream_to_file
3
~~~~~~~~~~~~
4
5
Convert a stream(DASH or HLS) to File
6
7
8
:copyright: (c) 2020 by Amin Yazdanpanah.
9
:website: https://www.aminyazdanpanah.com
10
:email: [email protected]
11
:license: MIT, see LICENSE for more details.
12
"""
13
14
import argparse
15
import sys
16
import logging
17
18
import ffmpeg_streaming
19
20
logging.basicConfig(filename='streaming.log', level=logging.NOTSET, format='[%(asctime)s] %(levelname)s: %(message)s')
21
22
23
def progress(per, ffmpeg):
24
    sys.stdout.write("\n%s%% - %s" % (per, ffmpeg))
25
26
27
def main():
28
    parser = argparse.ArgumentParser()
29
    parser.add_argument('-i', '--input', required=True,
30
                        help='A URL to a stream manifest (HLS or DASH) (required).')
31
    parser.add_argument('-o', '--output', default=None,
32
                        help='The output to write a file. e.x. /var/www/media/new-video.mp4')
33
    args = parser.parse_args()
34
35
    (
36
        ffmpeg_streaming
37
            .stream2file(args.input)
38
            .format('libx264')
39
            .save(args.output, progress=progress)
40
    )
41
42
43
if __name__ == "__main__":
44
    sys.exit(main())
45