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.

553 lines
20KB

  1. /*
  2. * JPEG 2000 encoding support via OpenJPEG
  3. * Copyright (c) 2011 Michael Bradshaw <mjbshaw gmail com>
  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. * JPEG 2000 encoder using libopenjpeg
  24. */
  25. #define OPJ_STATIC
  26. #include "libavutil/avassert.h"
  27. #include "libavutil/common.h"
  28. #include "libavutil/imgutils.h"
  29. #include "libavutil/intreadwrite.h"
  30. #include "libavutil/opt.h"
  31. #include "avcodec.h"
  32. #include "internal.h"
  33. #if HAVE_OPENJPEG_1_5_OPENJPEG_H
  34. # include <openjpeg-1.5/openjpeg.h>
  35. #else
  36. # include <openjpeg.h>
  37. #endif
  38. typedef struct {
  39. AVClass *avclass;
  40. opj_image_t *image;
  41. opj_cparameters_t enc_params;
  42. opj_cinfo_t *compress;
  43. opj_event_mgr_t event_mgr;
  44. int format;
  45. int profile;
  46. int prog_order;
  47. int cinema_mode;
  48. int numresolution;
  49. int numlayers;
  50. int disto_alloc;
  51. int fixed_alloc;
  52. int fixed_quality;
  53. } LibOpenJPEGContext;
  54. static void error_callback(const char *msg, void *data)
  55. {
  56. av_log(data, AV_LOG_ERROR, "%s\n", msg);
  57. }
  58. static void warning_callback(const char *msg, void *data)
  59. {
  60. av_log(data, AV_LOG_WARNING, "%s\n", msg);
  61. }
  62. static void info_callback(const char *msg, void *data)
  63. {
  64. av_log(data, AV_LOG_DEBUG, "%s\n", msg);
  65. }
  66. static opj_image_t *mj2_create_image(AVCodecContext *avctx, opj_cparameters_t *parameters)
  67. {
  68. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
  69. opj_image_cmptparm_t *cmptparm;
  70. opj_image_t *img;
  71. int i;
  72. int sub_dx[4];
  73. int sub_dy[4];
  74. int numcomps;
  75. OPJ_COLOR_SPACE color_space = CLRSPC_UNKNOWN;
  76. sub_dx[0] = sub_dx[3] = 1;
  77. sub_dy[0] = sub_dy[3] = 1;
  78. sub_dx[1] = sub_dx[2] = 1 << desc->log2_chroma_w;
  79. sub_dy[1] = sub_dy[2] = 1 << desc->log2_chroma_h;
  80. numcomps = desc->nb_components;
  81. switch (avctx->pix_fmt) {
  82. case AV_PIX_FMT_GRAY8:
  83. case AV_PIX_FMT_GRAY8A:
  84. case AV_PIX_FMT_GRAY16:
  85. color_space = CLRSPC_GRAY;
  86. break;
  87. case AV_PIX_FMT_RGB24:
  88. case AV_PIX_FMT_RGBA:
  89. case AV_PIX_FMT_RGB48:
  90. case AV_PIX_FMT_RGBA64:
  91. case AV_PIX_FMT_GBR24P:
  92. case AV_PIX_FMT_GBRP9:
  93. case AV_PIX_FMT_GBRP10:
  94. case AV_PIX_FMT_GBRP12:
  95. case AV_PIX_FMT_GBRP14:
  96. case AV_PIX_FMT_GBRP16:
  97. color_space = CLRSPC_SRGB;
  98. break;
  99. case AV_PIX_FMT_YUV410P:
  100. case AV_PIX_FMT_YUV411P:
  101. case AV_PIX_FMT_YUV420P:
  102. case AV_PIX_FMT_YUV422P:
  103. case AV_PIX_FMT_YUV440P:
  104. case AV_PIX_FMT_YUV444P:
  105. case AV_PIX_FMT_YUVA420P:
  106. case AV_PIX_FMT_YUVA422P:
  107. case AV_PIX_FMT_YUVA444P:
  108. case AV_PIX_FMT_YUV420P9:
  109. case AV_PIX_FMT_YUV422P9:
  110. case AV_PIX_FMT_YUV444P9:
  111. case AV_PIX_FMT_YUVA420P9:
  112. case AV_PIX_FMT_YUVA422P9:
  113. case AV_PIX_FMT_YUVA444P9:
  114. case AV_PIX_FMT_YUV420P10:
  115. case AV_PIX_FMT_YUV422P10:
  116. case AV_PIX_FMT_YUV444P10:
  117. case AV_PIX_FMT_YUVA420P10:
  118. case AV_PIX_FMT_YUVA422P10:
  119. case AV_PIX_FMT_YUVA444P10:
  120. case AV_PIX_FMT_YUV420P12:
  121. case AV_PIX_FMT_YUV422P12:
  122. case AV_PIX_FMT_YUV444P12:
  123. case AV_PIX_FMT_YUV420P14:
  124. case AV_PIX_FMT_YUV422P14:
  125. case AV_PIX_FMT_YUV444P14:
  126. case AV_PIX_FMT_YUV420P16:
  127. case AV_PIX_FMT_YUV422P16:
  128. case AV_PIX_FMT_YUV444P16:
  129. case AV_PIX_FMT_YUVA420P16:
  130. case AV_PIX_FMT_YUVA422P16:
  131. case AV_PIX_FMT_YUVA444P16:
  132. color_space = CLRSPC_SYCC;
  133. break;
  134. default:
  135. av_log(avctx, AV_LOG_ERROR,
  136. "The requested pixel format '%s' is not supported\n",
  137. av_get_pix_fmt_name(avctx->pix_fmt));
  138. return NULL;
  139. }
  140. cmptparm = av_mallocz(numcomps * sizeof(*cmptparm));
  141. if (!cmptparm) {
  142. av_log(avctx, AV_LOG_ERROR, "Not enough memory\n");
  143. return NULL;
  144. }
  145. for (i = 0; i < numcomps; i++) {
  146. cmptparm[i].prec = desc->comp[i].depth_minus1 + 1;
  147. cmptparm[i].bpp = desc->comp[i].depth_minus1 + 1;
  148. cmptparm[i].sgnd = 0;
  149. cmptparm[i].dx = sub_dx[i];
  150. cmptparm[i].dy = sub_dy[i];
  151. cmptparm[i].w = avctx->width / sub_dx[i];
  152. cmptparm[i].h = avctx->height / sub_dy[i];
  153. }
  154. img = opj_image_create(numcomps, cmptparm, color_space);
  155. av_freep(&cmptparm);
  156. return img;
  157. }
  158. static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx)
  159. {
  160. LibOpenJPEGContext *ctx = avctx->priv_data;
  161. int err = AVERROR(ENOMEM);
  162. opj_set_default_encoder_parameters(&ctx->enc_params);
  163. ctx->enc_params.cp_rsiz = ctx->profile;
  164. ctx->enc_params.mode = !!avctx->global_quality;
  165. ctx->enc_params.cp_cinema = ctx->cinema_mode;
  166. ctx->enc_params.prog_order = ctx->prog_order;
  167. ctx->enc_params.numresolution = ctx->numresolution;
  168. ctx->enc_params.cp_disto_alloc = ctx->disto_alloc;
  169. ctx->enc_params.cp_fixed_alloc = ctx->fixed_alloc;
  170. ctx->enc_params.cp_fixed_quality = ctx->fixed_quality;
  171. ctx->enc_params.tcp_numlayers = ctx->numlayers;
  172. ctx->enc_params.tcp_rates[0] = FFMAX(avctx->compression_level, 0) * 2;
  173. ctx->compress = opj_create_compress(ctx->format);
  174. if (!ctx->compress) {
  175. av_log(avctx, AV_LOG_ERROR, "Error creating the compressor\n");
  176. return AVERROR(ENOMEM);
  177. }
  178. avctx->coded_frame = avcodec_alloc_frame();
  179. if (!avctx->coded_frame) {
  180. av_log(avctx, AV_LOG_ERROR, "Error allocating coded frame\n");
  181. goto fail;
  182. }
  183. ctx->image = mj2_create_image(avctx, &ctx->enc_params);
  184. if (!ctx->image) {
  185. av_log(avctx, AV_LOG_ERROR, "Error creating the mj2 image\n");
  186. err = AVERROR(EINVAL);
  187. goto fail;
  188. }
  189. memset(&ctx->event_mgr, 0, sizeof(opj_event_mgr_t));
  190. ctx->event_mgr.info_handler = info_callback;
  191. ctx->event_mgr.error_handler = error_callback;
  192. ctx->event_mgr.warning_handler = warning_callback;
  193. opj_set_event_mgr((opj_common_ptr)ctx->compress, &ctx->event_mgr, avctx);
  194. return 0;
  195. fail:
  196. av_freep(&ctx->compress);
  197. av_freep(&avctx->coded_frame);
  198. return err;
  199. }
  200. static int libopenjpeg_copy_packed8(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
  201. {
  202. int compno;
  203. int x;
  204. int y;
  205. int image_index;
  206. int frame_index;
  207. const int numcomps = image->numcomps;
  208. for (compno = 0; compno < numcomps; ++compno) {
  209. if (image->comps[compno].w > frame->linesize[0] / numcomps) {
  210. av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n");
  211. return 0;
  212. }
  213. }
  214. for (compno = 0; compno < numcomps; ++compno) {
  215. for (y = 0; y < avctx->height; ++y) {
  216. image_index = y * avctx->width;
  217. frame_index = y * frame->linesize[0] + compno;
  218. for (x = 0; x < avctx->width; ++x) {
  219. image->comps[compno].data[image_index++] = frame->data[0][frame_index];
  220. frame_index += numcomps;
  221. }
  222. }
  223. }
  224. return 1;
  225. }
  226. static int libopenjpeg_copy_packed16(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
  227. {
  228. int compno;
  229. int x;
  230. int y;
  231. int image_index;
  232. int frame_index;
  233. const int numcomps = image->numcomps;
  234. uint16_t *frame_ptr = (uint16_t*)frame->data[0];
  235. for (compno = 0; compno < numcomps; ++compno) {
  236. if (image->comps[compno].w > frame->linesize[0] / numcomps) {
  237. av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n");
  238. return 0;
  239. }
  240. }
  241. for (compno = 0; compno < numcomps; ++compno) {
  242. for (y = 0; y < avctx->height; ++y) {
  243. image_index = y * avctx->width;
  244. frame_index = y * (frame->linesize[0] / 2) + compno;
  245. for (x = 0; x < avctx->width; ++x) {
  246. image->comps[compno].data[image_index++] = frame_ptr[frame_index];
  247. frame_index += numcomps;
  248. }
  249. }
  250. }
  251. return 1;
  252. }
  253. static int libopenjpeg_copy_unpacked8(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
  254. {
  255. int compno;
  256. int x;
  257. int y;
  258. int width;
  259. int height;
  260. int image_index;
  261. int frame_index;
  262. const int numcomps = image->numcomps;
  263. for (compno = 0; compno < numcomps; ++compno) {
  264. if (image->comps[compno].w > frame->linesize[compno]) {
  265. av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n");
  266. return 0;
  267. }
  268. }
  269. for (compno = 0; compno < numcomps; ++compno) {
  270. width = avctx->width / image->comps[compno].dx;
  271. height = avctx->height / image->comps[compno].dy;
  272. for (y = 0; y < height; ++y) {
  273. image_index = y * width;
  274. frame_index = y * frame->linesize[compno];
  275. for (x = 0; x < width; ++x)
  276. image->comps[compno].data[image_index++] = frame->data[compno][frame_index++];
  277. }
  278. }
  279. return 1;
  280. }
  281. static int libopenjpeg_copy_unpacked16(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
  282. {
  283. int compno;
  284. int x;
  285. int y;
  286. int width;
  287. int height;
  288. int image_index;
  289. int frame_index;
  290. const int numcomps = image->numcomps;
  291. uint16_t *frame_ptr;
  292. for (compno = 0; compno < numcomps; ++compno) {
  293. if (image->comps[compno].w > frame->linesize[compno]) {
  294. av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n");
  295. return 0;
  296. }
  297. }
  298. for (compno = 0; compno < numcomps; ++compno) {
  299. width = avctx->width / image->comps[compno].dx;
  300. height = avctx->height / image->comps[compno].dy;
  301. frame_ptr = (uint16_t*)frame->data[compno];
  302. for (y = 0; y < height; ++y) {
  303. image_index = y * width;
  304. frame_index = y * (frame->linesize[compno] / 2);
  305. for (x = 0; x < width; ++x)
  306. image->comps[compno].data[image_index++] = frame_ptr[frame_index++];
  307. }
  308. }
  309. return 1;
  310. }
  311. static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  312. const AVFrame *frame, int *got_packet)
  313. {
  314. LibOpenJPEGContext *ctx = avctx->priv_data;
  315. opj_cinfo_t *compress = ctx->compress;
  316. opj_image_t *image = ctx->image;
  317. opj_cio_t *stream;
  318. int cpyresult = 0;
  319. int ret, len;
  320. AVFrame gbrframe;
  321. // x0, y0 is the top left corner of the image
  322. // x1, y1 is the width, height of the reference grid
  323. image->x0 = 0;
  324. image->y0 = 0;
  325. image->x1 = (avctx->width - 1) * ctx->enc_params.subsampling_dx + 1;
  326. image->y1 = (avctx->height - 1) * ctx->enc_params.subsampling_dy + 1;
  327. switch (avctx->pix_fmt) {
  328. case AV_PIX_FMT_RGB24:
  329. case AV_PIX_FMT_RGBA:
  330. case AV_PIX_FMT_GRAY8A:
  331. cpyresult = libopenjpeg_copy_packed8(avctx, frame, image);
  332. break;
  333. case AV_PIX_FMT_RGB48:
  334. case AV_PIX_FMT_RGBA64:
  335. cpyresult = libopenjpeg_copy_packed16(avctx, frame, image);
  336. break;
  337. case AV_PIX_FMT_GBR24P:
  338. case AV_PIX_FMT_GBRP9:
  339. case AV_PIX_FMT_GBRP10:
  340. case AV_PIX_FMT_GBRP12:
  341. case AV_PIX_FMT_GBRP14:
  342. case AV_PIX_FMT_GBRP16:
  343. gbrframe = *frame;
  344. gbrframe.data[0] = frame->data[2]; // swap to be rgb
  345. gbrframe.data[1] = frame->data[0];
  346. gbrframe.data[2] = frame->data[1];
  347. gbrframe.linesize[0] = frame->linesize[2];
  348. gbrframe.linesize[1] = frame->linesize[0];
  349. gbrframe.linesize[2] = frame->linesize[1];
  350. if (avctx->pix_fmt == AV_PIX_FMT_GBR24P) {
  351. cpyresult = libopenjpeg_copy_unpacked8(avctx, &gbrframe, image);
  352. } else {
  353. cpyresult = libopenjpeg_copy_unpacked16(avctx, &gbrframe, image);
  354. }
  355. break;
  356. case AV_PIX_FMT_GRAY8:
  357. case AV_PIX_FMT_YUV410P:
  358. case AV_PIX_FMT_YUV411P:
  359. case AV_PIX_FMT_YUV420P:
  360. case AV_PIX_FMT_YUV422P:
  361. case AV_PIX_FMT_YUV440P:
  362. case AV_PIX_FMT_YUV444P:
  363. case AV_PIX_FMT_YUVA420P:
  364. case AV_PIX_FMT_YUVA422P:
  365. case AV_PIX_FMT_YUVA444P:
  366. cpyresult = libopenjpeg_copy_unpacked8(avctx, frame, image);
  367. break;
  368. case AV_PIX_FMT_GRAY16:
  369. case AV_PIX_FMT_YUV420P9:
  370. case AV_PIX_FMT_YUV422P9:
  371. case AV_PIX_FMT_YUV444P9:
  372. case AV_PIX_FMT_YUVA420P9:
  373. case AV_PIX_FMT_YUVA422P9:
  374. case AV_PIX_FMT_YUVA444P9:
  375. case AV_PIX_FMT_YUV444P10:
  376. case AV_PIX_FMT_YUV422P10:
  377. case AV_PIX_FMT_YUV420P10:
  378. case AV_PIX_FMT_YUVA444P10:
  379. case AV_PIX_FMT_YUVA422P10:
  380. case AV_PIX_FMT_YUVA420P10:
  381. case AV_PIX_FMT_YUV420P12:
  382. case AV_PIX_FMT_YUV422P12:
  383. case AV_PIX_FMT_YUV444P12:
  384. case AV_PIX_FMT_YUV420P14:
  385. case AV_PIX_FMT_YUV422P14:
  386. case AV_PIX_FMT_YUV444P14:
  387. case AV_PIX_FMT_YUV444P16:
  388. case AV_PIX_FMT_YUV422P16:
  389. case AV_PIX_FMT_YUV420P16:
  390. case AV_PIX_FMT_YUVA444P16:
  391. case AV_PIX_FMT_YUVA422P16:
  392. case AV_PIX_FMT_YUVA420P16:
  393. cpyresult = libopenjpeg_copy_unpacked16(avctx, frame, image);
  394. break;
  395. default:
  396. av_log(avctx, AV_LOG_ERROR,
  397. "The frame's pixel format '%s' is not supported\n",
  398. av_get_pix_fmt_name(avctx->pix_fmt));
  399. return AVERROR(EINVAL);
  400. break;
  401. }
  402. if (!cpyresult) {
  403. av_log(avctx, AV_LOG_ERROR,
  404. "Could not copy the frame data to the internal image buffer\n");
  405. return -1;
  406. }
  407. opj_setup_encoder(compress, &ctx->enc_params, image);
  408. stream = opj_cio_open((opj_common_ptr)compress, NULL, 0);
  409. if (!stream) {
  410. av_log(avctx, AV_LOG_ERROR, "Error creating the cio stream\n");
  411. return AVERROR(ENOMEM);
  412. }
  413. if (!opj_encode(compress, stream, image, NULL)) {
  414. opj_cio_close(stream);
  415. av_log(avctx, AV_LOG_ERROR, "Error during the opj encode\n");
  416. return -1;
  417. }
  418. len = cio_tell(stream);
  419. if ((ret = ff_alloc_packet2(avctx, pkt, len)) < 0) {
  420. opj_cio_close(stream);
  421. return ret;
  422. }
  423. memcpy(pkt->data, stream->buffer, len);
  424. pkt->flags |= AV_PKT_FLAG_KEY;
  425. *got_packet = 1;
  426. opj_cio_close(stream);
  427. return 0;
  428. }
  429. static av_cold int libopenjpeg_encode_close(AVCodecContext *avctx)
  430. {
  431. LibOpenJPEGContext *ctx = avctx->priv_data;
  432. opj_destroy_compress(ctx->compress);
  433. opj_image_destroy(ctx->image);
  434. av_freep(&avctx->coded_frame);
  435. return 0;
  436. }
  437. #define OFFSET(x) offsetof(LibOpenJPEGContext, x)
  438. #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  439. static const AVOption options[] = {
  440. { "format", "Codec Format", OFFSET(format), AV_OPT_TYPE_INT, { .i64 = CODEC_JP2 }, CODEC_J2K, CODEC_JP2, VE, "format" },
  441. { "j2k", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CODEC_J2K }, 0, 0, VE, "format" },
  442. { "jp2", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CODEC_JP2 }, 0, 0, VE, "format" },
  443. { "profile", NULL, OFFSET(profile), AV_OPT_TYPE_INT, { .i64 = STD_RSIZ }, STD_RSIZ, CINEMA4K, VE, "profile" },
  444. { "jpeg2000", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = STD_RSIZ }, 0, 0, VE, "profile" },
  445. { "cinema2k", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CINEMA2K }, 0, 0, VE, "profile" },
  446. { "cinema4k", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CINEMA4K }, 0, 0, VE, "profile" },
  447. { "cinema_mode", "Digital Cinema", OFFSET(cinema_mode), AV_OPT_TYPE_INT, { .i64 = OFF }, OFF, CINEMA4K_24, VE, "cinema_mode" },
  448. { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OFF }, 0, 0, VE, "cinema_mode" },
  449. { "2k_24", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CINEMA2K_24 }, 0, 0, VE, "cinema_mode" },
  450. { "2k_48", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CINEMA2K_48 }, 0, 0, VE, "cinema_mode" },
  451. { "4k_24", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CINEMA4K_24 }, 0, 0, VE, "cinema_mode" },
  452. { "prog_order", "Progression Order", OFFSET(prog_order), AV_OPT_TYPE_INT, { .i64 = LRCP }, LRCP, CPRL, VE, "prog_order" },
  453. { "lrcp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LRCP }, 0, 0, VE, "prog_order" },
  454. { "rlcp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = RLCP }, 0, 0, VE, "prog_order" },
  455. { "rpcl", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = RPCL }, 0, 0, VE, "prog_order" },
  456. { "pcrl", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PCRL }, 0, 0, VE, "prog_order" },
  457. { "cprl", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPRL }, 0, 0, VE, "prog_order" },
  458. { "numresolution", NULL, OFFSET(numresolution), AV_OPT_TYPE_INT, { .i64 = 6 }, 1, INT_MAX, VE },
  459. { "numlayers", NULL, OFFSET(numlayers), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 10, VE },
  460. { "disto_alloc", NULL, OFFSET(disto_alloc), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
  461. { "fixed_alloc", NULL, OFFSET(fixed_alloc), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
  462. { "fixed_quality", NULL, OFFSET(fixed_quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
  463. { NULL },
  464. };
  465. static const AVClass class = {
  466. .class_name = "libopenjpeg",
  467. .item_name = av_default_item_name,
  468. .option = options,
  469. .version = LIBAVUTIL_VERSION_INT,
  470. };
  471. AVCodec ff_libopenjpeg_encoder = {
  472. .name = "libopenjpeg",
  473. .type = AVMEDIA_TYPE_VIDEO,
  474. .id = AV_CODEC_ID_JPEG2000,
  475. .priv_data_size = sizeof(LibOpenJPEGContext),
  476. .init = libopenjpeg_encode_init,
  477. .encode2 = libopenjpeg_encode_frame,
  478. .close = libopenjpeg_encode_close,
  479. .capabilities = 0,
  480. .pix_fmts = (const enum AVPixelFormat[]) {
  481. AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA, AV_PIX_FMT_RGB48, AV_PIX_FMT_RGBA64,
  482. AV_PIX_FMT_GBR24P,
  483. AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
  484. AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A, AV_PIX_FMT_GRAY16,
  485. AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVA420P,
  486. AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVA422P,
  487. AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUVA444P,
  488. AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9,
  489. AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA444P9,
  490. AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10,
  491. AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10,
  492. AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12,
  493. AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
  494. AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
  495. AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16,
  496. AV_PIX_FMT_NONE
  497. },
  498. .long_name = NULL_IF_CONFIG_SMALL("OpenJPEG JPEG 2000"),
  499. .priv_class = &class,
  500. };