FFmpeg
Loading...
Searching...
No Matches
vf_readeia608.c File Reference

Filter for reading closed captioning data (EIA-608). More...

#include <string.h>
#include "libavutil/internal.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  LineItem
 
struct  CodeItem
 
struct  ScanItem
 
struct  ReadEIA608Context
 

Macros

#define LAG   25
 
#define CLOCK_BITSIZE_MIN   0.2f
 
#define CLOCK_BITSIZE_MAX   1.5f
 
#define SYNC_BITSIZE_MIN   12.f
 
#define SYNC_BITSIZE_MAX   15.f
 
#define OFFSET(x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
 
#define READ_LINE(type, name)
 

Functions

 AVFILTER_DEFINE_CLASS (readeia608)
 
static int config_filter (AVFilterContext *ctx, int start, int end)
 
static void build_histogram (ReadEIA608Context *s, ScanItem *scan, const LineItem *line, int len)
 
static void find_black_and_white (ReadEIA608Context *s, ScanItem *scan)
 
static float meanf (const LineItem *line, int len)
 
static float stddevf (const LineItem *line, int len)
 
static void thresholding (ReadEIA608Context *s, ScanItem *scan, LineItem *line, int lag, float threshold, float influence, int len)
 
static int periods (const LineItem *line, CodeItem *code, int len)
 
static void dump_code (AVFilterContext *ctx, ScanItem *scan, int len, int item)
 
static int config_input (AVFilterLink *inlink)
 
static void extract_line (AVFilterContext *ctx, AVFrame *in, ScanItem *scan, int w, int nb_line)
 
static int extract_lines (AVFilterContext *ctx, void *arg, int job, int nb_jobs)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int process_command (AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
 

Variables

static const AVOption readeia608_options []
 
static enum AVPixelFormat pixel_fmts []
 
static const AVFilterPad readeia608_inputs []
 
const FFFilter ff_vf_readeia608
 

Detailed Description

Filter for reading closed captioning data (EIA-608).

See also https://en.wikipedia.org/wiki/EIA-608

Definition in file vf_readeia608.c.

Macro Definition Documentation

◆ LAG

#define LAG   25

Definition at line 38 of file vf_readeia608.c.

Referenced by build_histogram(), config_filter(), extract_line(), and periods().

◆ CLOCK_BITSIZE_MIN

#define CLOCK_BITSIZE_MIN   0.2f

Definition at line 39 of file vf_readeia608.c.

Referenced by extract_line().

◆ CLOCK_BITSIZE_MAX

#define CLOCK_BITSIZE_MAX   1.5f

Definition at line 40 of file vf_readeia608.c.

Referenced by extract_line().

◆ SYNC_BITSIZE_MIN

#define SYNC_BITSIZE_MIN   12.f

Definition at line 41 of file vf_readeia608.c.

Referenced by extract_line().

◆ SYNC_BITSIZE_MAX

#define SYNC_BITSIZE_MAX   15.f

Definition at line 42 of file vf_readeia608.c.

Referenced by extract_line().

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 88 of file vf_readeia608.c.

◆ FLAGS

◆ READ_LINE

#define READ_LINE ( type,
name )
Value:
static void read_##name(AVFrame *in, int nb_line, LineItem *line, int lp, int w) \
{ \
const type *src = (const type *)(&in->data[0][nb_line * in->linesize[0]]);\
\
if (lp) { \
for (int i = 0; i < w; i++) { \
int a = FFMAX(i - 3, 0); \
int b = FFMAX(i - 2, 0); \
int c = FFMAX(i - 1, 0); \
int d = FFMIN(i + 3, w-1); \
int e = FFMIN(i + 2, w-1); \
int f = FFMIN(i + 1, w-1); \
\
line[LAG + i].input = (src[a] + src[b] + src[c] + src[i] + \
src[d] + src[e] + src[f] + 6) / 7; \
} \
} else { \
for (int i = 0; i < w; i++) { \
line[LAG + i].input = src[i]; \
} \
} \
}
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
int a
cl_device_type type
#define b
Definition input.c:43
uint8_t w
Definition llvidencdsp.c:39
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
const char * name
Definition qsvenc.c:142
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
#define src
Definition vp8dsp.c:248
#define LAG
static double c[64]

Definition at line 316 of file vf_readeia608.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( readeia608 )

◆ config_filter()

static int config_filter ( AVFilterContext * ctx,
int start,
int end )
static

Definition at line 126 of file vf_readeia608.c.

Referenced by config_input(), and process_command().

◆ build_histogram()

static void build_histogram ( ReadEIA608Context * s,
ScanItem * scan,
const LineItem * line,
int len )
static

Definition at line 171 of file vf_readeia608.c.

Referenced by extract_line().

◆ find_black_and_white()

static void find_black_and_white ( ReadEIA608Context * s,
ScanItem * scan )
static

Definition at line 179 of file vf_readeia608.c.

Referenced by extract_line().

◆ meanf()

static float meanf ( const LineItem * line,
int len )
static

Definition at line 222 of file vf_readeia608.c.

Referenced by stddevf(), and thresholding().

◆ stddevf()

static float stddevf ( const LineItem * line,
int len )
static

Definition at line 234 of file vf_readeia608.c.

Referenced by thresholding().

◆ thresholding()

static void thresholding ( ReadEIA608Context * s,
ScanItem * scan,
LineItem * line,
int lag,
float threshold,
float influence,
int len )
static

Definition at line 245 of file vf_readeia608.c.

Referenced by extract_line().

◆ periods()

static int periods ( const LineItem * line,
CodeItem * code,
int len )
static

Definition at line 284 of file vf_readeia608.c.

Referenced by extract_line().

◆ dump_code()

static void dump_code ( AVFilterContext * ctx,
ScanItem * scan,
int len,
int item )
static

Definition at line 307 of file vf_readeia608.c.

Referenced by extract_line().

◆ config_input()

static int config_input ( AVFilterLink * inlink)
static

Definition at line 343 of file vf_readeia608.c.

◆ extract_line()

static void extract_line ( AVFilterContext * ctx,
AVFrame * in,
ScanItem * scan,
int w,
int nb_line )
static

Definition at line 359 of file vf_readeia608.c.

Referenced by extract_lines().

◆ extract_lines()

static int extract_lines ( AVFilterContext * ctx,
void * arg,
int job,
int nb_jobs )
static

Definition at line 443 of file vf_readeia608.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink * inlink,
AVFrame * in )
static

Definition at line 462 of file vf_readeia608.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext * ctx)
static

Definition at line 497 of file vf_readeia608.c.

◆ process_command()

static int process_command ( AVFilterContext * ctx,
const char * cmd,
const char * args,
char * res,
int res_len,
int flags )
static

Definition at line 513 of file vf_readeia608.c.

Variable Documentation

◆ readeia608_options

const AVOption readeia608_options[]
static
Initial value:
= {
{ "scan_min", "set from which line to scan for codes", OFFSET(start), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
{ "scan_max", "set to which line to scan for codes", OFFSET(end), AV_OPT_TYPE_INT, {.i64=29}, 0, INT_MAX, FLAGS },
{ "spw", "set ratio of width reserved for sync code detection", OFFSET(spw), AV_OPT_TYPE_FLOAT, {.dbl=.27}, 0.1, 0.7, FLAGS },
{ "chp", "check and apply parity bit", OFFSET(chp), AV_OPT_TYPE_BOOL, {.i64= 0}, 0, 1, FLAGS },
{ "lp", "lowpass line prior to processing", OFFSET(lp), AV_OPT_TYPE_BOOL, {.i64= 1}, 0, 1, FLAGS },
{ NULL }
}
#define FLAGS
Definition cmdutils.c:598
#define NULL
Definition coverity.c:32
#define OFFSET(x)
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition opt.h:270
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326

Definition at line 91 of file vf_readeia608.c.

◆ pixel_fmts

enum AVPixelFormat pixel_fmts[]
static
Initial value:
= {
}
#define AV_PIX_FMT_YUV420P16
Definition pixfmt.h:556
#define AV_PIX_FMT_YUV444P12
Definition pixfmt.h:552
#define AV_PIX_FMT_YUV444P9
Definition pixfmt.h:544
#define AV_PIX_FMT_YUV420P10
Definition pixfmt.h:545
#define AV_PIX_FMT_YUV440P12
Definition pixfmt.h:551
#define AV_PIX_FMT_GRAY9
Definition pixfmt.h:524
#define AV_PIX_FMT_YUV422P9
Definition pixfmt.h:543
#define AV_PIX_FMT_YUVA444P10
Definition pixfmt.h:598
#define AV_PIX_FMT_YUVA420P16
Definition pixfmt.h:601
#define AV_PIX_FMT_YUV420P12
Definition pixfmt.h:549
#define AV_PIX_FMT_YUVA420P10
Definition pixfmt.h:596
#define AV_PIX_FMT_YUVA422P9
Definition pixfmt.h:594
#define AV_PIX_FMT_YUV422P12
Definition pixfmt.h:550
#define AV_PIX_FMT_YUV422P10
Definition pixfmt.h:546
#define AV_PIX_FMT_GRAY12
Definition pixfmt.h:526
#define AV_PIX_FMT_YUV420P9
Definition pixfmt.h:542
#define AV_PIX_FMT_YUVA420P9
Definition pixfmt.h:593
#define AV_PIX_FMT_YUVA422P10
Definition pixfmt.h:597
#define AV_PIX_FMT_YUV420P14
Definition pixfmt.h:553
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition pixfmt.h:106
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition pixfmt.h:108
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition pixfmt.h:107
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition pixfmt.h:79
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition pixfmt.h:80
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition pixfmt.h:174
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition pixfmt.h:283
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition pixfmt.h:86
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition pixfmt.h:173
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition pixfmt.h:87
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition pixfmt.h:85
#define AV_PIX_FMT_YUVA422P12
Definition pixfmt.h:599
#define AV_PIX_FMT_YUV422P14
Definition pixfmt.h:554
#define AV_PIX_FMT_GRAY10
Definition pixfmt.h:525
#define AV_PIX_FMT_GRAY14
Definition pixfmt.h:527
#define AV_PIX_FMT_YUV422P16
Definition pixfmt.h:557
#define AV_PIX_FMT_YUV440P10
Definition pixfmt.h:547
#define AV_PIX_FMT_GRAY16
Definition pixfmt.h:528
#define AV_PIX_FMT_YUVA444P16
Definition pixfmt.h:603
#define AV_PIX_FMT_YUVA422P16
Definition pixfmt.h:602
#define AV_PIX_FMT_YUV444P14
Definition pixfmt.h:555
#define AV_PIX_FMT_YUVA444P9
Definition pixfmt.h:595
#define AV_PIX_FMT_YUVA444P12
Definition pixfmt.h:600
#define AV_PIX_FMT_YUV444P16
Definition pixfmt.h:558
#define AV_PIX_FMT_YUV444P10
Definition pixfmt.h:548

Definition at line 102 of file vf_readeia608.c.

◆ readeia608_inputs

const AVFilterPad readeia608_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_input,
},
}
static int config_input(AVFilterLink *inlink)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200

Definition at line 532 of file vf_readeia608.c.

◆ ff_vf_readeia608

const FFFilter ff_vf_readeia608
Initial value:
= {
.p.name = "readeia608",
.p.description = NULL_IF_CONFIG_SMALL("Read EIA-608 Closed Caption codes from input video and write them to frame metadata."),
.p.priv_class = &readeia608_class,
.priv_size = sizeof(ReadEIA608Context),
.uninit = uninit,
.process_command = process_command,
}
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition avfilter.h:196
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition avfilter.h:166
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
Definition avfilter.h:182
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define FILTER_PIXFMTS_ARRAY(array)
Definition filters.h:244
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static enum AVPixelFormat pixel_fmts[]
Definition vf_amplify.c:52
static const AVFilterPad readeia608_inputs[]
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition video.c:37

Definition at line 541 of file vf_readeia608.c.