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 "bytestream.h"
32 #include "put_bits.h"
33 #include "dsputil.h"
34 #include "mathops.h"
35 #include "utvideo.h"
36 #include "huffman.h"
37 
38 /* Compare huffentry symbols */
39 static int huff_cmp_sym(const void *a, const void *b)
40 {
41  const HuffEntry *aa = a, *bb = b;
42  return aa->sym - bb->sym;
43 }
44 
46 {
47  UtvideoContext *c = avctx->priv_data;
48  int i;
49 
50  av_freep(&avctx->coded_frame);
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_dsputil_init(&c->dsp, avctx);
112 
113  /* Check the prediction method, and error out if unsupported */
114  if (avctx->prediction_method < 0 || avctx->prediction_method > 4) {
115  av_log(avctx, AV_LOG_WARNING,
116  "Prediction method %d is not supported in Ut Video.\n",
117  avctx->prediction_method);
119  }
120 
121  if (avctx->prediction_method == FF_PRED_PLANE) {
122  av_log(avctx, AV_LOG_ERROR,
123  "Plane prediction is not supported in Ut Video.\n");
125  }
126 
127  /* Convert from libavcodec prediction type to Ut Video's */
129 
130  if (c->frame_pred == PRED_GRADIENT) {
131  av_log(avctx, AV_LOG_ERROR, "Gradient prediction is not supported.\n");
133  }
134 
135  /*
136  * Check the asked slice count for obviously invalid
137  * values (> 256 or negative).
138  */
139  if (avctx->slices > 256 || avctx->slices < 0) {
140  av_log(avctx, AV_LOG_ERROR,
141  "Slice count %d is not supported in Ut Video (theoretical range is 0-256).\n",
142  avctx->slices);
143  return AVERROR(EINVAL);
144  }
145 
146  /* Check that the slice count is not larger than the subsampled height */
147  subsampled_height = avctx->height >> av_pix_fmt_desc_get(avctx->pix_fmt)->log2_chroma_h;
148  if (avctx->slices > subsampled_height) {
149  av_log(avctx, AV_LOG_ERROR,
150  "Slice count %d is larger than the subsampling-applied height %d.\n",
151  avctx->slices, subsampled_height);
152  return AVERROR(EINVAL);
153  }
154 
155  avctx->coded_frame = av_frame_alloc();
156 
157  if (!avctx->coded_frame) {
158  av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
159  utvideo_encode_close(avctx);
160  return AVERROR(ENOMEM);
161  }
162 
163  /* extradata size is 4 * 32bit */
164  avctx->extradata_size = 16;
165 
166  avctx->extradata = av_mallocz(avctx->extradata_size +
168 
169  if (!avctx->extradata) {
170  av_log(avctx, AV_LOG_ERROR, "Could not allocate extradata.\n");
171  utvideo_encode_close(avctx);
172  return AVERROR(ENOMEM);
173  }
174 
175  for (i = 0; i < c->planes; i++) {
176  c->slice_buffer[i] = av_malloc(c->slice_stride * (avctx->height + 2) +
178  if (!c->slice_buffer[i]) {
179  av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer 1.\n");
180  utvideo_encode_close(avctx);
181  return AVERROR(ENOMEM);
182  }
183  }
184 
185  /*
186  * Set the version of the encoder.
187  * Last byte is "implementation ID", which is
188  * obtained from the creator of the format.
189  * Libavcodec has been assigned with the ID 0xF0.
190  */
191  AV_WB32(avctx->extradata, MKTAG(1, 0, 0, 0xF0));
192 
193  /*
194  * Set the "original format"
195  * Not used for anything during decoding.
196  */
197  AV_WL32(avctx->extradata + 4, original_format);
198 
199  /* Write 4 as the 'frame info size' */
200  AV_WL32(avctx->extradata + 8, c->frame_info_size);
201 
202  /*
203  * Set how many slices are going to be used.
204  * By default uses multiple slices depending on the subsampled height.
205  * This enables multithreading in the official decoder.
206  */
207  if (!avctx->slices) {
208  c->slices = subsampled_height / 120;
209 
210  if (!c->slices)
211  c->slices = 1;
212  else if (c->slices > 256)
213  c->slices = 256;
214  } else {
215  c->slices = avctx->slices;
216  }
217 
218  /* Set compression mode */
219  c->compression = COMP_HUFF;
220 
221  /*
222  * Set the encoding flags:
223  * - Slice count minus 1
224  * - Interlaced encoding mode flag, set to zero for now.
225  * - Compression mode (none/huff)
226  * And write the flags.
227  */
228  c->flags = (c->slices - 1) << 24;
229  c->flags |= 0 << 11; // bit field to signal interlaced encoding mode
230  c->flags |= c->compression;
231 
232  AV_WL32(avctx->extradata + 12, c->flags);
233 
234  return 0;
235 }
236 
237 static void mangle_rgb_planes(uint8_t *dst[4], int dst_stride, uint8_t *src,
238  int step, int stride, int width, int height)
239 {
240  int i, j;
241  int k = 2 * dst_stride;
242  unsigned int g;
243 
244  for (j = 0; j < height; j++) {
245  if (step == 3) {
246  for (i = 0; i < width * step; i += step) {
247  g = src[i + 1];
248  dst[0][k] = g;
249  g += 0x80;
250  dst[1][k] = src[i + 2] - g;
251  dst[2][k] = src[i + 0] - g;
252  k++;
253  }
254  } else {
255  for (i = 0; i < width * step; i += step) {
256  g = src[i + 1];
257  dst[0][k] = g;
258  g += 0x80;
259  dst[1][k] = src[i + 2] - g;
260  dst[2][k] = src[i + 0] - g;
261  dst[3][k] = src[i + 3];
262  k++;
263  }
264  }
265  k += dst_stride - width;
266  src += stride;
267  }
268 }
269 
270 /* Write data to a plane with left prediction */
271 static void left_predict(uint8_t *src, uint8_t *dst, int stride,
272  int width, int height)
273 {
274  int i, j;
275  uint8_t prev;
276 
277  prev = 0x80; /* Set the initial value */
278  for (j = 0; j < height; j++) {
279  for (i = 0; i < width; i++) {
280  *dst++ = src[i] - prev;
281  prev = src[i];
282  }
283  src += stride;
284  }
285 }
286 
287 /* Write data to a plane with median prediction */
288 static void median_predict(UtvideoContext *c, uint8_t *src, uint8_t *dst, int stride,
289  int width, int height)
290 {
291  int i, j;
292  int A, B;
293  uint8_t prev;
294 
295  /* First line uses left neighbour prediction */
296  prev = 0x80; /* Set the initial value */
297  for (i = 0; i < width; i++) {
298  *dst++ = src[i] - prev;
299  prev = src[i];
300  }
301 
302  if (height == 1)
303  return;
304 
305  src += stride;
306 
307  /*
308  * Second line uses top prediction for the first sample,
309  * and median for the rest.
310  */
311  A = B = 0;
312 
313  /* Rest of the coded part uses median prediction */
314  for (j = 1; j < height; j++) {
315  c->dsp.sub_hfyu_median_prediction(dst, src - stride, src, width, &A, &B);
316  dst += width;
317  src += stride;
318  }
319 }
320 
321 /* Count the usage of values in a plane */
322 static void count_usage(uint8_t *src, int width,
323  int height, uint64_t *counts)
324 {
325  int i, j;
326 
327  for (j = 0; j < height; j++) {
328  for (i = 0; i < width; i++) {
329  counts[src[i]]++;
330  }
331  src += width;
332  }
333 }
334 
335 /* Calculate the actual huffman codes from the code lengths */
336 static void calculate_codes(HuffEntry *he)
337 {
338  int last, i;
339  uint32_t code;
340 
341  qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len);
342 
343  last = 255;
344  while (he[last].len == 255 && last)
345  last--;
346 
347  code = 1;
348  for (i = last; i >= 0; i--) {
349  he[i].code = code >> (32 - he[i].len);
350  code += 0x80000000u >> (he[i].len - 1);
351  }
352 
353  qsort(he, 256, sizeof(*he), huff_cmp_sym);
354 }
355 
356 /* Write huffman bit codes to a memory block */
357 static int write_huff_codes(uint8_t *src, uint8_t *dst, int dst_size,
358  int width, int height, HuffEntry *he)
359 {
360  PutBitContext pb;
361  int i, j;
362  int count;
363 
364  init_put_bits(&pb, dst, dst_size);
365 
366  /* Write the codes */
367  for (j = 0; j < height; j++) {
368  for (i = 0; i < width; i++)
369  put_bits(&pb, he[src[i]].len, he[src[i]].code);
370 
371  src += width;
372  }
373 
374  /* Pad output to a 32bit boundary */
375  count = put_bits_count(&pb) & 0x1F;
376 
377  if (count)
378  put_bits(&pb, 32 - count, 0);
379 
380  /* Get the amount of bits written */
381  count = put_bits_count(&pb);
382 
383  /* Flush the rest with zeroes */
384  flush_put_bits(&pb);
385 
386  return count;
387 }
388 
389 static int encode_plane(AVCodecContext *avctx, uint8_t *src,
390  uint8_t *dst, int stride,
391  int width, int height, PutByteContext *pb)
392 {
393  UtvideoContext *c = avctx->priv_data;
394  uint8_t lengths[256];
395  uint64_t counts[256] = { 0 };
396 
397  HuffEntry he[256];
398 
399  uint32_t offset = 0, slice_len = 0;
400  int i, sstart, send = 0;
401  int symbol;
402 
403  /* Do prediction / make planes */
404  switch (c->frame_pred) {
405  case PRED_NONE:
406  for (i = 0; i < c->slices; i++) {
407  sstart = send;
408  send = height * (i + 1) / c->slices;
409  av_image_copy_plane(dst + sstart * width, width,
410  src + sstart * stride, stride,
411  width, send - sstart);
412  }
413  break;
414  case PRED_LEFT:
415  for (i = 0; i < c->slices; i++) {
416  sstart = send;
417  send = height * (i + 1) / c->slices;
418  left_predict(src + sstart * stride, dst + sstart * width,
419  stride, width, send - sstart);
420  }
421  break;
422  case PRED_MEDIAN:
423  for (i = 0; i < c->slices; i++) {
424  sstart = send;
425  send = height * (i + 1) / c->slices;
426  median_predict(c, src + sstart * stride, dst + sstart * width,
427  stride, width, send - sstart);
428  }
429  break;
430  default:
431  av_log(avctx, AV_LOG_ERROR, "Unknown prediction mode: %d\n",
432  c->frame_pred);
434  }
435 
436  /* Count the usage of values */
437  count_usage(dst, width, height, counts);
438 
439  /* Check for a special case where only one symbol was used */
440  for (symbol = 0; symbol < 256; symbol++) {
441  /* If non-zero count is found, see if it matches width * height */
442  if (counts[symbol]) {
443  /* Special case if only one symbol was used */
444  if (counts[symbol] == width * height) {
445  /*
446  * Write a zero for the single symbol
447  * used in the plane, else 0xFF.
448  */
449  for (i = 0; i < 256; i++) {
450  if (i == symbol)
451  bytestream2_put_byte(pb, 0);
452  else
453  bytestream2_put_byte(pb, 0xFF);
454  }
455 
456  /* Write zeroes for lengths */
457  for (i = 0; i < c->slices; i++)
458  bytestream2_put_le32(pb, 0);
459 
460  /* And that's all for that plane folks */
461  return 0;
462  }
463  break;
464  }
465  }
466 
467  /* Calculate huffman lengths */
468  ff_huff_gen_len_table(lengths, counts);
469 
470  /*
471  * Write the plane's header into the output packet:
472  * - huffman code lengths (256 bytes)
473  * - slice end offsets (gotten from the slice lengths)
474  */
475  for (i = 0; i < 256; i++) {
476  bytestream2_put_byte(pb, lengths[i]);
477 
478  he[i].len = lengths[i];
479  he[i].sym = i;
480  }
481 
482  /* Calculate the huffman codes themselves */
483  calculate_codes(he);
484 
485  send = 0;
486  for (i = 0; i < c->slices; i++) {
487  sstart = send;
488  send = height * (i + 1) / c->slices;
489 
490  /*
491  * Write the huffman codes to a buffer,
492  * get the offset in bits and convert to bytes.
493  */
494  offset += write_huff_codes(dst + sstart * width, c->slice_bits,
495  width * (send - sstart), width,
496  send - sstart, he) >> 3;
497 
498  slice_len = offset - slice_len;
499 
500  /* Byteswap the written huffman codes */
501  c->dsp.bswap_buf((uint32_t *) c->slice_bits,
502  (uint32_t *) c->slice_bits,
503  slice_len >> 2);
504 
505  /* Write the offset to the stream */
506  bytestream2_put_le32(pb, offset);
507 
508  /* Seek to the data part of the packet */
509  bytestream2_seek_p(pb, 4 * (c->slices - i - 1) +
510  offset - slice_len, SEEK_CUR);
511 
512  /* Write the slices' data into the output packet */
513  bytestream2_put_buffer(pb, c->slice_bits, slice_len);
514 
515  /* Seek back to the slice offsets */
516  bytestream2_seek_p(pb, -4 * (c->slices - i - 1) - offset,
517  SEEK_CUR);
518 
519  slice_len = offset;
520  }
521 
522  /* And at the end seek to the end of written slice(s) */
523  bytestream2_seek_p(pb, offset, SEEK_CUR);
524 
525  return 0;
526 }
527 
529  const AVFrame *pic, int *got_packet)
530 {
531  UtvideoContext *c = avctx->priv_data;
532  PutByteContext pb;
533 
534  uint32_t frame_info;
535 
536  uint8_t *dst;
537 
538  int width = avctx->width, height = avctx->height;
539  int i, ret = 0;
540 
541  /* Allocate a new packet if needed, and set it to the pointer dst */
542  ret = ff_alloc_packet(pkt, (256 + 4 * c->slices + width * height) *
543  c->planes + 4);
544 
545  if (ret < 0) {
546  av_log(avctx, AV_LOG_ERROR,
547  "Error allocating the output packet, or the provided packet "
548  "was too small.\n");
549  return ret;
550  }
551 
552  dst = pkt->data;
553 
554  bytestream2_init_writer(&pb, dst, pkt->size);
555 
557  width * height + FF_INPUT_BUFFER_PADDING_SIZE);
558 
559  if (!c->slice_bits) {
560  av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer 2.\n");
561  return AVERROR(ENOMEM);
562  }
563 
564  /* In case of RGB, mangle the planes to Ut Video's format */
565  if (avctx->pix_fmt == AV_PIX_FMT_RGBA || avctx->pix_fmt == AV_PIX_FMT_RGB24)
567  c->planes, pic->linesize[0], width, height);
568 
569  /* Deal with the planes */
570  switch (avctx->pix_fmt) {
571  case AV_PIX_FMT_RGB24:
572  case AV_PIX_FMT_RGBA:
573  for (i = 0; i < c->planes; i++) {
574  ret = encode_plane(avctx, c->slice_buffer[i] + 2 * c->slice_stride,
575  c->slice_buffer[i], c->slice_stride,
576  width, height, &pb);
577 
578  if (ret) {
579  av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
580  return ret;
581  }
582  }
583  break;
584  case AV_PIX_FMT_YUV422P:
585  for (i = 0; i < c->planes; i++) {
586  ret = encode_plane(avctx, pic->data[i], c->slice_buffer[0],
587  pic->linesize[i], width >> !!i, height, &pb);
588 
589  if (ret) {
590  av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
591  return ret;
592  }
593  }
594  break;
595  case AV_PIX_FMT_YUV420P:
596  for (i = 0; i < c->planes; i++) {
597  ret = encode_plane(avctx, pic->data[i], c->slice_buffer[0],
598  pic->linesize[i], width >> !!i, height >> !!i,
599  &pb);
600 
601  if (ret) {
602  av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
603  return ret;
604  }
605  }
606  break;
607  default:
608  av_log(avctx, AV_LOG_ERROR, "Unknown pixel format: %d\n",
609  avctx->pix_fmt);
610  return AVERROR_INVALIDDATA;
611  }
612 
613  /*
614  * Write frame information (LE 32bit unsigned)
615  * into the output packet.
616  * Contains the prediction method.
617  */
618  frame_info = c->frame_pred << 8;
619  bytestream2_put_le32(&pb, frame_info);
620 
621  /*
622  * At least currently Ut Video is IDR only.
623  * Set flags accordingly.
624  */
625  avctx->coded_frame->key_frame = 1;
627 
628  pkt->size = bytestream2_tell_p(&pb);
629  pkt->flags |= AV_PKT_FLAG_KEY;
630 
631  /* Packet should be done */
632  *got_packet = 1;
633 
634  return 0;
635 }
636 
638  .name = "utvideo",
639  .long_name = NULL_IF_CONFIG_SMALL("Ut Video"),
640  .type = AVMEDIA_TYPE_VIDEO,
641  .id = AV_CODEC_ID_UTVIDEO,
642  .priv_data_size = sizeof(UtvideoContext),
644  .encode2 = utvideo_encode_frame,
646  .pix_fmts = (const enum AVPixelFormat[]) {
649  },
650 };
int slice_stride
Definition: utvideo.h:77
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
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
Definition: dsputil.c:2440
#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:1507
This structure describes decoded (raw) audio or video data.
Definition: frame.h:107
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:237
#define B
Definition: dsputil.c:1836
uint32_t flags
Definition: utvideo.h:70
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:39
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:67
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2506
int slice_bits_size
Definition: utvideo.h:79
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:139
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:1247
static av_cold int utvideo_encode_init(AVCodecContext *avctx)
Definition: utvideoenc.c:58
int stride
Definition: mace.c:144
AVCodec.
Definition: avcodec.h:2755
#define FFALIGN(x, a)
Definition: common.h:62
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:43
#define AV_WB32(p, d)
Definition: intreadwrite.h:239
AVCodec ff_utvideo_encoder
Definition: utvideoenc.c:637
#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:1162
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:528
uint32_t code
Definition: utvideo.h:85
static void left_predict(uint8_t *src, uint8_t *dst, int stride, int width, int height)
Definition: utvideoenc.c:271
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1023
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:77
void(* sub_hfyu_median_prediction)(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 note, this might read from src1[-1], src2[-1]
Definition: dsputil.h:198
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
Definition: dsputil.h:202
#define AVERROR(e)
Definition: error.h:43
uint8_t sym
Definition: utvideo.h:83
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:142
AVCodecContext * avctx
Definition: utvideo.h:67
g
Definition: yuv2rgb.c:535
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:148
const char * name
Name of the codec implementation.
Definition: avcodec.h:2762
uint32_t frame_info_size
Definition: utvideo.h:70
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
Definition: put_bits.h:139
static int write_huff_codes(uint8_t *src, uint8_t *dst, int dst_size, int width, int height, HuffEntry *he)
Definition: utvideoenc.c:357
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
Definition: bytestream.h:188
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:72
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:69
static void median_predict(UtvideoContext *c, uint8_t *src, uint8_t *dst, int stride, int width, int height)
Definition: utvideoenc.c:288
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:509
int compression
Definition: utvideo.h:73
DSPContext dsp
Definition: utvideo.h:68
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:168
int width
picture width / height.
Definition: avcodec.h:1217
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1125
static int encode_plane(AVCodecContext *avctx, uint8_t *src, uint8_t *dst, int stride, int width, int height, PutByteContext *pb)
Definition: utvideoenc.c:389
static av_always_inline unsigned int bytestream2_put_buffer(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition: bytestream.h:267
Definition: vf_drawbox.c:37
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
Definition: bytestream.h:217
Common Ut Video header.
static int width
Definition: utils.c:156
int frame_pred
Definition: utvideo.h:75
uint8_t len
Definition: utvideo.h:84
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: avcodec.h:581
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:125
main external API structure.
Definition: avcodec.h:1054
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:489
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1080
int extradata_size
Definition: avcodec.h:1163
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1747
huffman tree builder and VLC generator
static int step
Definition: avplay.c:247
uint8_t * slice_bits
Definition: utvideo.h:78
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:113
static void calculate_codes(HuffEntry *he)
Definition: utvideoenc.c:336
int height
Definition: gxfenc.c:72
static void count_usage(uint8_t *src, int width, int height, uint64_t *counts)
Definition: utvideoenc.c:322
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:368
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:88
int prediction_method
prediction method (needed for huffyuv)
Definition: avcodec.h:1403
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:53
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:498
DSP utils.
int slices
Number of slices.
Definition: avcodec.h:1770
void * priv_data
Definition: avcodec.h:1090
uint8_t * slice_buffer[4]
Definition: utvideo.h:78
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:56
int len
#define FF_PRED_PLANE
Definition: avcodec.h:1405
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:163
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:231
#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:45
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