Skip to main content

av_subtitle_to_subtitle_frame

Function av_subtitle_to_subtitle_frame 

Source
pub unsafe fn av_subtitle_to_subtitle_frame(
    av_subtitle: *const AVSubtitle,
    time_base: Timebase,
) -> Result<SubtitleFrame<SubtitleFrameExtra, FfmpegBuffer>, ConvertError>
Expand description

Converts an FFmpeg AVSubtitle into a mediadecode::SubtitleFrame.

Strategy:

  • If the subtitle contains any text/ASS rects, produce a SubtitlePayload::Text whose buffer is the concatenation of their UTF-8 contents (newline-separated).
  • Otherwise, if the subtitle contains bitmap rects, produce a SubtitlePayload::Bitmap with one mediadecode::subtitle::BitmapRegion per rect (paletted indices and RGBA palette copied into fresh refcounted FfmpegBuffers, since AVSubtitleRect data is not refcounted).
  • An empty subtitle (no rects) becomes an empty Text payload.

time_base is the source stream’s time base, used to label pts / duration. The duration is computed as (end_display_time - start_display_time) in milliseconds, then rescaled into time_base.

§Safety

av_subtitle must be a live *const AVSubtitle for the duration of this call; the rect array (av_subtitle.rects) must be valid for av_subtitle.num_rects entries.