Skip to content

Commit

Permalink
Remove setup.cfg, drop flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Nov 23, 2023
1 parent 594c037 commit 5d628cf
Show file tree
Hide file tree
Showing 27 changed files with 125 additions and 196 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ jobs:
- name: Packages
run: |
. scripts/activate.sh
python -m pip install black flake8 isort
python -m pip install black isort
- name: "Test Style"
run: |
python -m black av examples tests
python -m flake8 av examples tests
python -m isort --profile black --check-only --diff av examples tests
nix:
Expand Down
1 change: 0 additions & 1 deletion av/_core.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
cimport libav as lib


# Initialise libraries.
lib.avformat_network_init()
lib.avdevice_register_all()
Expand Down
2 changes: 1 addition & 1 deletion av/audio/fifo.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from libc.stdint cimport int64_t, uint64_t
cimport libav as lib
from libc.stdint cimport int64_t, uint64_t

from av.audio.frame cimport AudioFrame

Expand Down
2 changes: 1 addition & 1 deletion av/audio/frame.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from libc.stdint cimport uint8_t, uint64_t
cimport libav as lib
from libc.stdint cimport uint8_t, uint64_t

from av.audio.format cimport AudioFormat
from av.audio.layout cimport AudioLayout
Expand Down
2 changes: 1 addition & 1 deletion av/codec/context.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from libc.stdint cimport int64_t
cimport libav as lib
from libc.stdint cimport int64_t

from av.bytesource cimport ByteSource
from av.codec.codec cimport Codec
Expand Down
222 changes: 91 additions & 131 deletions av/codec/context.pyx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import warnings

cimport libav as lib
from libc.errno cimport EAGAIN
from libc.stdint cimport uint8_t
from libc.string cimport memcpy
cimport libav as lib

from av.bytesource cimport ByteSource, bytesource
from av.codec.codec cimport Codec, wrap_codec
Expand Down Expand Up @@ -43,100 +43,70 @@ cdef CodecContext wrap_codec_context(lib.AVCodecContext *c_ctx, const lib.AVCode
return py_ctx


ThreadType = define_enum('ThreadType', __name__, (
('NONE', 0),
('FRAME', lib.FF_THREAD_FRAME,
"""Decode more than one frame at once"""),
('SLICE', lib.FF_THREAD_SLICE,
"""Decode more than one part of a single frame at once"""),
('AUTO', lib.FF_THREAD_SLICE | lib.FF_THREAD_FRAME,
"""Decode using both FRAME and SLICE methods."""),
ThreadType = define_enum("ThreadType", __name__, (
("NONE", 0),
("FRAME", lib.FF_THREAD_FRAME, "Decode more than one frame at once"),
("SLICE", lib.FF_THREAD_SLICE, "Decode more than one part of a single frame at once"),
("AUTO", lib.FF_THREAD_SLICE | lib.FF_THREAD_FRAME, "Decode using both FRAME and SLICE methods."),
), is_flags=True)

SkipType = define_enum('SkipType', __name__, (
('NONE', lib.AVDISCARD_NONE,
"""Discard nothing"""),
('DEFAULT', lib.AVDISCARD_DEFAULT,
"""Discard useless packets like 0 size packets in AVI"""),
('NONREF', lib.AVDISCARD_NONREF,
"""Discard all non reference"""),
('BIDIR', lib.AVDISCARD_BIDIR,
"""Discard all bidirectional frames"""),
('NONINTRA', lib.AVDISCARD_NONINTRA,
"""Discard all non intra frames"""),
('NONKEY', lib.AVDISCARD_NONKEY,
"""Discard all frames except keyframes"""),
('ALL', lib.AVDISCARD_ALL,
"""Discard all"""),
SkipType = define_enum("SkipType", __name__, (
("NONE", lib.AVDISCARD_NONE, "Discard nothing"),
("DEFAULT", lib.AVDISCARD_DEFAULT, "Discard useless packets like 0 size packets in AVI"),
("NONREF", lib.AVDISCARD_NONREF, "Discard all non reference"),
("BIDIR", lib.AVDISCARD_BIDIR, "Discard all bidirectional frames"),
("NONINTRA", lib.AVDISCARD_NONINTRA, "Discard all non intra frames"),
("NONKEY", lib.AVDISCARD_NONKEY, "Discard all frames except keyframes"),
("ALL", lib.AVDISCARD_ALL, "Discard all"),
))

Flags = define_enum('Flags', __name__, (
('NONE', 0),
('UNALIGNED', lib.AV_CODEC_FLAG_UNALIGNED,
Flags = define_enum("Flags", __name__, (
("NONE", 0),
("UNALIGNED", lib.AV_CODEC_FLAG_UNALIGNED,
"""Allow decoders to produce frames with data planes that are not aligned
to CPU requirements (e.g. due to cropping)."""),
('QSCALE', lib.AV_CODEC_FLAG_QSCALE,
"""Use fixed qscale."""),
('4MV', lib.AV_CODEC_FLAG_4MV,
"""4 MV per MB allowed / advanced prediction for H.263."""),
('OUTPUT_CORRUPT', lib.AV_CODEC_FLAG_OUTPUT_CORRUPT,
"""Output even those frames that might be corrupted."""),
('QPEL', lib.AV_CODEC_FLAG_QPEL,
"""Use qpel MC."""),
('DROPCHANGED', 1 << 5,
("QSCALE", lib.AV_CODEC_FLAG_QSCALE, "Use fixed qscale."),
("4MV", lib.AV_CODEC_FLAG_4MV, "4 MV per MB allowed / advanced prediction for H.263."),
("OUTPUT_CORRUPT", lib.AV_CODEC_FLAG_OUTPUT_CORRUPT, "Output even those frames that might be corrupted."),
("QPEL", lib.AV_CODEC_FLAG_QPEL, "Use qpel MC."),
("DROPCHANGED", 1 << 5,
"""Don't output frames whose parameters differ from first
decoded frame in stream."""),
('PASS1', lib.AV_CODEC_FLAG_PASS1,
"""Use internal 2pass ratecontrol in first pass mode."""),
('PASS2', lib.AV_CODEC_FLAG_PASS2,
"""Use internal 2pass ratecontrol in second pass mode."""),
('LOOP_FILTER', lib.AV_CODEC_FLAG_LOOP_FILTER,
"""loop filter."""),
('GRAY', lib.AV_CODEC_FLAG_GRAY,
"""Only decode/encode grayscale."""),
('PSNR', lib.AV_CODEC_FLAG_PSNR,
"""error[?] variables will be set during encoding."""),
('INTERLACED_DCT', lib.AV_CODEC_FLAG_INTERLACED_DCT,
"""Use interlaced DCT."""),
('LOW_DELAY', lib.AV_CODEC_FLAG_LOW_DELAY,
"""Force low delay."""),
('GLOBAL_HEADER', lib.AV_CODEC_FLAG_GLOBAL_HEADER,
"""Place global headers in extradata instead of every keyframe."""),
('BITEXACT', lib.AV_CODEC_FLAG_BITEXACT,
"""Use only bitexact stuff (except (I)DCT)."""),
('AC_PRED', lib.AV_CODEC_FLAG_AC_PRED,
"""H.263 advanced intra coding / MPEG-4 AC prediction"""),
('INTERLACED_ME', lib.AV_CODEC_FLAG_INTERLACED_ME,
"""Interlaced motion estimation"""),
('CLOSED_GOP', lib.AV_CODEC_FLAG_CLOSED_GOP),
("PASS1", lib.AV_CODEC_FLAG_PASS1, "Use internal 2pass ratecontrol in first pass mode."),
("PASS2", lib.AV_CODEC_FLAG_PASS2, "Use internal 2pass ratecontrol in second pass mode."),
("LOOP_FILTER", lib.AV_CODEC_FLAG_LOOP_FILTER, "loop filter."),
("GRAY", lib.AV_CODEC_FLAG_GRAY, "Only decode/encode grayscale."),
("PSNR", lib.AV_CODEC_FLAG_PSNR, "error[?] variables will be set during encoding."),
("INTERLACED_DCT", lib.AV_CODEC_FLAG_INTERLACED_DCT, "Use interlaced DCT."),
("LOW_DELAY", lib.AV_CODEC_FLAG_LOW_DELAY, "Force low delay."),
("GLOBAL_HEADER", lib.AV_CODEC_FLAG_GLOBAL_HEADER,
"Place global headers in extradata instead of every keyframe."),
("BITEXACT", lib.AV_CODEC_FLAG_BITEXACT, "Use only bitexact stuff (except (I)DCT)."),
("AC_PRED", lib.AV_CODEC_FLAG_AC_PRED, "H.263 advanced intra coding / MPEG-4 AC prediction"),
("INTERLACED_ME", lib.AV_CODEC_FLAG_INTERLACED_ME, "Interlaced motion estimation"),
("CLOSED_GOP", lib.AV_CODEC_FLAG_CLOSED_GOP),
), is_flags=True)

Flags2 = define_enum('Flags2', __name__, (
('NONE', 0),
('FAST', lib.AV_CODEC_FLAG2_FAST,
"""Allow non spec compliant speedup tricks."""),
('NO_OUTPUT', lib.AV_CODEC_FLAG2_NO_OUTPUT,
"""Skip bitstream encoding."""),
('LOCAL_HEADER', lib.AV_CODEC_FLAG2_LOCAL_HEADER,
"""Place global headers at every keyframe instead of in extradata."""),
('CHUNKS', lib.AV_CODEC_FLAG2_CHUNKS,
Flags2 = define_enum("Flags2", __name__, (
("NONE", 0),
("FAST", lib.AV_CODEC_FLAG2_FAST, "Allow non spec compliant speedup tricks."),
("NO_OUTPUT", lib.AV_CODEC_FLAG2_NO_OUTPUT, "Skip bitstream encoding."),
("LOCAL_HEADER", lib.AV_CODEC_FLAG2_LOCAL_HEADER,
"Place global headers at every keyframe instead of in extradata."),
("CHUNKS", lib.AV_CODEC_FLAG2_CHUNKS,
"""Input bitstream might be truncated at a packet boundaries
instead of only at frame boundaries."""),
('IGNORE_CROP', lib.AV_CODEC_FLAG2_IGNORE_CROP,
"""Discard cropping information from SPS."""),
('SHOW_ALL', lib.AV_CODEC_FLAG2_SHOW_ALL,
"""Show all frames before the first keyframe"""),
('EXPORT_MVS', lib.AV_CODEC_FLAG2_EXPORT_MVS,
"""Export motion vectors through frame side data"""),
('SKIP_MANUAL', lib.AV_CODEC_FLAG2_SKIP_MANUAL,
"""Do not skip samples and export skip information as frame side data"""),
('RO_FLUSH_NOOP', lib.AV_CODEC_FLAG2_RO_FLUSH_NOOP,
"""Do not reset ASS ReadOrder field on flush (subtitles decoding)"""),
("IGNORE_CROP", lib.AV_CODEC_FLAG2_IGNORE_CROP, "Discard cropping information from SPS."),
("SHOW_ALL", lib.AV_CODEC_FLAG2_SHOW_ALL, "Show all frames before the first keyframe"),
("EXPORT_MVS", lib.AV_CODEC_FLAG2_EXPORT_MVS, "Export motion vectors through frame side data"),
("SKIP_MANUAL", lib.AV_CODEC_FLAG2_SKIP_MANUAL,
"Do not skip samples and export skip information as frame side data"),
("RO_FLUSH_NOOP", lib.AV_CODEC_FLAG2_RO_FLUSH_NOOP,
"Do not reset ASS ReadOrder field on flush (subtitles decoding)"),
), is_flags=True)


cdef class CodecContext:

@staticmethod
def create(codec, mode=None):
cdef Codec cy_codec = codec if isinstance(codec, Codec) else Codec(codec, mode)
Expand All @@ -145,16 +115,15 @@ cdef class CodecContext:

def __cinit__(self, sentinel=None, *args, **kwargs):
if sentinel is not _cinit_sentinel:
raise RuntimeError('Cannot instantiate CodecContext')
raise RuntimeError("Cannot instantiate CodecContext")

self.options = {}
self.stream_index = -1 # This is set by the container immediately.

cdef _init(self, lib.AVCodecContext *ptr, const lib.AVCodec *codec):

self.ptr = ptr
if self.ptr.codec and codec and self.ptr.codec != codec:
raise RuntimeError('Wrapping CodecContext with mismatched codec.')
raise RuntimeError("Wrapping CodecContext with mismatched codec.")
self.codec = wrap_codec(codec if codec != NULL else self.ptr.codec)

# Set reasonable threading defaults.
Expand All @@ -169,52 +138,44 @@ cdef class CodecContext:
def _set_flags(self, value):
self.ptr.flags = value

flags = Flags.property(
_get_flags,
_set_flags,
"""Flag property of :class:`.Flags`."""
)

unaligned = flags.flag_property('UNALIGNED')
qscale = flags.flag_property('QSCALE')
four_mv = flags.flag_property('4MV')
output_corrupt = flags.flag_property('OUTPUT_CORRUPT')
qpel = flags.flag_property('QPEL')
drop_changed = flags.flag_property('DROPCHANGED')
pass1 = flags.flag_property('PASS1')
pass2 = flags.flag_property('PASS2')
loop_filter = flags.flag_property('LOOP_FILTER')
gray = flags.flag_property('GRAY')
psnr = flags.flag_property('PSNR')
interlaced_dct = flags.flag_property('INTERLACED_DCT')
low_delay = flags.flag_property('LOW_DELAY')
global_header = flags.flag_property('GLOBAL_HEADER')
bitexact = flags.flag_property('BITEXACT')
ac_pred = flags.flag_property('AC_PRED')
interlaced_me = flags.flag_property('INTERLACED_ME')
closed_gop = flags.flag_property('CLOSED_GOP')
flags = Flags.property(_get_flags, _set_flags, "Flag property of :class:`.Flags`.")

unaligned = flags.flag_property("UNALIGNED")
qscale = flags.flag_property("QSCALE")
four_mv = flags.flag_property("4MV")
output_corrupt = flags.flag_property("OUTPUT_CORRUPT")
qpel = flags.flag_property("QPEL")
drop_changed = flags.flag_property("DROPCHANGED")
pass1 = flags.flag_property("PASS1")
pass2 = flags.flag_property("PASS2")
loop_filter = flags.flag_property("LOOP_FILTER")
gray = flags.flag_property("GRAY")
psnr = flags.flag_property("PSNR")
interlaced_dct = flags.flag_property("INTERLACED_DCT")
low_delay = flags.flag_property("LOW_DELAY")
global_header = flags.flag_property("GLOBAL_HEADER")
bitexact = flags.flag_property("BITEXACT")
ac_pred = flags.flag_property("AC_PRED")
interlaced_me = flags.flag_property("INTERLACED_ME")
closed_gop = flags.flag_property("CLOSED_GOP")

def _get_flags2(self):
return self.ptr.flags2

def _set_flags2(self, value):
self.ptr.flags2 = value

flags2 = Flags2.property(
_get_flags2,
_set_flags2,
"""Flag property of :class:`.Flags2`."""
)

fast = flags2.flag_property('FAST')
no_output = flags2.flag_property('NO_OUTPUT')
local_header = flags2.flag_property('LOCAL_HEADER')
chunks = flags2.flag_property('CHUNKS')
ignore_crop = flags2.flag_property('IGNORE_CROP')
show_all = flags2.flag_property('SHOW_ALL')
export_mvs = flags2.flag_property('EXPORT_MVS')
skip_manual = flags2.flag_property('SKIP_MANUAL')
ro_flush_noop = flags2.flag_property('RO_FLUSH_NOOP')
flags2 = Flags2.property(_get_flags2, _set_flags2, "Flag property of :class:`.Flags2`.")

fast = flags2.flag_property("FAST")
no_output = flags2.flag_property("NO_OUTPUT")
local_header = flags2.flag_property("LOCAL_HEADER")
chunks = flags2.flag_property("CHUNKS")
ignore_crop = flags2.flag_property("IGNORE_CROP")
show_all = flags2.flag_property("SHOW_ALL")
export_mvs = flags2.flag_property("EXPORT_MVS")
skip_manual = flags2.flag_property("SKIP_MANUAL")
ro_flush_noop = flags2.flag_property("RO_FLUSH_NOOP")

property extradata:
def __get__(self):
Expand Down Expand Up @@ -256,10 +217,9 @@ cdef class CodecContext:
return lib.av_codec_is_decoder(self.ptr.codec)

cpdef open(self, bint strict=True):

if lib.avcodec_is_open(self.ptr):
if strict:
raise ValueError('CodecContext is already open.')
raise ValueError("CodecContext is already open.")
return

# We might pass partial frames.
Expand Down Expand Up @@ -288,7 +248,7 @@ cdef class CodecContext:
cpdef close(self, bint strict=True):
if not lib.avcodec_is_open(self.ptr):
if strict:
raise ValueError('CodecContext is already closed.')
raise ValueError("CodecContext is already closed.")
return
err_check(lib.avcodec_close(self.ptr))

Expand All @@ -302,10 +262,10 @@ cdef class CodecContext:
lib.av_parser_close(self.parser)

def __repr__(self):
return '<av.%s %s/%s at 0x%x>' % (
return "<av.%s %s/%s at 0x%x>" % (
self.__class__.__name__,
self.type or '<notype>',
self.name or '<nocodec>',
self.type or "<notype>",
self.name or "<nocodec>",
id(self),
)

Expand All @@ -329,7 +289,7 @@ cdef class CodecContext:
if not self.parser:
self.parser = lib.av_parser_init(self.codec.ptr.id)
if not self.parser:
raise ValueError('No parser for %s' % self.codec.name)
raise ValueError("No parser for %s" % self.codec.name)

cdef ByteSource source = bytesource(raw_input, allow_none=True)

Expand Down Expand Up @@ -424,7 +384,7 @@ cdef class CodecContext:
return [frame]

cdef Frame _alloc_next_frame(self):
raise NotImplementedError('Base CodecContext cannot decode.')
raise NotImplementedError("Base CodecContext cannot decode.")

cdef _recv_frame(self):
if not self._next_frame:
Expand Down Expand Up @@ -460,7 +420,7 @@ cdef class CodecContext:
"""Encode a list of :class:`.Packet` from the given :class:`.Frame`."""

if self.ptr.codec_type not in [lib.AVMEDIA_TYPE_VIDEO, lib.AVMEDIA_TYPE_AUDIO]:
raise NotImplementedError('Encoding is only supported for audio and video.')
raise NotImplementedError("Encoding is only supported for audio and video.")

self.open(strict=False)

Expand Down Expand Up @@ -499,7 +459,7 @@ cdef class CodecContext:
"""

if not self.codec.ptr:
raise ValueError('cannot decode unknown codec')
raise ValueError("cannot decode unknown codec")

self.open(strict=False)

Expand Down
1 change: 0 additions & 1 deletion av/container/core.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ from av.dictionary cimport _Dictionary
from av.format cimport ContainerFormat
from av.stream cimport Stream


# Interrupt callback information, times are in seconds.
ctypedef struct timeout_info:
double start_time
Expand Down
Loading

0 comments on commit 5d628cf

Please sign in to comment.