Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH v2 1/5] ccfifo: Properly handle CEA-708 captions through framerate conversion
Date: Fri, 14 Apr 2023 10:22:06 -0300
Message-ID: <9f8ed9f7-90fb-acb2-c8c4-15743c68734c@gmail.com> (raw)
In-Reply-To: <1680904709-25951-2-git-send-email-dheitmueller@ltnglobal.com>

On 4/7/2023 6:58 PM, Devin Heitmueller wrote:
> When transcoding video that contains 708 closed captions, the
> caption data is tied to the frames as side data.  Simply dropping
> or adding frames to change the framerate will result in loss of
> data, so the caption data needs to be preserved and reformatted.
> 
> For example, without this patch converting 720p59 to 1080i59
> would result in loss of 50% of the caption bytes, resulting in
> garbled 608 captions and 708 probably wouldn't render at all.
> Further, the frames that are there will have an illegal
> cc_count for the target framerate, so some decoders may ignore
> the packets entirely.
> 
> Extract the 608 and 708 tuples and insert them onto queues.  Then
> after dropping/adding frames, re-write the tuples back into the
> resulting frames at the appropriate rate given the target
> framerate.  This includes both having the correct cc_count as
> well as clocking out the 608 pairs at the appropriate rate.
> 
> Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
> ---
>   libavfilter/Makefile |   1 +
>   libavfilter/ccfifo.c | 191 +++++++++++++++++++++++++++++++++++++++++++++++++++
>   libavfilter/ccfifo.h |  85 +++++++++++++++++++++++
>   3 files changed, 277 insertions(+)
>   create mode 100644 libavfilter/ccfifo.c
>   create mode 100644 libavfilter/ccfifo.h
> 
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 71e198b..628ade8 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -14,6 +14,7 @@ OBJS = allfilters.o                                                     \
>          buffersink.o                                                     \
>          buffersrc.o                                                      \
>          colorspace.o                                                     \
> +       ccfifo.o                                                         \
>          drawutils.o                                                      \
>          fifo.o                                                           \
>          formats.o                                                        \
> diff --git a/libavfilter/ccfifo.c b/libavfilter/ccfifo.c
> new file mode 100644
> index 0000000..5db4149
> --- /dev/null
> +++ b/libavfilter/ccfifo.c
> @@ -0,0 +1,191 @@
> +/*
> + * 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 "ccfifo.h"
> +
> +struct AVCCFifo {
> +    AVFifo *cc_608_fifo;
> +    AVFifo *cc_708_fifo;
> +    int expected_cc_count;
> +    int expected_608;
> +    int cc_detected;
> +    void *log_ctx;
> +};
> +
> +#define MAX_CC_ELEMENTS 128
> +#define CC_BYTES_PER_ENTRY 3
> +
> +struct cc_lookup {
> +    int num;
> +    int den;
> +    int cc_count;
> +    int num_608;
> +};
> +
> +const static struct cc_lookup cc_lookup_vals[] = {
> +    { 15, 1, 40, 4 },
> +    { 24, 1, 25, 3 },
> +    { 24000, 1001, 25, 3 },
> +    { 30, 1, 20, 2 },
> +    { 30000, 1001, 20, 2},
> +    { 60, 1, 10, 1 },
> +    { 60000, 1001, 10, 1},
> +};
> +
> +void av_ccfifo_freep(AVCCFifo **ccf)
> +{
> +    if (ccf && *ccf) {
> +        AVCCFifo *tmp = *ccf;
> +        if (tmp->cc_608_fifo)
> +            av_fifo_freep2(&tmp->cc_608_fifo);
> +        if (tmp->cc_708_fifo)
> +            av_fifo_freep2(&tmp->cc_708_fifo);
> +        av_freep(*ccf);
> +    }
> +}
> +
> +AVCCFifo *av_ccfifo_alloc(AVRational *framerate, void *log_ctx)

None of these functions should use the av_* prefix if they are meant to 
be internal, otherwise the symbols will be exported. Use ff_* instead.
_______________________________________________
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-14 13:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-07 21:58 [FFmpeg-devel] [PATCH v2 0/5] Add support for Closed Caption FIFO Devin Heitmueller
2023-04-07 21:58 ` [FFmpeg-devel] [PATCH v2 1/5] ccfifo: Properly handle CEA-708 captions through framerate conversion Devin Heitmueller
2023-04-14 13:22   ` James Almer [this message]
2023-04-14 15:19     ` Devin Heitmueller
2023-04-16  9:37       ` Thilo Borgmann
2023-04-17  0:29         ` Devin Heitmueller
2023-04-07 21:58 ` [FFmpeg-devel] [PATCH v2 2/5] vf_fps: properly preserve CEA-708 captions Devin Heitmueller
2023-04-07 21:58 ` [FFmpeg-devel] [PATCH v2 3/5] yadif: Properly preserve CEA-708 closed captions Devin Heitmueller
2023-04-07 21:58 ` [FFmpeg-devel] [PATCH v2 4/5] tinterlace: " Devin Heitmueller
2023-04-10  1:28   ` Lance Wang
2023-04-10 12:45     ` Devin Heitmueller
2023-04-07 21:58 ` [FFmpeg-devel] [PATCH v2 5/5] vf_ccrepack: Add new filter to repack CEA-708 side data Devin Heitmueller
2023-04-14 13:19 ` [FFmpeg-devel] [PATCH v2 0/5] Add support for Closed Caption FIFO Devin Heitmueller

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=9f8ed9f7-90fb-acb2-c8c4-15743c68734c@gmail.com \
    --to=jamrial@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