FFmpeg
Data Structures | Macros | Functions | Variables
vf_readeia608.c File Reference
#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)   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 38 of file vf_readeia608.c.

◆ CLOCK_BITSIZE_MIN

#define CLOCK_BITSIZE_MIN   0.2f

Definition at line 39 of file vf_readeia608.c.

◆ CLOCK_BITSIZE_MAX

#define CLOCK_BITSIZE_MAX   1.5f

Definition at line 40 of file vf_readeia608.c.

◆ SYNC_BITSIZE_MIN

#define SYNC_BITSIZE_MIN   12.f

Definition at line 41 of file vf_readeia608.c.

◆ SYNC_BITSIZE_MAX

#define SYNC_BITSIZE_MAX   15.f

Definition at line 42 of file vf_readeia608.c.

◆ OFFSET

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

Definition at line 88 of file vf_readeia608.c.

◆ FLAGS

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

Definition at line 91 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 532 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 541 of file vf_readeia608.c.

AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:546
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:513
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: filters.h:242
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:538
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:545
w
uint8_t w
Definition: llviddspenc.c:38
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:540
b
#define b
Definition: input.c:41
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:502
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:462
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:541
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:482
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:537
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:547
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:500
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:486
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:505
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:514
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:71
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:515
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:544
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:499
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:513
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:485
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:102
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
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:483
if
if(ret)
Definition: filter_design.txt:179
FLAGS
#define FLAGS
Definition: vf_readeia608.c:89
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:504
readeia608_inputs
static const AVFilterPad readeia608_inputs[]
Definition: vf_readeia608.c:532
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:503
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:497
f
f
Definition: af_crystalizer.c:122
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:94
OFFSET
#define OFFSET(x)
Definition: vf_readeia608.c:88
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:507
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:509
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:542
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:182
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_readeia608.c:343
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
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:501
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:539
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:506
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:511
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:543
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
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:168
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:152
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
Underlying C type is int.
Definition: opt.h:327
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
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:508
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:512
LAG
#define LAG
Definition: vf_readeia608.c:38
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:484
LineItem
Definition: vf_readeia608.c:44
src
#define src
Definition: vp8dsp.c:248
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:510