Skip to content

Commit

Permalink
Sync with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Aug 17, 2024
1 parent 829532e commit f8bf6fb
Show file tree
Hide file tree
Showing 60 changed files with 478 additions and 547 deletions.
33 changes: 21 additions & 12 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ jobs:
with:
python-version: 3.12

- name: Packages
run: pip install -r tests/requirements.txt

- name: Linters
run: make lint

Expand All @@ -37,10 +34,9 @@ jobs:
fail-fast: false
matrix:
config:
- {os: ubuntu-latest, python: "3.10", ffmpeg: "6.1", extras: true}
- {os: ubuntu-latest, python: "3.9", ffmpeg: "6.0"}
- {os: ubuntu-latest, python: pypy3.9, ffmpeg: "6.0"}
- {os: macos-12, python: "3.10", ffmpeg: "6.1"}
- {os: ubuntu-latest, python: "3.9", ffmpeg: "7.0.2", extras: true}
- {os: ubuntu-latest, python: pypy3.9, ffmpeg: "7.0.2"}
- {os: macos-12, python: "3.9", ffmpeg: "7.0.2"}

env:
PYAV_PYTHON: python${{ matrix.config.python }}
Expand All @@ -62,15 +58,15 @@ jobs:
sudo apt-get update
sudo apt-get install autoconf automake build-essential cmake \
libtool mercurial pkg-config texinfo wget yasm zlib1g-dev
sudo apt-get install libass-dev libfreetype6-dev libjpeg-dev \
sudo apt-get install libfreetype6-dev libjpeg-dev \
libtheora-dev libvorbis-dev libx264-dev
if [[ "${{ matrix.config.extras }}" ]]; then
sudo apt-get install doxygen
fi
;;
macos-12)
brew install automake libtool nasm pkg-config shtool texi2html wget
brew install libass libjpeg libpng libvorbis libvpx opus theora x264
brew install libjpeg libpng libvorbis libvpx opus theora x264
;;
esac
Expand All @@ -88,7 +84,19 @@ jobs:
run: |
. scripts/activate.sh ffmpeg-${{ matrix.config.ffmpeg }}
python -m av --version # Assert it can import.
scripts/test
make test
- name: Docs
if: matrix.config.extras
run: |
. scripts/activate.sh ffmpeg-${{ matrix.config.ffmpeg }}
make -C docs html
- name: Doctest
if: matrix.config.extras
run: |
. scripts/activate.sh ffmpeg-${{ matrix.config.ffmpeg }}
make -C docs test
- name: Examples
if: matrix.config.extras
Expand All @@ -104,7 +112,7 @@ jobs:
fail-fast: false
matrix:
config:
- {os: windows-latest, python: "3.10", ffmpeg: "6.1"}
- {os: windows-latest, python: "3.10", ffmpeg: "7.0"}

steps:
- name: Checkout
Expand All @@ -120,6 +128,7 @@ jobs:
cython \
numpy \
pillow \
pytest \
python=${{ matrix.config.python }} \
setuptools
Expand All @@ -136,4 +145,4 @@ jobs:
run: |
. $CONDA/etc/profile.d/conda.sh
conda activate pyav
python setup.py test
python -m pytest
10 changes: 4 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Build source package
run: |
pip install cython
python scripts/fetch-vendor.py --config-file scripts/ffmpeg-6.1.json /tmp/vendor
python scripts/fetch-vendor.py --config-file scripts/ffmpeg-7.0.json /tmp/vendor
PKG_CONFIG_PATH=/tmp/vendor/lib/pkgconfig python setup.py sdist
- name: Upload source package
uses: actions/upload-artifact@v4
Expand All @@ -32,8 +32,6 @@ jobs:
arch: arm64
- os: macos-13
arch: x86_64
# - os: ubuntu-latest
# arch: aarch64
- os: ubuntu-latest
arch: i686
- os: ubuntu-latest
Expand All @@ -60,8 +58,8 @@ jobs:
env:
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_BEFORE_ALL_LINUX: yum install -y alsa-lib libxcb
CIBW_BEFORE_BUILD: python scripts/fetch-vendor.py --config-file scripts/ffmpeg-6.1.json /tmp/vendor
CIBW_BEFORE_BUILD_WINDOWS: python scripts\fetch-vendor.py --config-file scripts\ffmpeg-6.1.json C:\cibw\vendor
CIBW_BEFORE_BUILD: python scripts/fetch-vendor.py --config-file scripts/ffmpeg-7.0.json /tmp/vendor
CIBW_BEFORE_BUILD_WINDOWS: python scripts\fetch-vendor.py --config-file scripts\ffmpeg-7.0.json C:\cibw\vendor
CIBW_ENVIRONMENT_LINUX: LD_LIBRARY_PATH=/tmp/vendor/lib:$LD_LIBRARY_PATH PKG_CONFIG_PATH=/tmp/vendor/lib/pkgconfig
CIBW_ENVIRONMENT_MACOS: PKG_CONFIG_PATH=/tmp/vendor/lib/pkgconfig LDFLAGS=-headerpad_max_install_names
CIBW_ENVIRONMENT_WINDOWS: INCLUDE=C:\\cibw\\vendor\\include LIB=C:\\cibw\\vendor\\lib PYAV_SKIP_TESTS=unicode_filename
Expand All @@ -70,7 +68,7 @@ jobs:
CIBW_TEST_COMMAND: mv {project}/av {project}/av.disabled && python -m unittest discover -t {project} -s tests && mv {project}/av.disabled {project}/av
CIBW_TEST_REQUIRES: numpy
# skip tests when there are no binary wheels of numpy
CIBW_TEST_SKIP: pp* *_i686
CIBW_TEST_SKIP: pp* *_i686 cp313-win_amd64
run: |
pip install cibuildwheel delvewheel
cibuildwheel --output-dir dist
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@
/sandbox
/tests/assets
/tests/samples
sync.sh
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
LDFLAGS ?= ""
CFLAGS ?= "-O0"
CFLAGS ?= "-O0 -Wno-incompatible-function-pointer-types"

PYAV_PYTHON ?= python
PYAV_PIP ?= pip
PYTHON := $(PYAV_PYTHON)
PIP := $(PYAV_PIP)


.PHONY: default build clean fate-suite lint test
Expand All @@ -11,6 +13,7 @@ default: build


build:
$(PIP) install --upgrade cython
CFLAGS=$(CFLAGS) LDFLAGS=$(LDFLAGS) $(PYTHON) setup.py build_ext --inplace --debug

clean:
Expand All @@ -25,10 +28,12 @@ fate-suite:
rsync -vrltLW rsync://fate-suite.ffmpeg.org/fate-suite/ tests/assets/fate-suite/

lint:
$(PIP) install -U black isort flake8 flake8-pyproject pillow numpy mypy==1.10.0
black --check av examples tests setup.py
flake8 av examples tests
isort --check-only --diff av examples tests
mypy av tests

test:
$(PYTHON) setup.py test
$(PIP) install --upgrade cython numpy pillow pytest
$(PYTHON) -m pytest
2 changes: 1 addition & 1 deletion av/about.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "12.3.0"
__version__ = "13.0.0rc1"
Empty file added av/attachments/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions av/attachments/stream.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from av.stream cimport Stream


cdef class AttachmentStream(Stream):
pass
8 changes: 8 additions & 0 deletions av/attachments/stream.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import Literal

from av.stream import Stream

class AttachmentStream(Stream):
type: Literal["attachment"]
@property
def mimetype(self) -> str | None: ...
26 changes: 26 additions & 0 deletions av/attachments/stream.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from av.stream cimport Stream


cdef class AttachmentStream(Stream):
"""
An :class:`AttachmentStream` represents a stream of attachment data within a media container.
Typically used to attach font files that are referenced in ASS/SSA Subtitle Streams.
"""

@property
def name(self):
"""
Returns the file name of the attachment.
:rtype: str | None
"""
return self.metadata.get("filename")

@property
def mimetype(self):
"""
Returns the MIME type of the attachment.
:rtype: str | None
"""
return self.metadata.get("mimetype")
2 changes: 0 additions & 2 deletions av/audio/codeccontext.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ from av.codec.context cimport CodecContext


cdef class AudioCodecContext(CodecContext):

# Hold onto the frames that we will decode until we have a full one.
cdef AudioFrame next_frame

# For encoding.
cdef AudioResampler resampler
4 changes: 2 additions & 2 deletions av/audio/codeccontext.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class AudioCodecContext(CodecContext):
frame_size: int
sample_rate: int
rate: int
channels: int
channel_layout: int
layout: AudioLayout
format: AudioFormat
type: Literal["audio"]

@property
def channels(self) -> int: ...
def encode(self, frame: AudioFrame | None = None) -> list[Packet]: ...
def encode_lazy(self, frame: AudioFrame | None = None) -> Iterator[Packet]: ...
def decode(self, packet: Packet | None = None) -> list[AudioFrame]: ...
24 changes: 3 additions & 21 deletions av/audio/codeccontext.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ cdef class AudioCodecContext(CodecContext):
cdef _init(self, lib.AVCodecContext *ptr, const lib.AVCodec *codec):
CodecContext._init(self, ptr, codec)

# Sometimes there isn't a layout set, but there are a number of
# channels. Assume it is the default layout.
# TODO: Put this behind `not bare_metal`.
# TODO: Do this more efficiently.
if self.ptr.channels and not self.ptr.channel_layout:
self.ptr.channel_layout = get_audio_layout(self.ptr.channels, 0).layout

cdef _set_default_time_base(self):
self.ptr.time_base.num = 1
self.ptr.time_base.den = self.ptr.sample_rate
Expand Down Expand Up @@ -62,7 +55,6 @@ cdef class AudioCodecContext(CodecContext):
"""
return self.ptr.frame_size


@property
def sample_rate(self):
"""
Expand All @@ -85,18 +77,9 @@ cdef class AudioCodecContext(CodecContext):
def rate(self, value):
self.sample_rate = value

# TODO: Integrate into AudioLayout.
@property
def channels(self):
return self.ptr.channels

@channels.setter
def channels(self, value):
self.ptr.channels = value
self.ptr.channel_layout = lib.av_get_default_channel_layout(value)
@property
def channel_layout(self):
return self.ptr.channel_layout
return self.layout.nb_channels

@property
def layout(self):
Expand All @@ -105,13 +88,12 @@ cdef class AudioCodecContext(CodecContext):
:type: AudioLayout
"""
return get_audio_layout(self.ptr.channels, self.ptr.channel_layout)
return get_audio_layout(self.ptr.ch_layout)

@layout.setter
def layout(self, value):
cdef AudioLayout layout = AudioLayout(value)
self.ptr.channel_layout = layout.layout
self.ptr.channels = layout.nb_channels
self.ptr.ch_layout = layout.layout

@property
def format(self):
Expand Down
6 changes: 3 additions & 3 deletions av/audio/fifo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ cdef class AudioFifo:

self.ptr = lib.av_audio_fifo_alloc(
<lib.AVSampleFormat>frame.ptr.format,
len(frame.layout.channels), # TODO: Can we safely use frame.ptr.nb_channels?
frame.layout.nb_channels,
frame.ptr.nb_samples * 2, # Just a default number of samples; it will adjust.
)

Expand All @@ -71,7 +71,7 @@ cdef class AudioFifo:
# Make sure nothing changed.
elif (
frame.ptr.format != self.template.ptr.format or
frame.ptr.channel_layout != self.template.ptr.channel_layout or
# TODO: frame.ptr.ch_layout != self.template.ptr.ch_layout or
frame.ptr.sample_rate != self.template.ptr.sample_rate or
(frame._time_base.num and self.template._time_base.num and (
frame._time_base.num != self.template._time_base.num or
Expand Down Expand Up @@ -131,7 +131,7 @@ cdef class AudioFifo:
frame._copy_internal_attributes(self.template)
frame._init(
<lib.AVSampleFormat>self.template.ptr.format,
self.template.ptr.channel_layout,
<lib.AVChannelLayout>self.template.ptr.ch_layout,
samples,
1, # Align?
)
Expand Down
3 changes: 1 addition & 2 deletions av/audio/frame.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ from av.frame cimport Frame


cdef class AudioFrame(Frame):

# For raw storage of the frame's data; don't ever touch this.
cdef uint8_t *_buffer
cdef size_t _buffer_size
Expand All @@ -26,7 +25,7 @@ cdef class AudioFrame(Frame):
:type: AudioFormat
"""

cdef _init(self, lib.AVSampleFormat format, uint64_t layout, unsigned int nb_samples, unsigned int align)
cdef _init(self, lib.AVSampleFormat format, lib.AVChannelLayout layout, unsigned int nb_samples, unsigned int align)
cdef _init_user_attributes(self)

cdef AudioFrame alloc_audio_frame()
Loading

0 comments on commit f8bf6fb

Please sign in to comment.