PyAV icon indicating copy to clipboard operation
PyAV copied to clipboard

Allow a path to using av_write_frame instead of forcing av_inteleaved_write_frame

Open hmaarrfk opened this issue 1 year ago • 1 comments

Overview

It seems that av_interleaved_write_frame adds some buffered that may be unecessary in some applications.

It would be good to be able to remove that need. Would you consider creating a code path toward using av_write_frame instead of forcing av_interleaved_write_frame?

https://ffmpeg.org/doxygen/3.3/group__lavf__encoding.html#gaa85cc1774f18f306cd20a40fc50d0b36

Desired Behavior

No added reference, no

Example API

# av/container/output.pyx
cdef class OutputContainer(Container):
    def mux_one(self, Packet packet not None, interleaved=True):
        # switch code paths for interleaved=False

Additional context

Honestly, I'm just trying to tighten up the performance on our muxing pipeline and I fear that there is some uncontrolled buffered (either in FFMPEG/PyAv/my own code) that is causing strange performance bugs to appear.

hmaarrfk avatar Feb 09 '24 12:02 hmaarrfk

may be unnecessary in some applications.

Such as?

First, I think it would be very annoying to implement because of this line: "The caller is responsible for correctly interleaving the packets if the format requires it."

Second, I think any memory saved would be too trivial compared to the weight of the Python interpreter.

WyattBlue avatar Feb 16 '24 03:02 WyattBlue

"The caller is responsible for correctly interleaving the packets if the format requires it."

In many application, the data is not coming in "interleaved" ways and it seems that pyav take effort to label the frame timestamps correctly.

You are right that it is likely a minor optimization. I'll eveluate more locally and try to remember to report my findings.

hmaarrfk avatar Mar 04 '24 16:03 hmaarrfk