FFmpeg  4.4.9
vf_readeia608.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * Filter for reading closed captioning data (EIA-608).
24  * See also https://en.wikipedia.org/wiki/EIA-608
25  */
26 
27 #include <string.h>
28 
29 #include "libavutil/internal.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/timestamp.h"
33 
34 #include "avfilter.h"
35 #include "formats.h"
36 #include "filters.h"
37 #include "internal.h"
38 #include "video.h"
39 
40 #define LAG 25
41 #define CLOCK_BITSIZE_MIN 0.2f
42 #define CLOCK_BITSIZE_MAX 1.5f
43 #define SYNC_BITSIZE_MIN 12.f
44 #define SYNC_BITSIZE_MAX 15.f
45 
46 typedef struct LineItem {
47  int input;
48  int output;
49 
50  float unfiltered;
51  float filtered;
52  float average;
53  float deviation;
54 } LineItem;
55 
56 typedef struct CodeItem {
58  int size;
59 } CodeItem;
60 
61 typedef struct ScanItem {
62  int nb_line;
63  int found;
64  int white;
65  int black;
66  uint64_t *histogram;
67  uint8_t byte[2];
68 
71 } ScanItem;
72 
73 typedef struct ReadEIA608Context {
74  const AVClass *class;
75 
76  int start, end;
77  float spw;
78  int chp;
79  int lp;
80 
81  int depth;
82  int max;
85 
86  void (*read_line[2])(AVFrame *in, int nb_line,
87  LineItem *line, int lp, int w);
89 
90 #define OFFSET(x) offsetof(ReadEIA608Context, x)
91 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
92 
93 static const AVOption readeia608_options[] = {
94  { "scan_min", "set from which line to scan for codes", OFFSET(start), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
95  { "scan_max", "set to which line to scan for codes", OFFSET(end), AV_OPT_TYPE_INT, {.i64=29}, 0, INT_MAX, FLAGS },
96  { "spw", "set ratio of width reserved for sync code detection", OFFSET(spw), AV_OPT_TYPE_FLOAT, {.dbl=.27}, 0.1, 0.7, FLAGS },
97  { "chp", "check and apply parity bit", OFFSET(chp), AV_OPT_TYPE_BOOL, {.i64= 0}, 0, 1, FLAGS },
98  { "lp", "lowpass line prior to processing", OFFSET(lp), AV_OPT_TYPE_BOOL, {.i64= 1}, 0, 1, FLAGS },
99  { NULL }
100 };
101 
103 
105 {
106  static const enum AVPixelFormat pixel_fmts[] = {
128  };
130  if (!formats)
131  return AVERROR(ENOMEM);
133 }
134 
135 static int config_filter(AVFilterContext *ctx, int start, int end)
136 {
137  ReadEIA608Context *s = ctx->priv;
138  AVFilterLink *inlink = ctx->inputs[0];
139  int size = inlink->w + LAG;
140 
141  if (end >= inlink->h) {
142  av_log(ctx, AV_LOG_WARNING, "Last line to scan too large, clipping.\n");
143  end = inlink->h - 1;
144  }
145 
146  if (start > end) {
147  av_log(ctx, AV_LOG_ERROR, "Invalid range.\n");
148  return AVERROR(EINVAL);
149  }
150 
151  if (s->nb_allocated < end - start + 1) {
152  const int diff = end - start + 1 - s->nb_allocated;
153 
154  s->scan = av_realloc_f(s->scan, end - start + 1, sizeof(*s->scan));
155  if (!s->scan)
156  return AVERROR(ENOMEM);
157  memset(&s->scan[s->nb_allocated], 0, diff * sizeof(*s->scan));
158  s->nb_allocated = end - start + 1;
159  }
160 
161  for (int i = 0; i < s->nb_allocated; i++) {
162  ScanItem *scan = &s->scan[i];
163 
164  if (!scan->histogram)
165  scan->histogram = av_calloc(s->max + 1, sizeof(*scan->histogram));
166  if (!scan->line)
167  scan->line = av_calloc(size, sizeof(*scan->line));
168  if (!scan->code)
169  scan->code = av_calloc(size, sizeof(*scan->code));
170  if (!scan->line || !scan->code || !scan->histogram)
171  return AVERROR(ENOMEM);
172  }
173 
174  s->start = start;
175  s->end = end;
176 
177  return 0;
178 }
179 
180 static void build_histogram(ReadEIA608Context *s, ScanItem *scan, const LineItem *line, int len)
181 {
182  memset(scan->histogram, 0, (s->max + 1) * sizeof(*scan->histogram));
183 
184  for (int i = LAG; i < len + LAG; i++)
185  scan->histogram[FFMIN(line[i].input, s->max)]++;
186 }
187 
189 {
190  const int max = s->max;
191  int start = 0, end = 0, middle;
192  int black = 0, white = 0;
193  int cnt;
194 
195  for (int i = 0; i <= max; i++) {
196  if (scan->histogram[i]) {
197  start = i;
198  break;
199  }
200  }
201 
202  for (int i = max; i >= 0; i--) {
203  if (scan->histogram[i]) {
204  end = i;
205  break;
206  }
207  }
208 
209  middle = start + (end - start) / 2;
210 
211  cnt = 0;
212  for (int i = start; i <= middle; i++) {
213  if (scan->histogram[i] > cnt) {
214  cnt = scan->histogram[i];
215  black = i;
216  }
217  }
218 
219  cnt = 0;
220  for (int i = end; i >= middle; i--) {
221  if (scan->histogram[i] > cnt) {
222  cnt = scan->histogram[i];
223  white = i;
224  }
225  }
226 
227  scan->black = black;
228  scan->white = white;
229 }
230 
231 static float meanf(const LineItem *line, int len)
232 {
233  float sum = 0.0, mean = 0.0;
234 
235  for (int i = 0; i < len; i++)
236  sum += line[i].filtered;
237 
238  mean = sum / len;
239 
240  return mean;
241 }
242 
243 static float stddevf(const LineItem *line, int len)
244 {
245  float m = meanf(line, len);
246  float standard_deviation = 0.f;
247 
248  for (int i = 0; i < len; i++)
249  standard_deviation += (line[i].filtered - m) * (line[i].filtered - m);
250 
251  return sqrtf(standard_deviation / (len - 1));
252 }
253 
255  int lag, float threshold, float influence, int len)
256 {
257  for (int i = lag; i < len + lag; i++) {
258  line[i].unfiltered = line[i].input / 255.f;
259  line[i].filtered = line[i].unfiltered;
260  }
261 
262  for (int i = 0; i < lag; i++) {
263  line[i].unfiltered = meanf(line, len * s->spw);
264  line[i].filtered = line[i].unfiltered;
265  }
266 
267  line[lag - 1].average = meanf(line, lag);
268  line[lag - 1].deviation = stddevf(line, lag);
269 
270  for (int i = lag; i < len + lag; i++) {
271  if (fabsf(line[i].unfiltered - line[i-1].average) > threshold * line[i-1].deviation) {
272  if (line[i].unfiltered > line[i-1].average) {
273  line[i].output = 255;
274  } else {
275  line[i].output = 0;
276  }
277 
278  line[i].filtered = influence * line[i].unfiltered + (1.f - influence) * line[i-1].filtered;
279  } else {
280  int distance_from_black, distance_from_white;
281 
282  distance_from_black = FFABS(line[i].input - scan->black);
283  distance_from_white = FFABS(line[i].input - scan->white);
284 
285  line[i].output = distance_from_black <= distance_from_white ? 0 : 255;
286  }
287 
288  line[i].average = meanf(line + i - lag, lag);
289  line[i].deviation = stddevf(line + i - lag, lag);
290  }
291 }
292 
293 static int periods(const LineItem *line, CodeItem *code, int len)
294 {
295  int hold = line[LAG].output, cnt = 0;
296  int last = LAG;
297 
298  memset(code, 0, len * sizeof(*code));
299 
300  for (int i = LAG + 1; i < len + LAG; i++) {
301  if (line[i].output != hold) {
302  code[cnt].size = i - last;
303  code[cnt].bit = hold;
304  hold = line[i].output;
305  last = i;
306  cnt++;
307  }
308  }
309 
310  code[cnt].size = LAG + len - last;
311  code[cnt].bit = hold;
312 
313  return cnt + 1;
314 }
315 
316 static void dump_code(AVFilterContext *ctx, ScanItem *scan, int len, int item)
317 {
318  av_log(ctx, AV_LOG_DEBUG, "%d:", item);
319  for (int i = 0; i < len; i++) {
320  av_log(ctx, AV_LOG_DEBUG, " %03d", scan->code[i].size);
321  }
322  av_log(ctx, AV_LOG_DEBUG, "\n");
323 }
324 
325 #define READ_LINE(type, name) \
326 static void read_##name(AVFrame *in, int nb_line, LineItem *line, int lp, int w) \
327 { \
328  const type *src = (const type *)(&in->data[0][nb_line * in->linesize[0]]);\
329  \
330  if (lp) { \
331  for (int i = 0; i < w; i++) { \
332  int a = FFMAX(i - 3, 0); \
333  int b = FFMAX(i - 2, 0); \
334  int c = FFMAX(i - 1, 0); \
335  int d = FFMIN(i + 3, w-1); \
336  int e = FFMIN(i + 2, w-1); \
337  int f = FFMIN(i + 1, w-1); \
338  \
339  line[LAG + i].input = (src[a] + src[b] + src[c] + src[i] + \
340  src[d] + src[e] + src[f] + 6) / 7; \
341  } \
342  } else { \
343  for (int i = 0; i < w; i++) { \
344  line[LAG + i].input = src[i]; \
345  } \
346  } \
347 }
348 
349 READ_LINE(uint8_t, byte)
350 READ_LINE(uint16_t, word)
351 
352 static int config_input(AVFilterLink *inlink)
353 {
354  AVFilterContext *ctx = inlink->dst;
355  ReadEIA608Context *s = ctx->priv;
356  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
357 
358  if (!desc)
359  return AVERROR_BUG;
360  s->depth = desc->comp[0].depth;
361  s->max = (1 << desc->comp[0].depth) - 1;
362  s->read_line[0] = read_byte;
363  s->read_line[1] = read_word;
364 
365  return config_filter(ctx, s->start, s->end);
366 }
367 
368 static void extract_line(AVFilterContext *ctx, AVFrame *in, ScanItem *scan, int w, int nb_line)
369 {
370  ReadEIA608Context *s = ctx->priv;
371  LineItem *line = scan->line;
372  int i, j, ch, len;
373  uint8_t codes[19] = { 0 };
374  float bit_size = 0.f;
375  int parity;
376 
377  memset(line, 0, (w + LAG) * sizeof(*line));
378  scan->byte[0] = scan->byte[1] = 0;
379  scan->found = 0;
380 
381  s->read_line[s->depth > 8](in, nb_line, line, s->lp, w);
382 
383  build_histogram(s, scan, line, w);
384  find_black_and_white(s, scan);
385  if (scan->white - scan->black < 5)
386  return;
387 
388  thresholding(s, scan, line, LAG, 1, 0, w);
389  len = periods(line, scan->code, w);
390  dump_code(ctx, scan, len, nb_line);
391  if (len < 15 ||
392  scan->code[14].bit != 0 ||
393  w / (float)scan->code[14].size < SYNC_BITSIZE_MIN ||
394  w / (float)scan->code[14].size > SYNC_BITSIZE_MAX) {
395  return;
396  }
397 
398  for (i = 14; i < len; i++) {
399  bit_size += scan->code[i].size;
400  }
401 
402  bit_size /= 19.f;
403  for (i = 1; i < 14; i++) {
404  if (scan->code[i].size / bit_size > CLOCK_BITSIZE_MAX ||
405  scan->code[i].size / bit_size < CLOCK_BITSIZE_MIN) {
406  return;
407  }
408  }
409 
410  if (scan->code[15].size / bit_size < 0.45f) {
411  return;
412  }
413 
414  for (j = 0, i = 14; i < len; i++) {
415  int run, bit;
416 
417  run = lrintf(scan->code[i].size / bit_size);
418  bit = scan->code[i].bit;
419 
420  for (int k = 0; j < 19 && k < run; k++) {
421  codes[j++] = bit;
422  }
423 
424  if (j >= 19)
425  break;
426  }
427 
428  for (ch = 0; ch < 2; ch++) {
429  for (parity = 0, i = 0; i < 8; i++) {
430  int b = codes[3 + ch * 8 + i];
431 
432  if (b == 255) {
433  parity++;
434  b = 1;
435  } else {
436  b = 0;
437  }
438  scan->byte[ch] |= b << i;
439  }
440 
441  if (s->chp) {
442  if (!(parity & 1)) {
443  scan->byte[ch] = 0x7F;
444  }
445  }
446  }
447 
448  scan->nb_line = nb_line;
449  scan->found = 1;
450 }
451 
453  int job, int nb_jobs)
454 {
455  ReadEIA608Context *s = ctx->priv;
456  AVFilterLink *inlink = ctx->inputs[0];
457  const int h = s->end - s->start + 1;
458  const int start = ff_slice_pos(h, job, nb_jobs);
459  const int end = ff_slice_pos(h, job + 1, nb_jobs);
460  AVFrame *in = arg;
461 
462  for (int i = start; i < end; i++) {
463  ScanItem *scan = &s->scan[i];
464 
465  extract_line(ctx, in, scan, inlink->w, i);
466  }
467 
468  return 0;
469 }
470 
471 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
472 {
473  AVFilterContext *ctx = inlink->dst;
474  AVFilterLink *outlink = ctx->outputs[0];
475  ReadEIA608Context *s = ctx->priv;
476  int nb_found;
477 
478  ctx->internal->execute(ctx, extract_lines, in, NULL, FFMIN(FFMAX(s->end - s->start + 1, 1),
480 
481  nb_found = 0;
482  for (int i = 0; i < s->end - s->start + 1; i++) {
483  ScanItem *scan = &s->scan[i];
484  uint8_t key[128], value[128];
485 
486  if (!scan->found)
487  continue;
488 
489  //snprintf(key, sizeof(key), "lavfi.readeia608.%d.bits", nb_found);
490  //snprintf(value, sizeof(value), "0b%d%d%d%d%d%d%d%d 0b%d%d%d%d%d%d%d%d", codes[3]==255,codes[4]==255,codes[5]==255,codes[6]==255,codes[7]==255,codes[8]==255,codes[9]==255,codes[10]==255,codes[11]==255,codes[12]==255,codes[13]==255,codes[14]==255,codes[15]==255,codes[16]==255,codes[17]==255,codes[18]==255);
491  //av_dict_set(&in->metadata, key, value, 0);
492 
493  snprintf(key, sizeof(key), "lavfi.readeia608.%d.cc", nb_found);
494  snprintf(value, sizeof(value), "0x%02X%02X", scan->byte[0], scan->byte[1]);
495  av_dict_set(&in->metadata, key, value, 0);
496 
497  snprintf(key, sizeof(key), "lavfi.readeia608.%d.line", nb_found);
498  snprintf(value, sizeof(value), "%d", scan->nb_line);
499  av_dict_set(&in->metadata, key, value, 0);
500 
501  nb_found++;
502  }
503 
504  return ff_filter_frame(outlink, in);
505 }
506 
508 {
509  ReadEIA608Context *s = ctx->priv;
510 
511  for (int i = 0; i < s->nb_allocated; i++) {
512  ScanItem *scan = &s->scan[i];
513 
514  av_freep(&scan->histogram);
515  av_freep(&scan->code);
516  av_freep(&scan->line);
517  }
518 
519  s->nb_allocated = 0;
520  av_freep(&s->scan);
521 }
522 
523 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
524  char *res, int res_len, int flags)
525 {
526  ReadEIA608Context *s = ctx->priv;
527  int ret, start = s->start, end = s->end;
528 
529  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
530  if (ret < 0)
531  return ret;
532 
533  ret = config_filter(ctx, s->start, s->end);
534  if (ret < 0) {
535  s->start = start;
536  s->end = end;
537  }
538 
539  return 0;
540 }
541 
542 static const AVFilterPad readeia608_inputs[] = {
543  {
544  .name = "default",
545  .type = AVMEDIA_TYPE_VIDEO,
546  .filter_frame = filter_frame,
547  .config_props = config_input,
548  },
549  { NULL }
550 };
551 
552 static const AVFilterPad readeia608_outputs[] = {
553  {
554  .name = "default",
555  .type = AVMEDIA_TYPE_VIDEO,
556  },
557  { NULL }
558 };
559 
561  .name = "readeia608",
562  .description = NULL_IF_CONFIG_SMALL("Read EIA-608 Closed Caption codes from input video and write them to frame metadata."),
563  .priv_size = sizeof(ReadEIA608Context),
564  .priv_class = &readeia608_class,
568  .uninit = uninit,
571 };
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
#define av_cold
Definition: attributes.h:88
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
uint8_t
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1099
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition: avfilter.c:885
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:805
Main libavfilter public API header.
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define bit(string, value)
Definition: cbs_mpeg2.c:58
#define s(width, name)
Definition: cbs_vp9.c:257
#define FFMIN(a, b)
Definition: common.h:105
#define FFMAX(a, b)
Definition: common.h:103
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define NULL
Definition: coverity.c:32
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
#define max(a, b)
Definition: cuda_runtime.h:33
double value
Definition: eval.c:100
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
Definition: filters.h:282
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:587
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
#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
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
const char * key
int i
Definition: input.c:407
const char * arg
Definition: jacosubdec.c:67
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
#define lrintf(x)
Definition: libm_mips.h:70
const char * desc
Definition: libsvtav1.c:83
uint8_t w
Definition: llviddspenc.c:39
AVOptions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:410
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:406
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:398
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:405
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:379
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:397
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:438
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:441
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:403
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:436
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:434
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:404
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:381
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:396
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:433
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:437
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:407
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
@ 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:100
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
@ 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:258
@ 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:79
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
@ 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:80
@ 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:78
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:439
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:408
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:380
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:382
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:411
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:401
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:383
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:443
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:442
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:409
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:435
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:440
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:412
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
typedef void(RENAME(mix_any_func_type))
formats
Definition: signature.h:48
#define snprintf
Definition: snprintf.h:34
const uint8_t * code
Definition: spdifenc.c:413
Describe the class of an AVClass context structure.
Definition: log.h:67
An instance of a filter.
Definition: avfilter.h:341
A list of supported formats for one end of a filter link.
Definition: formats.h:65
A filter pad used for either input or output.
Definition: internal.h:54
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1699
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
AVOption.
Definition: opt.h:248
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
uint8_t bit
Definition: vf_readeia608.c:57
float average
Definition: vf_readeia608.c:52
float deviation
Definition: vf_readeia608.c:53
float unfiltered
Definition: vf_readeia608.c:50
float filtered
Definition: vf_readeia608.c:51
void(* read_line[2])(AVFrame *in, int nb_line, LineItem *line, int lp, int w)
Definition: vf_readeia608.c:86
uint8_t byte[2]
Definition: vf_readeia608.c:67
uint64_t * histogram
Definition: vf_readeia608.c:66
CodeItem * code
Definition: vf_readeia608.c:69
LineItem * line
Definition: vf_readeia608.c:70
Definition: graph2dot.c:48
uint8_t run
Definition: svq3.c:205
#define av_realloc_f(p, o, n)
#define av_freep(p)
#define av_log(a,...)
AVFormatContext * ctx
Definition: movenc.c:48
timestamp utils, mostly useful for debugging/logging purposes
int size
const char * b
Definition: vf_curves.c:119
mcdeint parity
Definition: vf_mcdeint.c:277
static float mean(const float *input, int size)
Definition: vf_nnedi.c:867
static av_always_inline int diff(const uint32_t a, const uint32_t b)
#define CLOCK_BITSIZE_MIN
Definition: vf_readeia608.c:41
static const AVOption readeia608_options[]
Definition: vf_readeia608.c:93
static float meanf(const LineItem *line, int len)
AVFILTER_DEFINE_CLASS(readeia608)
#define READ_LINE(type, name)
#define SYNC_BITSIZE_MAX
Definition: vf_readeia608.c:44
static void build_histogram(ReadEIA608Context *s, ScanItem *scan, const LineItem *line, int len)
static int query_formats(AVFilterContext *ctx)
#define LAG
Definition: vf_readeia608.c:40
static int config_input(AVFilterLink *inlink)
static const AVFilterPad readeia608_outputs[]
#define FLAGS
Definition: vf_readeia608.c:91
#define SYNC_BITSIZE_MIN
Definition: vf_readeia608.c:43
static void extract_line(AVFilterContext *ctx, AVFrame *in, ScanItem *scan, int w, int nb_line)
static void find_black_and_white(ReadEIA608Context *s, ScanItem *scan)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int periods(const LineItem *line, CodeItem *code, int len)
static int config_filter(AVFilterContext *ctx, int start, int end)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static av_cold void uninit(AVFilterContext *ctx)
static float stddevf(const LineItem *line, int len)
AVFilter ff_vf_readeia608
#define OFFSET(x)
Definition: vf_readeia608.c:90
static void dump_code(AVFilterContext *ctx, ScanItem *scan, int len, int item)
static int extract_lines(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
#define CLOCK_BITSIZE_MAX
Definition: vf_readeia608.c:42
static const AVFilterPad readeia608_inputs[]
static void thresholding(ReadEIA608Context *s, ScanItem *scan, LineItem *line, int lag, float threshold, float influence, int len)
int len