[haiku-development] BMediaTrack->ReadChunk() query

  • From: Zenja Solaja <solaja@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Fri, 11 Oct 2019 23:01:37 +1100

Hi everyone.

From the Haiku community forums some of you may have seen that 'm
developing a Haiku native media editor (audio + video).  I'm currently
working on the Export media functionality, and have 2 (user selectable)
export engines:  native BMediaKit and ffmpeg.

During video editing, the number of untouched frames is proportionally
quite high. ie. a majority of frames are simply trimming and repositioning,
so the bulk of frames have no applied graphical effects.  The source frames
are typically in a YCrCb format (eg. YUV420p planner instead of chunky), as
are the destination frames in mp4 and webm formats.  Since colour
conversion is lossy, quality suffers in the YCrCb->RGB->YCrCb pipeline.

Some of you can probably see the nature of my query.  Is it possible to get
the YCrCb data from BMediaTrack using ReadChunk() instead of ReadFrames(),
eg. using the BMediaTrack->ReadChunk() API (which uses the ffmpeg media
addon under the covers)).  If this were possible, then for a majority of
frames I could simply redirect the YCrCb frame to the ffmpeg encoder
without performing the lossy colour conversion to RBG and back again.

BMediaTrack->ReadChunk() was originally designed to work with RAW
(unencoded) videos.  But there is a very valid use case to read the YCrCb
image without performing colour correction, and to write it during
editing.  ReadChunk() specifies a byte size, and ideally it would return a
full frame (instead of 2 or more) and ignore the input buffer size (or
treat it like a max size but I cannot do anything with a partial frame).
Also, can I arbitrary call ReadChunk() after a previous ReadFrame(), mix
their calls (so to speak).  The original R5 header files says that this is
discouraged, but this was pre ffmpeg add-on.

Does anyone have experience with this matter?

Kind regards,
Zenja

Other related posts: