-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move encode and decode to concrete classes
- Loading branch information
Showing
7 changed files
with
99 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,36 @@ | ||
from av.packet cimport Packet | ||
|
||
|
||
cdef class AudioStream(Stream): | ||
def __repr__(self): | ||
form = self.format.name if self.format else None | ||
return ( | ||
f"<av.{self.__class__.__name__} #{self.index} {self.name} at {self.rate}Hz," | ||
f"<av.AudioStream #{self.index} {self.name} at {self.rate}Hz," | ||
f" {self.layout.name}, {form} at 0x{id(self):x}>" | ||
) | ||
|
||
def encode(self, frame=None): | ||
""" | ||
Encode an :class:`.AudioFrame` and return a list of :class:`.Packet`. | ||
:return: :class:`list` of :class:`.Packet`. | ||
.. seealso:: This is mostly a passthrough to :meth:`.CodecContext.encode`. | ||
""" | ||
|
||
packets = self.codec_context.encode(frame) | ||
cdef Packet packet | ||
for packet in packets: | ||
packet._stream = self | ||
packet.ptr.stream_index = self.ptr.index | ||
|
||
return packets | ||
|
||
def decode(self, packet=None): | ||
""" | ||
Decode a :class:`.Packet` and return a list of :class:`.AudioFrame`. | ||
:return: :class:`list` of :class:`.AudioFrame` | ||
.. seealso:: This is a passthrough to :meth:`.CodecContext.decode`. | ||
""" | ||
|
||
return self.codec_context.decode(packet) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
from av.packet cimport Packet | ||
|
||
|
||
cdef class VideoStream(Stream): | ||
def __repr__(self): | ||
return ( | ||
f"<av.{self.__class__.__name__} #{self.index} {self.name}, " | ||
f"<av.VideoStream #{self.index} {self.name}, " | ||
f"{self.format.name if self.format else None} {self.codec_context.width}x" | ||
f"{self.codec_context.height} at 0x{id(self):x}>" | ||
) | ||
|
||
def encode(self, frame=None): | ||
""" | ||
Encode an :class:`.VideoFrame` and return a list of :class:`.Packet`. | ||
:return: :class:`list` of :class:`.Packet`. | ||
.. seealso:: This is mostly a passthrough to :meth:`.CodecContext.encode`. | ||
""" | ||
|
||
packets = self.codec_context.encode(frame) | ||
cdef Packet packet | ||
for packet in packets: | ||
packet._stream = self | ||
packet.ptr.stream_index = self.ptr.index | ||
|
||
return packets | ||
|
||
|
||
def decode(self, packet=None): | ||
""" | ||
Decode a :class:`.Packet` and return a list of :class:`.VideoFrame`. | ||
:return: :class:`list` of :class:`.Frame` subclasses. | ||
.. seealso:: This is a passthrough to :meth:`.CodecContext.decode`. | ||
""" | ||
|
||
return self.codec_context.decode(packet) |