The AV_FRAME_DATA_S12M_TIMECODE field is described as:
/**
* Timecode which conforms to SMPTE ST 12-1. The data is an array of 4 uint32_t
* where the first uint32_t describes how many (1-3) of the other timecodes are used.
* The timecode format is described in the documentation of av_timecode_get_smpte_from_framenum()
* function in libavutil/timecode.h.
*/
AV_FRAME_DATA_S12M_TIMECODE
import av
container = av.open("video.mkv")
for frame in container.decode(video=0):
timecode_data = frame.side_data.get(av.sidedata.sidedata.Type.S12M_TIMECODE)
# ... use timecode_data
Investigation
N/A
Reproduction
N/A
Versions
OS: Ubuntu 22.04
PyAV runtime:
This refers to the PyAV installation in a virtualenv, installed with pip install av. Not sure if it is useful:
I tried manually adding a S12M_TIMECODE field to av.sidedata.sidedata, with this edits on the latest commit on main branch (1dfe7763023102a98cf94416c456eaafe67fdb93):
diff --git a/av/sidedata/sidedata.pyi b/av/sidedata/sidedata.pyi
index ac28f0d..e814bb2 100644
--- a/av/sidedata/sidedata.pyi
+++ b/av/sidedata/sidedata.pyi
@@ -23,6 +23,7 @@ class Type(EnumItem):
CONTENT_LIGHT_LEVEL: int
ICC_PROFILE: int
SEI_UNREGISTERED: int
+ S12M_TIMECODE: int
class SideData(Buffer):
type: Type
diff --git a/av/sidedata/sidedata.pyx b/av/sidedata/sidedata.pyx
index 05ed002..1e62dff 100644
--- a/av/sidedata/sidedata.pyx
+++ b/av/sidedata/sidedata.pyx
@@ -26,6 +26,7 @@ Type = define_enum("Type", __name__, (
("CONTENT_LIGHT_LEVEL", lib.AV_FRAME_DATA_CONTENT_LIGHT_LEVEL),
("ICC_PROFILE", lib.AV_FRAME_DATA_ICC_PROFILE),
("SEI_UNREGISTERED", lib.AV_FRAME_DATA_SEI_UNREGISTERED) if lib.AV_FRAME_DATA_SEI_UNREGISTERED != -1 else None,
+ ("S12M_TIMECODE", lib.AV_FRAME_DATA_S12M_TIMECODE) if lib.AV_FRAME_DATA_S12M_TIMECODE != -1 else None,
))
But the compilation fails with this message:
Compiling av/sidedata/sidedata.pyx because it changed.
[1/1] Cythonizing av/sidedata/sidedata.pyx
Error compiling Cython file:
------------------------------------------------------------
...
("GOP_TIMECODE", lib.AV_FRAME_DATA_GOP_TIMECODE),
("SPHERICAL", lib.AV_FRAME_DATA_SPHERICAL),
("CONTENT_LIGHT_LEVEL", lib.AV_FRAME_DATA_CONTENT_LIGHT_LEVEL),
("ICC_PROFILE", lib.AV_FRAME_DATA_ICC_PROFILE),
("SEI_UNREGISTERED", lib.AV_FRAME_DATA_SEI_UNREGISTERED) if lib.AV_FRAME_DATA_SEI_UNREGISTERED != -1 else None,
("S12M_TIMECODE", lib.AV_FRAME_DATA_S12M_TIMECODE) if lib.AV_FRAME_DATA_S12M_TIMECODE != -1 else None,
^
------------------------------------------------------------
av/sidedata/sidedata.pyx:29:61: cimported module has no attribute 'AV_FRAME_DATA_S12M_TIMECODE'
Error compiling Cython file:
------------------------------------------------------------
...
("GOP_TIMECODE", lib.AV_FRAME_DATA_GOP_TIMECODE),
("SPHERICAL", lib.AV_FRAME_DATA_SPHERICAL),
("CONTENT_LIGHT_LEVEL", lib.AV_FRAME_DATA_CONTENT_LIGHT_LEVEL),
("ICC_PROFILE", lib.AV_FRAME_DATA_ICC_PROFILE),
("SEI_UNREGISTERED", lib.AV_FRAME_DATA_SEI_UNREGISTERED) if lib.AV_FRAME_DATA_SEI_UNREGISTERED != -1 else None,
("S12M_TIMECODE", lib.AV_FRAME_DATA_S12M_TIMECODE) if lib.AV_FRAME_DATA_S12M_TIMECODE != -1 else None,
^
------------------------------------------------------------
av/sidedata/sidedata.pyx:29:25: cimported module has no attribute 'AV_FRAME_DATA_S12M_TIMECODE'
Traceback (most recent call last):
File "/code/PyAV/setup.py", line 156, in <module>
ext_modules += cythonize(
File "/code/PyAV/venvs/Linux.6.5.0-21-generic.cpython3.10/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
cythonize_one(*args)
File "/code/PyAV/venvs/Linux.6.5.0-21-generic.cpython3.10/lib/python3.10/site-packages/Cython/Build/Dependencies.py", line 1321, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: av/sidedata/sidedata.pyx
make: *** [Makefile:14: build] Error 1
From FFmpeg sources, I can see that AV_FRAME_DATA_S12M_TIMECODE was added in libavutil version 56.20.100:
And I have installed the package libavutil-dev version 7:4.4.2-0ubuntu0.22.04.1 and libavutil56, which for Ubuntu22.04 provide libavutil version 56.70.100 as can be seen in the following lines:
So the libavutil version should be sufficient, as far as I understand, but maybe I need something else to make this work, I do not have sufficient experience.
Overview
Adding
S12M_TIMECODE
field to theav.sidedata.sidedata.Type
Enum would give the ability to read timecode information from SEI metadata.Existing FFmpeg API
The existing FFmpeg enum is defined in
libavutil/frame.h
and is calledAVFrameSideDataType
.The documentation is at https://ffmpeg.org/doxygen/trunk/group__lavu__frame.html#gae01fa7e427274293aacdf2adc17076bc.
The
AV_FRAME_DATA_S12M_TIMECODE
field is described as:This is the link to the
AV_FRAME_DATA_S12M_TIMECODE
field in the docs: https://ffmpeg.org/doxygen/trunk/group__lavu__frame.html#ggae01fa7e427274293aacdf2adc17076bca9f4e4ed5a874d1089ec07c384b81bb70Expected PyAV API
PyAV should have a
S12M_TIMECODE
field in theav.sidedata.sidedata.Type
Enum, which is currently defined as: https://github.com/PyAV-Org/PyAV/blob/1b27fc96ff3d1dc9eb7774f065a5e8e9c43475d8/av/sidedata/sidedata.pyx#L11-L29Example:
Investigation
N/A
Reproduction
N/A
Versions
pip install av
. Not sure if it is useful:Additional context
I tried manually adding a
S12M_TIMECODE
field toav.sidedata.sidedata
, with this edits on the latest commit on main branch (1dfe7763023102a98cf94416c456eaafe67fdb93):But the compilation fails with this message:
From FFmpeg sources, I can see that
AV_FRAME_DATA_S12M_TIMECODE
was added in libavutil version 56.20.100:https://github.com/FFmpeg/FFmpeg/blob/89215237dd6ac64f94e14aa20a000e0440a00aac/doc/APIchanges#L894-L895
And I have installed the package libavutil-dev version 7:4.4.2-0ubuntu0.22.04.1 and libavutil56, which for Ubuntu22.04 provide libavutil version 56.70.100 as can be seen in the following lines:
So the
libavutil
version should be sufficient, as far as I understand, but maybe I need something else to make this work, I do not have sufficient experience.