Libav
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 Libav.
6  *
7  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
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(&avctx->coded_frame);
52  av_freep(&c->slice_bits);
53  for (i = 0; i < 4; i++)
54  av_freep(&c->slice_buffer[i]);
55 
56  return 0;
57 }
58 
60 {
61  UtvideoContext *c = avctx->priv_data;
62  int i, subsampled_height;
63  uint32_t original_format;
64 
65  c->avctx = avctx;
66  c->frame_info_size = 4;
67  c->slice_stride = FFALIGN(avctx->width, 32);
68 
69  switch (avctx->pix_fmt) {
70  case AV_PIX_FMT_RGB24:
71  c->planes = 3;
72  avctx->codec_tag = MKTAG('U', 'L', 'R', 'G');
73  original_format = UTVIDEO_RGB;
74  break;
75  case AV_PIX_FMT_RGBA:
76  c->planes = 4;
77  avctx->codec_tag = MKTAG('U', 'L', 'R', 'A');
78  original_format = UTVIDEO_RGBA;
79  break;
80  case AV_PIX_FMT_YUV420P:
81  if (avctx->width & 1 || avctx->height & 1) {
82  av_log(avctx, AV_LOG_ERROR,
83  "4:2:0 video requires even width and height.\n");
84  return AVERROR_INVALIDDATA;
85  }
86  c->planes = 3;
87  if (avctx->colorspace == AVCOL_SPC_BT709)
88  avctx->codec_tag = MKTAG('U', 'L', 'H', '0');
89  else
90  avctx->codec_tag = MKTAG('U', 'L', 'Y', '0');
91  original_format = UTVIDEO_420;
92  break;
93  case AV_PIX_FMT_YUV422P:
94  if (avctx->width & 1) {
95  av_log(avctx, AV_LOG_ERROR,
96  "4:2:2 video requires even width.\n");
97  return AVERROR_INVALIDDATA;
98  }
99  c->planes = 3;
100  if (avctx->colorspace == AVCOL_SPC_BT709)
101  avctx->codec_tag = MKTAG('U', 'L', 'H', '2');
102  else
103  avctx->codec_tag = MKTAG('U', 'L', 'Y', '2');
104  original_format = UTVIDEO_422;
105  break;
106  default:
107  av_log(avctx, AV_LOG_ERROR, "Unknown pixel format: %d\n",
108  avctx->pix_fmt);
109  return AVERROR_INVALIDDATA;
110  }
111 
112  ff_bswapdsp_init(&c->bdsp);
114 
115  /* Check the prediction method, and error out if unsupported */
116  if (avctx->prediction_method < 0 || avctx->prediction_method > 4) {
117  av_log(avctx, AV_LOG_WARNING,
118  "Prediction method %d is not supported in Ut Video.\n",
119  avctx->prediction_method);
121  }
122 
123  if (avctx->prediction_method == FF_PRED_PLANE) {
124  av_log(avctx, AV_LOG_ERROR,
125  "Plane prediction is not supported in Ut Video.\n");
127  }
128 
129  /* Convert from libavcodec prediction type to Ut Video's */
131 
132  if (c->frame_pred == PRED_GRADIENT) {
133  av_log(avctx, AV_LOG_ERROR, "Gradient prediction is not supported.\n");
135  }
136 
137  /*
138  * Check the asked slice count for obviously invalid
139  * values (> 256 or negative).
140  */
141  if (avctx->slices > 256 || avctx->slices < 0) {
142  av_log(avctx, AV_LOG_ERROR,
143  "Slice count %d is not supported in Ut Video (theoretical range is 0-256).\n",
144  avctx->slices);
145  return AVERROR(EINVAL);
146  }
147 
148  /* Check that the slice count is not larger than the subsampled height */
149  subsampled_height = avctx->height >> av_pix_fmt_desc_get(avctx->pix_fmt)->log2_chroma_h;
150  if (avctx->slices > subsampled_height) {
151  av_log(avctx, AV_LOG_ERROR,
152  "Slice count %d is larger than the subsampling-applied height %d.\n",
153  avctx->slices, subsampled_height);
154  return AVERROR(EINVAL);
155  }
156 
157  avctx->coded_frame = av_frame_alloc();
158 
159  if (!avctx->coded_frame) {
160  av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
161  utvideo_encode_close(avctx);
162  return AVERROR(ENOMEM);
163  }
164 
165  /* extradata size is 4 * 32bit */
166  avctx->extradata_size = 16;
167 
168  avctx->extradata = av_mallocz(avctx->extradata_size +
170 
171  if (!avctx->extradata) {
172  av_log(avctx, AV_LOG_ERROR, "Could not allocate extradata.\n");
173  utvideo_encode_close(avctx);
174  return AVERROR(ENOMEM);
175  }
176 
177  for (i = 0; i < c->planes; i++) {
178  c->slice_buffer[i] = av_malloc(c->slice_stride * (avctx->height + 2) +
180  if (!c->slice_buffer[i]) {
181  av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer 1.\n");
182  utvideo_encode_close(avctx);
183  return AVERROR(ENOMEM);
184  }
185  }
186 
187  /*
188  * Set the version of the encoder.
189  * Last byte is "implementation ID", which is
190  * obtained from the creator of the format.
191  * Libavcodec has been assigned with the ID 0xF0.
192  */
193  AV_WB32(avctx->extradata, MKTAG(1, 0, 0, 0xF0));
194 
195  /*
196  * Set the "original format"
197  * Not used for anything during decoding.
198  */
199  AV_WL32(avctx->extradata + 4, original_format);
200 
201  /* Write 4 as the 'frame info size' */
202  AV_WL32(avctx->extradata + 8, c->frame_info_size);
203 
204  /*
205  * Set how many slices are going to be used.
206  * By default uses multiple slices depending on the subsampled height.
207  * This enables multithreading in the official decoder.
208  */
209  if (!avctx->slices) {
210  c->slices = subsampled_height / 120;
211 
212  if (!c->slices)
213  c->slices = 1;
214  else if (c->slices > 256)
215  c->slices = 256;
216  } else {
217  c->slices = avctx->slices;
218  }
219 
220  /* Set compression mode */
221  c->compression = COMP_HUFF;
222 
223  /*
224  * Set the encoding flags:
225  * - Slice count minus 1
226  * - Interlaced encoding mode flag, set to zero for now.
227  * - Compression mode (none/huff)
228  * And write the flags.
229  */
230  c->flags = (c->slices - 1) << 24;
231  c->flags |= 0 << 11; // bit field to signal interlaced encoding mode
232  c->flags |= c->compression;
233 
234  AV_WL32(avctx->extradata + 12, c->flags);
235 
236  return 0;
237 }
238 
239 static void mangle_rgb_planes(uint8_t *dst[4], int dst_stride, uint8_t *src,
240  int step, int stride, int width, int height)
241 {
242  int i, j;
243  int k = 2 * dst_stride;
244  unsigned int g;
245 
246  for (j = 0; j < height; j++) {
247  if (step == 3) {
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  k++;
255  }
256  } else {
257  for (i = 0; i < width * step; i += step) {
258  g = src[i + 1];
259  dst[0][k] = g;
260  g += 0x80;
261  dst[1][k] = src[i + 2] - g;
262  dst[2][k] = src[i + 0] - g;
263  dst[3][k] = src[i + 3];
264  k++;
265  }
266  }
267  k += dst_stride - width;
268  src += stride;
269  }
270 }
271 
272 /* Write data to a plane with left prediction */
273 static void left_predict(uint8_t *src, uint8_t *dst, int stride,
274  int width, int height)
275 {
276  int i, j;
277  uint8_t prev;
278 
279  prev = 0x80; /* Set the initial value */
280  for (j = 0; j < height; j++) {
281  for (i = 0; i < width; i++) {
282  *dst++ = src[i] - prev;
283  prev = src[i];
284  }
285  src += stride;
286  }
287 }
288 
289 /* Write data to a plane with median prediction */
290 static void median_predict(UtvideoContext *c, uint8_t *src, uint8_t *dst, int stride,
291  int width, int height)
292 {
293  int i, j;
294  int A, B;
295  uint8_t prev;
296 
297  /* First line uses left neighbour prediction */
298  prev = 0x80; /* Set the initial value */
299  for (i = 0; i < width; i++) {
300  *dst++ = src[i] - prev;
301  prev = src[i];
302  }
303 
304  if (height == 1)
305  return;
306 
307  src += stride;
308 
309  /*
310  * Second line uses top prediction for the first sample,
311  * and median for the rest.
312  */
313  A = B = 0;
314 
315  /* Rest of the coded part uses median prediction */
316  for (j = 1; j < height; j++) {
317  c->hdsp.sub_hfyu_median_pred(dst, src - stride, src, width, &A, &B);
318  dst += width;
319  src += stride;
320  }
321 }
322 
323 /* Count the usage of values in a plane */
324 static void count_usage(uint8_t *src, int width,
325  int height, uint64_t *counts)
326 {
327  int i, j;
328 
329  for (j = 0; j < height; j++) {
330  for (i = 0; i < width; i++) {
331  counts[src[i]]++;
332  }
333  src += width;
334  }
335 }
336 
337 /* Calculate the actual huffman codes from the code lengths */
338 static void calculate_codes(HuffEntry *he)
339 {
340  int last, i;
341  uint32_t code;
342 
343  qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len);
344 
345  last = 255;
346  while (he[last].len == 255 && last)
347  last--;
348 
349  code = 1;
350  for (i = last; i >= 0; i--) {
351  he[i].code = code >> (32 - he[i].len);
352  code += 0x80000000u >> (he[i].len - 1);
353  }
354 
355  qsort(he, 256, sizeof(*he), huff_cmp_sym);
356 }
357 
358 /* Write huffman bit codes to a memory block */
359 static int write_huff_codes(uint8_t *src, uint8_t *dst, int dst_size,
360  int width, int height, HuffEntry *he)
361 {
362  PutBitContext pb;
363  int i, j;
364  int count;
365 
366  init_put_bits(&pb, dst, dst_size);
367 
368  /* Write the codes */
369  for (j = 0; j < height; j++) {
370  for (i = 0; i < width; i++)
371  put_bits(&pb, he[src[i]].len, he[src[i]].code);
372 
373  src += width;
374  }
375 
376  /* Pad output to a 32bit boundary */
377  count = put_bits_count(&pb) & 0x1F;
378 
379  if (count)
380  put_bits(&pb, 32 - count, 0);
381 
382  /* Get the amount of bits written */
383  count = put_bits_count(&pb);
384 
385  /* Flush the rest with zeroes */
386  flush_put_bits(&pb);
387 
388  return count;
389 }
390 
391 static int encode_plane(AVCodecContext *avctx, uint8_t *src,
392  uint8_t *dst, int stride,
393  int width, int height, PutByteContext *pb)
394 {
395  UtvideoContext *c = avctx->priv_data;
396  uint8_t lengths[256];
397  uint64_t counts[256] = { 0 };
398 
399  HuffEntry he[256];
400 
401  uint32_t offset = 0, slice_len = 0;
402  int i, sstart, send = 0;
403  int symbol;
404 
405  /* Do prediction / make planes */
406  switch (c->frame_pred) {
407  case PRED_NONE:
408  for (i = 0; i < c->slices; i++) {
409  sstart = send;
410  send = height * (i + 1) / c->slices;
411  av_image_copy_plane(dst + sstart * width, width,
412  src + sstart * stride, stride,
413  width, send - sstart);
414  }
415  break;
416  case PRED_LEFT:
417  for (i = 0; i < c->slices; i++) {
418  sstart = send;
419  send = height * (i + 1) / c->slices;
420  left_predict(src + sstart * stride, dst + sstart * width,
421  stride, width, send - sstart);
422  }
423  break;
424  case PRED_MEDIAN:
425  for (i = 0; i < c->slices; i++) {
426  sstart = send;
427  send = height * (i + 1) / c->slices;
428  median_predict(c, src + sstart * stride, dst + sstart * width,
429  stride, width, send - sstart);
430  }
431  break;
432  default:
433  av_log(avctx, AV_LOG_ERROR, "Unknown prediction mode: %d\n",
434  c->frame_pred);
436  }
437 
438  /* Count the usage of values */
439  count_usage(dst, width, height, counts);
440 
441  /* Check for a special case where only one symbol was used */
442  for (symbol = 0; symbol < 256; symbol++) {
443  /* If non-zero count is found, see if it matches width * height */
444  if (counts[symbol]) {
445  /* Special case if only one symbol was used */
446  if (counts[symbol] == width * height) {
447  /*
448  * Write a zero for the single symbol
449  * used in the plane, else 0xFF.
450  */
451  for (i = 0; i < 256; i++) {
452  if (i == symbol)
453  bytestream2_put_byte(pb, 0);
454  else
455  bytestream2_put_byte(pb, 0xFF);
456  }
457 
458  /* Write zeroes for lengths */
459  for (i = 0; i < c->slices; i++)
460  bytestream2_put_le32(pb, 0);
461 
462  /* And that's all for that plane folks */
463  return 0;
464  }
465  break;
466  }
467  }
468 
469  /* Calculate huffman lengths */
470  ff_huff_gen_len_table(lengths, counts);
471 
472  /*
473  * Write the plane's header into the output packet:
474  * - huffman code lengths (256 bytes)
475  * - slice end offsets (gotten from the slice lengths)
476  */
477  for (i = 0; i < 256; i++) {
478  bytestream2_put_byte(pb, lengths[i]);
479 
480  he[i].len = lengths[i];
481  he[i].sym = i;
482  }
483 
484  /* Calculate the huffman codes themselves */
485  calculate_codes(he);
486 
487  send = 0;
488  for (i = 0; i < c->slices; i++) {
489  sstart = send;
490  send = height * (i + 1) / c->slices;
491 
492  /*
493  * Write the huffman codes to a buffer,
494  * get the offset in bits and convert to bytes.
495  */
496  offset += write_huff_codes(dst + sstart * width, c->slice_bits,
497  width * (send - sstart), width,
498  send - sstart, he) >> 3;
499 
500  slice_len = offset - slice_len;
501 
502  /* Byteswap the written huffman codes */
503  c->bdsp.bswap_buf((uint32_t *) c->slice_bits,
504  (uint32_t *) c->slice_bits,
505  slice_len >> 2);
506 
507  /* Write the offset to the stream */
508  bytestream2_put_le32(pb, offset);
509 
510  /* Seek to the data part of the packet */
511  bytestream2_seek_p(pb, 4 * (c->slices - i - 1) +
512  offset - slice_len, SEEK_CUR);
513 
514  /* Write the slices' data into the output packet */
515  bytestream2_put_buffer(pb, c->slice_bits, slice_len);
516 
517  /* Seek back to the slice offsets */
518  bytestream2_seek_p(pb, -4 * (c->slices - i - 1) - offset,
519  SEEK_CUR);
520 
521  slice_len = offset;
522  }
523 
524  /* And at the end seek to the end of written slice(s) */
525  bytestream2_seek_p(pb, offset, SEEK_CUR);
526 
527  return 0;
528 }
529 
531  const AVFrame *pic, int *got_packet)
532 {
533  UtvideoContext *c = avctx->priv_data;
534  PutByteContext pb;
535 
536  uint32_t frame_info;
537 
538  uint8_t *dst;
539 
540  int width = avctx->width, height = avctx->height;
541  int i, ret = 0;
542 
543  /* Allocate a new packet if needed, and set it to the pointer dst */
544  ret = ff_alloc_packet(pkt, (256 + 4 * c->slices + width * height) *
545  c->planes + 4);
546 
547  if (ret < 0) {
548  av_log(avctx, AV_LOG_ERROR,
549  "Error allocating the output packet, or the provided packet "
550  "was too small.\n");
551  return ret;
552  }
553 
554  dst = pkt->data;
555 
556  bytestream2_init_writer(&pb, dst, pkt->size);
557 
559  width * height + FF_INPUT_BUFFER_PADDING_SIZE);
560 
561  if (!c->slice_bits) {
562  av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer 2.\n");
563  return AVERROR(ENOMEM);
564  }
565 
566  /* In case of RGB, mangle the planes to Ut Video's format */
567  if (avctx->pix_fmt == AV_PIX_FMT_RGBA || avctx->pix_fmt == AV_PIX_FMT_RGB24)
569  c->planes, pic->linesize[0], width, height);
570 
571  /* Deal with the planes */
572  switch (avctx->pix_fmt) {
573  case AV_PIX_FMT_RGB24:
574  case AV_PIX_FMT_RGBA:
575  for (i = 0; i < c->planes; i++) {
576  ret = encode_plane(avctx, c->slice_buffer[i] + 2 * c->slice_stride,
577  c->slice_buffer[i], c->slice_stride,
578  width, 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_YUV422P:
587  for (i = 0; i < c->planes; i++) {
588  ret = encode_plane(avctx, pic->data[i], c->slice_buffer[0],
589  pic->linesize[i], width >> !!i, height, &pb);
590 
591  if (ret) {
592  av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
593  return ret;
594  }
595  }
596  break;
597  case AV_PIX_FMT_YUV420P:
598  for (i = 0; i < c->planes; i++) {
599  ret = encode_plane(avctx, pic->data[i], c->slice_buffer[0],
600  pic->linesize[i], width >> !!i, height >> !!i,
601  &pb);
602 
603  if (ret) {
604  av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
605  return ret;
606  }
607  }
608  break;
609  default:
610  av_log(avctx, AV_LOG_ERROR, "Unknown pixel format: %d\n",
611  avctx->pix_fmt);
612  return AVERROR_INVALIDDATA;
613  }
614 
615  /*
616  * Write frame information (LE 32bit unsigned)
617  * into the output packet.
618  * Contains the prediction method.
619  */
620  frame_info = c->frame_pred << 8;
621  bytestream2_put_le32(&pb, frame_info);
622 
623  /*
624  * At least currently Ut Video is IDR only.
625  * Set flags accordingly.
626  */
627  avctx->coded_frame->key_frame = 1;
629 
630  pkt->size = bytestream2_tell_p(&pb);
631  pkt->flags |= AV_PKT_FLAG_KEY;
632 
633  /* Packet should be done */
634  *got_packet = 1;
635 
636  return 0;
637 }
638 
640  .name = "utvideo",
641  .long_name = NULL_IF_CONFIG_SMALL("Ut Video"),
642  .type = AVMEDIA_TYPE_VIDEO,
643  .id = AV_CODEC_ID_UTVIDEO,
644  .priv_data_size = sizeof(UtvideoContext),
646  .encode2 = utvideo_encode_frame,
648  .pix_fmts = (const enum AVPixelFormat[]) {
651  },
652 };
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:346
int slice_stride
Definition: utvideo.h:79
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1599
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
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:239
uint32_t flags
Definition: utvideo.h:72
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:129
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:67
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2548
int slice_bits_size
Definition: utvideo.h:81
int size
Definition: avcodec.h:974
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:141
void ff_huff_gen_len_table(uint8_t *dst, const uint64_t *stats)
Definition: huffman.c:55
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1270
static av_cold int utvideo_encode_init(AVCodecContext *avctx)
Definition: utvideoenc.c:59
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
int stride
Definition: mace.c:144
AVCodec.
Definition: avcodec.h:2812
#define FFALIGN(x, a)
Definition: common.h:62
av_cold void ff_huffyuvencdsp_init(HuffYUVEncDSPContext *c)
Definition: huffyuvencdsp.c:77
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
uint8_t
#define av_cold
Definition: attributes.h:66
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:57
#define AV_WB32(p, d)
Definition: intreadwrite.h:239
AVCodec ff_utvideo_encoder
Definition: utvideoenc.c:639
#define b
Definition: input.c:52
#define AV_WL32(p, d)
Definition: intreadwrite.h:255
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1164
uint8_t * data
Definition: avcodec.h:973
static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic, int *got_packet)
Definition: utvideoenc.c:530
#define B
Definition: huffyuv.h:49
uint32_t code
Definition: utvideo.h:87
static void left_predict(uint8_t *src, uint8_t *dst, int stride, int width, int height)
Definition: utvideoenc.c:273
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1019
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:123
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:145
AVCodecContext * avctx
Definition: utvideo.h:68
g
Definition: yuv2rgb.c:535
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
const char * name
Name of the codec implementation.
Definition: avcodec.h:2819
uint32_t frame_info_size
Definition: utvideo.h:72
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
Definition: put_bits.h:134
static int write_huff_codes(uint8_t *src, uint8_t *dst, int dst_size, int width, int height, HuffEntry *he)
Definition: utvideoenc.c:359
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
Definition: bytestream.h:190
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:96
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:979
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:67
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:69
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
Definition: bswapdsp.c:49
static void median_predict(UtvideoContext *c, uint8_t *src, uint8_t *dst, int stride, int width, int height)
Definition: utvideoenc.c:290
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:531
int compression
Definition: utvideo.h:75
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:196
int width
picture width / height.
Definition: avcodec.h:1229
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1257
static int encode_plane(AVCodecContext *avctx, uint8_t *src, uint8_t *dst, int stride, int width, int height, PutByteContext *pb)
Definition: utvideoenc.c:391
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition: bytestream.h:279
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
Definition: bytestream.h:229
Common Ut Video header.
static int width
Definition: utils.c:156
int frame_pred
Definition: utvideo.h:77
uint8_t len
Definition: utvideo.h:86
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:153
main external API structure.
Definition: avcodec.h:1050
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:490
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1082
int extradata_size
Definition: avcodec.h:1165
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1775
huffman tree builder and VLC generator
static int step
Definition: avplay.c:247
Definition: vf_drawbox.c:37
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:141
static void calculate_codes(HuffEntry *he)
Definition: utvideoenc.c:338
int height
Definition: gxfenc.c:72
static void count_usage(uint8_t *src, int width, int height, uint64_t *counts)
Definition: utvideoenc.c:324
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: mem.c:388
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:83
int prediction_method
prediction method (needed for huffyuv)
Definition: avcodec.h:1426
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:48
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
int slices
Number of slices.
Definition: avcodec.h:1798
void * priv_data
Definition: avcodec.h:1092
HuffYUVEncDSPContext hdsp
Definition: utvideo.h:70
uint8_t * slice_buffer[4]
Definition: utvideo.h:80
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:56
int len
#define FF_PRED_PLANE
Definition: avcodec.h:1428
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:191
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:254
#define MKTAG(a, b, c, d)
Definition: common.h:238
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
static av_cold int utvideo_encode_close(AVCodecContext *avctx)
Definition: utvideoenc.c:46
This structure stores compressed data.
Definition: avcodec.h:950
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:205
bitstream writer API