| 1 |
import cython |
| 2 |
from cython.cimports.av.audio.frame import AudioFrame |
| 3 |
from cython.cimports.av.packet import Packet |
| 4 |
|
| 5 |
|
| 6 |
@cython.final |
| 7 |
@cython.cclass |
| 8 |
class AudioStream(Stream): |
| 9 |
def __repr__(self): |
| 10 |
if self.codec_context is None: |
| 11 |
return f"<av.AudioStream #{self.index} audio/<nocodec> at 0x{id(self):x}>" |
| 12 |
form = self.format.name if self.format else None |
| 13 |
return ( |
| 14 |
f"<av.AudioStream #{self.index} {self.name} at {self.rate}Hz," |
| 15 |
f" {self.layout.name}, {form} at 0x{id(self):x}>" |
| 16 |
) |
| 17 |
|
| 18 |
def __getattr__(self, name): |
| 19 |
if self.codec_context is None: |
| 20 |
raise AttributeError( |
| 21 |
f"'{type(self).__name__}' object has no attribute '{name}'" |
| 22 |
) |
| 23 |
return getattr(self.codec_context, name) |
| 24 |
|
| 25 |
@cython.ccall |
| 26 |
def encode(self, frame: AudioFrame | None = None): |
| 27 |
""" |
| 28 |
Encode an :class:`.AudioFrame` and return a list of :class:`.Packet`. |
| 29 |
|
| 30 |
:rtype: list[Packet] |
| 31 |
|
| 32 |
.. seealso:: This is mostly a passthrough to :meth:`.CodecContext.encode`. |
| 33 |
""" |
| 34 |
|
| 35 |
packets = self.codec_context.encode(frame) |
| 36 |
packet: Packet |
| 37 |
for packet in packets: |
| 38 |
packet._stream = self |
| 39 |
packet.ptr.stream_index = self.ptr.index |
| 40 |
|
| 41 |
return packets |
| 42 |
|
| 43 |
@cython.ccall |
| 44 |
def decode(self, packet: Packet | None = None): |
| 45 |
""" |
| 46 |
Decode a :class:`.Packet` and return a list of :class:`.AudioFrame`. |
| 47 |
|
| 48 |
:rtype: list[AudioFrame] |
| 49 |
|
| 50 |
.. seealso:: This is a passthrough to :meth:`.CodecContext.decode`. |
| 51 |
""" |
| 52 |
|
| 53 |
return self.codec_context.decode(packet) |