Skip to content

Commit

Permalink
See if we can not inherit from object
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Oct 25, 2023
1 parent 6d5b375 commit 672944a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 41 deletions.
49 changes: 15 additions & 34 deletions av/format.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cdef object _cinit_bypass_sentinel = object()

cdef ContainerFormat build_container_format(lib.AVInputFormat* iptr, lib.AVOutputFormat* optr):
if not iptr and not optr:
raise ValueError('needs input format or output format')
raise ValueError("needs input format or output format")
cdef ContainerFormat format = ContainerFormat.__new__(ContainerFormat, _cinit_bypass_sentinel)
format.iptr = iptr
format.optr = optr
Expand All @@ -18,31 +18,24 @@ cdef ContainerFormat build_container_format(lib.AVInputFormat* iptr, lib.AVOutpu

Flags = define_enum('Flags', __name__, (
('NOFILE', lib.AVFMT_NOFILE),
('NEEDNUMBER', lib.AVFMT_NEEDNUMBER,
"""Needs '%d' in filename."""),
('SHOW_IDS', lib.AVFMT_SHOW_IDS,
"""Show format stream IDs numbers."""),
('GLOBALHEADER', lib.AVFMT_GLOBALHEADER,
"""Format wants global header."""),
('NEEDNUMBER', lib.AVFMT_NEEDNUMBER, "Needs '%d' in filename."),
('SHOW_IDS', lib.AVFMT_SHOW_IDS, "Show format stream IDs numbers."),
('GLOBALHEADER', lib.AVFMT_GLOBALHEADER, "Format wants global header."),
('NOTIMESTAMPS', lib.AVFMT_NOTIMESTAMPS,
"""Format does not need / have any timestamps."""),
('GENERIC_INDEX', lib.AVFMT_GENERIC_INDEX,
"""Use generic index building code."""),
"Format does not need / have any timestamps."),
('GENERIC_INDEX', lib.AVFMT_GENERIC_INDEX, "Use generic index building code."),
('TS_DISCONT', lib.AVFMT_TS_DISCONT,
"""Format allows timestamp discontinuities.
Note, muxers always require valid (monotone) timestamps"""),
('VARIABLE_FPS', lib.AVFMT_VARIABLE_FPS,
"""Format allows variable fps."""),
('NODIMENSIONS', lib.AVFMT_NODIMENSIONS,
"""Format does not need width/height"""),
('NOSTREAMS', lib.AVFMT_NOSTREAMS,
"""Format does not require any streams"""),
('VARIABLE_FPS', lib.AVFMT_VARIABLE_FPS, "Format allows variable fps."),
('NODIMENSIONS', lib.AVFMT_NODIMENSIONS, "Format does not need width/height"),
('NOSTREAMS', lib.AVFMT_NOSTREAMS, "Format does not require any streams"),
('NOBINSEARCH', lib.AVFMT_NOBINSEARCH,
"""Format does not allow to fall back on binary search via read_timestamp"""),
"Format does not allow to fall back on binary search via read_timestamp"),
('NOGENSEARCH', lib.AVFMT_NOGENSEARCH,
"""Format does not allow to fall back on generic search"""),
"Format does not allow to fall back on generic search"),
('NO_BYTE_SEEK', lib.AVFMT_NO_BYTE_SEEK,
"""Format does not allow seeking by bytes"""),
"Format does not allow seeking by bytes"),
('ALLOW_FLUSH', lib.AVFMT_ALLOW_FLUSH,
"""Format allows flushing. If not set, the muxer will not receive a NULL
packet in the write_packet function."""),
Expand All @@ -54,23 +47,12 @@ Flags = define_enum('Flags', __name__, (
will be shifted in av_write_frame and av_interleaved_write_frame so they
start from 0. The user or muxer can override this through
AVFormatContext.avoid_negative_ts"""),
('SEEK_TO_PTS', lib.AVFMT_SEEK_TO_PTS,
"""Seeking is based on PTS"""),
('SEEK_TO_PTS', lib.AVFMT_SEEK_TO_PTS, "Seeking is based on PTS"),
), is_flags=True)


cdef class ContainerFormat(object):

"""Descriptor of a container format.
:param str name: The name of the format.
:param str mode: ``'r'`` or ``'w'`` for input and output formats; defaults
to None which will grab either.
"""

cdef class ContainerFormat:
def __cinit__(self, name, mode=None):

if name is _cinit_bypass_sentinel:
return

Expand All @@ -90,7 +72,7 @@ cdef class ContainerFormat(object):
raise ValueError('no container format %r' % name)

def __repr__(self):
return '<av.%s %r>' % (self.__class__.__name__, self.name)
return f"<av.{self.__class__.__name__} {self.name!r}>"

property descriptor:
def __get__(self):
Expand Down Expand Up @@ -199,5 +181,4 @@ cdef get_input_format_names():
formats_available = get_output_format_names()
formats_available.update(get_input_format_names())


format_descriptor = wrap_avclass(lib.avformat_get_class())
8 changes: 1 addition & 7 deletions av/frame.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ from fractions import Fraction
from av.sidedata.sidedata import SideDataContainer


cdef class Frame(object):
"""
Base class for audio and video frames.
See also :class:`~av.audio.frame.AudioFrame` and :class:`~av.video.frame.VideoFrame`.
"""

cdef class Frame:
def __cinit__(self, *args, **kwargs):
with nogil:
self.ptr = lib.av_frame_alloc()
Expand Down

0 comments on commit 672944a

Please sign in to comment.