mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-07 11:13:41 +02:00
2b0e794ffc
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. Thanks to Lance Wang <lance.lmwang@gmail.com>, Anton Khirnov <anton@khirnov.net>, and Michael Niedermayer <michael@niedermayer.cc> for providing review/feedback. Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
111 lines
3.3 KiB
C
111 lines
3.3 KiB
C
/*
|
|
* 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
|
|
*/
|
|
|
|
/**
|
|
* @file
|
|
* CC FIFO Buffer
|
|
*/
|
|
|
|
#ifndef AVFILTER_CCFIFO_H
|
|
#define AVFILTER_CCFIFO_H
|
|
|
|
#include "libavutil/avutil.h"
|
|
#include "libavutil/frame.h"
|
|
#include "libavutil/fifo.h"
|
|
|
|
typedef struct AVCCFifo AVCCFifo;
|
|
|
|
/**
|
|
* Allocate an AVCCFifo.
|
|
*
|
|
* @param framerate output framerate
|
|
* @param log_ctx used for any av_log() calls
|
|
* @return newly allocated AVCCFifo, or NULL on error
|
|
*/
|
|
AVCCFifo *ff_ccfifo_alloc(AVRational framerate, void *log_ctx);
|
|
|
|
/**
|
|
* Free an AVCCFifo
|
|
*
|
|
* @param ccf Pointer to the pointer to the AVCCFifo which should be freed
|
|
* @note `*ptr = NULL` is safe and leads to no action.
|
|
*/
|
|
void ff_ccfifo_freep(AVCCFifo **ccf);
|
|
|
|
|
|
/**
|
|
* Extract CC data from an AVFrame
|
|
*
|
|
* Extract CC bytes from the AVFrame, insert them into our queue, and
|
|
* remove the side data from the AVFrame. The side data is removed
|
|
* as it will be re-inserted at the appropriate rate later in the
|
|
* filter.
|
|
*
|
|
* @param af AVCCFifo to write to
|
|
* @param frame AVFrame with the video frame to operate on
|
|
* @return Zero on success, or negative AVERROR
|
|
* code on failure.
|
|
*/
|
|
int ff_ccfifo_extract(AVCCFifo *ccf, AVFrame *frame);
|
|
|
|
/**
|
|
*Just like ff_ccfifo_extract(), but takes the raw bytes instead of an AVFrame
|
|
*/
|
|
int ff_ccfifo_extractbytes(AVCCFifo *ccf, uint8_t *data, size_t len);
|
|
|
|
/**
|
|
* Provide the size in bytes of an output buffer to allocate
|
|
*
|
|
* Ask for how many bytes the output will contain, so the caller can allocate
|
|
* an appropriately sized buffer and pass it to ff_ccfifo_injectbytes()
|
|
*
|
|
*/
|
|
int ff_ccfifo_getoutputsize(AVCCFifo *ccf);
|
|
|
|
/**
|
|
* Insert CC data from the FIFO into an AVFrame (as side data)
|
|
*
|
|
* Dequeue the appropriate number of CC tuples based on the
|
|
* frame rate, and insert them into the AVFrame
|
|
*
|
|
* @param af AVCCFifo to read from
|
|
* @param frame AVFrame with the video frame to operate on
|
|
* @return Zero on success, or negative AVERROR
|
|
* code on failure.
|
|
*/
|
|
int ff_ccfifo_inject(AVCCFifo *ccf, AVFrame *frame);
|
|
|
|
/**
|
|
* Just like ff_ccfifo_inject(), but takes the raw bytes to insert the CC data
|
|
* int rather than an AVFrame
|
|
*/
|
|
int ff_ccfifo_injectbytes(AVCCFifo *ccf, uint8_t *data, size_t len);
|
|
|
|
/**
|
|
* Returns 1 if captions have been found as a prior call
|
|
* to ff_ccfifo_extract() or ff_ccfifo_extractbytes()
|
|
*/
|
|
int ff_ccfifo_ccdetected(AVCCFifo *ccf);
|
|
|
|
#endif /* AVFILTER_CCFIFO_H */
|