You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

686 lines
21KB

  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. * @file
  23. * Ut Video encoder
  24. */
  25. #include "libavutil/imgutils.h"
  26. #include "libavutil/intreadwrite.h"
  27. #include "libavutil/opt.h"
  28. #include "avcodec.h"
  29. #include "internal.h"
  30. #include "bswapdsp.h"
  31. #include "bytestream.h"
  32. #include "put_bits.h"
  33. #include "mathops.h"
  34. #include "utvideo.h"
  35. #include "huffman.h"
  36. /* Compare huffentry symbols */
  37. static int huff_cmp_sym(const void *a, const void *b)
  38. {
  39. const HuffEntry *aa = a, *bb = b;
  40. return aa->sym - bb->sym;
  41. }
  42. static av_cold int utvideo_encode_close(AVCodecContext *avctx)
  43. {
  44. UtvideoContext *c = avctx->priv_data;
  45. int i;
  46. av_freep(&c->slice_bits);
  47. for (i = 0; i < 4; i++)
  48. av_freep(&c->slice_buffer[i]);
  49. return 0;
  50. }
  51. static av_cold int utvideo_encode_init(AVCodecContext *avctx)
  52. {
  53. UtvideoContext *c = avctx->priv_data;
  54. int i, subsampled_height;
  55. uint32_t original_format;
  56. c->avctx = avctx;
  57. c->frame_info_size = 4;
  58. c->slice_stride = FFALIGN(avctx->width, 32);
  59. switch (avctx->pix_fmt) {
  60. case AV_PIX_FMT_GBRP:
  61. c->planes = 3;
  62. avctx->codec_tag = MKTAG('U', 'L', 'R', 'G');
  63. original_format = UTVIDEO_RGB;
  64. break;
  65. case AV_PIX_FMT_GBRAP:
  66. c->planes = 4;
  67. avctx->codec_tag = MKTAG('U', 'L', 'R', 'A');
  68. original_format = UTVIDEO_RGBA;
  69. avctx->bits_per_coded_sample = 32;
  70. break;
  71. case AV_PIX_FMT_YUV420P:
  72. if (avctx->width & 1 || avctx->height & 1) {
  73. av_log(avctx, AV_LOG_ERROR,
  74. "4:2:0 video requires even width and height.\n");
  75. return AVERROR_INVALIDDATA;
  76. }
  77. c->planes = 3;
  78. if (avctx->colorspace == AVCOL_SPC_BT709)
  79. avctx->codec_tag = MKTAG('U', 'L', 'H', '0');
  80. else
  81. avctx->codec_tag = MKTAG('U', 'L', 'Y', '0');
  82. original_format = UTVIDEO_420;
  83. break;
  84. case AV_PIX_FMT_YUV422P:
  85. if (avctx->width & 1) {
  86. av_log(avctx, AV_LOG_ERROR,
  87. "4:2:2 video requires even width.\n");
  88. return AVERROR_INVALIDDATA;
  89. }
  90. c->planes = 3;
  91. if (avctx->colorspace == AVCOL_SPC_BT709)
  92. avctx->codec_tag = MKTAG('U', 'L', 'H', '2');
  93. else
  94. avctx->codec_tag = MKTAG('U', 'L', 'Y', '2');
  95. original_format = UTVIDEO_422;
  96. break;
  97. case AV_PIX_FMT_YUV444P:
  98. c->planes = 3;
  99. if (avctx->colorspace == AVCOL_SPC_BT709)
  100. avctx->codec_tag = MKTAG('U', 'L', 'H', '4');
  101. else
  102. avctx->codec_tag = MKTAG('U', 'L', 'Y', '4');
  103. original_format = UTVIDEO_444;
  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. ff_bswapdsp_init(&c->bdsp);
  111. ff_llvidencdsp_init(&c->llvidencdsp);
  112. #if FF_API_PRIVATE_OPT
  113. FF_DISABLE_DEPRECATION_WARNINGS
  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);
  119. return AVERROR_OPTION_NOT_FOUND;
  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");
  124. return AVERROR_OPTION_NOT_FOUND;
  125. }
  126. /* Convert from libavcodec prediction type to Ut Video's */
  127. if (avctx->prediction_method)
  128. c->frame_pred = ff_ut_pred_order[avctx->prediction_method];
  129. FF_ENABLE_DEPRECATION_WARNINGS
  130. #endif
  131. if (c->frame_pred == PRED_GRADIENT) {
  132. av_log(avctx, AV_LOG_ERROR, "Gradient prediction is not supported.\n");
  133. return AVERROR_OPTION_NOT_FOUND;
  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. /* Check that the slice count is not larger than the subsampled height */
  146. subsampled_height = avctx->height >> av_pix_fmt_desc_get(avctx->pix_fmt)->log2_chroma_h;
  147. if (avctx->slices > subsampled_height) {
  148. av_log(avctx, AV_LOG_ERROR,
  149. "Slice count %d is larger than the subsampling-applied height %d.\n",
  150. avctx->slices, subsampled_height);
  151. return AVERROR(EINVAL);
  152. }
  153. /* extradata size is 4 * 32 bits */
  154. avctx->extradata_size = 16;
  155. avctx->extradata = av_mallocz(avctx->extradata_size +
  156. AV_INPUT_BUFFER_PADDING_SIZE);
  157. if (!avctx->extradata) {
  158. av_log(avctx, AV_LOG_ERROR, "Could not allocate extradata.\n");
  159. utvideo_encode_close(avctx);
  160. return AVERROR(ENOMEM);
  161. }
  162. for (i = 0; i < c->planes; i++) {
  163. c->slice_buffer[i] = av_malloc(c->slice_stride * (avctx->height + 2) +
  164. AV_INPUT_BUFFER_PADDING_SIZE);
  165. if (!c->slice_buffer[i]) {
  166. av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer 1.\n");
  167. utvideo_encode_close(avctx);
  168. return AVERROR(ENOMEM);
  169. }
  170. }
  171. /*
  172. * Set the version of the encoder.
  173. * Last byte is "implementation ID", which is
  174. * obtained from the creator of the format.
  175. * Libavcodec has been assigned with the ID 0xF0.
  176. */
  177. AV_WB32(avctx->extradata, MKTAG(1, 0, 0, 0xF0));
  178. /*
  179. * Set the "original format"
  180. * Not used for anything during decoding.
  181. */
  182. AV_WL32(avctx->extradata + 4, original_format);
  183. /* Write 4 as the 'frame info size' */
  184. AV_WL32(avctx->extradata + 8, c->frame_info_size);
  185. /*
  186. * Set how many slices are going to be used.
  187. * By default uses multiple slices depending on the subsampled height.
  188. * This enables multithreading in the official decoder.
  189. */
  190. if (!avctx->slices) {
  191. c->slices = subsampled_height / 120;
  192. if (!c->slices)
  193. c->slices = 1;
  194. else if (c->slices > 256)
  195. c->slices = 256;
  196. } else {
  197. c->slices = avctx->slices;
  198. }
  199. /* Set compression mode */
  200. c->compression = COMP_HUFF;
  201. /*
  202. * Set the encoding flags:
  203. * - Slice count minus 1
  204. * - Interlaced encoding mode flag, set to zero for now.
  205. * - Compression mode (none/huff)
  206. * And write the flags.
  207. */
  208. c->flags = (c->slices - 1) << 24;
  209. c->flags |= 0 << 11; // bit field to signal interlaced encoding mode
  210. c->flags |= c->compression;
  211. AV_WL32(avctx->extradata + 12, c->flags);
  212. return 0;
  213. }
  214. static void mangle_rgb_planes(uint8_t *dst[4], ptrdiff_t dst_stride,
  215. uint8_t *const src[4], int planes, const int stride[4],
  216. int width, int height)
  217. {
  218. int i, j;
  219. int k = 2 * dst_stride;
  220. const uint8_t *sg = src[0];
  221. const uint8_t *sb = src[1];
  222. const uint8_t *sr = src[2];
  223. const uint8_t *sa = src[3];
  224. unsigned int g;
  225. for (j = 0; j < height; j++) {
  226. if (planes == 3) {
  227. for (i = 0; i < width; i++) {
  228. g = sg[i];
  229. dst[0][k] = g;
  230. g += 0x80;
  231. dst[1][k] = sb[i] - g;
  232. dst[2][k] = sr[i] - g;
  233. k++;
  234. }
  235. } else {
  236. for (i = 0; i < width; i++) {
  237. g = sg[i];
  238. dst[0][k] = g;
  239. g += 0x80;
  240. dst[1][k] = sb[i] - g;
  241. dst[2][k] = sr[i] - g;
  242. dst[3][k] = sa[i];
  243. k++;
  244. }
  245. sa += stride[3];
  246. }
  247. k += dst_stride - width;
  248. sg += stride[0];
  249. sb += stride[1];
  250. sr += stride[2];
  251. }
  252. }
  253. #undef A
  254. #undef B
  255. /* Write data to a plane with median prediction */
  256. static void median_predict(UtvideoContext *c, uint8_t *src, uint8_t *dst,
  257. ptrdiff_t stride, int width, int height)
  258. {
  259. int i, j;
  260. int A, B;
  261. uint8_t prev;
  262. /* First line uses left neighbour prediction */
  263. prev = 0x80; /* Set the initial value */
  264. for (i = 0; i < width; i++) {
  265. *dst++ = src[i] - prev;
  266. prev = src[i];
  267. }
  268. if (height == 1)
  269. return;
  270. src += stride;
  271. /*
  272. * Second line uses top prediction for the first sample,
  273. * and median for the rest.
  274. */
  275. A = B = 0;
  276. /* Rest of the coded part uses median prediction */
  277. for (j = 1; j < height; j++) {
  278. c->llvidencdsp.sub_median_pred(dst, src - stride, src, width, &A, &B);
  279. dst += width;
  280. src += stride;
  281. }
  282. }
  283. /* Count the usage of values in a plane */
  284. static void count_usage(uint8_t *src, int width,
  285. int height, uint64_t *counts)
  286. {
  287. int i, j;
  288. for (j = 0; j < height; j++) {
  289. for (i = 0; i < width; i++) {
  290. counts[src[i]]++;
  291. }
  292. src += width;
  293. }
  294. }
  295. /* Calculate the actual huffman codes from the code lengths */
  296. static void calculate_codes(HuffEntry *he)
  297. {
  298. int last, i;
  299. uint32_t code;
  300. qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len);
  301. last = 255;
  302. while (he[last].len == 255 && last)
  303. last--;
  304. code = 1;
  305. for (i = last; i >= 0; i--) {
  306. he[i].code = code >> (32 - he[i].len);
  307. code += 0x80000000u >> (he[i].len - 1);
  308. }
  309. qsort(he, 256, sizeof(*he), huff_cmp_sym);
  310. }
  311. /* Write huffman bit codes to a memory block */
  312. static int write_huff_codes(uint8_t *src, uint8_t *dst, int dst_size,
  313. int width, int height, HuffEntry *he)
  314. {
  315. PutBitContext pb;
  316. int i, j;
  317. int count;
  318. init_put_bits(&pb, dst, dst_size);
  319. /* Write the codes */
  320. for (j = 0; j < height; j++) {
  321. for (i = 0; i < width; i++)
  322. put_bits(&pb, he[src[i]].len, he[src[i]].code);
  323. src += width;
  324. }
  325. /* Pad output to a 32-bit boundary */
  326. count = put_bits_count(&pb) & 0x1F;
  327. if (count)
  328. put_bits(&pb, 32 - count, 0);
  329. /* Get the amount of bits written */
  330. count = put_bits_count(&pb);
  331. /* Flush the rest with zeroes */
  332. flush_put_bits(&pb);
  333. return count;
  334. }
  335. static int encode_plane(AVCodecContext *avctx, uint8_t *src,
  336. uint8_t *dst, ptrdiff_t stride, int plane_no,
  337. int width, int height, PutByteContext *pb)
  338. {
  339. UtvideoContext *c = avctx->priv_data;
  340. uint8_t lengths[256];
  341. uint64_t counts[256] = { 0 };
  342. HuffEntry he[256];
  343. uint32_t offset = 0, slice_len = 0;
  344. const int cmask = ~(!plane_no && avctx->pix_fmt == AV_PIX_FMT_YUV420P);
  345. int i, sstart, send = 0;
  346. int symbol;
  347. int ret;
  348. /* Do prediction / make planes */
  349. switch (c->frame_pred) {
  350. case PRED_NONE:
  351. for (i = 0; i < c->slices; i++) {
  352. sstart = send;
  353. send = height * (i + 1) / c->slices & cmask;
  354. av_image_copy_plane(dst + sstart * width, width,
  355. src + sstart * stride, stride,
  356. width, send - sstart);
  357. }
  358. break;
  359. case PRED_LEFT:
  360. for (i = 0; i < c->slices; i++) {
  361. sstart = send;
  362. send = height * (i + 1) / c->slices & cmask;
  363. c->llvidencdsp.sub_left_predict(dst + sstart * width, src + sstart * stride, stride, width, send - sstart);
  364. }
  365. break;
  366. case PRED_MEDIAN:
  367. for (i = 0; i < c->slices; i++) {
  368. sstart = send;
  369. send = height * (i + 1) / c->slices & cmask;
  370. median_predict(c, src + sstart * stride, dst + sstart * width,
  371. stride, width, send - sstart);
  372. }
  373. break;
  374. default:
  375. av_log(avctx, AV_LOG_ERROR, "Unknown prediction mode: %d\n",
  376. c->frame_pred);
  377. return AVERROR_OPTION_NOT_FOUND;
  378. }
  379. /* Count the usage of values */
  380. count_usage(dst, width, height, counts);
  381. /* Check for a special case where only one symbol was used */
  382. for (symbol = 0; symbol < 256; symbol++) {
  383. /* If non-zero count is found, see if it matches width * height */
  384. if (counts[symbol]) {
  385. /* Special case if only one symbol was used */
  386. if (counts[symbol] == width * (int64_t)height) {
  387. /*
  388. * Write a zero for the single symbol
  389. * used in the plane, else 0xFF.
  390. */
  391. for (i = 0; i < 256; i++) {
  392. if (i == symbol)
  393. bytestream2_put_byte(pb, 0);
  394. else
  395. bytestream2_put_byte(pb, 0xFF);
  396. }
  397. /* Write zeroes for lengths */
  398. for (i = 0; i < c->slices; i++)
  399. bytestream2_put_le32(pb, 0);
  400. /* And that's all for that plane folks */
  401. return 0;
  402. }
  403. break;
  404. }
  405. }
  406. /* Calculate huffman lengths */
  407. if ((ret = ff_huff_gen_len_table(lengths, counts, 256, 1)) < 0)
  408. return ret;
  409. /*
  410. * Write the plane's header into the output packet:
  411. * - huffman code lengths (256 bytes)
  412. * - slice end offsets (gotten from the slice lengths)
  413. */
  414. for (i = 0; i < 256; i++) {
  415. bytestream2_put_byte(pb, lengths[i]);
  416. he[i].len = lengths[i];
  417. he[i].sym = i;
  418. }
  419. /* Calculate the huffman codes themselves */
  420. calculate_codes(he);
  421. send = 0;
  422. for (i = 0; i < c->slices; i++) {
  423. sstart = send;
  424. send = height * (i + 1) / c->slices & cmask;
  425. /*
  426. * Write the huffman codes to a buffer,
  427. * get the offset in bits and convert to bytes.
  428. */
  429. offset += write_huff_codes(dst + sstart * width, c->slice_bits,
  430. width * height + 4, width,
  431. send - sstart, he) >> 3;
  432. slice_len = offset - slice_len;
  433. /* Byteswap the written huffman codes */
  434. c->bdsp.bswap_buf((uint32_t *) c->slice_bits,
  435. (uint32_t *) c->slice_bits,
  436. slice_len >> 2);
  437. /* Write the offset to the stream */
  438. bytestream2_put_le32(pb, offset);
  439. /* Seek to the data part of the packet */
  440. bytestream2_seek_p(pb, 4 * (c->slices - i - 1) +
  441. offset - slice_len, SEEK_CUR);
  442. /* Write the slices' data into the output packet */
  443. bytestream2_put_buffer(pb, c->slice_bits, slice_len);
  444. /* Seek back to the slice offsets */
  445. bytestream2_seek_p(pb, -4 * (c->slices - i - 1) - offset,
  446. SEEK_CUR);
  447. slice_len = offset;
  448. }
  449. /* And at the end seek to the end of written slice(s) */
  450. bytestream2_seek_p(pb, offset, SEEK_CUR);
  451. return 0;
  452. }
  453. static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  454. const AVFrame *pic, int *got_packet)
  455. {
  456. UtvideoContext *c = avctx->priv_data;
  457. PutByteContext pb;
  458. uint32_t frame_info;
  459. uint8_t *dst;
  460. int width = avctx->width, height = avctx->height;
  461. int i, ret = 0;
  462. /* Allocate a new packet if needed, and set it to the pointer dst */
  463. ret = ff_alloc_packet2(avctx, pkt, (256 + 4 * c->slices + width * height) *
  464. c->planes + 4, 0);
  465. if (ret < 0)
  466. return ret;
  467. dst = pkt->data;
  468. bytestream2_init_writer(&pb, dst, pkt->size);
  469. av_fast_padded_malloc(&c->slice_bits, &c->slice_bits_size, width * height + 4);
  470. if (!c->slice_bits) {
  471. av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer 2.\n");
  472. return AVERROR(ENOMEM);
  473. }
  474. /* In case of RGB, mangle the planes to Ut Video's format */
  475. if (avctx->pix_fmt == AV_PIX_FMT_GBRAP || avctx->pix_fmt == AV_PIX_FMT_GBRP)
  476. mangle_rgb_planes(c->slice_buffer, c->slice_stride, pic->data,
  477. c->planes, pic->linesize, width, height);
  478. /* Deal with the planes */
  479. switch (avctx->pix_fmt) {
  480. case AV_PIX_FMT_GBRP:
  481. case AV_PIX_FMT_GBRAP:
  482. for (i = 0; i < c->planes; i++) {
  483. ret = encode_plane(avctx, c->slice_buffer[i] + 2 * c->slice_stride,
  484. c->slice_buffer[i], c->slice_stride, i,
  485. width, height, &pb);
  486. if (ret) {
  487. av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
  488. return ret;
  489. }
  490. }
  491. break;
  492. case AV_PIX_FMT_YUV444P:
  493. for (i = 0; i < c->planes; i++) {
  494. ret = encode_plane(avctx, pic->data[i], c->slice_buffer[0],
  495. pic->linesize[i], i, width, height, &pb);
  496. if (ret) {
  497. av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
  498. return ret;
  499. }
  500. }
  501. break;
  502. case AV_PIX_FMT_YUV422P:
  503. for (i = 0; i < c->planes; i++) {
  504. ret = encode_plane(avctx, pic->data[i], c->slice_buffer[0],
  505. pic->linesize[i], i, width >> !!i, height, &pb);
  506. if (ret) {
  507. av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
  508. return ret;
  509. }
  510. }
  511. break;
  512. case AV_PIX_FMT_YUV420P:
  513. for (i = 0; i < c->planes; i++) {
  514. ret = encode_plane(avctx, pic->data[i], c->slice_buffer[0],
  515. pic->linesize[i], i, width >> !!i, height >> !!i,
  516. &pb);
  517. if (ret) {
  518. av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
  519. return ret;
  520. }
  521. }
  522. break;
  523. default:
  524. av_log(avctx, AV_LOG_ERROR, "Unknown pixel format: %d\n",
  525. avctx->pix_fmt);
  526. return AVERROR_INVALIDDATA;
  527. }
  528. /*
  529. * Write frame information (LE 32-bit unsigned)
  530. * into the output packet.
  531. * Contains the prediction method.
  532. */
  533. frame_info = c->frame_pred << 8;
  534. bytestream2_put_le32(&pb, frame_info);
  535. /*
  536. * At least currently Ut Video is IDR only.
  537. * Set flags accordingly.
  538. */
  539. #if FF_API_CODED_FRAME
  540. FF_DISABLE_DEPRECATION_WARNINGS
  541. avctx->coded_frame->key_frame = 1;
  542. avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
  543. FF_ENABLE_DEPRECATION_WARNINGS
  544. #endif
  545. pkt->size = bytestream2_tell_p(&pb);
  546. pkt->flags |= AV_PKT_FLAG_KEY;
  547. /* Packet should be done */
  548. *got_packet = 1;
  549. return 0;
  550. }
  551. #define OFFSET(x) offsetof(UtvideoContext, x)
  552. #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  553. static const AVOption options[] = {
  554. { "pred", "Prediction method", OFFSET(frame_pred), AV_OPT_TYPE_INT, { .i64 = PRED_LEFT }, PRED_NONE, PRED_MEDIAN, VE, "pred" },
  555. { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRED_NONE }, INT_MIN, INT_MAX, VE, "pred" },
  556. { "left", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRED_LEFT }, INT_MIN, INT_MAX, VE, "pred" },
  557. { "gradient", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRED_GRADIENT }, INT_MIN, INT_MAX, VE, "pred" },
  558. { "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRED_MEDIAN }, INT_MIN, INT_MAX, VE, "pred" },
  559. { NULL},
  560. };
  561. static const AVClass utvideo_class = {
  562. .class_name = "utvideo",
  563. .item_name = av_default_item_name,
  564. .option = options,
  565. .version = LIBAVUTIL_VERSION_INT,
  566. };
  567. AVCodec ff_utvideo_encoder = {
  568. .name = "utvideo",
  569. .long_name = NULL_IF_CONFIG_SMALL("Ut Video"),
  570. .type = AVMEDIA_TYPE_VIDEO,
  571. .id = AV_CODEC_ID_UTVIDEO,
  572. .priv_data_size = sizeof(UtvideoContext),
  573. .priv_class = &utvideo_class,
  574. .init = utvideo_encode_init,
  575. .encode2 = utvideo_encode_frame,
  576. .close = utvideo_encode_close,
  577. .capabilities = AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_INTRA_ONLY,
  578. .pix_fmts = (const enum AVPixelFormat[]) {
  579. AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_YUV422P,
  580. AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_NONE
  581. },
  582. };