Debian Codegraph @

examples/basics/thread_type.py

raw
1 import time
2
3 import av
4 import av.datasets
5
6 print("Decoding with default (slice) threading...")
7
8 container = av.open(
9 av.datasets.curated("pexels/time-lapse-video-of-night-sky-857195.mp4")
10 )
11
12 start_time = time.time()
13 for packet in container.demux():
14 print(packet)
15 for frame in packet.decode():
16 print(frame)
17
18 default_time = time.time() - start_time
19 container.close()
20
21
22 print("Decoding with auto threading...")
23
24 container = av.open(
25 av.datasets.curated("pexels/time-lapse-video-of-night-sky-857195.mp4")
26 )
27
28 # !!! This is the only difference.
29 container.streams.video[0].thread_type = "AUTO"
30
31 start_time = time.time()
32 for packet in container.demux():
33 print(packet)
34 for frame in packet.decode():
35 print(frame)
36
37 auto_time = time.time() - start_time
38 container.close()
39
40
41 print("Decoded with default threading in {:.2f}s.".format(default_time))
42 print("Decoded with auto threading in {:.2f}s.".format(auto_time))