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];
89 } EXRContext;
90 
91 static int encode_init(AVCodecContext *avctx)
92 {
93  EXRContext *s = avctx->priv_data;
94 
95  float2half_tables(s->basetable, s->shifttable);
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 
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:
434  break;
435  case EXR_ZIP16:
436  case EXR_ZIP1:
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 
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 };
AVCodec
AVCodec.
Definition: codec.h:197
EXR_NBCOMPR
@ EXR_NBCOMPR
Definition: exrenc.c:44
EXR_ZIP16
@ EXR_ZIP16
Definition: exrenc.c:43
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
EXRContext::ch_names
const char * ch_names
Definition: exrenc.c:81
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
out
FILE * out
Definition: movenc.c:54
FFSWAP
#define FFSWAP(type, a, b)
Definition: common.h:108
EXR_FLOAT
@ EXR_FLOAT
Definition: exrenc.c:50
out_size
int out_size
Definition: movenc.c:55
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:324
pixdesc.h
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:369
ExrPixelType
ExrPixelType
Definition: exr.c:73
AVOption
AVOption.
Definition: opt.h:248
bytestream2_tell_p
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
Definition: bytestream.h:197
gbra_order
static const uint8_t gbra_order[4]
Definition: exrenc.c:56
EXRContext::planes
int planes
Definition: exrenc.c:77
float.h
t1
#define t1
Definition: regdef.h:29
av_float2int
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
Definition: intfloat.h:50
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:410
exr_class
static const AVClass exr_class
Definition: exrenc.c:530
EXRContext::scanline_height
int scanline_height
Definition: exrenc.c:79
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:2071
EXR_RAW
@ EXR_RAW
Definition: exrenc.c:40
EXRScanlineData::uncompressed_data
uint8_t * uncompressed_data
Definition: exrenc.c:63
av_shrink_packet
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: avpacket.c:114
abgr_chlist
static const char abgr_chlist[4]
Definition: exrenc.c:54
type
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 type
Definition: writing_filters.txt:86
AVRational::num
int num
Numerator.
Definition: rational.h:59
EXRScanlineData::actual_size
int64_t actual_size
Definition: exrenc.c:69
avassert.h
pkt
AVPacket * pkt
Definition: movenc.c:59
ff_exr_encoder
AVCodec ff_exr_encoder
Definition: exrenc.c:537
EXRScanlineData::tmp
uint8_t * tmp
Definition: exrenc.c:66
bytestream2_init_writer
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:147
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
bytestream2_put_buffer
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition: bytestream.h:286
gbr_order
static const uint8_t gbr_order[4]
Definition: exrenc.c:57
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:303
EXRContext::scanline
EXRScanlineData * scanline
Definition: exrenc.c:85
f
#define f(width, name)
Definition: cbs_vp9.c:255
EXRContext::ch_order
const uint8_t * ch_order
Definition: exrenc.c:82
OFFSET
#define OFFSET(x)
Definition: exrenc.c:515
bgr_chlist
static const char bgr_chlist[4]
Definition: exrenc.c:55
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:108
AV_CODEC_ID_EXR
@ AV_CODEC_ID_EXR
Definition: codec_id.h:229
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
rle_compress
static int64_t rle_compress(uint8_t *out, int64_t out_size, const uint8_t *in, int64_t in_size)
Definition: exrenc.c:175
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
run
uint8_t run
Definition: svq3.c:203
EXRContext::compression
int compression
Definition: exrenc.c:75
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
src
#define src
Definition: vp8dsp.c:255
float2half
static uint16_t float2half(uint32_t f, uint16_t *basetable, uint8_t *shifttable)
Definition: float2half.h:58
EXRScanlineData::tmp_size
unsigned int tmp_size
Definition: exrenc.c:67
encode_scanline_zip
static int encode_scanline_zip(EXRContext *s, const AVFrame *frame)
Definition: exrenc.c:272
PutByteContext
Definition: bytestream.h:37
AVPacket::size
int size
Definition: packet.h:370
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:117
copy
static void copy(const float *p1, float *p2, const int length)
Definition: vf_vaguedenoiser.c:194
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:428
EXRContext::nb_scanlines
int nb_scanlines
Definition: exrenc.c:78
size
int size
Definition: twinvq_data.h:10344
EXRContext::gamma
float gamma
Definition: exr.c:190
EXRContext::pb
PutByteContext pb
Definition: exrenc.c:83
av_image_get_buffer_size
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
FFMIN
#define FFMIN(a, b)
Definition: common.h:105
offset
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
Definition: writing_filters.txt:86
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:375
predictor
static void predictor(uint8_t *src, ptrdiff_t size)
Definition: exrenc.c:163
EXRScanlineData::compressed_data
uint8_t * compressed_data
Definition: exrenc.c:60
EXRScanlineData::compressed_size
unsigned int compressed_size
Definition: exrenc.c:61
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
EXR_UNKNOWN
@ EXR_UNKNOWN
Definition: exrenc.c:51
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
EXRScanlineData::uncompressed_size
unsigned int uncompressed_size
Definition: exrenc.c:64
i
int i
Definition: input.c:407
av_fast_padded_malloc
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
EXR_UINT
@ EXR_UINT
Definition: exrenc.c:48
uint8_t
uint8_t
Definition: audio_convert.c:194
EXRScanlineData
Definition: exrenc.c:59
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:204
EXR_HALF
@ EXR_HALF
Definition: exrenc.c:49
AVCodecContext::height
int height
Definition: avcodec.h:709
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:746
float2half_tables
static void float2half_tables(uint16_t *basetable, uint8_t *shifttable)
Definition: float2half.h:24
avcodec.h
options
static const AVOption options[]
Definition: exrenc.c:517
encode_scanline_rle
static int encode_scanline_rle(EXRContext *s, const AVFrame *frame)
Definition: exrenc.c:214
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
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
frame
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
Definition: filter_design.txt:264
EXRContext::basetable
uint16_t basetable[512]
Definition: exrenc.c:87
EXRContext::shifttable
uint8_t shifttable[512]
Definition: exrenc.c:88
reorder_pixels
static void reorder_pixels(uint8_t *dst, const uint8_t *src, ptrdiff_t size)
Definition: exrenc.c:151
AVCodecContext
main external API structure.
Definition: avcodec.h:536
EXRContext::pixel_type
int pixel_type
Definition: exrenc.c:76
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
t2
#define t2
Definition: regdef.h:30
encode_init
static int encode_init(AVCodecContext *avctx)
Definition: exrenc.c:91
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:429
EXR_RLE
@ EXR_RLE
Definition: exrenc.c:41
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
ExrCompr
ExrCompr
Definition: exr.c:59
AVPacket
This structure stores compressed data.
Definition: packet.h:346
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:563
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
d
d
Definition: ffmpeg_filter.c:158
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:709
bytestream.h
VE
#define VE
Definition: exrenc.c:516
imgutils.h
encode_frame
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: exrenc.c:343
ff_alloc_packet2
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
EXR_ZIP1
@ EXR_ZIP1
Definition: exrenc.c:42
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
encode_close
static int encode_close(AVCodecContext *avctx)
Definition: exrenc.c:134
float2half.h
AVCodecContext::sample_aspect_ratio
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
EXRContext
Definition: exr.c:145