FFmpeg
exrenc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 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  * OpenEXR encoder
24  */
25 
26 #include <float.h>
27 #include <zlib.h>
28 
29 #include "libavutil/avassert.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/intreadwrite.h"
32 #include "libavutil/imgutils.h"
33 #include "libavutil/pixdesc.h"
34 #include "avcodec.h"
35 #include "bytestream.h"
36 #include "internal.h"
37 #include "float2half.h"
38 
39 enum ExrCompr {
45 };
46 
52 };
53 
54 static const char abgr_chlist[4] = { 'A', 'B', 'G', 'R' };
55 static const char bgr_chlist[4] = { 'B', 'G', 'R', 'A' };
56 static const uint8_t gbra_order[4] = { 3, 1, 0, 2 };
57 static const uint8_t gbr_order[4] = { 1, 0, 2, 0 };
58 
59 typedef struct EXRScanlineData {
61  unsigned int compressed_size;
62 
64  unsigned int uncompressed_size;
65 
67  unsigned int tmp_size;
68 
69  int64_t actual_size;
71 
72 typedef struct EXRContext {
73  const AVClass *class;
74 
77  int planes;
80  float gamma;
81  const char *ch_names;
82  const uint8_t *ch_order;
84 
86 
87  uint16_t basetable[512];
88  uint8_t shifttable[512];
89 } EXRContext;
90 
91 static int encode_init(AVCodecContext *avctx)
92 {
93  EXRContext *s = avctx->priv_data;
94 
96 
97  switch (avctx->pix_fmt) {
98  case AV_PIX_FMT_GBRPF32:
99  s->planes = 3;
100  s->ch_names = bgr_chlist;
101  s->ch_order = gbr_order;
102  break;
103  case AV_PIX_FMT_GBRAPF32:
104  s->planes = 4;
105  s->ch_names = abgr_chlist;
106  s->ch_order = gbra_order;
107  break;
108  default:
109  av_assert0(0);
110  }
111 
112  switch (s->compression) {
113  case EXR_RAW:
114  case EXR_RLE:
115  case EXR_ZIP1:
116  s->scanline_height = 1;
117  s->nb_scanlines = avctx->height;
118  break;
119  case EXR_ZIP16:
120  s->scanline_height = 16;
121  s->nb_scanlines = (avctx->height + s->scanline_height - 1) / s->scanline_height;
122  break;
123  default:
124  av_assert0(0);
125  }
126 
127  s->scanline = av_calloc(s->nb_scanlines, sizeof(*s->scanline));
128  if (!s->scanline)
129  return AVERROR(ENOMEM);
130 
131  return 0;
132 }
133 
134 static int encode_close(AVCodecContext *avctx)
135 {
136  EXRContext *s = avctx->priv_data;
137 
138  for (int y = 0; y < s->nb_scanlines && s->scanline; y++) {
139  EXRScanlineData *scanline = &s->scanline[y];
140 
141  av_freep(&scanline->tmp);
142  av_freep(&scanline->compressed_data);
143  av_freep(&scanline->uncompressed_data);
144  }
145 
146  av_freep(&s->scanline);
147 
148  return 0;
149 }
150 
151 static void reorder_pixels(uint8_t *dst, const uint8_t *src, ptrdiff_t size)
152 {
153  const ptrdiff_t half_size = (size + 1) / 2;
154  uint8_t *t1 = dst;
155  uint8_t *t2 = dst + half_size;
156 
157  for (ptrdiff_t i = 0; i < half_size; i++) {
158  t1[i] = *(src++);
159  t2[i] = *(src++);
160  }
161 }
162 
163 static void predictor(uint8_t *src, ptrdiff_t size)
164 {
165  int p = src[0];
166 
167  for (ptrdiff_t i = 1; i < size; i++) {
168  int d = src[i] - p + 384;
169 
170  p = src[i];
171  src[i] = d;
172  }
173 }
174 
175 static int64_t rle_compress(uint8_t *out, int64_t out_size,
176  const uint8_t *in, int64_t in_size)
177 {
178  int64_t i = 0, o = 0, run = 1, copy = 0;
179 
180  while (i < in_size) {
181  while (i + run < in_size && in[i] == in[i + run] && run < 128)
182  run++;
183 
184  if (run >= 3) {
185  if (o + 2 >= out_size)
186  return -1;
187  out[o++] = run - 1;
188  out[o++] = in[i];
189  i += run;
190  } else {
191  if (i + run < in_size)
192  copy += run;
193  while (i + copy < in_size && copy < 127 && in[i + copy] != in[i + copy - 1])
194  copy++;
195 
196  if (o + 1 + copy >= out_size)
197  return -1;
198  out[o++] = -copy;
199 
200  for (int x = 0; x < copy; x++)
201  out[o + x] = in[i + x];
202 
203  o += copy;
204  i += copy;
205  copy = 0;
206  }
207 
208  run = 1;
209  }
210 
211  return o;
212 }
213 
215 {
216  const int64_t element_size = s->pixel_type == EXR_HALF ? 2LL : 4LL;
217 
218  for (int y = 0; y < frame->height; y++) {
219  EXRScanlineData *scanline = &s->scanline[y];
220  int64_t tmp_size = element_size * s->planes * frame->width;
221  int64_t max_compressed_size = tmp_size * 3 / 2;
222 
223  av_fast_padded_malloc(&scanline->uncompressed_data, &scanline->uncompressed_size, tmp_size);
224  if (!scanline->uncompressed_data)
225  return AVERROR(ENOMEM);
226 
227  av_fast_padded_malloc(&scanline->tmp, &scanline->tmp_size, tmp_size);
228  if (!scanline->tmp)
229  return AVERROR(ENOMEM);
230 
231  av_fast_padded_malloc(&scanline->compressed_data, &scanline->compressed_size, max_compressed_size);
232  if (!scanline->compressed_data)
233  return AVERROR(ENOMEM);
234 
235  switch (s->pixel_type) {
236  case EXR_FLOAT:
237  for (int p = 0; p < s->planes; p++) {
238  int ch = s->ch_order[p];
239 
240  memcpy(scanline->uncompressed_data + frame->width * 4 * p,
241  frame->data[ch] + y * frame->linesize[ch], frame->width * 4);
242  }
243  break;
244  case EXR_HALF:
245  for (int p = 0; p < s->planes; p++) {
246  int ch = s->ch_order[p];
247  uint16_t *dst = (uint16_t *)(scanline->uncompressed_data + frame->width * 2 * p);
248  uint32_t *src = (uint32_t *)(frame->data[ch] + y * frame->linesize[ch]);
249 
250  for (int x = 0; x < frame->width; x++)
251  dst[x] = float2half(src[x], s->basetable, s->shifttable);
252  }
253  break;
254  }
255 
256  reorder_pixels(scanline->tmp, scanline->uncompressed_data, tmp_size);
257  predictor(scanline->tmp, tmp_size);
258  scanline->actual_size = rle_compress(scanline->compressed_data,
259  max_compressed_size,
260  scanline->tmp, tmp_size);
261 
262  if (scanline->actual_size <= 0 || scanline->actual_size >= tmp_size) {
263  FFSWAP(uint8_t *, scanline->uncompressed_data, scanline->compressed_data);
264  FFSWAP(int, scanline->uncompressed_size, scanline->compressed_size);
265  scanline->actual_size = tmp_size;
266  }
267  }
268 
269  return 0;
270 }
271 
273 {
274  const int64_t element_size = s->pixel_type == EXR_HALF ? 2LL : 4LL;
275 
276  for (int y = 0; y < s->nb_scanlines; y++) {
277  EXRScanlineData *scanline = &s->scanline[y];
278  const int scanline_height = FFMIN(s->scanline_height, frame->height - y * s->scanline_height);
279  int64_t tmp_size = element_size * s->planes * frame->width * scanline_height;
280  int64_t max_compressed_size = tmp_size * 3 / 2;
281  unsigned long actual_size, source_size;
282 
283  av_fast_padded_malloc(&scanline->uncompressed_data, &scanline->uncompressed_size, tmp_size);
284  if (!scanline->uncompressed_data)
285  return AVERROR(ENOMEM);
286 
287  av_fast_padded_malloc(&scanline->tmp, &scanline->tmp_size, tmp_size);
288  if (!scanline->tmp)
289  return AVERROR(ENOMEM);
290 
291  av_fast_padded_malloc(&scanline->compressed_data, &scanline->compressed_size, max_compressed_size);
292  if (!scanline->compressed_data)
293  return AVERROR(ENOMEM);
294 
295  switch (s->pixel_type) {
296  case EXR_FLOAT:
297  for (int l = 0; l < scanline_height; l++) {
298  const int scanline_size = frame->width * 4 * s->planes;
299 
300  for (int p = 0; p < s->planes; p++) {
301  int ch = s->ch_order[p];
302 
303  memcpy(scanline->uncompressed_data + scanline_size * l + p * frame->width * 4,
304  frame->data[ch] + (y * s->scanline_height + l) * frame->linesize[ch],
305  frame->width * 4);
306  }
307  }
308  break;
309  case EXR_HALF:
310  for (int l = 0; l < scanline_height; l++) {
311  const int scanline_size = frame->width * 2 * s->planes;
312 
313  for (int p = 0; p < s->planes; p++) {
314  int ch = s->ch_order[p];
315  uint16_t *dst = (uint16_t *)(scanline->uncompressed_data + scanline_size * l + p * frame->width * 2);
316  uint32_t *src = (uint32_t *)(frame->data[ch] + (y * s->scanline_height + l) * frame->linesize[ch]);
317 
318  for (int x = 0; x < frame->width; x++)
319  dst[x] = float2half(src[x], s->basetable, s->shifttable);
320  }
321  }
322  break;
323  }
324 
325  reorder_pixels(scanline->tmp, scanline->uncompressed_data, tmp_size);
326  predictor(scanline->tmp, tmp_size);
327  source_size = tmp_size;
328  actual_size = max_compressed_size;
329  compress(scanline->compressed_data, &actual_size,
330  scanline->tmp, source_size);
331 
332  scanline->actual_size = actual_size;
333  if (scanline->actual_size >= tmp_size) {
334  FFSWAP(uint8_t *, scanline->uncompressed_data, scanline->compressed_data);
335  FFSWAP(int, scanline->uncompressed_size, scanline->compressed_size);
336  scanline->actual_size = tmp_size;
337  }
338  }
339 
340  return 0;
341 }
342 
344  const AVFrame *frame, int *got_packet)
345 {
346  EXRContext *s = avctx->priv_data;
347  PutByteContext *pb = &s->pb;
348  int64_t offset;
349  int ret;
350  int64_t out_size = 2048LL + avctx->height * 16LL +
352  avctx->width,
353  avctx->height, 64) * 3LL / 2;
354 
355  if ((ret = ff_alloc_packet2(avctx, pkt, out_size, out_size)) < 0)
356  return ret;
357 
358  bytestream2_init_writer(pb, pkt->data, pkt->size);
359 
360  bytestream2_put_le32(pb, 20000630);
361  bytestream2_put_byte(pb, 2);
362  bytestream2_put_le24(pb, 0);
363  bytestream2_put_buffer(pb, "channels\0chlist\0", 16);
364  bytestream2_put_le32(pb, s->planes * 18 + 1);
365 
366  for (int p = 0; p < s->planes; p++) {
367  bytestream2_put_byte(pb, s->ch_names[p]);
368  bytestream2_put_byte(pb, 0);
369  bytestream2_put_le32(pb, s->pixel_type);
370  bytestream2_put_le32(pb, 0);
371  bytestream2_put_le32(pb, 1);
372  bytestream2_put_le32(pb, 1);
373  }
374  bytestream2_put_byte(pb, 0);
375 
376  bytestream2_put_buffer(pb, "compression\0compression\0", 24);
377  bytestream2_put_le32(pb, 1);
378  bytestream2_put_byte(pb, s->compression);
379 
380  bytestream2_put_buffer(pb, "dataWindow\0box2i\0", 17);
381  bytestream2_put_le32(pb, 16);
382  bytestream2_put_le32(pb, 0);
383  bytestream2_put_le32(pb, 0);
384  bytestream2_put_le32(pb, avctx->width - 1);
385  bytestream2_put_le32(pb, avctx->height - 1);
386 
387  bytestream2_put_buffer(pb, "displayWindow\0box2i\0", 20);
388  bytestream2_put_le32(pb, 16);
389  bytestream2_put_le32(pb, 0);
390  bytestream2_put_le32(pb, 0);
391  bytestream2_put_le32(pb, avctx->width - 1);
392  bytestream2_put_le32(pb, avctx->height - 1);
393 
394  bytestream2_put_buffer(pb, "lineOrder\0lineOrder\0", 20);
395  bytestream2_put_le32(pb, 1);
396  bytestream2_put_byte(pb, 0);
397 
398  bytestream2_put_buffer(pb, "screenWindowCenter\0v2f\0", 23);
399  bytestream2_put_le32(pb, 8);
400  bytestream2_put_le64(pb, 0);
401 
402  bytestream2_put_buffer(pb, "screenWindowWidth\0float\0", 24);
403  bytestream2_put_le32(pb, 4);
404  bytestream2_put_le32(pb, av_float2int(1.f));
405 
406  if (avctx->sample_aspect_ratio.num && avctx->sample_aspect_ratio.den) {
407  bytestream2_put_buffer(pb, "pixelAspectRatio\0float\0", 23);
408  bytestream2_put_le32(pb, 4);
409  bytestream2_put_le32(pb, av_float2int(av_q2d(avctx->sample_aspect_ratio)));
410  }
411 
412  if (avctx->framerate.num && avctx->framerate.den) {
413  bytestream2_put_buffer(pb, "framesPerSecond\0rational\0", 25);
414  bytestream2_put_le32(pb, 8);
415  bytestream2_put_le32(pb, avctx->framerate.num);
416  bytestream2_put_le32(pb, avctx->framerate.den);
417  }
418 
419  bytestream2_put_buffer(pb, "gamma\0float\0", 12);
420  bytestream2_put_le32(pb, 4);
421  bytestream2_put_le32(pb, av_float2int(s->gamma));
422 
423  bytestream2_put_buffer(pb, "writer\0string\0", 14);
424  bytestream2_put_le32(pb, 4);
425  bytestream2_put_buffer(pb, "lavc", 4);
426  bytestream2_put_byte(pb, 0);
427 
428  switch (s->compression) {
429  case EXR_RAW:
430  /* nothing to do */
431  break;
432  case EXR_RLE:
433  encode_scanline_rle(s, frame);
434  break;
435  case EXR_ZIP16:
436  case EXR_ZIP1:
437  encode_scanline_zip(s, frame);
438  break;
439  default:
440  av_assert0(0);
441  }
442 
443  switch (s->compression) {
444  case EXR_RAW:
445  offset = bytestream2_tell_p(pb) + avctx->height * 8LL;
446 
447  if (s->pixel_type == EXR_FLOAT) {
448 
449  for (int y = 0; y < avctx->height; y++) {
450  bytestream2_put_le64(pb, offset);
451  offset += avctx->width * s->planes * 4 + 8;
452  }
453 
454  for (int y = 0; y < avctx->height; y++) {
455  bytestream2_put_le32(pb, y);
456  bytestream2_put_le32(pb, s->planes * avctx->width * 4);
457  for (int p = 0; p < s->planes; p++) {
458  int ch = s->ch_order[p];
459  bytestream2_put_buffer(pb, frame->data[ch] + y * frame->linesize[ch],
460  avctx->width * 4);
461  }
462  }
463  } else {
464  for (int y = 0; y < avctx->height; y++) {
465  bytestream2_put_le64(pb, offset);
466  offset += avctx->width * s->planes * 2 + 8;
467  }
468 
469  for (int y = 0; y < avctx->height; y++) {
470  bytestream2_put_le32(pb, y);
471  bytestream2_put_le32(pb, s->planes * avctx->width * 2);
472  for (int p = 0; p < s->planes; p++) {
473  int ch = s->ch_order[p];
474  uint32_t *src = (uint32_t *)(frame->data[ch] + y * frame->linesize[ch]);
475 
476  for (int x = 0; x < frame->width; x++)
477  bytestream2_put_le16(pb, float2half(src[x], s->basetable, s->shifttable));
478  }
479  }
480  }
481  break;
482  case EXR_ZIP16:
483  case EXR_ZIP1:
484  case EXR_RLE:
485  offset = bytestream2_tell_p(pb) + s->nb_scanlines * 8LL;
486 
487  for (int y = 0; y < s->nb_scanlines; y++) {
488  EXRScanlineData *scanline = &s->scanline[y];
489 
490  bytestream2_put_le64(pb, offset);
491  offset += scanline->actual_size + 8;
492  }
493 
494  for (int y = 0; y < s->nb_scanlines; y++) {
495  EXRScanlineData *scanline = &s->scanline[y];
496 
497  bytestream2_put_le32(pb, y * s->scanline_height);
498  bytestream2_put_le32(pb, scanline->actual_size);
500  scanline->actual_size);
501  }
502  break;
503  default:
504  av_assert0(0);
505  }
506 
508 
509  pkt->flags |= AV_PKT_FLAG_KEY;
510  *got_packet = 1;
511 
512  return 0;
513 }
514 
515 #define OFFSET(x) offsetof(EXRContext, x)
516 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
517 static const AVOption options[] = {
518  { "compression", "set compression type", OFFSET(compression), AV_OPT_TYPE_INT, {.i64=0}, 0, EXR_NBCOMPR-1, VE, "compr" },
519  { "none", "none", 0, AV_OPT_TYPE_CONST, {.i64=EXR_RAW}, 0, 0, VE, "compr" },
520  { "rle" , "RLE", 0, AV_OPT_TYPE_CONST, {.i64=EXR_RLE}, 0, 0, VE, "compr" },
521  { "zip1", "ZIP1", 0, AV_OPT_TYPE_CONST, {.i64=EXR_ZIP1}, 0, 0, VE, "compr" },
522  { "zip16", "ZIP16", 0, AV_OPT_TYPE_CONST, {.i64=EXR_ZIP16}, 0, 0, VE, "compr" },
523  { "format", "set pixel type", OFFSET(pixel_type), AV_OPT_TYPE_INT, {.i64=EXR_FLOAT}, EXR_HALF, EXR_UNKNOWN-1, VE, "pixel" },
524  { "half" , NULL, 0, AV_OPT_TYPE_CONST, {.i64=EXR_HALF}, 0, 0, VE, "pixel" },
525  { "float", NULL, 0, AV_OPT_TYPE_CONST, {.i64=EXR_FLOAT}, 0, 0, VE, "pixel" },
526  { "gamma", "set gamma", OFFSET(gamma), AV_OPT_TYPE_FLOAT, {.dbl=1.f}, 0.001, FLT_MAX, VE },
527  { NULL},
528 };
529 
530 static const AVClass exr_class = {
531  .class_name = "exr",
532  .item_name = av_default_item_name,
533  .option = options,
534  .version = LIBAVUTIL_VERSION_INT,
535 };
536 
538  .name = "exr",
539  .long_name = NULL_IF_CONFIG_SMALL("OpenEXR image"),
540  .priv_data_size = sizeof(EXRContext),
541  .priv_class = &exr_class,
543  .id = AV_CODEC_ID_EXR,
544  .init = encode_init,
545  .encode2 = encode_frame,
546  .close = encode_close,
547  .capabilities = AV_CODEC_CAP_FRAME_THREADS,
548  .pix_fmts = (const enum AVPixelFormat[]) {
551  AV_PIX_FMT_NONE },
552 };
#define NULL
Definition: coverity.c:32
AVRational framerate
Definition: avcodec.h:2071
static int encode_scanline_rle(EXRContext *s, const AVFrame *frame)
Definition: exrenc.c:214
unsigned int tmp_size
Definition: exrenc.c:67
static void copy(const float *p1, float *p2, const int length)
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
AVOption.
Definition: opt.h:248
misc image utilities
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: avpacket.c:114
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
static const uint8_t gbra_order[4]
Definition: exrenc.c:56
unsigned int compressed_size
Definition: exrenc.c:61
int num
Numerator.
Definition: rational.h:59
int size
Definition: packet.h:370
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:147
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:915
int scanline_height
Definition: exrenc.c:79
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:746
unsigned int uncompressed_size
Definition: exrenc.c:64
GLint GLenum type
Definition: opengl_enc.c:104
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
Definition: utils.c:50
enum ExrPixelType pixel_type
Definition: exr.c:156
int out_size
Definition: movenc.c:55
uint8_t run
Definition: svq3.c:203
AVPacket * pkt
Definition: movenc.c:59
const char * ch_names
Definition: exrenc.c:81
AVCodec.
Definition: codec.h:197
#define OFFSET(x)
Definition: exrenc.c:515
static const char bgr_chlist[4]
Definition: exrenc.c:55
static const AVClass exr_class
Definition: exrenc.c:530
static int64_t rle_compress(uint8_t *out, int64_t out_size, const uint8_t *in, int64_t in_size)
Definition: exrenc.c:175
AVCodec ff_exr_encoder
Definition: exrenc.c:537
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
uint8_t * compressed_data
Definition: exrenc.c:60
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: encode.c:33
float gamma
Definition: exr.c:190
static int encode_close(AVCodecContext *avctx)
Definition: exrenc.c:134
uint8_t
static const char abgr_chlist[4]
Definition: exrenc.c:54
AVOptions.
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 offset
#define f(width, name)
Definition: cbs_vp9.c:255
uint8_t * data
Definition: packet.h:369
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
EXRScanlineData * scanline
Definition: exrenc.c:85
ptrdiff_t size
Definition: opengl_enc.c:100
static const uint8_t gbr_order[4]
Definition: exrenc.c:57
static uint16_t float2half(uint32_t f, uint16_t *basetable, uint8_t *shifttable)
Definition: float2half.h:58
int planes
Definition: exrenc.c:77
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:410
int nb_scanlines
Definition: exrenc.c:78
#define src
Definition: vp8dsp.c:255
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters...
Definition: imgutils.c:466
int width
Definition: frame.h:376
static const AVOption options[]
Definition: exrenc.c:517
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:117
#define t1
Definition: regdef.h:29
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
Definition: codec.h:204
Definition: exrenc.c:40
static void reorder_pixels(uint8_t *dst, const uint8_t *src, ptrdiff_t size)
Definition: exrenc.c:151
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
Definition: bytestream.h:197
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:108
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:375
int compression
Definition: exrenc.c:75
uint8_t shifttable[512]
Definition: exrenc.c:88
#define FFMIN(a, b)
Definition: common.h:105
static int encode_scanline_zip(EXRContext *s, const AVFrame *frame)
Definition: exrenc.c:272
static void predictor(uint8_t *src, ptrdiff_t size)
Definition: exrenc.c:163
int width
picture width / height.
Definition: avcodec.h:709
enum ExrCompr compression
Definition: exr.c:155
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 the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define s(width, name)
Definition: cbs_vp9.c:257
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: exrenc.c:343
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition: bytestream.h:286
int pixel_type
Definition: exrenc.c:76
Libavcodec external API header.
ExrCompr
Definition: exr.c:59
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
main external API structure.
Definition: avcodec.h:536
uint8_t * uncompressed_data
Definition: exrenc.c:63
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
Describe the class of an AVClass context structure.
Definition: log.h:67
ExrPixelType
Definition: exr.c:73
PutByteContext pb
Definition: exrenc.c:83
uint16_t basetable[512]
Definition: exrenc.c:87
Definition: exrenc.c:41
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
Definition: intfloat.h:50
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:303
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:428
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:429
common internal api header.
static void float2half_tables(uint16_t *basetable, uint8_t *shifttable)
Definition: float2half.h:24
int64_t actual_size
Definition: exrenc.c:69
int den
Denominator.
Definition: rational.h:60
void * priv_data
Definition: avcodec.h:563
uint8_t * tmp
Definition: exrenc.c:66
#define VE
Definition: exrenc.c:516
int height
Definition: frame.h:376
FILE * out
Definition: movenc.c:54
#define av_freep(p)
#define FFSWAP(type, a, b)
Definition: common.h:108
const uint8_t * ch_order
Definition: exrenc.c:82
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
static int encode_init(AVCodecContext *avctx)
Definition: exrenc.c:91
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
This structure stores compressed data.
Definition: packet.h:346
#define t2
Definition: regdef.h:30
int i
Definition: input.c:407