FFmpeg
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 "internal.h"
37 #include "video.h"
38 
39 #define LAG 25
40 #define CLOCK_BITSIZE_MIN 0.2f
41 #define CLOCK_BITSIZE_MAX 1.5f
42 #define SYNC_BITSIZE_MIN 12.f
43 #define SYNC_BITSIZE_MAX 15.f
44 
45 typedef struct LineItem {
46  int input;
47  int output;
48 
49  float unfiltered;
50  float filtered;
51  float average;
52  float deviation;
53 } LineItem;
54 
55 typedef struct CodeItem {
57  int size;
58 } CodeItem;
59 
60 typedef struct ScanItem {
61  int nb_line;
62  int found;
63  int white;
64  int black;
65  uint64_t *histogram;
66  uint8_t byte[2];
67 
70 } ScanItem;
71 
72 typedef struct ReadEIA608Context {
73  const AVClass *class;
74 
75  int start, end;
76  float spw;
77  int chp;
78  int lp;
79 
80  int depth;
81  int max;
84 
85  void (*read_line[2])(AVFrame *in, int nb_line,
86  LineItem *line, int lp, int w);
88 
89 #define OFFSET(x) offsetof(ReadEIA608Context, x)
90 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
91 
92 static const AVOption readeia608_options[] = {
93  { "scan_min", "set from which line to scan for codes", OFFSET(start), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
94  { "scan_max", "set to which line to scan for codes", OFFSET(end), AV_OPT_TYPE_INT, {.i64=29}, 0, INT_MAX, FLAGS },
95  { "spw", "set ratio of width reserved for sync code detection", OFFSET(spw), AV_OPT_TYPE_FLOAT, {.dbl=.27}, 0.1, 0.7, FLAGS },
96  { "chp", "check and apply parity bit", OFFSET(chp), AV_OPT_TYPE_BOOL, {.i64= 0}, 0, 1, FLAGS },
97  { "lp", "lowpass line prior to processing", OFFSET(lp), AV_OPT_TYPE_BOOL, {.i64= 1}, 0, 1, FLAGS },
98  { NULL }
99 };
100 
101 AVFILTER_DEFINE_CLASS(readeia608);
102 
104 {
105  static const enum AVPixelFormat pixel_fmts[] = {
127  };
129  if (!formats)
130  return AVERROR(ENOMEM);
132 }
133 
134 static int config_filter(AVFilterContext *ctx, int start, int end)
135 {
136  ReadEIA608Context *s = ctx->priv;
137  AVFilterLink *inlink = ctx->inputs[0];
138  int size = inlink->w + LAG;
139 
140  if (end >= inlink->h) {
141  av_log(ctx, AV_LOG_WARNING, "Last line to scan too large, clipping.\n");
142  end = inlink->h - 1;
143  }
144 
145  if (start > end) {
146  av_log(ctx, AV_LOG_ERROR, "Invalid range.\n");
147  return AVERROR(EINVAL);
148  }
149 
150  if (s->nb_allocated < end - start + 1) {
151  const int diff = end - start + 1 - s->nb_allocated;
152 
153  s->scan = av_realloc_f(s->scan, end - start + 1, sizeof(*s->scan));
154  if (!s->scan)
155  return AVERROR(ENOMEM);
156  memset(&s->scan[s->nb_allocated], 0, diff * sizeof(*s->scan));
157  s->nb_allocated = end - start + 1;
158  }
159 
160  for (int i = 0; i < s->nb_allocated; i++) {
161  ScanItem *scan = &s->scan[i];
162 
163  if (!scan->histogram)
164  scan->histogram = av_calloc(s->max + 1, sizeof(*scan->histogram));
165  if (!scan->line)
166  scan->line = av_calloc(size, sizeof(*scan->line));
167  if (!scan->code)
168  scan->code = av_calloc(size, sizeof(*scan->code));
169  if (!scan->line || !scan->code || !scan->histogram)
170  return AVERROR(ENOMEM);
171  }
172 
173  s->start = start;
174  s->end = end;
175 
176  return 0;
177 }
178 
179 static void build_histogram(ReadEIA608Context *s, ScanItem *scan, const LineItem *line, int len)
180 {
181  memset(scan->histogram, 0, (s->max + 1) * sizeof(*scan->histogram));
182 
183  for (int i = LAG; i < len + LAG; i++)
184  scan->histogram[line[i].input]++;
185 }
186 
188 {
189  const int max = s->max;
190  int start = 0, end = 0, middle;
191  int black = 0, white = 0;
192  int cnt;
193 
194  for (int i = 0; i <= max; i++) {
195  if (scan->histogram[i]) {
196  start = i;
197  break;
198  }
199  }
200 
201  for (int i = max; i >= 0; i--) {
202  if (scan->histogram[i]) {
203  end = i;
204  break;
205  }
206  }
207 
208  middle = start + (end - start) / 2;
209 
210  cnt = 0;
211  for (int i = start; i <= middle; i++) {
212  if (scan->histogram[i] > cnt) {
213  cnt = scan->histogram[i];
214  black = i;
215  }
216  }
217 
218  cnt = 0;
219  for (int i = end; i >= middle; i--) {
220  if (scan->histogram[i] > cnt) {
221  cnt = scan->histogram[i];
222  white = i;
223  }
224  }
225 
226  scan->black = black;
227  scan->white = white;
228 }
229 
230 static float meanf(const LineItem *line, int len)
231 {
232  float sum = 0.0, mean = 0.0;
233 
234  for (int i = 0; i < len; i++)
235  sum += line[i].filtered;
236 
237  mean = sum / len;
238 
239  return mean;
240 }
241 
242 static float stddevf(const LineItem *line, int len)
243 {
244  float m = meanf(line, len);
245  float standard_deviation = 0.f;
246 
247  for (int i = 0; i < len; i++)
248  standard_deviation += (line[i].filtered - m) * (line[i].filtered - m);
249 
250  return sqrtf(standard_deviation / (len - 1));
251 }
252 
254  int lag, float threshold, float influence, int len)
255 {
256  for (int i = lag; i < len + lag; i++) {
257  line[i].unfiltered = line[i].input / 255.f;
258  line[i].filtered = line[i].unfiltered;
259  }
260 
261  for (int i = 0; i < lag; i++) {
262  line[i].unfiltered = meanf(line, len * s->spw);
263  line[i].filtered = line[i].unfiltered;
264  }
265 
266  line[lag - 1].average = meanf(line, lag);
267  line[lag - 1].deviation = stddevf(line, lag);
268 
269  for (int i = lag; i < len + lag; i++) {
270  if (fabsf(line[i].unfiltered - line[i-1].average) > threshold * line[i-1].deviation) {
271  if (line[i].unfiltered > line[i-1].average) {
272  line[i].output = 255;
273  } else {
274  line[i].output = 0;
275  }
276 
277  line[i].filtered = influence * line[i].unfiltered + (1.f - influence) * line[i-1].filtered;
278  } else {
279  int distance_from_black, distance_from_white;
280 
281  distance_from_black = FFABS(line[i].input - scan->black);
282  distance_from_white = FFABS(line[i].input - scan->white);
283 
284  line[i].output = distance_from_black <= distance_from_white ? 0 : 255;
285  }
286 
287  line[i].average = meanf(line + i - lag, lag);
288  line[i].deviation = stddevf(line + i - lag, lag);
289  }
290 }
291 
292 static int periods(const LineItem *line, CodeItem *code, int len)
293 {
294  int hold = line[LAG].output, cnt = 0;
295  int last = LAG;
296 
297  memset(code, 0, len * sizeof(*code));
298 
299  for (int i = LAG + 1; i < len + LAG; i++) {
300  if (line[i].output != hold) {
301  code[cnt].size = i - last;
302  code[cnt].bit = hold;
303  hold = line[i].output;
304  last = i;
305  cnt++;
306  }
307  }
308 
309  code[cnt].size = LAG + len - last;
310  code[cnt].bit = hold;
311 
312  return cnt + 1;
313 }
314 
315 static void dump_code(AVFilterContext *ctx, ScanItem *scan, int len, int item)
316 {
317  av_log(ctx, AV_LOG_DEBUG, "%d:", item);
318  for (int i = 0; i < len; i++) {
319  av_log(ctx, AV_LOG_DEBUG, " %03d", scan->code[i].size);
320  }
321  av_log(ctx, AV_LOG_DEBUG, "\n");
322 }
323 
324 #define READ_LINE(type, name) \
325 static void read_##name(AVFrame *in, int nb_line, LineItem *line, int lp, int w) \
326 { \
327  const type *src = (const type *)(&in->data[0][nb_line * in->linesize[0]]);\
328  \
329  if (lp) { \
330  for (int i = 0; i < w; i++) { \
331  int a = FFMAX(i - 3, 0); \
332  int b = FFMAX(i - 2, 0); \
333  int c = FFMAX(i - 1, 0); \
334  int d = FFMIN(i + 3, w-1); \
335  int e = FFMIN(i + 2, w-1); \
336  int f = FFMIN(i + 1, w-1); \
337  \
338  line[LAG + i].input = (src[a] + src[b] + src[c] + src[i] + \
339  src[d] + src[e] + src[f] + 6) / 7; \
340  } \
341  } else { \
342  for (int i = 0; i < w; i++) { \
343  line[LAG + i].input = src[i]; \
344  } \
345  } \
346 }
347 
348 READ_LINE(uint8_t, byte)
349 READ_LINE(uint16_t, word)
350 
352 {
353  AVFilterContext *ctx = inlink->dst;
354  ReadEIA608Context *s = ctx->priv;
356 
357  if (!desc)
358  return AVERROR_BUG;
359  s->depth = desc->comp[0].depth;
360  s->max = (1 << desc->comp[0].depth) - 1;
361  s->read_line[0] = read_byte;
362  s->read_line[1] = read_word;
363 
364  return config_filter(ctx, s->start, s->end);
365 }
366 
367 static void extract_line(AVFilterContext *ctx, AVFrame *in, ScanItem *scan, int w, int nb_line)
368 {
369  ReadEIA608Context *s = ctx->priv;
370  LineItem *line = scan->line;
371  int i, j, ch, len;
372  uint8_t codes[19] = { 0 };
373  float bit_size = 0.f;
374  int parity;
375 
376  memset(line, 0, (w + LAG) * sizeof(*line));
377  scan->byte[0] = scan->byte[1] = 0;
378  scan->found = 0;
379 
380  s->read_line[s->depth > 8](in, nb_line, line, s->lp, w);
381 
382  build_histogram(s, scan, line, w);
383  find_black_and_white(s, scan);
384  if (scan->white - scan->black < 5)
385  return;
386 
387  thresholding(s, scan, line, LAG, 1, 0, w);
388  len = periods(line, scan->code, w);
389  dump_code(ctx, scan, len, nb_line);
390  if (len < 15 ||
391  scan->code[14].bit != 0 ||
392  w / (float)scan->code[14].size < SYNC_BITSIZE_MIN ||
393  w / (float)scan->code[14].size > SYNC_BITSIZE_MAX) {
394  return;
395  }
396 
397  for (i = 14; i < len; i++) {
398  bit_size += scan->code[i].size;
399  }
400 
401  bit_size /= 19.f;
402  for (i = 1; i < 14; i++) {
403  if (scan->code[i].size / bit_size > CLOCK_BITSIZE_MAX ||
404  scan->code[i].size / bit_size < CLOCK_BITSIZE_MIN) {
405  return;
406  }
407  }
408 
409  if (scan->code[15].size / bit_size < 0.45f) {
410  return;
411  }
412 
413  for (j = 0, i = 14; i < len; i++) {
414  int run, bit;
415 
416  run = lrintf(scan->code[i].size / bit_size);
417  bit = scan->code[i].bit;
418 
419  for (int k = 0; j < 19 && k < run; k++) {
420  codes[j++] = bit;
421  }
422 
423  if (j >= 19)
424  break;
425  }
426 
427  for (ch = 0; ch < 2; ch++) {
428  for (parity = 0, i = 0; i < 8; i++) {
429  int b = codes[3 + ch * 8 + i];
430 
431  if (b == 255) {
432  parity++;
433  b = 1;
434  } else {
435  b = 0;
436  }
437  scan->byte[ch] |= b << i;
438  }
439 
440  if (s->chp) {
441  if (!(parity & 1)) {
442  scan->byte[ch] = 0x7F;
443  }
444  }
445  }
446 
447  scan->nb_line = nb_line;
448  scan->found = 1;
449 }
450 
452  int job, int nb_jobs)
453 {
454  ReadEIA608Context *s = ctx->priv;
455  AVFilterLink *inlink = ctx->inputs[0];
456  const int h = s->end - s->start + 1;
457  const int start = (h * job) / nb_jobs;
458  const int end = (h * (job+1)) / nb_jobs;
459  AVFrame *in = arg;
460 
461  for (int i = start; i < end; i++) {
462  ScanItem *scan = &s->scan[i];
463 
464  extract_line(ctx, in, scan, inlink->w, i);
465  }
466 
467  return 0;
468 }
469 
471 {
472  AVFilterContext *ctx = inlink->dst;
473  AVFilterLink *outlink = ctx->outputs[0];
474  ReadEIA608Context *s = ctx->priv;
475  int nb_found;
476 
477  ctx->internal->execute(ctx, extract_lines, in, NULL, FFMIN(FFMAX(s->end - s->start + 1, 1),
479 
480  nb_found = 0;
481  for (int i = 0; i < s->end - s->start + 1; i++) {
482  ScanItem *scan = &s->scan[i];
483  uint8_t key[128], value[128];
484 
485  if (!scan->found)
486  continue;
487 
488  //snprintf(key, sizeof(key), "lavfi.readeia608.%d.bits", nb_found);
489  //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);
490  //av_dict_set(&in->metadata, key, value, 0);
491 
492  snprintf(key, sizeof(key), "lavfi.readeia608.%d.cc", nb_found);
493  snprintf(value, sizeof(value), "0x%02X%02X", scan->byte[0], scan->byte[1]);
494  av_dict_set(&in->metadata, key, value, 0);
495 
496  snprintf(key, sizeof(key), "lavfi.readeia608.%d.line", nb_found);
497  snprintf(value, sizeof(value), "%d", scan->nb_line);
498  av_dict_set(&in->metadata, key, value, 0);
499 
500  nb_found++;
501  }
502 
503  return ff_filter_frame(outlink, in);
504 }
505 
507 {
508  ReadEIA608Context *s = ctx->priv;
509 
510  for (int i = 0; i < s->nb_allocated; i++) {
511  ScanItem *scan = &s->scan[i];
512 
513  av_freep(&scan->histogram);
514  av_freep(&scan->code);
515  av_freep(&scan->line);
516  }
517 
518  s->nb_allocated = 0;
519  av_freep(&s->scan);
520 }
521 
522 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
523  char *res, int res_len, int flags)
524 {
525  ReadEIA608Context *s = ctx->priv;
526  int ret, start = s->start, end = s->end;
527 
528  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
529  if (ret < 0)
530  return ret;
531 
532  ret = config_filter(ctx, s->start, s->end);
533  if (ret < 0) {
534  s->start = start;
535  s->end = end;
536  }
537 
538  return 0;
539 }
540 
541 static const AVFilterPad readeia608_inputs[] = {
542  {
543  .name = "default",
544  .type = AVMEDIA_TYPE_VIDEO,
545  .filter_frame = filter_frame,
546  .config_props = config_input,
547  },
548  { NULL }
549 };
550 
551 static const AVFilterPad readeia608_outputs[] = {
552  {
553  .name = "default",
554  .type = AVMEDIA_TYPE_VIDEO,
555  },
556  { NULL }
557 };
558 
560  .name = "readeia608",
561  .description = NULL_IF_CONFIG_SMALL("Read EIA-608 Closed Caption codes from input video and write them to frame metadata."),
562  .priv_size = sizeof(ReadEIA608Context),
563  .priv_class = &readeia608_class,
567  .uninit = uninit,
570 };
CodeItem::size
int size
Definition: vf_readeia608.c:57
formats
formats
Definition: signature.h:48
LineItem::average
float average
Definition: vf_readeia608.c:51
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:442
ReadEIA608Context::spw
float spw
Definition: vf_readeia608.c:76
LineItem::filtered
float filtered
Definition: vf_readeia608.c:50
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
CodeItem::bit
uint8_t bit
Definition: vf_readeia608.c:56
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
ScanItem::white
int white
Definition: vf_readeia608.c:63
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
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
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
ReadEIA608Context::end
int end
Definition: vf_readeia608.c:75
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1096
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
ReadEIA608Context::start
int start
Definition: vf_readeia608.c:75
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:434
readeia608_options
static const AVOption readeia608_options[]
Definition: vf_readeia608.c:92
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
pixdesc.h
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:441
w
uint8_t w
Definition: llviddspenc.c:39
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:436
AVOption
AVOption.
Definition: opt.h:248
b
#define b
Definition: input.c:41
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
LineItem::output
int output
Definition: vf_readeia608.c:47
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
max
#define max(a, b)
Definition: cuda_runtime.h:33
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:149
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_readeia608.c:470
video.h
AVFormatContext::internal
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1699
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:437
ff_vf_readeia608
AVFilter ff_vf_readeia608
Definition: vf_readeia608.c:559
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:379
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:65
formats.h
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:58
ScanItem::histogram
uint64_t * histogram
Definition: vf_readeia608.c:65
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:433
meanf
static float meanf(const LineItem *line, int len)
Definition: vf_readeia608.c:230
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:443
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:397
ScanItem::found
int found
Definition: vf_readeia608.c:62
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:383
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
ScanItem::nb_line
int nb_line
Definition: vf_readeia608.c:61
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
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:258
extract_lines
static int extract_lines(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
Definition: vf_readeia608.c:451
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:411
ff_set_common_formats
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
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_readeia608.c:103
ReadEIA608Context
Definition: vf_readeia608.c:72
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:79
s
#define s(width, name)
Definition: cbs_vp9.c:257
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:101
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:412
ReadEIA608Context::max
int max
Definition: vf_readeia608.c:81
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:440
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:396
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:410
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:382
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:66
key
const char * key
Definition: hwcontext_opencl.c:168
periods
static int periods(const LineItem *line, CodeItem *code, int len)
Definition: vf_readeia608.c:292
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:80
ReadEIA608Context::read_line
void(* read_line[2])(AVFrame *in, int nb_line, LineItem *line, int lp, int w)
Definition: vf_readeia608.c:85
arg
const char * arg
Definition: jacosubdec.c:66
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:380
ScanItem::byte
uint8_t byte[2]
Definition: vf_readeia608.c:66
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(readeia608)
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:33
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
FLAGS
#define FLAGS
Definition: vf_readeia608.c:90
ScanItem
Definition: vf_readeia608.c:60
NULL
#define NULL
Definition: coverity.c:32
run
uint8_t run
Definition: svq3.c:205
LineItem::unfiltered
float unfiltered
Definition: vf_readeia608.c:49
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:78
ReadEIA608Context::depth
int depth
Definition: vf_readeia608.c:80
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:401
find_black_and_white
static void find_black_and_white(ReadEIA608Context *s, ScanItem *scan)
Definition: vf_readeia608.c:187
ReadEIA608Context::scan
ScanItem * scan
Definition: vf_readeia608.c:83
readeia608_inputs
static const AVFilterPad readeia608_inputs[]
Definition: vf_readeia608.c:541
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
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
ReadEIA608Context::nb_allocated
int nb_allocated
Definition: vf_readeia608.c:82
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
READ_LINE
#define READ_LINE(type, name)
Definition: vf_readeia608.c:324
ReadEIA608Context::lp
int lp
Definition: vf_readeia608.c:78
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_readeia608.c:506
thresholding
static void thresholding(ReadEIA608Context *s, ScanItem *scan, LineItem *line, int lag, float threshold, float influence, int len)
Definition: vf_readeia608.c:253
LineItem::input
int input
Definition: vf_readeia608.c:46
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
dump_code
static void dump_code(AVFilterContext *ctx, ScanItem *scan, int len, int item)
Definition: vf_readeia608.c:315
stddevf
static float stddevf(const LineItem *line, int len)
Definition: vf_readeia608.c:242
FFMAX
#define FFMAX(a, b)
Definition: common.h:103
OFFSET
#define OFFSET(x)
Definition: vf_readeia608.c:89
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:404
size
int size
Definition: twinvq_data.h:10344
readeia608_outputs
static const AVFilterPad readeia608_outputs[]
Definition: vf_readeia608.c:551
CodeItem
Definition: vf_readeia608.c:55
parity
mcdeint parity
Definition: vf_mcdeint.c:277
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:406
ScanItem::black
int black
Definition: vf_readeia608.c:64
ff_filter_process_command
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:882
SYNC_BITSIZE_MAX
#define SYNC_BITSIZE_MAX
Definition: vf_readeia608.c:43
build_histogram
static void build_histogram(ReadEIA608Context *s, ScanItem *scan, const LineItem *line, int len)
Definition: vf_readeia608.c:179
FFMIN
#define FFMIN(a, b)
Definition: common.h:105
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:177
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:438
line
Definition: graph2dot.c:48
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
internal.h
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
lrintf
#define lrintf(x)
Definition: libm_mips.h:70
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_readeia608.c:351
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
extract_line
static void extract_line(AVFilterContext *ctx, AVFrame *in, ScanItem *scan, int w, int nb_line)
Definition: vf_readeia608.c:367
internal.h
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:802
value
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 value
Definition: writing_filters.txt:86
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:100
uint8_t
uint8_t
Definition: audio_convert.c:194
len
int len
Definition: vorbis_enc_data.h:452
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:398
AVFilter
Filter definition.
Definition: avfilter.h:145
CLOCK_BITSIZE_MAX
#define CLOCK_BITSIZE_MAX
Definition: vf_readeia608.c:41
ret
ret
Definition: filter_design.txt:187
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:435
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:403
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:408
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
LineItem::deviation
float deviation
Definition: vf_readeia608.c:52
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:439
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
mean
static float mean(const float *input, int size)
Definition: vf_nnedi.c:864
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:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:341
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
desc
const char * desc
Definition: libsvtav1.c:79
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:70
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
diff
static av_always_inline int diff(const uint32_t a, const uint32_t b)
Definition: vf_palettegen.c:136
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
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
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:73
ScanItem::code
CodeItem * code
Definition: vf_readeia608.c:68
ScanItem::line
LineItem * line
Definition: vf_readeia608.c:69
timestamp.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
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:72
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:405
h
h
Definition: vp9dsp_template.c:2038
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:409
ReadEIA608Context::chp
int chp
Definition: vf_readeia608.c:77
LAG
#define LAG
Definition: vf_readeia608.c:39
SYNC_BITSIZE_MIN
#define SYNC_BITSIZE_MIN
Definition: vf_readeia608.c:42
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:381
snprintf
#define snprintf
Definition: snprintf.h:34
LineItem
Definition: vf_readeia608.c:45
config_filter
static int config_filter(AVFilterContext *ctx, int start, int end)
Definition: vf_readeia608.c:134
line
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted line
Definition: swscale.txt:40
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:176
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:407
CLOCK_BITSIZE_MIN
#define CLOCK_BITSIZE_MIN
Definition: vf_readeia608.c:40