[FFmpeg-devel] [PATCH v15 01/16] global: Prepare AVFrame for subtitle handling

Michael Niedermayer michael at niedermayer.cc
Thu Nov 25 18:29:18 EET 2021


On Thu, Nov 25, 2021 at 12:48:11AM +0000, Soft Works wrote:
> Root commit for adding subtitle filtering capabilities.
> In detail:
> 
> - Add type (AVMediaType) field to AVFrame
>   Replaces previous way of distinction which was based on checking
>   width and height to determine whether a frame is audio or video
> - Add subtitle fields to AVFrame
> - Add new struct AVSubtitleArea, similar to AVSubtitleRect, but different
>   allocation logic. Cannot and must not be used interchangeably, hence
>   the new struct
> - Move enum AVSubtitleType, AVSubtitle and AVSubtitleRect to avutil
> - Add public-named members to enum AVSubtitleType (AV_SUBTITLE_FMT_)
> - Add avcodec_decode_subtitle3 which takes subtitle frames,
>   serving as compatibility shim to legacy subtitle decoding
> - Add additional methods for conversion between old and new API
> 
> Signed-off-by: softworkz <softworkz at hotmail.com>
> ---
>  libavcodec/avcodec.c       |  19 ---
>  libavcodec/avcodec.h       |  75 ++----------
>  libavcodec/decode.c        |  53 ++++++--
>  libavcodec/pgssubdec.c     |   1 +
>  libavcodec/utils.c         |  11 ++
>  libavfilter/vf_subtitles.c |  50 ++++++--
>  libavformat/utils.c        |   1 +
>  libavutil/Makefile         |   2 +
>  libavutil/frame.c          | 194 ++++++++++++++++++++++++++---
>  libavutil/frame.h          |  93 +++++++++++++-
>  libavutil/subfmt.c         | 243 +++++++++++++++++++++++++++++++++++++
>  libavutil/subfmt.h         | 185 ++++++++++++++++++++++++++++
>  12 files changed, 802 insertions(+), 125 deletions(-)
>  create mode 100644 libavutil/subfmt.c
>  create mode 100644 libavutil/subfmt.h
> 
> diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
> index c00a9b2af8..13e3711b9c 100644
> --- a/libavcodec/avcodec.c
> +++ b/libavcodec/avcodec.c
> @@ -422,25 +422,6 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
>          av_bsf_flush(avci->bsf);
>  }
>  
> -void avsubtitle_free(AVSubtitle *sub)
> -{
> -    int i;
> -
> -    for (i = 0; i < sub->num_rects; i++) {
> -        av_freep(&sub->rects[i]->data[0]);
> -        av_freep(&sub->rects[i]->data[1]);
> -        av_freep(&sub->rects[i]->data[2]);
> -        av_freep(&sub->rects[i]->data[3]);
> -        av_freep(&sub->rects[i]->text);
> -        av_freep(&sub->rects[i]->ass);
> -        av_freep(&sub->rects[i]);
> -    }
> -
> -    av_freep(&sub->rects);
> -
> -    memset(sub, 0, sizeof(*sub));
> -}
> -
>  av_cold int avcodec_close(AVCodecContext *avctx)
>  {
>      int i;
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 7ee8bc2b7c..0c5819b116 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -35,6 +35,7 @@
>  #include "libavutil/frame.h"
>  #include "libavutil/log.h"
>  #include "libavutil/pixfmt.h"
> +#include "libavutil/subfmt.h"
>  #include "libavutil/rational.h"
>  
>  #include "codec.h"
> @@ -1674,7 +1675,7 @@ typedef struct AVCodecContext {
>  
>      /**
>       * Header containing style information for text subtitles.
> -     * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
> +     * For AV_SUBTITLE_FMT_ASS subtitle type, it should contain the whole ASS
>       * [Script Info] and [V4+ Styles] section, plus the [Events] line and
>       * the Format line following. It shouldn't include any Dialogue line.
>       * - encoding: Set/allocated/freed by user (before avcodec_open2())
> @@ -2238,63 +2239,8 @@ typedef struct AVHWAccel {
>   * @}
>   */
>  
> -enum AVSubtitleType {
> -    SUBTITLE_NONE,
> -
> -    SUBTITLE_BITMAP,                ///< A bitmap, pict will be set
> -
> -    /**
> -     * Plain text, the text field must be set by the decoder and is
> -     * authoritative. ass and pict fields may contain approximations.
> -     */
> -    SUBTITLE_TEXT,
> -
> -    /**
> -     * Formatted text, the ass field must be set by the decoder and is
> -     * authoritative. pict and text fields may contain approximations.
> -     */
> -    SUBTITLE_ASS,
> -};

doesnt build so i cannot bisect breakages reliably

CC	libavcodec/libzvbi-teletextdec.o
libavcodec/libzvbi-teletextdec.c: In function ‘gen_sub_text’:
libavcodec/libzvbi-teletextdec.c:227:26: error: ‘SUBTITLE_NONE’ undeclared (first use in this function); did you mean ‘SUBTITLE_ASS’?
         sub_rect->type = SUBTITLE_NONE;
                          ^~~~~~~~~~~~~
                          SUBTITLE_ASS
libavcodec/libzvbi-teletextdec.c:227:26: note: each undeclared identifier is reported only once for each function it appears in
libavcodec/libzvbi-teletextdec.c: In function ‘gen_sub_ass’:
libavcodec/libzvbi-teletextdec.c:405:26: error: ‘SUBTITLE_NONE’ undeclared (first use in this function); did you mean ‘SUBTITLE_ASS’?
         sub_rect->type = SUBTITLE_NONE;
                          ^~~~~~~~~~~~~
                          SUBTITLE_ASS
libavcodec/libzvbi-teletextdec.c: In function ‘gen_sub_bitmap’:
libavcodec/libzvbi-teletextdec.c:465:26: error: ‘SUBTITLE_NONE’ undeclared (first use in this function); did you mean ‘SUBTITLE_ASS’?
         sub_rect->type = SUBTITLE_NONE;
                          ^~~~~~~~~~~~~
                          SUBTITLE_ASS
libavcodec/libzvbi-teletextdec.c: In function ‘teletext_decode_frame’:
libavcodec/libzvbi-teletextdec.c:698:43: error: ‘SUBTITLE_NONE’ undeclared (first use in this function); did you mean ‘SUBTITLE_ASS’?
         if (ctx->pages->sub_rect->type != SUBTITLE_NONE) {
                                           ^~~~~~~~~~~~~
                                           SUBTITLE_ASS
ffbuild/common.mak:70: recipe for target 'libavcodec/libzvbi-teletextdec.o' failed
make: *** [libavcodec/libzvbi-teletextdec.o] Error 1


[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

There will always be a question for which you do not know the correct answer.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20211125/b4090d5a/attachment.sig>


More information about the ffmpeg-devel mailing list