FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
utvideoenc.c
Go to the documentation of this file.
1 /*
2  * Ut Video encoder
3  * Copyright (c) 2012 Jan Ekström
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Ut Video encoder
25  */
26 
27 #include "libavutil/imgutils.h"
28 #include "libavutil/intreadwrite.h"
29 #include "avcodec.h"
30 #include "internal.h"
31 #include "bswapdsp.h"
32 #include "bytestream.h"
33 #include "put_bits.h"
34 #include "huffyuvencdsp.h"
35 #include "mathops.h"
36 #include "utvideo.h"
37 #include "huffman.h"
38 
39 /* Compare huffentry symbols */
40 static int huff_cmp_sym(const void *a, const void *b)
41 {
42  const HuffEntry *aa = a, *bb = b;
43  return aa->sym - bb->sym;
44 }
45 
47 {
48  UtvideoContext *c = avctx->priv_data;
49  int i;
50 
51  av_freep(&c->slice_bits);
52  for (i = 0; i < 4; i++)
53  av_freep(&c->slice_buffer[i]);
54 
55  return 0;
56 }
57 
59 {
60  UtvideoContext *c = avctx->priv_data;
61  int i, subsampled_height;
62  uint32_t original_format;
63 
64  c->avctx = avctx;
65  c->frame_info_size = 4;
66  c->slice_stride = FFALIGN(avctx->width, 32);
67 
68  switch (avctx->pix_fmt) {
69  case AV_PIX_FMT_RGB24:
70  c->planes = 3;
71  avctx->codec_tag = MKTAG('U', 'L', 'R', 'G');
72  original_format = UTVIDEO_RGB;
73  break;
74  case AV_PIX_FMT_RGBA:
75  c->planes = 4;
76  avctx->codec_tag = MKTAG('U', 'L', 'R', 'A');
77  original_format = UTVIDEO_RGBA;
78  break;
79  case AV_PIX_FMT_YUV420P:
80  if (avctx->width & 1 || avctx->height & 1) {
81  av_log(avctx, AV_LOG_ERROR,
82  "4:2:0 video requires even width and height.\n");
83  return AVERROR_INVALIDDATA;
84  }
85  c->planes = 3;
86  if (avctx->colorspace == AVCOL_SPC_BT709)
87  avctx->codec_tag = MKTAG('U', 'L', 'H', '0');
88  else
89  avctx->codec_tag = MKTAG('U', 'L', 'Y', '0');
90  original_format = UTVIDEO_420;
91  break;
92  case AV_PIX_FMT_YUV422P:
93  if (avctx->width & 1) {
94  av_log(avctx, AV_LOG_ERROR,
95  "4:2:2 video requires even width.\n");
96  return AVERROR_INVALIDDATA;
97  }
98  c->planes = 3;
99  if (avctx->colorspace == AVCOL_SPC_BT709)
100  avctx->codec_tag = MKTAG('U', 'L', 'H', '2');
101  else
102  avctx->codec_tag = MKTAG('U', 'L', 'Y', '2');
103  original_format = UTVIDEO_422;
104  break;
105  default:
106  av_log(avctx, AV_LOG_ERROR, "Unknown pixel format: %d\n",
107  avctx->pix_fmt);
108  return AVERROR_INVALIDDATA;
109  }
110 
111  ff_bswapdsp_init(&c->bdsp);
113 
114  /* Check the prediction method, and error out if unsupported */
115  if (avctx->prediction_method < 0 || avctx->prediction_method > 4) {
116  av_log(avctx, AV_LOG_WARNING,
117  "Prediction method %d is not supported in Ut Video.\n",
118  avctx->prediction_method);
120  }
121 
122  if (avctx->prediction_method == FF_PRED_PLANE) {
123  av_log(avctx, AV_LOG_ERROR,
124  "Plane prediction is not supported in Ut Video.\n");
126  }
127 
128  /* Convert from libavcodec prediction type to Ut Video's */
130 
131  if (c->frame_pred == PRED_GRADIENT) {
132  av_log(avctx, AV_LOG_ERROR, "Gradient prediction is not supported.\n");
134  }
135 
136  /*
137  * Check the asked slice count for obviously invalid
138  * values (> 256 or negative).
139  */
140  if (avctx->slices > 256 || avctx->slices < 0) {
141  av_log(avctx, AV_LOG_ERROR,
142  "Slice count %d is not supported in Ut Video (theoretical range is 0-256).\n",
143  avctx->slices);
144  return AVERROR(EINVAL);
145  }
146 
147  /* Check that the slice count is not larger than the subsampled height */
148  subsampled_height = avctx->height >> av_pix_fmt_desc_get(avctx->pix_fmt)->log2_chroma_h;
149  if (avctx->slices > subsampled_height) {
150  av_log(avctx, AV_LOG_ERROR,
151  "Slice count %d is larger than the subsampling-applied height %d.\n",
152  avctx->slices, subsampled_height);
153  return AVERROR(EINVAL);
154  }
155 
156  /* extradata size is 4 * 32bit */
157  avctx->extradata_size = 16;
158 
159  avctx->extradata = av_mallocz(avctx->extradata_size +
161 
162  if (!avctx->extradata) {
163  av_log(avctx, AV_LOG_ERROR, "Could not allocate extradata.\n");
164  utvideo_encode_close(avctx);
165  return AVERROR(ENOMEM);
166  }
167 
168  for (i = 0; i < c->planes; i++) {
169  c->slice_buffer[i] = av_malloc(c->slice_stride * (avctx->height + 2) +
171  if (!c->slice_buffer[i]) {
172  av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer 1.\n");
173  utvideo_encode_close(avctx);
174  return AVERROR(ENOMEM);
175  }
176  }
177 
178  /*
179  * Set the version of the encoder.
180  * Last byte is "implementation ID", which is
181  * obtained from the creator of the format.
182  * Libavcodec has been assigned with the ID 0xF0.
183  */
184  AV_WB32(avctx->extradata, MKTAG(1, 0, 0, 0xF0));
185 
186  /*
187  * Set the "original format"
188  * Not used for anything during decoding.
189  */
190  AV_WL32(avctx->extradata + 4, original_format);
191 
192  /* Write 4 as the 'frame info size' */
193  AV_WL32(avctx->extradata + 8, c->frame_info_size);
194 
195  /*
196  * Set how many slices are going to be used.
197  * By default uses multiple slices depending on the subsampled height.
198  * This enables multithreading in the official decoder.
199  */
200  if (!avctx->slices) {
201  c->slices = subsampled_height / 120;
202 
203  if (!c->slices)
204  c->slices = 1;
205  else if (c->slices > 256)
206  c->slices = 256;
207  } else {
208  c->slices = avctx->slices;
209  }
210 
211  /* Set compression mode */
212  c->compression = COMP_HUFF;
213 
214  /*
215  * Set the encoding flags:
216  * - Slice count minus 1
217  * - Interlaced encoding mode flag, set to zero for now.
218  * - Compression mode (none/huff)
219  * And write the flags.
220  */
221  c->flags = (c->slices - 1) << 24;
222  c->flags |= 0 << 11; // bit field to signal interlaced encoding mode
223  c->flags |= c->compression;
224 
225  AV_WL32(avctx->extradata + 12, c->flags);
226 
227  return 0;
228 }
229 
230 static void mangle_rgb_planes(uint8_t *dst[4], int dst_stride, uint8_t *src,
231  int step, int stride, int width, int height)
232 {
233  int i, j;
234  int k = 2 * dst_stride;
235  unsigned int g;
236 
237  for (j = 0; j < height; j++) {
238  if (step == 3) {
239  for (i = 0; i < width * step; i += step) {
240  g = src[i + 1];
241  dst[0][k] = g;
242  g += 0x80;
243  dst[1][k] = src[i + 2] - g;
244  dst[2][k] = src[i + 0] - g;
245  k++;
246  }
247  } else {
248  for (i = 0; i < width * step; i += step) {
249  g = src[i + 1];
250  dst[0][k] = g;
251  g += 0x80;
252  dst[1][k] = src[i + 2] - g;
253  dst[2][k] = src[i + 0] - g;
254  dst[3][k] = src[i + 3];
255  k++;
256  }
257  }
258  k += dst_stride - width;
259  src += stride;
260  }
261 }
262 
263 /* Write data to a plane with left prediction */
264 static void left_predict(uint8_t *src, uint8_t *dst, int stride,
265  int width, int height)
266 {
267  int i, j;
268  uint8_t prev;
269 
270  prev = 0x80; /* Set the initial value */
271  for (j = 0; j < height; j++) {
272  for (i = 0; i < width; i++) {
273  *dst++ = src[i] - prev;
274  prev = src[i];
275  }
276  src += stride;
277  }
278 }
279 
280 /* Write data to a plane with median prediction */
282  int width, int height)
283 {
284  int i, j;
285  int A, B;
286  uint8_t prev;
287 
288  /* First line uses left neighbour prediction */
289  prev = 0x80; /* Set the initial value */
290  for (i = 0; i < width; i++) {
291  *dst++ = src[i] - prev;
292  prev = src[i];
293  }
294 
295  if (height == 1)
296  return;
297 
298  src += stride;
299 
300  /*
301  * Second line uses top prediction for the first sample,
302  * and median for the rest.
303  */
304  A = B = 0;
305 
306  /* Rest of the coded part uses median prediction */
307  for (j = 1; j < height; j++) {
308  c->hdsp.sub_hfyu_median_pred(dst, src - stride, src, width, &A, &B);
309  dst += width;
310  src += stride;
311  }
312 }
313 
314 /* Count the usage of values in a plane */
315 static void count_usage(uint8_t *src, int width,
316  int height, uint64_t *counts)
317 {
318  int i, j;
319 
320  for (j = 0; j < height; j++) {
321  for (i = 0; i < width; i++) {
322  counts[src[i]]++;
323  }
324  src += width;
325  }
326 }
327 
328 /* Calculate the actual huffman codes from the code lengths */
329 static void calculate_codes(HuffEntry *he)
330 {
331  int last, i;
332  uint32_t code;
333 
334  qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len);
335 
336  last = 255;
337  while (he[last].len == 255 && last)
338  last--;
339 
340  code = 1;
341  for (i = last; i >= 0; i--) {
342  he[i].code = code >> (32 - he[i].len);
343  code += 0x80000000u >> (he[i].len - 1);
344  }
345 
346  qsort(he, 256, sizeof(*he), huff_cmp_sym);
347 }
348 
349 /* Write huffman bit codes to a memory block */
350 static int write_huff_codes(uint8_t *src, uint8_t *dst, int dst_size,
351  int width, int height, HuffEntry *he)
352 {
353  PutBitContext pb;
354  int i, j;
355  int count;
356 
357  init_put_bits(&pb, dst, dst_size);
358 
359  /* Write the codes */
360  for (j = 0; j < height; j++) {
361  for (i = 0; i < width; i++)
362  put_bits(&pb, he[src[i]].len, he[src[i]].code);
363 
364  src += width;
365  }
366 
367  /* Pad output to a 32bit boundary */
368  count = put_bits_count(&pb) & 0x1F;
369 
370  if (count)
371  put_bits(&pb, 32 - count, 0);
372 
373  /* Get the amount of bits written */
374  count = put_bits_count(&pb);
375 
376  /* Flush the rest with zeroes */
377  flush_put_bits(&pb);
378 
379  return count;
380 }
381 
383  uint8_t *dst, int stride, int plane_no,
384  int width, int height, PutByteContext *pb)
385 {
386  UtvideoContext *c = avctx->priv_data;
387  uint8_t lengths[256];
388  uint64_t counts[256] = { 0 };
389 
390  HuffEntry he[256];
391 
392  uint32_t offset = 0, slice_len = 0;
393  const int cmask = ~(!plane_no && avctx->pix_fmt == AV_PIX_FMT_YUV420P);
394  int i, sstart, send = 0;
395  int symbol;
396  int ret;
397 
398  /* Do prediction / make planes */
399  switch (c->frame_pred) {
400  case PRED_NONE:
401  for (i = 0; i < c->slices; i++) {
402  sstart = send;
403  send = height * (i + 1) / c->slices & cmask;
404  av_image_copy_plane(dst + sstart * width, width,
405  src + sstart * stride, stride,
406  width, send - sstart);
407  }
408  break;
409  case PRED_LEFT:
410  for (i = 0; i < c->slices; i++) {
411  sstart = send;
412  send = height * (i + 1) / c->slices & cmask;
413  left_predict(src + sstart * stride, dst + sstart * width,
414  stride, width, send - sstart);
415  }
416  break;
417  case PRED_MEDIAN:
418  for (i = 0; i < c->slices; i++) {
419  sstart = send;
420  send = height * (i + 1) / c->slices & cmask;
421  median_predict(c, src + sstart * stride, dst + sstart * width,
422  stride, width, send - sstart);
423  }
424  break;
425  default:
426  av_log(avctx, AV_LOG_ERROR, "Unknown prediction mode: %d\n",
427  c->frame_pred);
429  }
430 
431  /* Count the usage of values */
432  count_usage(dst, width, height, counts);
433 
434  /* Check for a special case where only one symbol was used */
435  for (symbol = 0; symbol < 256; symbol++) {
436  /* If non-zero count is found, see if it matches width * height */
437  if (counts[symbol]) {
438  /* Special case if only one symbol was used */
439  if (counts[symbol] == width * (int64_t)height) {
440  /*
441  * Write a zero for the single symbol
442  * used in the plane, else 0xFF.
443  */
444  for (i = 0; i < 256; i++) {
445  if (i == symbol)
446  bytestream2_put_byte(pb, 0);
447  else
448  bytestream2_put_byte(pb, 0xFF);
449  }
450 
451  /* Write zeroes for lengths */
452  for (i = 0; i < c->slices; i++)
453  bytestream2_put_le32(pb, 0);
454 
455  /* And that's all for that plane folks */
456  return 0;
457  }
458  break;
459  }
460  }
461 
462  /* Calculate huffman lengths */
463  if ((ret = ff_huff_gen_len_table(lengths, counts, 256, 1)) < 0)
464  return ret;
465 
466  /*
467  * Write the plane's header into the output packet:
468  * - huffman code lengths (256 bytes)
469  * - slice end offsets (gotten from the slice lengths)
470  */
471  for (i = 0; i < 256; i++) {
472  bytestream2_put_byte(pb, lengths[i]);
473 
474  he[i].len = lengths[i];
475  he[i].sym = i;
476  }
477 
478  /* Calculate the huffman codes themselves */
479  calculate_codes(he);
480 
481  send = 0;
482  for (i = 0; i < c->slices; i++) {
483  sstart = send;
484  send = height * (i + 1) / c->slices & cmask;
485 
486  /*
487  * Write the huffman codes to a buffer,
488  * get the offset in bits and convert to bytes.
489  */
490  offset += write_huff_codes(dst + sstart * width, c->slice_bits,
491  width * height + 4, width,
492  send - sstart, he) >> 3;
493 
494  slice_len = offset - slice_len;
495 
496  /* Byteswap the written huffman codes */
497  c->bdsp.bswap_buf((uint32_t *) c->slice_bits,
498  (uint32_t *) c->slice_bits,
499  slice_len >> 2);
500 
501  /* Write the offset to the stream */
502  bytestream2_put_le32(pb, offset);
503 
504  /* Seek to the data part of the packet */
505  bytestream2_seek_p(pb, 4 * (c->slices - i - 1) +
506  offset - slice_len, SEEK_CUR);
507 
508  /* Write the slices' data into the output packet */
509  bytestream2_put_buffer(pb, c->slice_bits, slice_len);
510 
511  /* Seek back to the slice offsets */
512  bytestream2_seek_p(pb, -4 * (c->slices - i - 1) - offset,
513  SEEK_CUR);
514 
515  slice_len = offset;
516  }
517 
518  /* And at the end seek to the end of written slice(s) */
519  bytestream2_seek_p(pb, offset, SEEK_CUR);
520 
521  return 0;
522 }
523 
525  const AVFrame *pic, int *got_packet)
526 {
527  UtvideoContext *c = avctx->priv_data;
528  PutByteContext pb;
529 
530  uint32_t frame_info;
531 
532  uint8_t *dst;
533 
534  int width = avctx->width, height = avctx->height;
535  int i, ret = 0;
536 
537  /* Allocate a new packet if needed, and set it to the pointer dst */
538  ret = ff_alloc_packet2(avctx, pkt, (256 + 4 * c->slices + width * height) *
539  c->planes + 4, 0);
540 
541  if (ret < 0)
542  return ret;
543 
544  dst = pkt->data;
545 
546  bytestream2_init_writer(&pb, dst, pkt->size);
547 
548  av_fast_padded_malloc(&c->slice_bits, &c->slice_bits_size, width * height + 4);
549 
550  if (!c->slice_bits) {
551  av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer 2.\n");
552  return AVERROR(ENOMEM);
553  }
554 
555  /* In case of RGB, mangle the planes to Ut Video's format */
556  if (avctx->pix_fmt == AV_PIX_FMT_RGBA || avctx->pix_fmt == AV_PIX_FMT_RGB24)
558  c->planes, pic->linesize[0], width, height);
559 
560  /* Deal with the planes */
561  switch (avctx->pix_fmt) {
562  case AV_PIX_FMT_RGB24:
563  case AV_PIX_FMT_RGBA:
564  for (i = 0; i < c->planes; i++) {
565  ret = encode_plane(avctx, c->slice_buffer[i] + 2 * c->slice_stride,
566  c->slice_buffer[i], c->slice_stride, i,
567  width, height, &pb);
568 
569  if (ret) {
570  av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
571  return ret;
572  }
573  }
574  break;
575  case AV_PIX_FMT_YUV422P:
576  for (i = 0; i < c->planes; i++) {
577  ret = encode_plane(avctx, pic->data[i], c->slice_buffer[0],
578  pic->linesize[i], i, width >> !!i, height, &pb);
579 
580  if (ret) {
581  av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
582  return ret;
583  }
584  }
585  break;
586  case AV_PIX_FMT_YUV420P:
587  for (i = 0; i < c->planes; i++) {
588  ret = encode_plane(avctx, pic->data[i], c->slice_buffer[0],
589  pic->linesize[i], i, width >> !!i, height >> !!i,
590  &pb);
591 
592  if (ret) {
593  av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
594  return ret;
595  }
596  }
597  break;
598  default:
599  av_log(avctx, AV_LOG_ERROR, "Unknown pixel format: %d\n",
600  avctx->pix_fmt);
601  return AVERROR_INVALIDDATA;
602  }
603 
604  /*
605  * Write frame information (LE 32bit unsigned)
606  * into the output packet.
607  * Contains the prediction method.
608  */
609  frame_info = c->frame_pred << 8;
610  bytestream2_put_le32(&pb, frame_info);
611 
612  /*
613  * At least currently Ut Video is IDR only.
614  * Set flags accordingly.
615  */
616 #if FF_API_CODED_FRAME
618  avctx->coded_frame->key_frame = 1;
621 #endif
622 
623  pkt->size = bytestream2_tell_p(&pb);
624  pkt->flags |= AV_PKT_FLAG_KEY;
625 
626  /* Packet should be done */
627  *got_packet = 1;
628 
629  return 0;
630 }
631 
633  .name = "utvideo",
634  .long_name = NULL_IF_CONFIG_SMALL("Ut Video"),
635  .type = AVMEDIA_TYPE_VIDEO,
636  .id = AV_CODEC_ID_UTVIDEO,
637  .priv_data_size = sizeof(UtvideoContext),
639  .encode2 = utvideo_encode_frame,
640  .close = utvideo_encode_close,
642  .pix_fmts = (const enum AVPixelFormat[]) {
645  },
646 };
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
Definition: bswapdsp.h:25
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:519
int slice_stride
Definition: utvideo.h:79
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2129
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
static void mangle_rgb_planes(uint8_t *dst[4], int dst_stride, uint8_t *src, int step, int stride, int width, int height)
Definition: utvideoenc.c:230
uint32_t flags
Definition: utvideo.h:72
misc image utilities
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:167
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
static int huff_cmp_sym(const void *a, const void *b)
Definition: utvideoenc.c:40
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:65
const char * g
Definition: vf_curves.c:108
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int slice_bits_size
Definition: utvideo.h:81
int size
Definition: avcodec.h:1424
const char * b
Definition: vf_curves.c:109
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:143
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1722
static av_cold int utvideo_encode_init(AVCodecContext *avctx)
Definition: utvideoenc.c:58
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:126
static AVPacket pkt
void(* sub_hfyu_median_pred)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top)
Subtract HuffYUV's variant of median prediction.
Definition: huffyuvencdsp.h:33
AVCodec.
Definition: avcodec.h:3472
#define FFALIGN(x, a)
Definition: common.h:86
av_cold void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c)
Definition: huffyuvencdsp.c:77
#define AV_CODEC_CAP_INTRA_ONLY
Codec is intra only.
Definition: avcodec.h:940
uint8_t
#define av_cold
Definition: attributes.h:74
#define av_malloc(s)
AVCodec ff_utvideo_encoder
Definition: utvideoenc.c:632
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1617
#define FF_PRED_PLANE
Definition: avcodec.h:1885
uint8_t * data
Definition: avcodec.h:1423
static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic, int *got_packet)
Definition: utvideoenc.c:524
uint32_t code
Definition: utvideo.h:87
#define A(x)
Definition: vp56_arith.h:28
#define av_log(a,...)
static void left_predict(uint8_t *src, uint8_t *dst, int stride, int width, int height)
Definition: utvideoenc.c:264
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1469
BswapDSPContext bdsp
Definition: utvideo.h:69
const int ff_ut_pred_order[5]
Definition: utvideo.c:29
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
#define AVERROR(e)
Definition: error.h:43
uint8_t sym
Definition: utvideo.h:85
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
AVCodecContext * avctx
Definition: utvideo.h:68
const char * name
Name of the codec implementation.
Definition: avcodec.h:3479
uint32_t frame_info_size
Definition: utvideo.h:72
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
GLsizei count
Definition: opengl_enc.c:109
static int write_huff_codes(uint8_t *src, uint8_t *dst, int dst_size, int width, int height, HuffEntry *he)
Definition: utvideoenc.c:350
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
Definition: bytestream.h:193
Libavcodec external API header.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:920
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:95
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1429
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:85
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:67
static void median_predict(UtvideoContext *c, uint8_t *src, uint8_t *dst, int stride, int width, int height)
Definition: utvideoenc.c:281
int compression
Definition: utvideo.h:75
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:242
int width
picture width / height.
Definition: avcodec.h:1681
float u
static int encode_plane(AVCodecContext *avctx, uint8_t *src, uint8_t *dst, int stride, int plane_no, int width, int height, PutByteContext *pb)
Definition: utvideoenc.c:382
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition: bytestream.h:282
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
Definition: bytestream.h:232
Common Ut Video header.
int frame_pred
Definition: utvideo.h:77
uint8_t len
Definition: utvideo.h:86
int ff_huff_gen_len_table(uint8_t *dst, const uint64_t *stats, int stats_size, int skip0)
Definition: huffman.c:55
AVS_Value src
Definition: avisynth_c.h:482
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
main external API structure.
Definition: avcodec.h:1502
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1534
int extradata_size
Definition: avcodec.h:1618
BYTE int const BYTE int int int height
Definition: avisynth_c.h:676
#define AV_WB32(p, v)
Definition: intreadwrite.h:419
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:2230
huffman tree builder and VLC generator
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1782
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:209
uint8_t * slice_bits
Definition: utvideo.h:80
int ff_ut_huff_cmp_len(const void *a, const void *b)
Definition: utvideo.c:35
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
static void calculate_codes(HuffEntry *he)
Definition: utvideoenc.c:329
static void count_usage(uint8_t *src, int width, int height, uint64_t *counts)
Definition: utvideoenc.c:315
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:63
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:79
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:101
static double c[64]
int prediction_method
prediction method (needed for huffyuv)
Definition: avcodec.h:1883
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:3024
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:48
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:636
int slices
Number of slices.
Definition: avcodec.h:2253
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
Definition: bswapdsp.c:49
void * priv_data
Definition: avcodec.h:1544
HuffYUVEncDSPContext hdsp
Definition: utvideo.h:70
Definition: vf_geq.c:46
uint8_t * slice_buffer[4]
Definition: utvideo.h:80
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:61
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:80
int len
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:237
#define av_freep(p)
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:273
#define stride
#define MKTAG(a, b, c, d)
Definition: common.h:330
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
static av_cold int utvideo_encode_close(AVCodecContext *avctx)
Definition: utvideoenc.c:46
This structure stores compressed data.
Definition: avcodec.h:1400
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:252
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
static int width
bitstream writer API