FFmpeg
Data Structures | Macros | Functions | Variables
vf_readeia608.c File Reference
#include <string.h>
#include "libavutil/internal.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "internal.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)   offsetof(ReadEIA608Context, 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 AVFilter 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 37 of file vf_readeia608.c.

◆ CLOCK_BITSIZE_MIN

#define CLOCK_BITSIZE_MIN   0.2f

Definition at line 38 of file vf_readeia608.c.

◆ CLOCK_BITSIZE_MAX

#define CLOCK_BITSIZE_MAX   1.5f

Definition at line 39 of file vf_readeia608.c.

◆ SYNC_BITSIZE_MIN

#define SYNC_BITSIZE_MIN   12.f

Definition at line 40 of file vf_readeia608.c.

◆ SYNC_BITSIZE_MAX

#define SYNC_BITSIZE_MAX   15.f

Definition at line 41 of file vf_readeia608.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(ReadEIA608Context, x)

Definition at line 87 of file vf_readeia608.c.

◆ FLAGS

Definition at line 88 of file vf_readeia608.c.

◆ 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]; \
} \
} \
}

Definition at line 315 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 125 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 170 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 178 of file vf_readeia608.c.

Referenced by extract_line().

◆ meanf()

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

Definition at line 221 of file vf_readeia608.c.

Referenced by stddevf(), and thresholding().

◆ stddevf()

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

Definition at line 233 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 244 of file vf_readeia608.c.

Referenced by extract_line().

◆ periods()

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

Definition at line 283 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 306 of file vf_readeia608.c.

Referenced by extract_line().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 342 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 358 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 442 of file vf_readeia608.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 461 of file vf_readeia608.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 496 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 512 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 }
}

Definition at line 90 of file vf_readeia608.c.

◆ pixel_fmts

enum AVPixelFormat pixel_fmts[]
static

◆ readeia608_inputs

const AVFilterPad readeia608_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_input,
},
}

Definition at line 531 of file vf_readeia608.c.

◆ ff_vf_readeia608

const AVFilter ff_vf_readeia608
Initial value:
= {
.name = "readeia608",
.description = NULL_IF_CONFIG_SMALL("Read EIA-608 Closed Caption codes from input video and write them to frame metadata."),
.priv_size = sizeof(ReadEIA608Context),
.priv_class = &readeia608_class,
.uninit = uninit,
.process_command = process_command,
}

Definition at line 540 of file vf_readeia608.c.

AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:522
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_readeia608.c:512
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:162
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:514
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:521
w
uint8_t w
Definition: llviddspenc.c:38
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:516
b
#define b
Definition: input.c:41
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:478
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_readeia608.c:461
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:517
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:458
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:513
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:523
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:476
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:462
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:481
AV_PIX_FMT_YUVJ411P
@ 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_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:490
ff_video_default_filterpad
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
ReadEIA608Context
Definition: vf_readeia608.c:70
AV_PIX_FMT_YUVJ422P
@ 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_YUVA420P
@ 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_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:491
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:520
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:475
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:489
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:461
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
pixel_fmts
static enum AVPixelFormat pixel_fmts[]
Definition: vf_readeia608.c:101
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:182
AV_PIX_FMT_YUVJ444P
@ 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_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:459
if
if(ret)
Definition: filter_design.txt:179
FLAGS
#define FLAGS
Definition: vf_readeia608.c:88
NULL
#define NULL
Definition: coverity.c:32
AV_PIX_FMT_YUVJ420P
@ 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
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:480
readeia608_inputs
static const AVFilterPad readeia608_inputs[]
Definition: vf_readeia608.c:531
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:479
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_readeia608.c:496
f
f
Definition: af_crystalizer.c:121
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
OFFSET
#define OFFSET(x)
Definition: vf_readeia608.c:87
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:483
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:485
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
AV_PIX_FMT_YUVA444P
@ 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_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:518
line
Definition: graph2dot.c:48
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#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:147
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:238
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_readeia608.c:342
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV_PIX_FMT_YUVJ440P
@ 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_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:477
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:515
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:482
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:487
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:519
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
AVFILTER_FLAG_METADATA_ONLY
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
Definition: avfilter.h:133
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:251
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:80
d
d
Definition: ffmpeg_filter.c:409
AV_PIX_FMT_YUV410P
@ 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_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:484
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:488
LAG
#define LAG
Definition: vf_readeia608.c:37
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:460
LineItem
Definition: vf_readeia608.c:43
AV_PIX_FMT_YUVA422P
@ 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_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:486