Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ v14.1.0 (Unreleased)
Features

- Add hardware decoding by :gh-user:`matthewlai` and :gh-user:`WyattBlue` in (:pr:`1685`).
- Add ``Stream.disposition`` and ``Disposition`` enum by :gh-user:`WyattBlue` in (:pr:`1720`).
- Add ``VideoFrame.rotation`` by :gh-user:`lgeiger` in (:pr:`1675`).
- Support grayf32le and gbrapf32le in numpy convertion by :gh-user:`robinechuca` in (:pr:`1712`).

Expand Down
23 changes: 23 additions & 0 deletions av/stream.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
from enum import Flag
from fractions import Fraction
from typing import Literal

from .codec import Codec, CodecContext
from .container import Container

class Disposition(Flag):
default: int
dub: int
original: int
comment: int
lyrics: int
karaoke: int
forced: int
hearing_impaired: int
visual_impaired: int
clean_effects: int
attached_pic: int
timed_thumbnails: int
non_diegetic: int
captions: int
descriptions: int
metadata: int
dependent: int
still_image: int
multilayer: int

class Stream:
name: str | None
container: Container
Expand All @@ -20,6 +42,7 @@ class Stream:
guessed_rate: Fraction | None
start_time: int | None
duration: int | None
disposition: Disposition
frames: int
language: str | None
type: Literal["video", "audio", "data", "subtitle", "attachment"]
31 changes: 30 additions & 1 deletion av/stream.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cimport libav as lib

from enum import Enum
from enum import Flag

from av.error cimport err_check
from av.packet cimport Packet
Expand All @@ -12,6 +12,28 @@ from av.utils cimport (
)


class Disposition(Flag):
default = 1 << 0
dub = 1 << 1
original = 1 << 2
comment = 1 << 3
lyrics = 1 << 4
karaoke = 1 << 5
forced = 1 << 6
hearing_impaired = 1 << 7
visual_impaired = 1 << 8
clean_effects = 1 << 9
attached_pic = 1 << 10
timed_thumbnails = 1 << 11
non_diegetic = 1 << 12
captions = 1 << 16
descriptions = 1 << 17
metadata = 1 << 18
dependent = 1 << 19
still_image = 1 << 20
multilayer = 1 << 21


cdef object _cinit_bypass_sentinel = object()

cdef Stream wrap_stream(Container container, lib.AVStream *c_stream, CodecContext codec_context):
Expand Down Expand Up @@ -96,6 +118,9 @@ cdef class Stream:
if name == "id":
self._set_id(value)
return
if name == "disposition":
self.ptr.disposition = value
return

# Convenience setter for codec context properties.
if self.codec_context is not None:
Expand Down Expand Up @@ -230,6 +255,10 @@ cdef class Stream:
"""
return self.metadata.get("language")

@property
def disposition(self):
return Disposition(self.ptr.disposition)

@property
def type(self):
"""
Expand Down
1 change: 0 additions & 1 deletion include/libav.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ include "libavfilter/buffersrc.pxd"


cdef extern from "stdio.h" nogil:

cdef int snprintf(char *output, int n, const char *format, ...)
cdef int vsnprintf(char *output, int n, const char *format, va_list args)
14 changes: 14 additions & 0 deletions include/libavcodec/avcodec.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ cdef extern from "libavcodec/codec_id.h":
AVCodecID av_codec_get_id(const AVCodecTag *const *tags, uint32_t tag)


cdef extern from "libavcodec/packet.h" nogil:
AVPacketSideData* av_packet_side_data_new(
AVPacketSideData **sides,
int *nb_sides,
AVPacketSideDataType type,
size_t size,
int free_opaque
)


cdef extern from "libavutil/channel_layout.h":
ctypedef enum AVChannelOrder:
AV_CHANNEL_ORDER_UNSPEC
Expand Down Expand Up @@ -542,6 +552,10 @@ cdef extern from "libavcodec/avcodec.h" nogil:
cdef struct AVCodecParameters:
AVMediaType codec_type
AVCodecID codec_id
AVPacketSideData *coded_side_data
int nb_coded_side_data
uint8_t *extradata
int extradata_size

cdef int avcodec_parameters_copy(
AVCodecParameters *dst,
Expand Down
4 changes: 1 addition & 3 deletions include/libavformat/avformat.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,16 @@ cdef extern from "libavformat/avformat.h" nogil:
cdef struct AVStream:
int index
int id
int disposition

AVCodecParameters *codecpar

AVRational time_base

int64_t start_time
int64_t duration
int64_t nb_frames
int64_t cur_dts

AVDictionary *metadata

AVRational avg_frame_rate
AVRational r_frame_rate
AVRational sample_aspect_ratio
Expand Down
1 change: 1 addition & 0 deletions include/libavutil/avutil.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cdef extern from "libavutil/avutil.h" nogil:
cdef enum AVPixelFormat:
AV_PIX_FMT_NONE
AV_PIX_FMT_YUV420P
AV_PIX_FMT_RGBA
AV_PIX_FMT_RGB24
PIX_FMT_RGB24
PIX_FMT_RGBA
Expand Down
2 changes: 2 additions & 0 deletions tests/test_colorspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def test_sky_timelapse() -> None:
)
stream = container.streams.video[0]

assert stream.disposition == av.stream.Disposition.default

assert stream.codec_context.color_range == 1
assert stream.codec_context.color_range == ColorRange.MPEG
assert stream.codec_context.color_primaries == 1
Expand Down
Loading