Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove CodecContext.close() #1592

Merged
merged 1 commit into from
Oct 20, 2024
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
2 changes: 0 additions & 2 deletions av/audio/stream.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ class AudioStream(Stream):
type: Literal["audio"]
format: _Format
layout: _Layout

def close(self, strict: bool = True) -> None: ...
1 change: 0 additions & 1 deletion av/codec/context.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ cdef class CodecContext:

# Public API.
cpdef open(self, bint strict=?)
cpdef close(self, bint strict=?)

cdef _set_default_time_base(self)

Expand Down
1 change: 0 additions & 1 deletion av/codec/context.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class CodecContext:
delay: bool

def open(self, strict: bool = True) -> None: ...
def close(self, strict: bool = True) -> None: ...
@staticmethod
def create(
codec: str | Codec, mode: Literal["r", "w"] | None = None
Expand Down
7 changes: 0 additions & 7 deletions av/codec/context.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,6 @@ cdef class CodecContext:
self.ptr.time_base.num = 1
self.ptr.time_base.den = lib.AV_TIME_BASE

cpdef close(self, bint strict=True):
if not self._is_open:
if strict:
raise ValueError("CodecContext is already closed.")
return
self._is_open = False
lib.avcodec_free_context(&self.ptr)

def __dealloc__(self):
if self.ptr and self.extradata_set:
Expand Down
3 changes: 1 addition & 2 deletions av/container/output.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ cdef class OutputContainer(Container):

def close(self):
for stream in self.streams:
if stream.codec_context:
stream.codec_context.close(strict=False)
del stream

close_output(self)

Expand Down
2 changes: 0 additions & 2 deletions av/video/stream.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,3 @@ class VideoStream(Stream):
color_trc: int
colorspace: int
type: Literal["video"]

def close(self, strict: bool = True) -> None: ...
15 changes: 2 additions & 13 deletions tests/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def test_selection(self) -> None:
data = container.streams.data[0]
assert data == container.streams.best("data")

def test_printing_closed_video_stream(self) -> None:
def test_printing_video_stream(self) -> None:
input_ = av.open(
fate_suite("amv/MTV_high_res_320x240_sample_Penguin_Joke_MTV_from_WMV.amv")
)
container = av.open("out.mkv", "w")

video_stream = container.add_stream("h264", rate=30)
# encoder = video_stream.codec.name + ""
encoder = video_stream.codec.name

video_stream.width = input_.streams.video[0].width
video_stream.height = input_.streams.video[0].height
Expand All @@ -52,21 +52,10 @@ def test_printing_closed_video_stream(self) -> None:
container.mux(video_stream.encode(frame))
break

encoder = "libx264"
repr = f"{video_stream}"
assert repr.startswith(f"<av.VideoStream #0 {encoder}, yuv420p 160x120 at ")
assert repr.endswith(">")

# repr = f"{video_stream}"
# assert repr.startswith(f"<av.VideoStream #0 {encoder}, yuv420p 160x120 at ")
# assert repr.endswith(">")

video_stream.close()

repr = f"{video_stream}"
assert repr.startswith(f"<av.VideoStream #0 {encoder}, yuv420p 0x0 at ")
assert repr.endswith(">")

container.close()
input_.close()

Expand Down
Loading