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
10 changes: 10 additions & 0 deletions av/container/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,16 @@ def _assert_open(self):
if self.ptr == cython.NULL:
raise AssertionError("Container is not open")

@property
def video_codec_id(self):
self._assert_open()
return self.ptr.video_codec_id

@video_codec_id.setter
def video_codec_id(self, value: lib.AVCodecID):
self._assert_open()
self.ptr.video_codec_id = value

@property
def flags(self):
self._assert_open()
Expand Down
1 change: 1 addition & 0 deletions av/container/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Container:
open_timeout: Real | None
read_timeout: Real | None
flags: int
video_codec_id: int
def __enter__(self) -> Container: ...
def __exit__(
self,
Expand Down
7 changes: 4 additions & 3 deletions include/avformat.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ cdef extern from "libavformat/avformat.h" nogil:
int64_t(*seek)(void *opaque, int64_t offset, int whence)
)

# http://ffmpeg.org/doxygen/trunk/structAVInputFormat.html
# https://ffmpeg.org/doxygen/trunk/structAVInputFormat.html
cdef struct AVInputFormat:
const char *name
const char *long_name
const char *extensions
int flags
const AVClass *priv_class

# http://ffmpeg.org/doxygen/trunk/structAVOutputFormat.html
# https://ffmpeg.org/doxygen/trunk/structAVOutputFormat.html
cdef struct AVOutputFormat:
const char *name
const char *long_name
const char *extensions
AVCodecID video_codec
AVCodecID audio_codec
AVCodecID video_codec
AVCodecID subtitle_codec
int flags
const AVClass *priv_class
Expand Down Expand Up @@ -156,6 +156,7 @@ cdef extern from "libavformat/avformat.h" nogil:
int bit_rate
int flags
AVCodecID audio_codec_id
AVCodecID video_codec_id
void *opaque
int (*io_open)(
AVFormatContext *s,
Expand Down
19 changes: 19 additions & 0 deletions tests/test_containerformat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from av import ContainerFormat, formats_available, open

from .common import fate_suite


def test_matroska() -> None:
with open("test.mkv", "w") as container:
Expand Down Expand Up @@ -56,5 +58,22 @@ def test_stream_segment() -> None:
assert fmt.no_file


def test_video_codec_id() -> None:
# Regression test for https://github.com/PyAV-Org/PyAV/issues/2243
# video_codec_id allows overriding the codec used when opening a container.
AV_CODEC_ID_NONE = 0
AV_CODEC_ID_H264 = 27

with open(fate_suite("h264/interlaced_crop.mp4")) as container:
assert container.video_codec_id == AV_CODEC_ID_NONE
container.video_codec_id = AV_CODEC_ID_H264
assert container.video_codec_id == AV_CODEC_ID_H264

with open("test.mkv", "w") as container:
assert container.video_codec_id == AV_CODEC_ID_NONE
container.video_codec_id = AV_CODEC_ID_H264
assert container.video_codec_id == AV_CODEC_ID_H264


def test_formats_available() -> None:
assert formats_available
Loading