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[256];
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 
83 
84 #define OFFSET(x) offsetof(ReadEIA608Context, x)
85 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
86 
87 static const AVOption readeia608_options[] = {
88  { "scan_min", "set from which line to scan for codes", OFFSET(start), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
89  { "scan_max", "set to which line to scan for codes", OFFSET(end), AV_OPT_TYPE_INT, {.i64=29}, 0, INT_MAX, FLAGS },
90  { "spw", "set ratio of width reserved for sync code detection", OFFSET(spw), AV_OPT_TYPE_FLOAT, {.dbl=.27}, 0.1, 0.7, FLAGS },
91  { "chp", "check and apply parity bit", OFFSET(chp), AV_OPT_TYPE_BOOL, {.i64= 0}, 0, 1, FLAGS },
92  { "lp", "lowpass line prior to processing", OFFSET(lp), AV_OPT_TYPE_BOOL, {.i64= 1}, 0, 1, FLAGS },
93  { NULL }
94 };
95 
96 AVFILTER_DEFINE_CLASS(readeia608);
97 
99 {
100  static const enum AVPixelFormat pixel_fmts[] = {
109  };
111  if (!formats)
112  return AVERROR(ENOMEM);
113  return ff_set_common_formats(ctx, formats);
114 }
115 
116 static int config_filter(AVFilterContext *ctx, int start, int end)
117 {
118  ReadEIA608Context *s = ctx->priv;
119  AVFilterLink *inlink = ctx->inputs[0];
120  int size = inlink->w + LAG;
121 
122  if (end >= inlink->h) {
123  av_log(ctx, AV_LOG_WARNING, "Last line to scan too large, clipping.\n");
124  end = inlink->h - 1;
125  }
126 
127  if (start > end) {
128  av_log(ctx, AV_LOG_ERROR, "Invalid range.\n");
129  return AVERROR(EINVAL);
130  }
131 
132  if (s->nb_allocated < end - start + 1) {
133  const int diff = end - start + 1 - s->nb_allocated;
134 
135  s->scan = av_realloc_f(s->scan, end - start + 1, sizeof(*s->scan));
136  if (!s->scan)
137  return AVERROR(ENOMEM);
138  memset(&s->scan[s->nb_allocated], 0, diff * sizeof(*s->scan));
139  s->nb_allocated = end - start + 1;
140  }
141 
142  for (int i = 0; i < s->nb_allocated; i++) {
143  ScanItem *scan = &s->scan[i];
144 
145  if (!scan->line)
146  scan->line = av_calloc(size, sizeof(*scan->line));
147  if (!scan->code)
148  scan->code = av_calloc(size, sizeof(*scan->code));
149  if (!scan->line || !scan->code)
150  return AVERROR(ENOMEM);
151  }
152 
153  s->start = start;
154  s->end = end;
155 
156  return 0;
157 }
158 
160 {
161  AVFilterContext *ctx = inlink->dst;
162  ReadEIA608Context *s = ctx->priv;
163 
164  return config_filter(ctx, s->start, s->end);
165 }
166 
167 static void build_histogram(ReadEIA608Context *s, ScanItem *scan, const LineItem *line, int len)
168 {
169  memset(scan->histogram, 0, sizeof(scan->histogram));
170 
171  for (int i = LAG; i < len + LAG; i++)
172  scan->histogram[line[i].input]++;
173 }
174 
176 {
177  int start = 0, end = 0, middle;
178  int black = 0, white = 0;
179  int cnt;
180 
181  for (int i = 0; i < 256; i++) {
182  if (scan->histogram[i]) {
183  start = i;
184  break;
185  }
186  }
187 
188  for (int i = 255; i >= 0; i--) {
189  if (scan->histogram[i]) {
190  end = i;
191  break;
192  }
193  }
194 
195  middle = start + (end - start) / 2;
196 
197  cnt = 0;
198  for (int i = start; i <= middle; i++) {
199  if (scan->histogram[i] > cnt) {
200  cnt = scan->histogram[i];
201  black = i;
202  }
203  }
204 
205  cnt = 0;
206  for (int i = end; i >= middle; i--) {
207  if (scan->histogram[i] > cnt) {
208  cnt = scan->histogram[i];
209  white = i;
210  }
211  }
212 
213  scan->black = black;
214  scan->white = white;
215 }
216 
217 static float meanf(const LineItem *line, int len)
218 {
219  float sum = 0.0, mean = 0.0;
220 
221  for (int i = 0; i < len; i++)
222  sum += line[i].filtered;
223 
224  mean = sum / len;
225 
226  return mean;
227 }
228 
229 static float stddevf(const LineItem *line, int len)
230 {
231  float m = meanf(line, len);
232  float standard_deviation = 0.f;
233 
234  for (int i = 0; i < len; i++)
235  standard_deviation += (line[i].filtered - m) * (line[i].filtered - m);
236 
237  return sqrtf(standard_deviation / (len - 1));
238 }
239 
241  int lag, float threshold, float influence, int len)
242 {
243  for (int i = lag; i < len + lag; i++) {
244  line[i].unfiltered = line[i].input / 255.f;
245  line[i].filtered = line[i].unfiltered;
246  }
247 
248  for (int i = 0; i < lag; i++) {
249  line[i].unfiltered = meanf(line, len * s->spw);
250  line[i].filtered = line[i].unfiltered;
251  }
252 
253  line[lag - 1].average = meanf(line, lag);
254  line[lag - 1].deviation = stddevf(line, lag);
255 
256  for (int i = lag; i < len + lag; i++) {
257  if (fabsf(line[i].unfiltered - line[i-1].average) > threshold * line[i-1].deviation) {
258  if (line[i].unfiltered > line[i-1].average) {
259  line[i].output = 255;
260  } else {
261  line[i].output = 0;
262  }
263 
264  line[i].filtered = influence * line[i].unfiltered + (1.f - influence) * line[i-1].filtered;
265  } else {
266  int distance_from_black, distance_from_white;
267 
268  distance_from_black = FFABS(line[i].input - scan->black);
269  distance_from_white = FFABS(line[i].input - scan->white);
270 
271  line[i].output = distance_from_black <= distance_from_white ? 0 : 255;
272  }
273 
274  line[i].average = meanf(line + i - lag, lag);
275  line[i].deviation = stddevf(line + i - lag, lag);
276  }
277 }
278 
279 static int periods(const LineItem *line, CodeItem *code, int len)
280 {
281  int hold = line[LAG].output, cnt = 0;
282  int last = LAG;
283 
284  memset(code, 0, len * sizeof(*code));
285 
286  for (int i = LAG + 1; i < len + LAG; i++) {
287  if (line[i].output != hold) {
288  code[cnt].size = i - last;
289  code[cnt].bit = hold;
290  hold = line[i].output;
291  last = i;
292  cnt++;
293  }
294  }
295 
296  code[cnt].size = LAG + len - last;
297  code[cnt].bit = hold;
298 
299  return cnt + 1;
300 }
301 
302 static void dump_code(AVFilterContext *ctx, ScanItem *scan, int len, int item)
303 {
304  av_log(ctx, AV_LOG_DEBUG, "%d:", item);
305  for (int i = 0; i < len; i++) {
306  av_log(ctx, AV_LOG_DEBUG, " %03d", scan->code[i].size);
307  }
308  av_log(ctx, AV_LOG_DEBUG, "\n");
309 }
310 
311 static void extract_line(AVFilterContext *ctx, AVFrame *in, ScanItem *scan, int w, int nb_line)
312 {
313  ReadEIA608Context *s = ctx->priv;
314  LineItem *line = scan->line;
315  int i, j, ch, len;
316  const uint8_t *src;
317  uint8_t codes[19] = { 0 };
318  float bit_size = 0.f;
319  int parity;
320 
321  memset(line, 0, (w + LAG) * sizeof(*line));
322  scan->byte[0] = scan->byte[1] = 0;
323  scan->found = 0;
324 
325  src = &in->data[0][nb_line * in->linesize[0]];
326  if (s->lp) {
327  for (i = 0; i < w; i++) {
328  int a = FFMAX(i - 3, 0);
329  int b = FFMAX(i - 2, 0);
330  int c = FFMAX(i - 1, 0);
331  int d = FFMIN(i + 3, w-1);
332  int e = FFMIN(i + 2, w-1);
333  int f = FFMIN(i + 1, w-1);
334 
335  line[LAG + i].input = (src[a] + src[b] + src[c] + src[i] + src[d] + src[e] + src[f] + 6) / 7;
336  }
337  } else {
338  for (i = 0; i < w; i++) {
339  line[LAG + i].input = src[i];
340  }
341  }
342 
343  build_histogram(s, scan, line, w);
344  find_black_and_white(s, scan);
345  if (scan->white - scan->black < 5)
346  return;
347 
348  thresholding(s, scan, line, LAG, 1, 0, w);
349  len = periods(line, scan->code, w);
350  dump_code(ctx, scan, len, nb_line);
351  if (len < 15 ||
352  scan->code[14].bit != 0 ||
353  w / (float)scan->code[14].size < SYNC_BITSIZE_MIN ||
354  w / (float)scan->code[14].size > SYNC_BITSIZE_MAX) {
355  return;
356  }
357 
358  for (i = 14; i < len; i++) {
359  bit_size += scan->code[i].size;
360  }
361 
362  bit_size /= 19.f;
363  for (i = 1; i < 14; i++) {
364  if (scan->code[i].size / bit_size > CLOCK_BITSIZE_MAX ||
365  scan->code[i].size / bit_size < CLOCK_BITSIZE_MIN) {
366  return;
367  }
368  }
369 
370  if (scan->code[15].size / bit_size < 0.45f) {
371  return;
372  }
373 
374  for (j = 0, i = 14; i < len; i++) {
375  int run, bit;
376 
377  run = lrintf(scan->code[i].size / bit_size);
378  bit = scan->code[i].bit;
379 
380  for (int k = 0; j < 19 && k < run; k++) {
381  codes[j++] = bit;
382  }
383 
384  if (j >= 19)
385  break;
386  }
387 
388  for (ch = 0; ch < 2; ch++) {
389  for (parity = 0, i = 0; i < 8; i++) {
390  int b = codes[3 + ch * 8 + i];
391 
392  if (b == 255) {
393  parity++;
394  b = 1;
395  } else {
396  b = 0;
397  }
398  scan->byte[ch] |= b << i;
399  }
400 
401  if (s->chp) {
402  if (!(parity & 1)) {
403  scan->byte[ch] = 0x7F;
404  }
405  }
406  }
407 
408  scan->nb_line = nb_line;
409  scan->found = 1;
410 }
411 
413  int job, int nb_jobs)
414 {
415  ReadEIA608Context *s = ctx->priv;
416  AVFilterLink *inlink = ctx->inputs[0];
417  const int h = s->end - s->start + 1;
418  const int start = (h * job) / nb_jobs;
419  const int end = (h * (job+1)) / nb_jobs;
420  AVFrame *in = arg;
421 
422  for (int i = start; i < end; i++) {
423  ScanItem *scan = &s->scan[i];
424 
425  extract_line(ctx, in, scan, inlink->w, i);
426  }
427 
428  return 0;
429 }
430 
432 {
433  AVFilterContext *ctx = inlink->dst;
434  AVFilterLink *outlink = ctx->outputs[0];
435  ReadEIA608Context *s = ctx->priv;
436  int nb_found;
437 
438  ctx->internal->execute(ctx, extract_lines, in, NULL, FFMIN(FFMAX(s->end - s->start + 1, 1),
440 
441  nb_found = 0;
442  for (int i = 0; i < s->end - s->start + 1; i++) {
443  ScanItem *scan = &s->scan[i];
444  uint8_t key[128], value[128];
445 
446  if (!scan->found)
447  continue;
448 
449  //snprintf(key, sizeof(key), "lavfi.readeia608.%d.bits", nb_found);
450  //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);
451  //av_dict_set(&in->metadata, key, value, 0);
452 
453  snprintf(key, sizeof(key), "lavfi.readeia608.%d.cc", nb_found);
454  snprintf(value, sizeof(value), "0x%02X%02X", scan->byte[0], scan->byte[1]);
455  av_dict_set(&in->metadata, key, value, 0);
456 
457  snprintf(key, sizeof(key), "lavfi.readeia608.%d.line", nb_found);
458  snprintf(value, sizeof(value), "%d", scan->nb_line);
459  av_dict_set(&in->metadata, key, value, 0);
460 
461  nb_found++;
462  }
463 
464  return ff_filter_frame(outlink, in);
465 }
466 
468 {
469  ReadEIA608Context *s = ctx->priv;
470 
471  for (int i = 0; i < s->nb_allocated; i++) {
472  ScanItem *scan = &s->scan[i];
473 
474  av_freep(&scan->code);
475  av_freep(&scan->line);
476  }
477 
478  s->nb_allocated = 0;
479  av_freep(&s->scan);
480 }
481 
482 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
483  char *res, int res_len, int flags)
484 {
485  ReadEIA608Context *s = ctx->priv;
486  int ret, start = s->start, end = s->end;
487 
488  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
489  if (ret < 0)
490  return ret;
491 
492  ret = config_filter(ctx, s->start, s->end);
493  if (ret < 0) {
494  s->start = start;
495  s->end = end;
496  }
497 
498  return 0;
499 }
500 
501 static const AVFilterPad readeia608_inputs[] = {
502  {
503  .name = "default",
504  .type = AVMEDIA_TYPE_VIDEO,
505  .filter_frame = filter_frame,
506  .config_props = config_input,
507  },
508  { NULL }
509 };
510 
511 static const AVFilterPad readeia608_outputs[] = {
512  {
513  .name = "default",
514  .type = AVMEDIA_TYPE_VIDEO,
515  },
516  { NULL }
517 };
518 
520  .name = "readeia608",
521  .description = NULL_IF_CONFIG_SMALL("Read EIA-608 Closed Caption codes from input video and write them to frame metadata."),
522  .priv_size = sizeof(ReadEIA608Context),
523  .priv_class = &readeia608_class,
525  .inputs = readeia608_inputs,
526  .outputs = readeia608_outputs,
527  .uninit = uninit,
530 };
#define NULL
Definition: coverity.c:32
static void find_black_and_white(ReadEIA608Context *s, ScanItem *scan)
This structure describes decoded (raw) audio or video data.
Definition: frame.h:314
#define av_realloc_f(p, o, n)
static void dump_code(AVFilterContext *ctx, ScanItem *scan, int len, int item)
AVOption.
Definition: opt.h:248
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
Main libavfilter public API header.
uint64_t histogram[256]
Definition: vf_readeia608.c:65
#define CLOCK_BITSIZE_MAX
Definition: vf_readeia608.c:41
float deviation
Definition: vf_readeia608.c:52
static int periods(const LineItem *line, CodeItem *code, int len)
uint8_t byte[2]
Definition: vf_readeia608.c:66
static float meanf(const LineItem *line, int len)
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:36
const char * key
uint8_t run
Definition: svq3.c:204
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:287
#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
const char * name
Pad name.
Definition: internal.h:60
static const AVOption readeia608_options[]
Definition: vf_readeia608.c:87
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:349
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1091
uint8_t
#define av_cold
Definition: attributes.h:88
AVOptions.
static int config_input(AVFilterLink *inlink)
timestamp utils, mostly useful for debugging/logging purposes
#define f(width, name)
Definition: cbs_vp9.c:255
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:92
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
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:108
static int config_filter(AVFilterContext *ctx, int start, int end)
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:100
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
#define lrintf(x)
Definition: libm_mips.h:70
AVDictionary * metadata
metadata.
Definition: frame.h:600
static av_cold void uninit(AVFilterContext *ctx)
ptrdiff_t size
Definition: opengl_enc.c:100
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:54
#define SYNC_BITSIZE_MIN
Definition: vf_readeia608.c:42
#define src
Definition: vp8dsp.c:254
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
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:588
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:153
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
void * priv
private data for use by the filter
Definition: avfilter.h:356
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
AVFilter ff_vf_readeia608
uint8_t bit
Definition: vf_readeia608.c:56
static const AVFilterPad readeia608_outputs[]
const char * arg
Definition: jacosubdec.c:66
Definition: graph2dot.c:48
#define FLAGS
Definition: vf_readeia608.c:85
#define FFMAX(a, b)
Definition: common.h:94
#define CLOCK_BITSIZE_MIN
Definition: vf_readeia608.c:40
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
common internal API header
#define b
Definition: input.c:41
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:800
#define FFMIN(a, b)
Definition: common.h:96
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
uint8_t w
Definition: llviddspenc.c:38
AVFormatContext * ctx
Definition: movenc.c:48
static const AVFilterPad readeia608_inputs[]
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define s(width, name)
Definition: cbs_vp9.c:257
mcdeint parity
Definition: vf_mcdeint.c:274
AVFILTER_DEFINE_CLASS(readeia608)
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static float stddevf(const LineItem *line, int len)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_WB16 unsigned int_TMPL byte
Definition: bytestream.h:91
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:345
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
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
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
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
#define snprintf
Definition: snprintf.h:34
static void build_histogram(ReadEIA608Context *s, ScanItem *scan, const LineItem *line, int len)
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:353
#define flags(name, subs,...)
Definition: cbs_av1.c:560
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
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:381
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:328
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
LineItem * line
Definition: vf_readeia608.c:69
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
Y , 8bpp.
Definition: pixfmt.h:74
#define bit(string, value)
Definition: cbs_mpeg2.c:58
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
static int query_formats(AVFilterContext *ctx)
Definition: vf_readeia608.c:98
#define SYNC_BITSIZE_MAX
Definition: vf_readeia608.c:43
avfilter_execute_func * execute
Definition: internal.h:136
float average
Definition: vf_readeia608.c:51
static av_always_inline int diff(const uint32_t a, const uint32_t b)
float filtered
Definition: vf_readeia608.c:50
int len
#define LAG
Definition: vf_readeia608.c:39
A list of supported formats for one end of a filter link.
Definition: formats.h:65
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:258
An instance of a filter.
Definition: avfilter.h:341
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
static int extract_lines(AVFilterContext *ctx, void *arg, int job, int nb_jobs)
formats
Definition: signature.h:48
static void extract_line(AVFilterContext *ctx, AVFrame *in, ScanItem *scan, int w, int nb_line)
internal API functions
static void thresholding(ReadEIA608Context *s, ScanItem *scan, LineItem *line, int lag, float threshold, float influence, int len)
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
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
CodeItem * code
Definition: vf_readeia608.c:68
int i
Definition: input.c:407
float unfiltered
Definition: vf_readeia608.c:49
#define OFFSET(x)
Definition: vf_readeia608.c:84