Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • P PyAV
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 37
    • Issues 37
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 26
    • Merge requests 26
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • PyAV
  • PyAV
  • Merge requests
  • !558

Expose Frame Sidedata

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Mike Boers requested to merge sidedata into develop 5 years ago
  • Overview 1
  • Commits 8
  • Pipelines 0
  • Changes 18

I wasn't too keen on #557 (because it appeared to be tailored to a specific use-case), but it did show me how to work with side data, so I whipped this together.

Thoughts, anyone?

Compare
  • develop (base)

and
  • latest version
    5c4658b2
    8 commits, 2 years ago

18 files
+ 463
- 5

    Preferences

    File browser
    Compare changes
a‎v‎
co‎dec‎
conte‎xt.pyx‎ +56 -0
side‎data‎
__ini‎t__.py‎ +0 -0
motionve‎ctors.pxd‎ +16 -0
motionve‎ctors.pyx‎ +106 -0
sideda‎ta.pxd‎ +23 -0
sideda‎ta.pyx‎ +99 -0
vi‎deo‎
codeccon‎text.pyx‎ +1 -0
fram‎e.pxd‎ +1 -1
fram‎e.pxd‎ +3 -1
fram‎e.pyx‎ +8 -0
inc‎lude‎
libav‎codec‎
avcod‎ec.pxd‎ +65 -2
liba‎vutil‎
fram‎e.pxd‎ +1 -0
motion_v‎ector.pxd‎ +22 -0
liba‎v.pxd‎ +1 -0
scrat‎chpad‎
sided‎ata.py‎ +23 -0
te‎sts‎
test_de‎code.py‎ +29 -0
test_e‎nums.py‎ +8 -0
Make‎file‎ +1 -1
av/codec/context.pyx
+ 56
- 0
  • View file @ 5c4658b2

  • Edit in single-file editor

  • Open in Web IDE


@@ -59,6 +59,43 @@ SkipType = define_enum('SkipType', (
('ALL', lib.AVDISCARD_ALL),
))
Flags = define_enum('Flags', (
('NONE', 0),
('UNALIGNED', lib.AV_CODEC_FLAG_UNALIGNED),
('QSCALE', lib.AV_CODEC_FLAG_QSCALE),
('4MV', lib.AV_CODEC_FLAG_4MV),
('OUTPUT_CORRUPT', lib.AV_CODEC_FLAG_OUTPUT_CORRUPT),
('QPEL', lib.AV_CODEC_FLAG_QPEL),
('PASS1', lib.AV_CODEC_FLAG_PASS1),
('PASS2', lib.AV_CODEC_FLAG_PASS2),
('LOOP_FILTER', lib.AV_CODEC_FLAG_LOOP_FILTER),
('GRAY', lib.AV_CODEC_FLAG_GRAY),
('PSNR', lib.AV_CODEC_FLAG_PSNR),
('TRUNCATED', lib.AV_CODEC_FLAG_TRUNCATED),
('INTERLACED_DCT', lib.AV_CODEC_FLAG_INTERLACED_DCT),
('LOW_DELAY', lib.AV_CODEC_FLAG_LOW_DELAY),
('GLOBAL_HEADER', lib.AV_CODEC_FLAG_GLOBAL_HEADER),
('BITEXACT', lib.AV_CODEC_FLAG_BITEXACT),
('AC_PRED', lib.AV_CODEC_FLAG_AC_PRED),
('INTERLACED_ME', lib.AV_CODEC_FLAG_INTERLACED_ME),
('CLOSED_GOP', lib.AV_CODEC_FLAG_CLOSED_GOP),
), is_flags=True)
Flags2 = define_enum('Flags2', (
('NONE', 0),
('FAST', lib.AV_CODEC_FLAG2_FAST),
('NO_OUTPUT', lib.AV_CODEC_FLAG2_NO_OUTPUT),
('LOCAL_HEADER', lib.AV_CODEC_FLAG2_LOCAL_HEADER),
('DROP_FRAME_TIMECODE', lib.AV_CODEC_FLAG2_DROP_FRAME_TIMECODE),
('CHUNKS', lib.AV_CODEC_FLAG2_CHUNKS),
('IGNORE_CROP', lib.AV_CODEC_FLAG2_IGNORE_CROP),
('SHOW_ALL', lib.AV_CODEC_FLAG2_SHOW_ALL),
('EXPORT_MVS', lib.AV_CODEC_FLAG2_EXPORT_MVS),
('SKIP_MANUAL', lib.AV_CODEC_FLAG2_SKIP_MANUAL),
('RO_FLUSH_NOOP', lib.AV_CODEC_FLAG2_RO_FLUSH_NOOP),
), is_flags=True)
cdef class CodecContext(object):
@staticmethod
@@ -87,6 +124,24 @@ cdef class CodecContext(object):
self.ptr.thread_count = 0
self.ptr.thread_type = 2
@property
def flags(self):
return Flags.get(self.ptr.flags)
@flags.setter
def flags(self, value):
enum = Flags.get(value)
self.ptr.flags = enum.value
@property
def flags2(self):
return Flags2.get(self.ptr.flags2)
@flags2.setter
def flags2(self, value):
enum = Flags2.get(value)
self.ptr.flags2 = enum.value
property extradata:
def __get__(self):
if self.ptr.extradata_size > 0:
@@ -110,6 +165,7 @@ cdef class CodecContext(object):
property is_encoder:
def __get__(self):
return lib.av_codec_is_encoder(self.ptr.codec)
property is_decoder:
def __get__(self):
return lib.av_codec_is_decoder(self.ptr.codec)
av/sidedata/__init__.py 0 → 100644
+ 0
- 0
  • View file @ 5c4658b2

  • Edit in single-file editor

  • Open in Web IDE

av/sidedata/motionvectors.pxd 0 → 100644
+ 16
- 0
  • View file @ 5c4658b2

  • Edit in single-file editor

  • Open in Web IDE

from av.frame cimport Frame
from av.sidedata.sidedata cimport SideData
cimport libav as lib
cdef class _MotionVectors(SideData):
cdef dict _vectors
cdef int _len
cdef class MotionVector(object):
cdef _MotionVectors parent
cdef lib.AVMotionVector *ptr
av/sidedata/motionvectors.pyx 0 → 100644
+ 106
- 0
  • View file @ 5c4658b2

  • Edit in single-file editor

  • Open in Web IDE

import collections
cdef object _cinit_bypass_sentinel = object()
# Cython doesn't let us inherit from the abstract Sequence, so we will subclass
# it later.
cdef class _MotionVectors(SideData):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._vectors = {}
self._len = self.ptr.size // sizeof(lib.AVMotionVector)
def __repr__(self):
return f'<av.sidedata.MotionVectors {self.ptr.size} bytes of {len(self)} vectors at 0x{<unsigned int>self.ptr.data:0x}'
def __getitem__(self, int index):
try:
return self._vectors[index]
except KeyError:
pass
if index >= self._len:
raise IndexError(index)
vector = self._vectors[index] = MotionVector(_cinit_bypass_sentinel, self, index)
return vector
def __len__(self):
return self._len
def to_ndarray(self):
import numpy as np
return np.frombuffer(self, dtype=np.dtype([
('source', 'int32'),
('w', 'uint8'),
('h', 'uint8'),
('src_x', 'int16'),
('src_y', 'int16'),
('dst_x', 'int16'),
('dst_y', 'int16'),
('flags', 'uint64'),
('motion_x', 'int32'),
('motion_y', 'int32'),
('motion_scale', 'uint16'),
], align=True))
class MotionVectors(_MotionVectors, collections.Sequence):
pass
cdef class MotionVector(object):
def __init__(self, sentinel, _MotionVectors parent, int index):
if sentinel is not _cinit_bypass_sentinel:
raise RuntimeError('cannot manually instatiate MotionVector')
self.parent = parent
cdef lib.AVMotionVector *base = <lib.AVMotionVector*>parent.ptr.data
self.ptr = base + index
def __repr__(self):
return f'<av.sidedata.MotionVector {self.w}x{self.h} from {self.src_x},{self.src_y} to {self.dst_x},{self.dst_y}>'
@property
def source(self):
return self.ptr.source
@property
def w(self):
return self.ptr.w
@property
def h(self):
return self.ptr.h
@property
def src_x(self):
return self.ptr.src_x
@property
def src_y(self):
return self.ptr.src_y
@property
def dst_x(self):
return self.ptr.dst_x
@property
def dst_y(self):
return self.ptr.dst_y
@property
def motion_x(self):
return self.ptr.motion_x
@property
def motion_y(self):
return self.ptr.motion_y
@property
def motion_scale(self):
return self.ptr.motion_scale
av/sidedata/sidedata.pxd 0 → 100644
+ 23
- 0
  • View file @ 5c4658b2

  • Edit in single-file editor

  • Open in Web IDE

from av.buffer cimport Buffer
from av.dictionary cimport _Dictionary, wrap_dictionary
from av.frame cimport Frame
cimport libav as lib
cdef class SideData(Buffer):
cdef Frame frame
cdef lib.AVFrameSideData *ptr
cdef _Dictionary metadata
cdef SideData wrap_side_data(Frame frame, int index)
cdef class _SideDataContainer(object):
cdef Frame frame
cdef list _by_index
cdef dict _by_type
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
2
Client: Ruby Feature: OAS 3.0 spec support
2
Client: Ruby Feature: OAS 3.0 spec support
    Assign labels
  • Manage project labels

Milestone
5.0.0
5.0.0 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference: OpenAPITools/openapi-generator!7415
Source branch: sidedata

Menu

Explore Projects Groups Snippets