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 "libavutil/timestamp.h"
#include "avfilter.h"
#include "formats.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 query_formats (AVFilterContext *ctx)
 
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 const AVFilterPad readeia608_inputs []
 
static const AVFilterPad readeia608_outputs []
 
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 39 of file vf_readeia608.c.

◆ CLOCK_BITSIZE_MIN

#define CLOCK_BITSIZE_MIN   0.2f

Definition at line 40 of file vf_readeia608.c.

◆ CLOCK_BITSIZE_MAX

#define CLOCK_BITSIZE_MAX   1.5f

Definition at line 41 of file vf_readeia608.c.

◆ SYNC_BITSIZE_MIN

#define SYNC_BITSIZE_MIN   12.f

Definition at line 42 of file vf_readeia608.c.

◆ SYNC_BITSIZE_MAX

#define SYNC_BITSIZE_MAX   15.f

Definition at line 43 of file vf_readeia608.c.

◆ OFFSET

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

Definition at line 89 of file vf_readeia608.c.

◆ FLAGS

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

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( readeia608  )

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 103 of file vf_readeia608.c.

◆ config_filter()

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

Definition at line 134 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 179 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 187 of file vf_readeia608.c.

Referenced by extract_line().

◆ meanf()

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

Definition at line 230 of file vf_readeia608.c.

Referenced by stddevf(), and thresholding().

◆ stddevf()

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

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

Referenced by extract_line().

◆ periods()

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

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

Referenced by extract_line().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 351 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 367 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 451 of file vf_readeia608.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 470 of file vf_readeia608.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 506 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 522 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 92 of file vf_readeia608.c.

◆ readeia608_inputs

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

Definition at line 541 of file vf_readeia608.c.

◆ readeia608_outputs

const AVFilterPad readeia608_outputs[]
static
Initial value:
= {
{
.name = "default",
},
{ NULL }
}

Definition at line 551 of file vf_readeia608.c.

◆ ff_vf_readeia608

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,
}

Definition at line 559 of file vf_readeia608.c.

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:522
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
w
uint8_t w
Definition: llviddspenc.c:39
b
#define b
Definition: input.c:41
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_readeia608.c:470
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
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_readeia608.c:103
ReadEIA608Context
Definition: vf_readeia608.c:72
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
f
#define f(width, name)
Definition: cbs_vp9.c:255
if
if(ret)
Definition: filter_design.txt:179
FLAGS
#define FLAGS
Definition: vf_readeia608.c:90
NULL
#define NULL
Definition: coverity.c:32
src
#define src
Definition: vp8dsp.c:255
readeia608_inputs
static const AVFilterPad readeia608_inputs[]
Definition: vf_readeia608.c:541
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
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:506
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:117
FFMAX
#define FFMAX(a, b)
Definition: common.h:103
OFFSET
#define OFFSET(x)
Definition: vf_readeia608.c:89
readeia608_outputs
static const AVFilterPad readeia608_outputs[]
Definition: vf_readeia608.c:551
FFMIN
#define FFMIN(a, b)
Definition: common.h:105
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
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:126
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
i
int i
Definition: input.c:407
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_readeia608.c:351
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
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_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
LAG
#define LAG
Definition: vf_readeia608.c:39
LineItem
Definition: vf_readeia608.c:45