File tree Expand file tree Collapse file tree 5 files changed +28
-9
lines changed Expand file tree Collapse file tree 5 files changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,12 @@ class InputContainer(Container):
21
21
def close (self ) -> None : ...
22
22
def demux (self , * args : Any , ** kwargs : Any ) -> Iterator [Packet ]: ...
23
23
@overload
24
+ def decode (self , video : int ) -> Iterator [VideoFrame ]: ...
25
+ @overload
26
+ def decode (self , audio : int ) -> Iterator [AudioFrame ]: ...
27
+ @overload
28
+ def decode (self , subtitles : int ) -> Iterator [SubtitleSet ]: ...
29
+ @overload
24
30
def decode (self , * args : VideoStream ) -> Iterator [VideoFrame ]: ...
25
31
@overload
26
32
def decode (self , * args : AudioStream ) -> Iterator [AudioFrame ]: ...
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ from av.filter.context cimport FilterContext
4
4
5
5
6
6
cdef class Graph:
7
-
8
7
cdef lib.AVFilterGraph * ptr
9
8
10
9
cdef readonly bint configured
Original file line number Diff line number Diff line change @@ -41,3 +41,5 @@ class Graph:
41
41
) -> FilterContext : ...
42
42
def push (self , frame : None | AudioFrame | VideoFrame ) -> None : ...
43
43
def pull (self ) -> VideoFrame | AudioFrame : ...
44
+ def vpush (self , frame : VideoFrame | None ) -> None : ...
45
+ def vpull (self ) -> VideoFrame : ...
Original file line number Diff line number Diff line change @@ -174,11 +174,15 @@ cdef class Graph:
174
174
else :
175
175
raise ValueError (f" can only AudioFrame, VideoFrame or None; got {type(frame)}" )
176
176
177
- if len (contexts) ! = 1 :
178
- raise ValueError (f " can only auto- push with single buffer; found {len(contexts)} " )
177
+ for ctx in contexts :
178
+ ctx. push(frame )
179
179
180
- contexts[0 ].push(frame)
180
+ def vpush (self , VideoFrame frame ):
181
+ for ctx in self ._context_by_type.get(" buffer" , []):
182
+ ctx.push(frame)
181
183
184
+
185
+ # TODO: Test complex filter graphs, add `at: int = 0` arg to pull() and vpull().
182
186
def pull (self ):
183
187
vsinks = self ._context_by_type.get(" buffersink" , [])
184
188
asinks = self ._context_by_type.get(" abuffersink" , [])
@@ -188,3 +192,11 @@ cdef class Graph:
188
192
raise ValueError (f" can only auto-pull with single sink; found {nsinks}" )
189
193
190
194
return (vsinks or asinks)[0 ].pull()
195
+
196
+ def vpull (self ):
197
+ vsinks = self ._context_by_type.get(" buffersink" , [])
198
+ nsinks = len (vsinks)
199
+ if nsinks != 1 :
200
+ raise ValueError (f" can only auto-pull with single sink; found {nsinks}" )
201
+
202
+ return vsinks[0 ].pull()
Original file line number Diff line number Diff line change @@ -204,7 +204,7 @@ def test_video_buffer(self):
204
204
205
205
for frame in input_container .decode ():
206
206
self .assertEqual (frame .time_base , Fraction (1 , 30 ))
207
- graph .push (frame )
207
+ graph .vpush (frame )
208
208
filtered_frames = pull_until_blocked (graph )
209
209
210
210
if frame .pts == 0 :
@@ -220,7 +220,7 @@ def test_video_buffer(self):
220
220
self .assertEqual (filtered_frames [1 ].pts , (frame .pts - 1 ) * 2 + 1 )
221
221
self .assertEqual (filtered_frames [1 ].time_base , Fraction (1 , 60 ))
222
222
223
- def test_EOF (self ):
223
+ def test_EOF (self ) -> None :
224
224
input_container = av .open (format = "lavfi" , file = "color=c=pink:duration=1:r=30" )
225
225
video_stream = input_container .streams .video [0 ]
226
226
@@ -233,12 +233,12 @@ def test_EOF(self):
233
233
graph .configure ()
234
234
235
235
for frame in input_container .decode (video = 0 ):
236
- graph .push (frame )
236
+ graph .vpush (frame )
237
237
238
- graph .push (None )
238
+ graph .vpush (None )
239
239
240
240
# if we do not push None, we get a BlockingIOError
241
- palette_frame = graph .pull ()
241
+ palette_frame = graph .vpull ()
242
242
243
243
self .assertIsInstance (palette_frame , av .VideoFrame )
244
244
self .assertEqual (palette_frame .width , 16 )
You can’t perform that action at this time.
0 commit comments