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 ReadEIA608Context {
61  const AVClass *class;
62  int start, end;
63  int nb_found;
64  int white;
65  int black;
66  float spw;
67  int chp;
68  int lp;
69 
70  uint64_t histogram[256];
71 
75 
76 #define OFFSET(x) offsetof(ReadEIA608Context, x)
77 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
78 
79 static const AVOption readeia608_options[] = {
80  { "scan_min", "set from which line to scan for codes", OFFSET(start), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
81  { "scan_max", "set to which line to scan for codes", OFFSET(end), AV_OPT_TYPE_INT, {.i64=29}, 0, INT_MAX, FLAGS },
82  { "spw", "set ratio of width reserved for sync code detection", OFFSET(spw), AV_OPT_TYPE_FLOAT, {.dbl=.27}, 0.1, 0.7, FLAGS },
83  { "chp", "check and apply parity bit", OFFSET(chp), AV_OPT_TYPE_BOOL, {.i64= 0}, 0, 1, FLAGS },
84  { "lp", "lowpass line prior to processing", OFFSET(lp), AV_OPT_TYPE_BOOL, {.i64= 1}, 0, 1, FLAGS },
85  { NULL }
86 };
87 
88 AVFILTER_DEFINE_CLASS(readeia608);
89 
91 {
92  static const enum AVPixelFormat pixel_fmts[] = {
101  };
103  if (!formats)
104  return AVERROR(ENOMEM);
106 }
107 
109 {
110  AVFilterContext *ctx = inlink->dst;
111  ReadEIA608Context *s = ctx->priv;
112  int size = inlink->w + LAG;
113 
114  if (s->end >= inlink->h) {
115  av_log(ctx, AV_LOG_WARNING, "Last line to scan too large, clipping.\n");
116  s->end = inlink->h - 1;
117  }
118 
119  if (s->start > s->end) {
120  av_log(ctx, AV_LOG_ERROR, "Invalid range.\n");
121  return AVERROR(EINVAL);
122  }
123 
124  s->line = av_calloc(size, sizeof(*s->line));
125  s->code = av_calloc(size, sizeof(*s->code));
126  if (!s->line || !s->code)
127  return AVERROR(ENOMEM);
128 
129  return 0;
130 }
131 
133 {
134  memset(s->histogram, 0, sizeof(s->histogram));
135 
136  for (int i = LAG; i < len + LAG; i++)
137  s->histogram[line[i].input]++;
138 }
139 
141 {
142  int start = 0, end = 0, middle;
143  int black = 0, white = 0;
144  int cnt;
145 
146  for (int i = 0; i < 256; i++) {
147  if (s->histogram[i]) {
148  start = i;
149  break;
150  }
151  }
152 
153  for (int i = 255; i >= 0; i--) {
154  if (s->histogram[i]) {
155  end = i;
156  break;
157  }
158  }
159 
160  middle = start + (end - start) / 2;
161 
162  cnt = 0;
163  for (int i = start; i <= middle; i++) {
164  if (s->histogram[i] > cnt) {
165  cnt = s->histogram[i];
166  black = i;
167  }
168  }
169 
170  cnt = 0;
171  for (int i = end; i >= middle; i--) {
172  if (s->histogram[i] > cnt) {
173  cnt = s->histogram[i];
174  white = i;
175  }
176  }
177 
178  s->black = black;
179  s->white = white;
180 }
181 
182 static float meanf(const LineItem *line, int len)
183 {
184  float sum = 0.0, mean = 0.0;
185 
186  for (int i = 0; i < len; i++)
187  sum += line[i].filtered;
188 
189  mean = sum / len;
190 
191  return mean;
192 }
193 
194 static float stddevf(const LineItem *line, int len)
195 {
196  float m = meanf(line, len);
197  float standard_deviation = 0.f;
198 
199  for (int i = 0; i < len; i++)
200  standard_deviation += (line[i].filtered - m) * (line[i].filtered - m);
201 
202  return sqrtf(standard_deviation / (len - 1));
203 }
204 
206  int lag, float threshold, float influence, int len)
207 {
208  for (int i = lag; i < len + lag; i++) {
209  line[i].unfiltered = line[i].input / 255.f;
210  line[i].filtered = line[i].unfiltered;
211  }
212 
213  for (int i = 0; i < lag; i++) {
214  line[i].unfiltered = meanf(line, len * s->spw);
215  line[i].filtered = line[i].unfiltered;
216  }
217 
218  line[lag - 1].average = meanf(line, lag);
219  line[lag - 1].deviation = stddevf(line, lag);
220 
221  for (int i = lag; i < len + lag; i++) {
222  if (fabsf(line[i].unfiltered - line[i-1].average) > threshold * line[i-1].deviation) {
223  if (line[i].unfiltered > line[i-1].average) {
224  line[i].output = 255;
225  } else {
226  line[i].output = 0;
227  }
228 
229  line[i].filtered = influence * line[i].unfiltered + (1.f - influence) * line[i-1].filtered;
230  } else {
231  int distance_from_black, distance_from_white;
232 
233  distance_from_black = FFABS(line[i].input - s->black);
234  distance_from_white = FFABS(line[i].input - s->white);
235 
236  line[i].output = distance_from_black <= distance_from_white ? 0 : 255;
237  }
238 
239  line[i].average = meanf(line + i - lag, lag);
240  line[i].deviation = stddevf(line + i - lag, lag);
241  }
242 }
243 
244 static int periods(const LineItem *line, CodeItem *code, int len)
245 {
246  int hold = line[LAG].output, cnt = 0;
247  int last = LAG;
248 
249  memset(code, 0, len * sizeof(*code));
250 
251  for (int i = LAG + 1; i < len + LAG; i++) {
252  if (line[i].output != hold) {
253  code[cnt].size = i - last;
254  code[cnt].bit = hold;
255  hold = line[i].output;
256  last = i;
257  cnt++;
258  }
259  }
260 
261  code[cnt].size = LAG + len - last;
262  code[cnt].bit = hold;
263 
264  return cnt + 1;
265 }
266 
267 static void dump_code(AVFilterContext *ctx, int len, int item)
268 {
269  ReadEIA608Context *s = ctx->priv;
270 
271  av_log(ctx, AV_LOG_DEBUG, "%d:", item);
272  for (int i = 0; i < len; i++) {
273  av_log(ctx, AV_LOG_DEBUG, " %03d", s->code[i].size);
274  }
275  av_log(ctx, AV_LOG_DEBUG, "\n");
276 }
277 
278 static void extract_line(AVFilterContext *ctx, AVFrame *in, int w, int nb_line)
279 {
280  ReadEIA608Context *s = ctx->priv;
281  LineItem *line = s->line;
282  int i, j, ch, len;
283  const uint8_t *src;
284  uint8_t byte[2] = { 0 };
285  uint8_t codes[19] = { 0 };
286  float bit_size = 0.f;
287  int parity;
288 
289  memset(line, 0, (w + LAG) * sizeof(*line));
290 
291  src = &in->data[0][nb_line * in->linesize[0]];
292  if (s->lp) {
293  for (i = 0; i < w; i++) {
294  int a = FFMAX(i - 3, 0);
295  int b = FFMAX(i - 2, 0);
296  int c = FFMAX(i - 1, 0);
297  int d = FFMIN(i + 3, w-1);
298  int e = FFMIN(i + 2, w-1);
299  int f = FFMIN(i + 1, w-1);
300 
301  line[LAG + i].input = (src[a] + src[b] + src[c] + src[i] + src[d] + src[e] + src[f] + 6) / 7;
302  }
303  } else {
304  for (i = 0; i < w; i++) {
305  line[LAG + i].input = src[i];
306  }
307  }
308 
309  build_histogram(s, line, w);
311  if (s->white - s->black < 5)
312  return;
313 
314  thresholding(s, line, LAG, 1, 0, w);
315  len = periods(line, s->code, w);
316  dump_code(ctx, len, nb_line);
317  if (len < 15 ||
318  s->code[14].bit != 0 ||
319  w / (float)s->code[14].size < SYNC_BITSIZE_MIN ||
320  w / (float)s->code[14].size > SYNC_BITSIZE_MAX) {
321  return;
322  }
323 
324  for (i = 14; i < len; i++) {
325  bit_size += s->code[i].size;
326  }
327 
328  bit_size /= 19.f;
329  for (i = 1; i < 14; i++) {
330  if (s->code[i].size / bit_size > CLOCK_BITSIZE_MAX ||
331  s->code[i].size / bit_size < CLOCK_BITSIZE_MIN) {
332  return;
333  }
334  }
335 
336  if (s->code[15].size / bit_size < 0.45f) {
337  return;
338  }
339 
340  for (j = 0, i = 14; i < len; i++) {
341  int run, bit;
342 
343  run = lrintf(s->code[i].size / bit_size);
344  bit = s->code[i].bit;
345 
346  for (int k = 0; j < 19 && k < run; k++) {
347  codes[j++] = bit;
348  }
349 
350  if (j >= 19)
351  break;
352  }
353 
354  for (ch = 0; ch < 2; ch++) {
355  for (parity = 0, i = 0; i < 8; i++) {
356  int b = codes[3 + ch * 8 + i];
357 
358  if (b == 255) {
359  parity++;
360  b = 1;
361  } else {
362  b = 0;
363  }
364  byte[ch] |= b << i;
365  }
366 
367  if (s->chp) {
368  if (!(parity & 1)) {
369  byte[ch] = 0x7F;
370  }
371  }
372  }
373 
374  {
375  uint8_t key[128], value[128];
376 
377  //snprintf(key, sizeof(key), "lavfi.readeia608.%d.bits", s->nb_found);
378  //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);
379  //av_dict_set(&in->metadata, key, value, 0);
380 
381  snprintf(key, sizeof(key), "lavfi.readeia608.%d.cc", s->nb_found);
382  snprintf(value, sizeof(value), "0x%02X%02X", byte[0], byte[1]);
383  av_dict_set(&in->metadata, key, value, 0);
384 
385  snprintf(key, sizeof(key), "lavfi.readeia608.%d.line", s->nb_found);
386  snprintf(value, sizeof(value), "%d", nb_line);
387  av_dict_set(&in->metadata, key, value, 0);
388  }
389 
390  s->nb_found++;
391 }
392 
394 {
395  AVFilterContext *ctx = inlink->dst;
396  AVFilterLink *outlink = ctx->outputs[0];
397  ReadEIA608Context *s = ctx->priv;
398  int i;
399 
400  s->nb_found = 0;
401  for (i = s->start; i <= s->end; i++)
402  extract_line(ctx, in, inlink->w, i);
403 
404  return ff_filter_frame(outlink, in);
405 }
406 
408 {
409  ReadEIA608Context *s = ctx->priv;
410 
411  av_freep(&s->code);
412  av_freep(&s->line);
413 }
414 
415 static const AVFilterPad readeia608_inputs[] = {
416  {
417  .name = "default",
418  .type = AVMEDIA_TYPE_VIDEO,
419  .filter_frame = filter_frame,
420  .config_props = config_input,
421  },
422  { NULL }
423 };
424 
425 static const AVFilterPad readeia608_outputs[] = {
426  {
427  .name = "default",
428  .type = AVMEDIA_TYPE_VIDEO,
429  },
430  { NULL }
431 };
432 
434  .name = "readeia608",
435  .description = NULL_IF_CONFIG_SMALL("Read EIA-608 Closed Caption codes from input video and write them to frame metadata."),
436  .priv_size = sizeof(ReadEIA608Context),
437  .priv_class = &readeia608_class,
441  .uninit = uninit,
443 };
CodeItem::size
int size
Definition: vf_readeia608.c:57
formats
formats
Definition: signature.h:48
LineItem::average
float average
Definition: vf_readeia608.c:51
thresholding
static void thresholding(ReadEIA608Context *s, LineItem *line, int lag, float threshold, float influence, int len)
Definition: vf_readeia608.c:205
ReadEIA608Context::spw
float spw
Definition: vf_readeia608.c:66
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:182
CodeItem::bit
uint8_t bit
Definition: vf_readeia608.c:56
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
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
dump_code
static void dump_code(AVFilterContext *ctx, int len, int item)
Definition: vf_readeia608.c:267
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:300
ReadEIA608Context::end
int end
Definition: vf_readeia608.c:62
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1075
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
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:92
ReadEIA608Context::start
int start
Definition: vf_readeia608.c:62
readeia608_options
static const AVOption readeia608_options[]
Definition: vf_readeia608.c:79
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
ReadEIA608Context::histogram
uint64_t histogram[256]
Definition: vf_readeia608.c:70
AVOption
AVOption.
Definition: opt.h:246
b
#define b
Definition: input.c:41
LineItem::output
int output
Definition: vf_readeia608.c:47
ReadEIA608Context::line
LineItem * line
Definition: vf_readeia608.c:73
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
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_readeia608.c:393
video.h
ff_vf_readeia608
AVFilter ff_vf_readeia608
Definition: vf_readeia608.c:433
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:58
meanf
static float meanf(const LineItem *line, int len)
Definition: vf_readeia608.c:182
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
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
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_cold
#define av_cold
Definition: attributes.h:90
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:605
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_readeia608.c:90
ReadEIA608Context
Definition: vf_readeia608.c:60
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
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
ctx
AVFormatContext * ctx
Definition: movenc.c:48
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
f
#define f(width, name)
Definition: cbs_vp9.c:255
periods
static int periods(const LineItem *line, CodeItem *code, int len)
Definition: vf_readeia608.c:244
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
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(readeia608)
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
FLAGS
#define FLAGS
Definition: vf_readeia608.c:77
NULL
#define NULL
Definition: coverity.c:32
run
uint8_t run
Definition: svq3.c:209
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
src
#define src
Definition: vp8dsp.c:254
readeia608_inputs
static const AVFilterPad readeia608_inputs[]
Definition: vf_readeia608.c:415
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
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ReadEIA608Context::lp
int lp
Definition: vf_readeia608.c:68
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_readeia608.c:407
ReadEIA608Context::white
int white
Definition: vf_readeia608.c:64
LineItem::input
int input
Definition: vf_readeia608.c:46
find_black_and_white
static void find_black_and_white(ReadEIA608Context *s)
Definition: vf_readeia608.c:140
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:188
stddevf
static float stddevf(const LineItem *line, int len)
Definition: vf_readeia608.c:194
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
OFFSET
#define OFFSET(x)
Definition: vf_readeia608.c:76
size
int size
Definition: twinvq_data.h:11134
readeia608_outputs
static const AVFilterPad readeia608_outputs[]
Definition: vf_readeia608.c:425
CodeItem
Definition: vf_readeia608.c:55
parity
mcdeint parity
Definition: vf_mcdeint.c:274
ReadEIA608Context::nb_found
int nb_found
Definition: vf_readeia608.c:63
SYNC_BITSIZE_MAX
#define SYNC_BITSIZE_MAX
Definition: vf_readeia608.c:43
build_histogram
static void build_histogram(ReadEIA608Context *s, const LineItem *line, int len)
Definition: vf_readeia608.c:132
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
line
Definition: graph2dot.c:48
extract_line
static void extract_line(AVFilterContext *ctx, AVFrame *in, int w, int nb_line)
Definition: vf_readeia608.c:278
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
ReadEIA608Context::black
int black
Definition: vf_readeia608.c:65
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:125
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:226
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
lrintf
#define lrintf(x)
Definition: libm_mips.h:70
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_readeia608.c:108
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
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
internal.h
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
AVFilter
Filter definition.
Definition: avfilter.h:144
CLOCK_BITSIZE_MAX
#define CLOCK_BITSIZE_MAX
Definition: vf_readeia608.c:41
ReadEIA608Context::code
CodeItem * code
Definition: vf_readeia608.c:72
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_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
avfilter.h
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:338
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
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:240
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
timestamp.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
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
ReadEIA608Context::chp
int chp
Definition: vf_readeia608.c:67
LAG
#define LAG
Definition: vf_readeia608.c:39
SYNC_BITSIZE_MIN
#define SYNC_BITSIZE_MIN
Definition: vf_readeia608.c:42
snprintf
#define snprintf
Definition: snprintf.h:34
LineItem
Definition: vf_readeia608.c:45
CLOCK_BITSIZE_MIN
#define CLOCK_BITSIZE_MIN
Definition: vf_readeia608.c:40