Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions av/audio/stream.pyx → av/audio/stream.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from av.packet cimport Packet
import cython
from cython.cimports.av.audio.frame import AudioFrame
from cython.cimports.av.packet import Packet

from .frame cimport AudioFrame


cdef class AudioStream(Stream):
@cython.cclass
class AudioStream(Stream):
def __repr__(self):
form = self.format.name if self.format else None
return (
Expand All @@ -14,7 +15,8 @@ def __repr__(self):
def __getattr__(self, name):
return getattr(self.codec_context, name)

cpdef encode(self, AudioFrame frame=None):
@cython.ccall
def encode(self, frame: AudioFrame | None = None):
"""
Encode an :class:`.AudioFrame` and return a list of :class:`.Packet`.

Expand All @@ -24,14 +26,15 @@ def __getattr__(self, name):
"""

packets = self.codec_context.encode(frame)
cdef Packet packet
packet: Packet
for packet in packets:
packet._stream = self
packet.ptr.stream_index = self.ptr.index

return packets

cpdef decode(self, Packet packet=None):
@cython.ccall
def decode(self, packet: Packet | None = None):
"""
Decode a :class:`.Packet` and return a list of :class:`.AudioFrame`.

Expand Down
Loading