Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Lance Wang <lance.lmwang@gmail.com>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH v4 6/6] decklink_enc: add support for playout of 608 captions in MOV files
Date: Mon, 1 May 2023 07:01:18 +0800
Message-ID: <CAM=jba8RgTA4vJOzYOoyhA_rH=diB+c6s8rjzHUWCgEycLOFzg@mail.gmail.com> (raw)
In-Reply-To: <1682699871-22331-7-git-send-email-dheitmueller@ltnglobal.com>

On Fri, Apr 28, 2023 at 11:43 PM Devin Heitmueller <
devin.heitmueller@ltnglobal.com> wrote:

> Unlike other cases where the closed captions are embedded in the
> video stream as MPEG-2 userdata or H.264 SEI data, with MOV files
> the captions are often found on a separate "e608" subtitle track.
>
> Add support for playout of such files, leveraging the new ccfifo
> mechanism to ensure that they are embedded into VANC at the correct
> rate (since e608 packets often contain batches of multiple 608 pairs).
>
> Note this patch includes a new file named libavdevice/ccfifo.c, which
> allows the ccfifo functionality in libavfilter to be reused even if
> doing shared builds.  This is the same approach used for log2_tab.c.
>
>
This implementation  is limited to decklink SDI output only,  If possible,
can we implement the function from demuxer layer,  and then passthrough
by SEI side data? By this way,  we can convert  such stream in streaming
to  embedded CC to video stream easily also.


Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
> ---
>  libavdevice/Makefile          |  1 +
>  libavdevice/ccfifo.c          | 24 ++++++++++++++++
>  libavdevice/decklink_common.h |  3 ++
>  libavdevice/decklink_enc.cpp  | 66
> +++++++++++++++++++++++++++++++++++++++++++
>  libavdevice/decklink_enc_c.c  |  2 +-
>  5 files changed, 95 insertions(+), 1 deletion(-)
>  create mode 100644 libavdevice/ccfifo.c
>
> diff --git a/libavdevice/Makefile b/libavdevice/Makefile
> index 8a62822..c304492 100644
> --- a/libavdevice/Makefile
> +++ b/libavdevice/Makefile
> @@ -57,6 +57,7 @@ OBJS-$(CONFIG_LIBDC1394_INDEV)           += libdc1394.o
>
>  # Objects duplicated from other libraries for shared builds
>  SHLIBOBJS-$(CONFIG_DECKLINK_INDEV)       += reverse.o
> +SHLIBOBJS-$(CONFIG_DECKLINK_OUTDEV)      += ccfifo.o
>
>  # Windows resource file
>  SHLIBOBJS-$(HAVE_GNU_WINDRES)            += avdeviceres.o
> diff --git a/libavdevice/ccfifo.c b/libavdevice/ccfifo.c
> new file mode 100644
> index 0000000..9007094
> --- /dev/null
> +++ b/libavdevice/ccfifo.c
> @@ -0,0 +1,24 @@
> +/*
> + * CEA-708 Closed Captioning FIFO
> + * Copyright (c) 2023 LTN Global Communications
> + *
> + * Author: Devin Heitmueller <dheitmueller@ltnglobal.com>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> 02110-1301 USA
> + */
> +
> +#include "libavfilter/ccfifo.c"
> diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
> index 088e165..0d33f94 100644
> --- a/libavdevice/decklink_common.h
> +++ b/libavdevice/decklink_common.h
> @@ -31,6 +31,7 @@
>
>  extern "C" {
>  #include "libavcodec/packet_internal.h"
> +#include "libavfilter/ccfifo.h"
>  }
>  #include "libavutil/thread.h"
>  #include "decklink_common_c.h"
> @@ -112,6 +113,8 @@ struct decklink_ctx {
>      /* Capture buffer queue */
>      AVPacketQueue queue;
>
> +    AVCCFifo *cc_fifo;      ///< closed captions
> +
>      /* Streams present */
>      int audio;
>      int video;
> diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp
> index 9f1a8df..616e9c7 100644
> --- a/libavdevice/decklink_enc.cpp
> +++ b/libavdevice/decklink_enc.cpp
> @@ -326,6 +326,25 @@ static int create_s337_payload(AVPacket *pkt, uint8_t
> **outbuf, int *outsize)
>      return 0;
>  }
>
> +static int decklink_setup_subtitle(AVFormatContext *avctx, AVStream *st)
> +{
> +    int ret = -1;
> +
> +    switch(st->codecpar->codec_id) {
> +#if CONFIG_LIBKLVANC
> +    case AV_CODEC_ID_EIA_608:
> +        /* No special setup required */
> +        ret = 0;
> +        break;
> +#endif
> +    default:
> +        av_log(avctx, AV_LOG_ERROR, "Unsupported subtitle codec
> specified\n");
> +        break;
> +    }
> +
> +    return ret;
> +}
> +
>  av_cold int ff_decklink_write_trailer(AVFormatContext *avctx)
>  {
>      struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
> @@ -352,6 +371,7 @@ av_cold int ff_decklink_write_trailer(AVFormatContext
> *avctx)
>      klvanc_context_destroy(ctx->vanc_ctx);
>  #endif
>
> +    ff_ccfifo_freep(&ctx->cc_fifo);
>      av_freep(&cctx->ctx);
>
>      return 0;
> @@ -503,6 +523,23 @@ out:
>          free(afd_words);
>  }
>
> +/* Parse any EIA-608 subtitles sitting on the queue, and write packet
> side data
> +   that will later be handled by construct_cc... */
> +static void parse_608subs(AVFormatContext *avctx, struct decklink_ctx
> *ctx, AVPacket *pkt)
> +{
> +    uint8_t *cc_data;
> +    size_t cc_size;
> +    int ret;
> +
> +    ret = ff_ccfifo_injectbytes(ctx->cc_fifo, &cc_data, &cc_size);
> +    if (ret == 0) {
> +        uint8_t *cc_buf = av_packet_new_side_data(pkt,
> AV_PKT_DATA_A53_CC, cc_size);
> +        if (cc_buf)
> +            memcpy(cc_buf, cc_data, cc_size);
> +        av_freep(&cc_data);
> +    }
> +}
> +
>  static int decklink_construct_vanc(AVFormatContext *avctx, struct
> decklink_ctx *ctx,
>                                     AVPacket *pkt, decklink_frame *frame,
>                                     AVStream *st)
> @@ -513,6 +550,7 @@ static int decklink_construct_vanc(AVFormatContext
> *avctx, struct decklink_ctx *
>      if (!ctx->supports_vanc)
>          return 0;
>
> +    parse_608subs(avctx, ctx, pkt);
>      construct_cc(avctx, ctx, pkt, &vanc_lines);
>      construct_afd(avctx, ctx, pkt, &vanc_lines, st);
>
> @@ -704,12 +742,23 @@ static int
> decklink_write_audio_packet(AVFormatContext *avctx, AVPacket *pkt)
>      return ret;
>  }
>
> +static int decklink_write_subtitle_packet(AVFormatContext *avctx,
> AVPacket *pkt)
> +{
> +    struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
> +    struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx;
> +
> +    ff_ccfifo_extractbytes(ctx->cc_fifo, pkt->data, pkt->size);
> +
> +    return 0;
> +}
> +
>  extern "C" {
>
>  av_cold int ff_decklink_write_header(AVFormatContext *avctx)
>  {
>      struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data;
>      struct decklink_ctx *ctx;
> +    AVRational frame_rate;
>      unsigned int n;
>      int ret;
>
> @@ -768,12 +817,27 @@ av_cold int ff_decklink_write_header(AVFormatContext
> *avctx)
>          } else if (c->codec_type == AVMEDIA_TYPE_VIDEO) {
>              if (decklink_setup_video(avctx, st))
>                  goto error;
> +        } else if (c->codec_type == AVMEDIA_TYPE_SUBTITLE) {
> +            if (decklink_setup_subtitle(avctx, st))
> +                goto error;
>          } else {
>              av_log(avctx, AV_LOG_ERROR, "Unsupported stream type.\n");
>              goto error;
>          }
>      }
>
> +    for (n = 0; n < avctx->nb_streams; n++) {
> +        AVStream *st = avctx->streams[n];
> +        AVCodecParameters *c = st->codecpar;
> +
> +        if(c->codec_type == AVMEDIA_TYPE_SUBTITLE)
> +            avpriv_set_pts_info(st, 64, ctx->bmd_tb_num, ctx->bmd_tb_den);
> +    }
> +
> +    frame_rate = av_make_q(ctx->bmd_tb_den, ctx->bmd_tb_num);
> +    if (!(ctx->cc_fifo = ff_ccfifo_alloc(&frame_rate, ctx)))
> +        av_log(ctx, AV_LOG_VERBOSE, "Failure to setup CC FIFO queue\n");
> +
>      return 0;
>
>  error:
> @@ -789,6 +853,8 @@ int ff_decklink_write_packet(AVFormatContext *avctx,
> AVPacket *pkt)
>          return decklink_write_video_packet(avctx, pkt);
>      else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
>          return decklink_write_audio_packet(avctx, pkt);
> +    else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
> +        return decklink_write_subtitle_packet(avctx, pkt);
>
>      return AVERROR(EIO);
>  }
> diff --git a/libavdevice/decklink_enc_c.c b/libavdevice/decklink_enc_c.c
> index f7e3150..0a3984b 100644
> --- a/libavdevice/decklink_enc_c.c
> +++ b/libavdevice/decklink_enc_c.c
> @@ -77,7 +77,7 @@ const FFOutputFormat ff_decklink_muxer = {
>      .p.long_name      = NULL_IF_CONFIG_SMALL("Blackmagic DeckLink
> output"),
>      .p.audio_codec    = AV_CODEC_ID_PCM_S16LE,
>      .p.video_codec    = AV_CODEC_ID_WRAPPED_AVFRAME,
> -    .p.subtitle_codec = AV_CODEC_ID_NONE,
> +    .p.subtitle_codec = AV_CODEC_ID_EIA_608,
>      .p.flags          = AVFMT_NOFILE,
>      .p.priv_class     = &decklink_muxer_class,
>      .get_device_list = ff_decklink_list_output_devices,
> --
> 1.8.3.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2023-04-30 23:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-28 16:37 [FFmpeg-devel] [PATCH v4 0/6] Add support for Closed Caption FIFO Devin Heitmueller
2023-04-28 16:37 ` [FFmpeg-devel] [PATCH v4 1/6] ccfifo: Properly handle CEA-708 captions through framerate conversion Devin Heitmueller
2023-05-03  9:20   ` Anton Khirnov
2023-05-03 13:15     ` Devin Heitmueller
2023-04-28 16:37 ` [FFmpeg-devel] [PATCH v4 2/6] vf_fps: properly preserve CEA-708 captions Devin Heitmueller
2023-04-28 16:37 ` [FFmpeg-devel] [PATCH v4 3/6] yadif: Properly preserve CEA-708 closed captions Devin Heitmueller
2023-04-28 16:37 ` [FFmpeg-devel] [PATCH v4 4/6] tinterlace: " Devin Heitmueller
2023-04-28 16:37 ` [FFmpeg-devel] [PATCH v4 5/6] vf_ccrepack: Add new filter to repack CEA-708 side data Devin Heitmueller
2023-04-30 22:42   ` Lance Wang
2023-05-02 14:17     ` Devin Heitmueller
2023-04-28 16:37 ` [FFmpeg-devel] [PATCH v4 6/6] decklink_enc: add support for playout of 608 captions in MOV files Devin Heitmueller
2023-04-30 23:01   ` Lance Wang [this message]
2023-05-02 14:47     ` Devin Heitmueller
2023-05-03  7:36       ` Lance Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAM=jba8RgTA4vJOzYOoyhA_rH=diB+c6s8rjzHUWCgEycLOFzg@mail.gmail.com' \
    --to=lance.lmwang@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git