diff --git a/.github/workflows/smoke.yml b/.github/workflows/smoke.yml index c40464af5..ca6a3f15c 100644 --- a/.github/workflows/smoke.yml +++ b/.github/workflows/smoke.yml @@ -34,7 +34,7 @@ jobs: fail-fast: false matrix: config: - - {os: ubuntu-latest, python: "3.9", ffmpeg: "7.1", extras: true} + - {os: ubuntu-latest, python: "3.12", ffmpeg: "7.1", extras: true} - {os: ubuntu-latest, python: "3.9", ffmpeg: "7.0.2"} - {os: ubuntu-latest, python: pypy3.9, ffmpeg: "7.1"} - {os: macos-14, python: "3.9", ffmpeg: "7.1"} diff --git a/Makefile b/Makefile index 818c14c00..2afb2e4c3 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ default: build build: - $(PIP) install --upgrade cython + $(PIP) install -U cython setuptools CFLAGS=$(CFLAGS) LDFLAGS=$(LDFLAGS) $(PYTHON) setup.py build_ext --inplace --debug clean: diff --git a/av/video/reformatter.pyx b/av/video/reformatter.pyx index 624454f0c..7e2b4c022 100644 --- a/av/video/reformatter.pyx +++ b/av/video/reformatter.pyx @@ -1,50 +1,49 @@ cimport libav as lib from libc.stdint cimport uint8_t -from av.enum cimport define_enum from av.error cimport err_check from av.video.format cimport VideoFormat from av.video.frame cimport alloc_video_frame -Interpolation = define_enum("Interpolation", __name__, ( - ("FAST_BILINEAR", lib.SWS_FAST_BILINEAR, "Fast bilinear"), - ("BILINEAR", lib.SWS_BILINEAR, "Bilinear"), - ("BICUBIC", lib.SWS_BICUBIC, "Bicubic"), - ("X", lib.SWS_X, "Experimental"), - ("POINT", lib.SWS_POINT, "Nearest neighbor / point"), - ("AREA", lib.SWS_AREA, "Area averaging"), - ("BICUBLIN", lib.SWS_BICUBLIN, "Luma bicubic / chroma bilinear"), - ("GAUSS", lib.SWS_GAUSS, "Gaussian"), - ("SINC", lib.SWS_SINC, "Sinc"), - ("LANCZOS", lib.SWS_LANCZOS, "Lanczos"), - ("SPLINE", lib.SWS_SPLINE, "Bicubic spline"), -)) - -Colorspace = define_enum("Colorspace", __name__, ( - ("ITU709", lib.SWS_CS_ITU709), - ("FCC", lib.SWS_CS_FCC), - ("ITU601", lib.SWS_CS_ITU601), - ("ITU624", lib.SWS_CS_ITU624), - ("SMPTE170M", lib.SWS_CS_SMPTE170M), - ("SMPTE240M", lib.SWS_CS_SMPTE240M), - ("DEFAULT", lib.SWS_CS_DEFAULT), - +from enum import IntEnum + + +class Interpolation(IntEnum): + FAST_BILINEAR: "Fast bilinear" = lib.SWS_FAST_BILINEAR + BILINEAR: "Bilinear" = lib.SWS_BILINEAR + BICUBIC: "Bicubic" = lib.SWS_BICUBIC + X: "Experimental" = lib.SWS_X + POINT: "Nearest neighbor / point" = lib.SWS_POINT + AREA: "Area averaging" = lib.SWS_AREA + BICUBLIN: "Luma bicubic / chroma bilinear" = lib.SWS_BICUBLIN + GAUSS: "Gaussian" = lib.SWS_GAUSS + SINC: "Sinc" = lib.SWS_SINC + LANCZOS: "Bicubic spline" = lib.SWS_LANCZOS + + +class Colorspace(IntEnum): + ITU709 = lib.SWS_CS_ITU709 + FCC = lib.SWS_CS_FCC + ITU601 = lib.SWS_CS_ITU601 + ITU624 = lib.SWS_CS_ITU624 + SMPTE170M = lib.SWS_CS_SMPTE170M + SMPTE240M = lib.SWS_CS_SMPTE240M + DEFAULT = lib.SWS_CS_DEFAULT # Lowercase for b/c. - ("itu709", lib.SWS_CS_ITU709), - ("fcc", lib.SWS_CS_FCC), - ("itu601", lib.SWS_CS_ITU601), - ("itu624", lib.SWS_CS_SMPTE170M), - ("smpte240", lib.SWS_CS_SMPTE240M), - ("default", lib.SWS_CS_DEFAULT), - -)) - -ColorRange = define_enum("ColorRange", __name__, ( - ("UNSPECIFIED", lib.AVCOL_RANGE_UNSPECIFIED, "Unspecified"), - ("MPEG", lib.AVCOL_RANGE_MPEG, "MPEG (limited) YUV range, 219*2^(n-8)"), - ("JPEG", lib.AVCOL_RANGE_JPEG, "JPEG (full) YUV range, 2^n-1"), - ("NB", lib.AVCOL_RANGE_NB, "Not part of ABI"), -)) + itu709 = lib.SWS_CS_ITU709 + fcc = lib.SWS_CS_FCC + itu601 = lib.SWS_CS_ITU601 + itu624 = lib.SWS_CS_SMPTE170M + smpte170m = lib.SWS_CS_SMPTE170M + smpte240m = lib.SWS_CS_SMPTE240M + default = lib.SWS_CS_DEFAULT + +class ColorRange(IntEnum): + UNSPECIFIED: "Unspecified" = lib.AVCOL_RANGE_UNSPECIFIED + MPEG: "MPEG (limited) YUV range, 219*2^(n-8)" = lib.AVCOL_RANGE_MPEG + JPEG: "JPEG (full) YUV range, 2^n-1" = lib.AVCOL_RANGE_JPEG + NB: "Not part of ABI" = lib.AVCOL_RANGE_NB + cdef class VideoReformatter: """An object for reformatting size and pixel format of :class:`.VideoFrame`. diff --git a/docs/Makefile b/docs/Makefile index e0662e90c..bb84c1dba 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,33 +1,31 @@ - SPHINXOPTS = SPHINXBUILD = sphinx-build BUILDDIR = _build FFMPEGDIR = _ffmpeg - PYAV_PIP ?= pip PIP := $(PYAV_PIP) - ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(SPHINXOPTS) . .PHONY: clean html open upload default default: html - TAGFILE := _build/doxygen/tagfile.xml -$(TAGFILE) : - git clone --depth=1 git://source.ffmpeg.org/ffmpeg.git $(FFMPEGDIR) - ./generate-tagfile --library $(FFMPEGDIR) -o $(TAGFILE) +$(TAGFILE): + @if [ ! -d "$(FFMPEGDIR)" ]; then \ + git clone --depth=1 git://source.ffmpeg.org/ffmpeg.git $(FFMPEGDIR); \ + fi + ./generate-tagfile --library $(FFMPEGDIR) -o $(TAGFILE) TEMPLATES := $(wildcard api/*.py development/*.py) RENDERED := $(TEMPLATES:%.py=_build/rst/%.rst) + _build/rst/%.rst: %.py $(TAGFILE) $(shell find ../include ../av -name '*.pyx' -or -name '*.pxd') @ mkdir -p $(@D) python $< > $@.tmp mv $@.tmp $@ - clean: rm -rf $(BUILDDIR) $(FFMPEGDIR) diff --git a/docs/api/codec.rst b/docs/api/codec.rst index bd1a6b5f0..770a271a4 100644 --- a/docs/api/codec.rst +++ b/docs/api/codec.rst @@ -65,7 +65,6 @@ Contexts .. automethod:: CodecContext.create .. automethod:: CodecContext.open -.. automethod:: CodecContext.close Attributes ~~~~~~~~~~ diff --git a/docs/api/video.rst b/docs/api/video.rst index 5e47b1db8..1c56788a1 100644 --- a/docs/api/video.rst +++ b/docs/api/video.rst @@ -117,3 +117,9 @@ Enums .. enumtable:: av.video.reformatter.Colorspace +.. autoclass:: av.video.reformatter.ColorRange + + Wraps the ``AVCOL*`` flags. + + .. enumtable:: av.video.reformatter.ColorRange + diff --git a/docs/conf.py b/docs/conf.py index 419b24238..59090193c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -238,24 +238,48 @@ def makerow(*texts): ) seen = set() - - for name, item in enum._by_name.items(): - if name.lower() in seen: - continue - seen.add(name.lower()) - - try: - attr = properties[item] - except KeyError: - if cls: + if hasattr(enum, "_by_name"): # Our custom enum class + enum_items = enum._by_name.items() + for name, item in enum_items: + if name.lower() in seen: + continue + seen.add(name.lower()) + + try: + attr = properties[item] + except KeyError: + if cls: + continue + attr = None + + value = f"0x{item.value:X}" + doc = item.__doc__ or "-" + tbody += makerow(attr, name, value, doc) + + return [table] + else: # Standard IntEnum + enum_items = [ + (name, item) + for name, item in vars(enum).items() + if isinstance(item, enum) + ] + for name, item in enum_items: + if name.lower() in seen: continue - attr = None + seen.add(name.lower()) + + try: + attr = properties[item] + except KeyError: + if cls: + continue + attr = None - value = f"0x{item.value:X}" - doc = item.__doc__ or "-" - tbody += makerow(attr, name, value, doc) + value = f"0x{item.value:X}" + doc = enum.__annotations__.get(name, "---")[1:-1] + tbody += makerow(attr, name, value, doc) - return [table] + return [table] doxylink = {} diff --git a/scripts/build b/scripts/build index 67b3836f2..7e27d7f74 100755 --- a/scripts/build +++ b/scripts/build @@ -21,6 +21,6 @@ which ffmpeg || exit 2 ffmpeg -version || exit 3 echo -$PYAV_PIP install -U cython 2> /dev/null +$PYAV_PIP install -U cython setuptools 2> /dev/null "$PYAV_PYTHON" scripts/comptime.py "$PYAV_PYTHON" setup.py config build_ext --inplace || exit 1 diff --git a/tests/test_videoframe.py b/tests/test_videoframe.py index 8e14dcdf3..6396f1f45 100644 --- a/tests/test_videoframe.py +++ b/tests/test_videoframe.py @@ -634,11 +634,11 @@ def test_reformat_identity() -> None: def test_reformat_colorspace() -> None: # This is allowed. frame = VideoFrame(640, 480, "rgb24") - frame.reformat(src_colorspace=None, dst_colorspace="smpte240") + frame.reformat(src_colorspace=None, dst_colorspace="smpte240m") # I thought this was not allowed, but it seems to be. frame = VideoFrame(640, 480, "yuv420p") - frame.reformat(src_colorspace=None, dst_colorspace="smpte240") + frame.reformat(src_colorspace=None, dst_colorspace="smpte240m") def test_reformat_pixel_format_align() -> None: