FFmpeg  4.3
yuvcmp.c
Go to the documentation of this file.
1 /*
2  * originally by Andreas Öman (andoma)
3  * some changes by Alexander Strange
4  */
5 
6 #include <string.h>
7 #include <stdlib.h>
8 #include <inttypes.h>
9 #include <stdio.h>
10 #include <sys/stat.h>
11 #include <fcntl.h>
12 
13 #if HAVE_UNISTD_H
14 #include <unistd.h>
15 #endif
16 
17 int
18 main(int argc, char **argv)
19 {
20  int fd[2];
21  int print_pixels = 0;
22  int dump_blocks = 0;
23 
24  int width;
25  int height;
26  int to_skip = 0;
27 
28  if (argc < 6) {
29  fprintf(stderr, "%s [YUV file 1] [YUV file 2] width height pixelcmp|blockdump (# to skip)\n", argv[0]);
30  return 1;
31  }
32 
33  width = atoi(argv[3]);
34  height = atoi(argv[4]);
35  if (argc > 6)
36  to_skip = atoi(argv[6]);
37 
38  uint8_t *Y[2], *C[2][2];
39  int i, v, c, p;
40  int lsiz = width * height;
41  int csiz = width * height / 4;
42  int x, y;
43  int cwidth = width / 2;
44  int fr = to_skip;
45  int mb;
46  char *mberrors;
47  int mb_x, mb_y;
48  uint8_t *a;
49  uint8_t *b;
50  int die = 0;
51 
52  print_pixels = strstr(argv[5], "pixelcmp") ? 1 : 0;
53  dump_blocks = strstr(argv[5], "blockdump") ? 1 : 0;
54 
55  for(i = 0; i < 2; i++) {
56  Y[i] = malloc(lsiz);
57  C[0][i] = malloc(csiz);
58  C[1][i] = malloc(csiz);
59 
60  fd[i] = open(argv[1 + i], O_RDONLY);
61  if(fd[i] == -1) {
62  perror("open");
63  exit(1);
64  }
65  fcntl(fd[i], F_NOCACHE, 1);
66 
67  if (to_skip)
68  lseek(fd[i], to_skip * (lsiz + 2*csiz), SEEK_SET);
69  }
70 
71  mb_x = width / 16;
72  mb_y = height / 16;
73 
74  mberrors = malloc(mb_x * mb_y);
75 
76  while(!die) {
77  memset(mberrors, 0, mb_x * mb_y);
78 
79  printf("Loading frame %d\n", ++fr);
80 
81  for(i = 0; i < 2; i++) {
82  v = read(fd[i], Y[i], lsiz);
83  if(v != lsiz) {
84  fprintf(stderr, "Unable to read Y from file %d, exiting\n", i + 1);
85  return 1;
86  }
87  }
88 
89 
90  for(c = 0; c < lsiz; c++) {
91  if(Y[0][c] != Y[1][c]) {
92  x = c % width;
93  y = c / width;
94 
95  mb = x / 16 + (y / 16) * mb_x;
96 
97  if(print_pixels)
98  printf("Luma diff 0x%02x != 0x%02x at pixel (%4d,%-4d) mb(%d,%d) #%d\n",
99  Y[0][c],
100  Y[1][c],
101  x, y,
102  x / 16,
103  y / 16,
104  mb);
105 
106  mberrors[mb] |= 1;
107  }
108  }
109 
110  /* Chroma planes */
111 
112  for(p = 0; p < 2; p++) {
113 
114  for(i = 0; i < 2; i++) {
115  v = read(fd[i], C[p][i], csiz);
116  if(v != csiz) {
117  fprintf(stderr, "Unable to read %c from file %d, exiting\n",
118  "UV"[p], i + 1);
119  return 1;
120  }
121  }
122 
123  for(c = 0; c < csiz; c++) {
124  if(C[p][0][c] != C[p][1][c]) {
125  x = c % cwidth;
126  y = c / cwidth;
127 
128  mb = x / 8 + (y / 8) * mb_x;
129 
130  mberrors[mb] |= 2 << p;
131 
132  if(print_pixels)
133 
134  printf("c%c diff 0x%02x != 0x%02x at pixel (%4d,%-4d) "
135  "mb(%3d,%-3d) #%d\n",
136  p ? 'r' : 'b',
137  C[p][0][c],
138  C[p][1][c],
139 
140  x, y,
141  x / 8,
142  y / 8,
143  x / 8 + y / 8 * cwidth / 8);
144  }
145  }
146  }
147 
148  for(i = 0; i < mb_x * mb_y; i++) {
149  x = i % mb_x;
150  y = i / mb_x;
151 
152  if(mberrors[i]) {
153  die = 1;
154 
155  printf("MB (%3d,%-3d) %4d %d %c%c%c damaged\n",
156  x, y, i, mberrors[i],
157  mberrors[i] & 1 ? 'Y' : ' ',
158  mberrors[i] & 2 ? 'U' : ' ',
159  mberrors[i] & 4 ? 'V' : ' ');
160 
161  if(dump_blocks) {
162  a = Y[0] + x * 16 + y * 16 * width;
163  b = Y[1] + x * 16 + y * 16 * width;
164 
165  for(y = 0; y < 16; y++) {
166  printf("%c ", "TB"[y&1]);
167  for(x = 0; x < 16; x++)
168  printf("%02x%c", a[x + y * width],
169  a[x + y * width] != b[x + y * width] ? '<' : ' ');
170 
171  printf("| ");
172  for(x = 0; x < 16; x++)
173  printf("%02x%c", b[x + y * width],
174  a[x + y * width] != b[x + y * width] ? '<' : ' ');
175 
176  printf("\n");
177  }
178  }
179  }
180  }
181  }
182 
183  return 0;
184 }
b
#define b
Definition: input.c:41
x
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new please make sure they are as small as space on each network bandwidth and so on benefit from smaller test cases Also keep in mind older checkouts use existing sample that means in practice generally do not remove or overwrite files as it likely would break older checkouts or releases Also all needed samples for a commit should be ideally before the push If you need an account for frequently uploading samples or you wish to help others by doing that send a mail to ffmpeg devel rsync vauL Duo x
Definition: fate.txt:150
C
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s your new playground is ready Some little details about what s going which in turn will define variables for the build system and the C
Definition: writing_filters.txt:58
width
#define width
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
printf
printf("static const uint8_t my_array[100] = {\n")
main
int main(int argc, char **argv)
Definition: yuvcmp.c:18
height
#define height
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
mb
#define mb
Definition: vf_colormatrix.c:101
Y
#define Y
Definition: boxblur.h:38
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
uint8_t
uint8_t
Definition: audio_convert.c:194