FFmpeg  4.3
videogen.c
Go to the documentation of this file.
1 /*
2  * Generate a synthetic YUV video sequence suitable for codec testing.
3  * NOTE: No floats are used to guarantee bitexact output.
4  *
5  * Copyright (c) 2002 Fabrice Bellard
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include <stdlib.h>
25 #include <stdint.h>
26 #include <stdio.h>
27 
28 #include "utils.c"
29 
30 static unsigned int myrnd(unsigned int *seed_ptr, int n)
31 {
32  unsigned int seed, val;
33 
34  seed = *seed_ptr;
35  seed = (seed * 314159) + 1;
36  if (n == 256) {
37  val = seed >> 24;
38  } else {
39  val = seed % n;
40  }
41  *seed_ptr = seed;
42  return val;
43 }
44 
45 #define NOISE_X 10
46 #define NOISE_Y 30
47 #define NOISE_W 26
48 
49 #define FRAC_BITS 8
50 #define FRAC_ONE (1 << FRAC_BITS)
51 
52 /* cosine approximate with 1-x^2 */
53 static int int_cos(int a)
54 {
55  int v, neg;
56  a = a & (FRAC_ONE - 1);
57  if (a >= (FRAC_ONE / 2))
58  a = FRAC_ONE - a;
59  neg = 0;
60  if (a > (FRAC_ONE / 4)) {
61  neg = -1;
62  a = (FRAC_ONE / 2) - a;
63  }
64  v = FRAC_ONE - ((a * a) >> 4);
65  v = (v ^ neg) - neg;
66  return v;
67 }
68 
69 #define NB_OBJS 10
70 
71 typedef struct VObj {
72  int x, y, w, h;
73  int r, g, b;
74 } VObj;
75 
76 static VObj objs[NB_OBJS];
77 
78 static unsigned int seed = 1;
79 
80 static void gen_image(int num, int w, int h)
81 {
82  int r, g, b, x, y, i, dx, dy, x1, y1;
83  unsigned int seed1;
84 
85  if (num == 0) {
86  for (i = 0; i < NB_OBJS; i++) {
87  objs[i].x = myrnd(&seed, w);
88  objs[i].y = myrnd(&seed, h);
89  objs[i].w = myrnd(&seed, w / 4) + 10;
90  objs[i].h = myrnd(&seed, h / 4) + 10;
91  objs[i].r = myrnd(&seed, 256);
92  objs[i].g = myrnd(&seed, 256);
93  objs[i].b = myrnd(&seed, 256);
94  }
95  }
96 
97  /* first a moving background with gradients */
98  /* test motion estimation */
99  dx = int_cos(num * FRAC_ONE / 50) * 35;
100  dy = int_cos(num * FRAC_ONE / 50 + FRAC_ONE / 10) * 30;
101  for (y = 0; y < h; y++) {
102  for (x = 0; x < w; x++) {
103  x1 = (x << FRAC_BITS) + dx;
104  y1 = (y << FRAC_BITS) + dy;
105  r = ((y1 * 7) >> FRAC_BITS) & 0xff;
106  g = (((x1 + y1) * 9) >> FRAC_BITS) & 0xff;
107  b = ((x1 * 5) >> FRAC_BITS) & 0xff;
108  put_pixel(x, y, r, g, b);
109  }
110  }
111 
112  /* then some noise with very high intensity to test saturation */
113  seed1 = num;
114  for (y = 0; y < NOISE_W; y++) {
115  for (x = 0; x < NOISE_W; x++) {
116  r = myrnd(&seed1, 256);
117  g = myrnd(&seed1, 256);
118  b = myrnd(&seed1, 256);
119  put_pixel(x + NOISE_X, y + NOISE_Y, r, g, b);
120  }
121  }
122 
123  /* then moving objects */
124  for (i = 0; i < NB_OBJS; i++) {
125  VObj *p = &objs[i];
126  seed1 = i;
127  for (y = 0; y < p->h; y++) {
128  for (x = 0; x < p->w; x++) {
129  r = p->r;
130  g = p->g;
131  b = p->b;
132  /* add a per object noise */
133  r += myrnd(&seed1, 50);
134  g += myrnd(&seed1, 50);
135  b += myrnd(&seed1, 50);
136  put_pixel(x + p->x, y + p->y, r, g, b);
137  }
138  }
139  p->x += myrnd(&seed, 21) - 10;
140  p->y += myrnd(&seed, 21) - 10;
141  }
142 }
143 
144 void print_help(const char* name)
145 {
146  printf("usage: %s file|dir [w=%i] [h=%i]\n"
147  "generate a test video stream\n",
149  exit(1);
150 }
151 
152 int main(int argc, char **argv)
153 {
154  int w, h, i;
155  char buf[1024];
156  int isdir = 0;
157 
158  if (argc < 2 || argc > 4) {
159  print_help(argv[0]);
160  }
161 
162  if (!freopen(argv[1], "wb", stdout))
163  isdir = 1;
164 
165  w = DEFAULT_WIDTH;
166  if(argc > 2) {
167  w = atoi(argv[2]);
168  if (w < 1) print_help(argv[0]);
169  }
170  h = DEFAULT_HEIGHT;
171  if(argc > 3) {
172  h = atoi(argv[3]);
173  if (h < 1) print_help(argv[0]);
174  }
175 
176  rgb_tab = malloc(w * h * 3);
177  wrap = w * 3;
178  width = w;
179  height = h;
180 
181  for (i = 0; i < DEFAULT_NB_PICT; i++) {
182  gen_image(i, w, h);
183  if (isdir) {
184  snprintf(buf, sizeof(buf), "%s%02d.pgm", argv[1], i);
185  pgmyuv_save(buf, w, h, rgb_tab);
186  } else {
187  pgmyuv_save(NULL, w, h, rgb_tab);
188  }
189  }
190 
191  free(rgb_tab);
192  return 0;
193 }
name
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 minimum maximum flags name is the option name
Definition: writing_filters.txt:88
main
int main(int argc, char **argv)
Definition: videogen.c:152
DEFAULT_HEIGHT
#define DEFAULT_HEIGHT
Definition: utils.c:103
DEFAULT_WIDTH
#define DEFAULT_WIDTH
Definition: utils.c:102
b
#define b
Definition: input.c:41
gen_image
static void gen_image(int num, int w, int h)
Definition: videogen.c:80
rgb_tab
static unsigned char * rgb_tab
Definition: utils.c:157
VObj::x
int x
Definition: videogen.c:72
objs
static VObj objs[NB_OBJS]
Definition: videogen.c:76
put_pixel
static void put_pixel(uint16_t *dst, ptrdiff_t linesize, const int16_t *in, int bits_per_raw_sample)
Add bias value, clamp and output pixels of a slice.
Definition: proresdsp.c:41
NB_OBJS
#define NB_OBJS
Definition: videogen.c:69
wrap
#define wrap(func)
Definition: neontest.h:65
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
val
static double val(void *priv, double ch)
Definition: aeval.c:76
VObj::b
int b
Definition: videogen.c:73
VObj::y
int y
Definition: videogen.c:72
DEFAULT_NB_PICT
#define DEFAULT_NB_PICT
Definition: utils.c:104
width
#define width
g
const char * g
Definition: vf_curves.c:115
FRAC_ONE
#define FRAC_ONE
Definition: videogen.c:50
NULL
#define NULL
Definition: coverity.c:32
VObj::r
int r
Definition: videogen.c:73
VObj
Definition: videogen.c:71
seed
static unsigned int seed
Definition: videogen.c:78
VObj::h
int h
Definition: videogen.c:72
FRAC_BITS
#define FRAC_BITS
Definition: videogen.c:49
NOISE_X
#define NOISE_X
Definition: videogen.c:45
NOISE_W
#define NOISE_W
Definition: videogen.c:47
printf
printf("static const uint8_t my_array[100] = {\n")
NOISE_Y
#define NOISE_Y
Definition: videogen.c:46
VObj::g
int g
Definition: videogen.c:73
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
r
#define r
Definition: input.c:40
pgmyuv_save
static void pgmyuv_save(const char *filename, int w, int h, const unsigned char *rgb_tab)
Definition: utils.c:106
print_help
void print_help(const char *name)
Definition: videogen.c:144
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
int_cos
static int int_cos(int a)
Definition: videogen.c:53
w
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 ug o o w
Definition: fate.txt:150
VObj::w
int w
Definition: videogen.c:72
h
h
Definition: vp9dsp_template.c:2038
myrnd
static unsigned int myrnd(unsigned int *seed_ptr, int n)
Definition: videogen.c:30
snprintf
#define snprintf
Definition: snprintf.h:34