Skip to content

Commit 5005628

Browse files
author
root
committed
Set filter graph threads to 1 for thread safety
Set the filter graph thread count to 1 in Graph.__cinit__ to prevent potential thread safety issues when using filter graphs in multi-threaded applications. By default, FFmpeg's filter graph may use multiple threads for parallel filter execution. However, this can cause race conditions or unexpected behavior when the filter graph is accessed from Python code that isn't designed for concurrent access. Setting threads=1 ensures deterministic, single-threaded filter execution, which is safer for typical PyAV usage patterns.
1 parent 8fb7d1d commit 5005628

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

av/filter/graph.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ from av.video.frame cimport VideoFrame
1414
cdef class Graph:
1515
def __cinit__(self):
1616
self.ptr = lib.avfilter_graph_alloc()
17+
lib.av_opt_set_int(self.ptr, "threads", 1, 0)
1718
self.configured = False
1819
self._name_counts = {}
1920

0 commit comments

Comments
 (0)