2 * JPEG 2000 encoding support via OpenJPEG
3 * Copyright (c) 2011 Michael Bradshaw <mjbshaw gmail com>
5 * This file is part of FFmpeg.
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.
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.
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
24 * JPEG 2000 encoder using libopenjpeg
27 #include "libavutil/avassert.h"
28 #include "libavutil/common.h"
29 #include "libavutil/imgutils.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/opt.h"
36 typedef struct LibOpenJPEGContext {
38 opj_cparameters_t enc_params;
49 static void error_callback(const char *msg, void *data)
51 av_log(data, AV_LOG_ERROR, "%s\n", msg);
54 static void warning_callback(const char *msg, void *data)
56 av_log(data, AV_LOG_WARNING, "%s\n", msg);
59 static void info_callback(const char *msg, void *data)
61 av_log(data, AV_LOG_DEBUG, "%s\n", msg);
64 typedef struct PacketWriter {
69 static OPJ_SIZE_T stream_write(void *out_buffer, OPJ_SIZE_T nb_bytes, void *user_data)
71 PacketWriter *writer = user_data;
72 AVPacket *packet = writer->packet;
73 int remaining = packet->size - writer->pos;
74 if (nb_bytes > remaining) {
75 OPJ_SIZE_T needed = nb_bytes - remaining;
76 int max_growth = INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - packet->size;
77 if (needed > max_growth) {
78 return (OPJ_SIZE_T)-1;
80 if (av_grow_packet(packet, (int)needed)) {
81 return (OPJ_SIZE_T)-1;
84 memcpy(packet->data + writer->pos, out_buffer, nb_bytes);
85 writer->pos += (int)nb_bytes;
89 static OPJ_OFF_T stream_skip(OPJ_OFF_T nb_bytes, void *user_data)
91 PacketWriter *writer = user_data;
92 AVPacket *packet = writer->packet;
94 if (writer->pos == 0) {
95 return (OPJ_SIZE_T)-1;
97 if (nb_bytes + writer->pos < 0) {
98 nb_bytes = -writer->pos;
101 int remaining = packet->size - writer->pos;
102 if (nb_bytes > remaining) {
103 OPJ_SIZE_T needed = nb_bytes - remaining;
104 int max_growth = INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - packet->size;
105 if (needed > max_growth) {
106 return (OPJ_SIZE_T)-1;
108 if (av_grow_packet(packet, (int)needed)) {
109 return (OPJ_SIZE_T)-1;
113 writer->pos += (int)nb_bytes;
117 static OPJ_BOOL stream_seek(OPJ_OFF_T nb_bytes, void *user_data)
119 PacketWriter *writer = user_data;
120 AVPacket *packet = writer->packet;
124 if (nb_bytes > packet->size) {
125 if (nb_bytes > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE ||
126 av_grow_packet(packet, (int)nb_bytes - packet->size)) {
130 writer->pos = (int)nb_bytes;
134 static void cinema_parameters(opj_cparameters_t *p)
144 /* Tile and Image shall be at (0, 0) */
147 p->image_offset_x0 = 0;
148 p->image_offset_y0 = 0;
150 /* Codeblock size= 32 * 32 */
151 p->cblockw_init = 32;
152 p->cblockh_init = 32;
155 /* The progression order shall be CPRL */
156 p->prog_order = OPJ_CPRL;
162 p->subsampling_dx = 1;
163 p->subsampling_dy = 1;
171 static opj_image_t *mj2_create_image(AVCodecContext *avctx, opj_cparameters_t *parameters)
173 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
174 opj_image_cmptparm_t cmptparm[4] = {{0}};
180 OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_UNKNOWN;
182 sub_dx[0] = sub_dx[3] = 1;
183 sub_dy[0] = sub_dy[3] = 1;
184 sub_dx[1] = sub_dx[2] = 1 << desc->log2_chroma_w;
185 sub_dy[1] = sub_dy[2] = 1 << desc->log2_chroma_h;
187 numcomps = desc->nb_components;
189 switch (avctx->pix_fmt) {
190 case AV_PIX_FMT_GRAY8:
192 case AV_PIX_FMT_GRAY16:
193 case AV_PIX_FMT_YA16:
194 color_space = OPJ_CLRSPC_GRAY;
196 case AV_PIX_FMT_RGB24:
197 case AV_PIX_FMT_RGBA:
198 case AV_PIX_FMT_RGB48:
199 case AV_PIX_FMT_RGBA64:
200 case AV_PIX_FMT_GBR24P:
201 case AV_PIX_FMT_GBRP9:
202 case AV_PIX_FMT_GBRP10:
203 case AV_PIX_FMT_GBRP12:
204 case AV_PIX_FMT_GBRP14:
205 case AV_PIX_FMT_GBRP16:
206 case AV_PIX_FMT_XYZ12:
207 color_space = OPJ_CLRSPC_SRGB;
209 case AV_PIX_FMT_YUV410P:
210 case AV_PIX_FMT_YUV411P:
211 case AV_PIX_FMT_YUV420P:
212 case AV_PIX_FMT_YUV422P:
213 case AV_PIX_FMT_YUV440P:
214 case AV_PIX_FMT_YUV444P:
215 case AV_PIX_FMT_YUVA420P:
216 case AV_PIX_FMT_YUVA422P:
217 case AV_PIX_FMT_YUVA444P:
218 case AV_PIX_FMT_YUV420P9:
219 case AV_PIX_FMT_YUV422P9:
220 case AV_PIX_FMT_YUV444P9:
221 case AV_PIX_FMT_YUVA420P9:
222 case AV_PIX_FMT_YUVA422P9:
223 case AV_PIX_FMT_YUVA444P9:
224 case AV_PIX_FMT_YUV420P10:
225 case AV_PIX_FMT_YUV422P10:
226 case AV_PIX_FMT_YUV444P10:
227 case AV_PIX_FMT_YUVA420P10:
228 case AV_PIX_FMT_YUVA422P10:
229 case AV_PIX_FMT_YUVA444P10:
230 case AV_PIX_FMT_YUV420P12:
231 case AV_PIX_FMT_YUV422P12:
232 case AV_PIX_FMT_YUV444P12:
233 case AV_PIX_FMT_YUV420P14:
234 case AV_PIX_FMT_YUV422P14:
235 case AV_PIX_FMT_YUV444P14:
236 case AV_PIX_FMT_YUV420P16:
237 case AV_PIX_FMT_YUV422P16:
238 case AV_PIX_FMT_YUV444P16:
239 case AV_PIX_FMT_YUVA420P16:
240 case AV_PIX_FMT_YUVA422P16:
241 case AV_PIX_FMT_YUVA444P16:
242 color_space = OPJ_CLRSPC_SYCC;
245 av_log(avctx, AV_LOG_ERROR,
246 "The requested pixel format '%s' is not supported\n",
247 av_get_pix_fmt_name(avctx->pix_fmt));
251 for (i = 0; i < numcomps; i++) {
252 cmptparm[i].prec = desc->comp[i].depth;
253 cmptparm[i].bpp = desc->comp[i].depth;
254 cmptparm[i].sgnd = 0;
255 cmptparm[i].dx = sub_dx[i];
256 cmptparm[i].dy = sub_dy[i];
257 cmptparm[i].w = (avctx->width + sub_dx[i] - 1) / sub_dx[i];
258 cmptparm[i].h = (avctx->height + sub_dy[i] - 1) / sub_dy[i];
261 img = opj_image_create(numcomps, cmptparm, color_space);
266 // x0, y0 is the top left corner of the image
267 // x1, y1 is the width, height of the reference grid
270 img->x1 = (avctx->width - 1) * parameters->subsampling_dx + 1;
271 img->y1 = (avctx->height - 1) * parameters->subsampling_dy + 1;
276 static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx)
278 LibOpenJPEGContext *ctx = avctx->priv_data;
281 opj_set_default_encoder_parameters(&ctx->enc_params);
283 switch (ctx->cinema_mode) {
284 case OPJ_CINEMA2K_24:
285 ctx->enc_params.rsiz = OPJ_PROFILE_CINEMA_2K;
286 ctx->enc_params.max_cs_size = OPJ_CINEMA_24_CS;
287 ctx->enc_params.max_comp_size = OPJ_CINEMA_24_COMP;
289 case OPJ_CINEMA2K_48:
290 ctx->enc_params.rsiz = OPJ_PROFILE_CINEMA_2K;
291 ctx->enc_params.max_cs_size = OPJ_CINEMA_48_CS;
292 ctx->enc_params.max_comp_size = OPJ_CINEMA_48_COMP;
294 case OPJ_CINEMA4K_24:
295 ctx->enc_params.rsiz = OPJ_PROFILE_CINEMA_4K;
296 ctx->enc_params.max_cs_size = OPJ_CINEMA_24_CS;
297 ctx->enc_params.max_comp_size = OPJ_CINEMA_24_COMP;
301 switch (ctx->profile) {
303 if (ctx->enc_params.rsiz == OPJ_PROFILE_CINEMA_4K) {
304 err = AVERROR(EINVAL);
307 ctx->enc_params.rsiz = OPJ_PROFILE_CINEMA_2K;
310 if (ctx->enc_params.rsiz == OPJ_PROFILE_CINEMA_2K) {
311 err = AVERROR(EINVAL);
314 ctx->enc_params.rsiz = OPJ_PROFILE_CINEMA_4K;
319 av_log(avctx, AV_LOG_ERROR,
320 "Invalid parameter pairing: cinema_mode and profile conflict.\n");
324 if (!ctx->numresolution) {
325 ctx->numresolution = 6;
326 while (FFMIN(avctx->width, avctx->height) >> ctx->numresolution < 1)
327 ctx->numresolution --;
330 ctx->enc_params.prog_order = ctx->prog_order;
331 ctx->enc_params.numresolution = ctx->numresolution;
332 ctx->enc_params.irreversible = ctx->irreversible;
333 ctx->enc_params.cp_disto_alloc = ctx->disto_alloc;
334 ctx->enc_params.cp_fixed_quality = ctx->fixed_quality;
335 ctx->enc_params.tcp_numlayers = 1;
336 ctx->enc_params.tcp_rates[0] = FFMAX(avctx->compression_level, 0) * 2;
338 if (ctx->cinema_mode > 0) {
339 cinema_parameters(&ctx->enc_params);
345 static int libopenjpeg_copy_packed8(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
352 const int numcomps = image->numcomps;
354 for (compno = 0; compno < numcomps; ++compno) {
355 if (image->comps[compno].w > frame->linesize[0] / numcomps) {
356 av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n");
361 for (compno = 0; compno < numcomps; ++compno) {
362 for (y = 0; y < avctx->height; ++y) {
363 image_line = image->comps[compno].data + y * image->comps[compno].w;
364 frame_index = y * frame->linesize[0] + compno;
365 for (x = 0; x < avctx->width; ++x) {
366 image_line[x] = frame->data[0][frame_index];
367 frame_index += numcomps;
369 for (; x < image->comps[compno].w; ++x) {
370 image_line[x] = image_line[x - 1];
373 for (; y < image->comps[compno].h; ++y) {
374 image_line = image->comps[compno].data + y * image->comps[compno].w;
375 for (x = 0; x < image->comps[compno].w; ++x) {
376 image_line[x] = image_line[x - (int)image->comps[compno].w];
385 static int libopenjpeg_copy_packed12(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
391 const int numcomps = image->numcomps;
392 uint16_t *frame_ptr = (uint16_t *)frame->data[0];
394 for (compno = 0; compno < numcomps; ++compno) {
395 if (image->comps[compno].w > frame->linesize[0] / numcomps) {
396 av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n");
401 for (compno = 0; compno < numcomps; ++compno) {
402 for (y = 0; y < avctx->height; ++y) {
403 image_line = image->comps[compno].data + y * image->comps[compno].w;
404 frame_index = y * (frame->linesize[0] / 2) + compno;
405 for (x = 0; x < avctx->width; ++x) {
406 image_line[x] = frame_ptr[frame_index] >> 4;
407 frame_index += numcomps;
409 for (; x < image->comps[compno].w; ++x) {
410 image_line[x] = image_line[x - 1];
413 for (; y < image->comps[compno].h; ++y) {
414 image_line = image->comps[compno].data + y * image->comps[compno].w;
415 for (x = 0; x < image->comps[compno].w; ++x) {
416 image_line[x] = image_line[x - (int)image->comps[compno].w];
424 static int libopenjpeg_copy_packed16(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
431 const int numcomps = image->numcomps;
432 uint16_t *frame_ptr = (uint16_t*)frame->data[0];
434 for (compno = 0; compno < numcomps; ++compno) {
435 if (image->comps[compno].w > frame->linesize[0] / numcomps) {
436 av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n");
441 for (compno = 0; compno < numcomps; ++compno) {
442 for (y = 0; y < avctx->height; ++y) {
443 image_line = image->comps[compno].data + y * image->comps[compno].w;
444 frame_index = y * (frame->linesize[0] / 2) + compno;
445 for (x = 0; x < avctx->width; ++x) {
446 image_line[x] = frame_ptr[frame_index];
447 frame_index += numcomps;
449 for (; x < image->comps[compno].w; ++x) {
450 image_line[x] = image_line[x - 1];
453 for (; y < image->comps[compno].h; ++y) {
454 image_line = image->comps[compno].data + y * image->comps[compno].w;
455 for (x = 0; x < image->comps[compno].w; ++x) {
456 image_line[x] = image_line[x - (int)image->comps[compno].w];
464 static int libopenjpeg_copy_unpacked8(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
473 const int numcomps = image->numcomps;
475 for (compno = 0; compno < numcomps; ++compno) {
476 if (image->comps[compno].w > frame->linesize[compno]) {
477 av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n");
482 for (compno = 0; compno < numcomps; ++compno) {
483 width = (avctx->width + image->comps[compno].dx - 1) / image->comps[compno].dx;
484 height = (avctx->height + image->comps[compno].dy - 1) / image->comps[compno].dy;
485 for (y = 0; y < height; ++y) {
486 image_line = image->comps[compno].data + y * image->comps[compno].w;
487 frame_index = y * frame->linesize[compno];
488 for (x = 0; x < width; ++x)
489 image_line[x] = frame->data[compno][frame_index++];
490 for (; x < image->comps[compno].w; ++x) {
491 image_line[x] = image_line[x - 1];
494 for (; y < image->comps[compno].h; ++y) {
495 image_line = image->comps[compno].data + y * image->comps[compno].w;
496 for (x = 0; x < image->comps[compno].w; ++x) {
497 image_line[x] = image_line[x - (int)image->comps[compno].w];
505 static int libopenjpeg_copy_unpacked16(AVCodecContext *avctx, const AVFrame *frame, opj_image_t *image)
514 const int numcomps = image->numcomps;
517 for (compno = 0; compno < numcomps; ++compno) {
518 if (image->comps[compno].w > frame->linesize[compno]) {
519 av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n");
524 for (compno = 0; compno < numcomps; ++compno) {
525 width = (avctx->width + image->comps[compno].dx - 1) / image->comps[compno].dx;
526 height = (avctx->height + image->comps[compno].dy - 1) / image->comps[compno].dy;
527 frame_ptr = (uint16_t *)frame->data[compno];
528 for (y = 0; y < height; ++y) {
529 image_line = image->comps[compno].data + y * image->comps[compno].w;
530 frame_index = y * (frame->linesize[compno] / 2);
531 for (x = 0; x < width; ++x)
532 image_line[x] = frame_ptr[frame_index++];
533 for (; x < image->comps[compno].w; ++x) {
534 image_line[x] = image_line[x - 1];
537 for (; y < image->comps[compno].h; ++y) {
538 image_line = image->comps[compno].data + y * image->comps[compno].w;
539 for (x = 0; x < image->comps[compno].w; ++x) {
540 image_line[x] = image_line[x - (int)image->comps[compno].w];
548 static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
549 const AVFrame *frame, int *got_packet)
551 LibOpenJPEGContext *ctx = avctx->priv_data;
555 PacketWriter writer = { 0 };
556 opj_codec_t *compress = NULL;
557 opj_stream_t *stream = NULL;
558 opj_image_t *image = mj2_create_image(avctx, &ctx->enc_params);
560 av_log(avctx, AV_LOG_ERROR, "Error creating the mj2 image\n");
561 ret = AVERROR(EINVAL);
565 switch (avctx->pix_fmt) {
566 case AV_PIX_FMT_RGB24:
567 case AV_PIX_FMT_RGBA:
569 cpyresult = libopenjpeg_copy_packed8(avctx, frame, image);
571 case AV_PIX_FMT_XYZ12:
572 cpyresult = libopenjpeg_copy_packed12(avctx, frame, image);
574 case AV_PIX_FMT_RGB48:
575 case AV_PIX_FMT_RGBA64:
576 case AV_PIX_FMT_YA16:
577 cpyresult = libopenjpeg_copy_packed16(avctx, frame, image);
579 case AV_PIX_FMT_GBR24P:
580 case AV_PIX_FMT_GBRP9:
581 case AV_PIX_FMT_GBRP10:
582 case AV_PIX_FMT_GBRP12:
583 case AV_PIX_FMT_GBRP14:
584 case AV_PIX_FMT_GBRP16:
585 gbrframe = av_frame_clone(frame);
587 ret = AVERROR(ENOMEM);
590 gbrframe->data[0] = frame->data[2]; // swap to be rgb
591 gbrframe->data[1] = frame->data[0];
592 gbrframe->data[2] = frame->data[1];
593 gbrframe->linesize[0] = frame->linesize[2];
594 gbrframe->linesize[1] = frame->linesize[0];
595 gbrframe->linesize[2] = frame->linesize[1];
596 if (avctx->pix_fmt == AV_PIX_FMT_GBR24P) {
597 cpyresult = libopenjpeg_copy_unpacked8(avctx, gbrframe, image);
599 cpyresult = libopenjpeg_copy_unpacked16(avctx, gbrframe, image);
601 av_frame_free(&gbrframe);
603 case AV_PIX_FMT_GRAY8:
604 case AV_PIX_FMT_YUV410P:
605 case AV_PIX_FMT_YUV411P:
606 case AV_PIX_FMT_YUV420P:
607 case AV_PIX_FMT_YUV422P:
608 case AV_PIX_FMT_YUV440P:
609 case AV_PIX_FMT_YUV444P:
610 case AV_PIX_FMT_YUVA420P:
611 case AV_PIX_FMT_YUVA422P:
612 case AV_PIX_FMT_YUVA444P:
613 cpyresult = libopenjpeg_copy_unpacked8(avctx, frame, image);
615 case AV_PIX_FMT_GRAY16:
616 case AV_PIX_FMT_YUV420P9:
617 case AV_PIX_FMT_YUV422P9:
618 case AV_PIX_FMT_YUV444P9:
619 case AV_PIX_FMT_YUVA420P9:
620 case AV_PIX_FMT_YUVA422P9:
621 case AV_PIX_FMT_YUVA444P9:
622 case AV_PIX_FMT_YUV444P10:
623 case AV_PIX_FMT_YUV422P10:
624 case AV_PIX_FMT_YUV420P10:
625 case AV_PIX_FMT_YUVA444P10:
626 case AV_PIX_FMT_YUVA422P10:
627 case AV_PIX_FMT_YUVA420P10:
628 case AV_PIX_FMT_YUV420P12:
629 case AV_PIX_FMT_YUV422P12:
630 case AV_PIX_FMT_YUV444P12:
631 case AV_PIX_FMT_YUV420P14:
632 case AV_PIX_FMT_YUV422P14:
633 case AV_PIX_FMT_YUV444P14:
634 case AV_PIX_FMT_YUV444P16:
635 case AV_PIX_FMT_YUV422P16:
636 case AV_PIX_FMT_YUV420P16:
637 case AV_PIX_FMT_YUVA444P16:
638 case AV_PIX_FMT_YUVA422P16:
639 case AV_PIX_FMT_YUVA420P16:
640 cpyresult = libopenjpeg_copy_unpacked16(avctx, frame, image);
643 av_log(avctx, AV_LOG_ERROR,
644 "The frame's pixel format '%s' is not supported\n",
645 av_get_pix_fmt_name(avctx->pix_fmt));
646 ret = AVERROR(EINVAL);
652 av_log(avctx, AV_LOG_ERROR,
653 "Could not copy the frame data to the internal image buffer\n");
658 if ((ret = ff_alloc_packet2(avctx, pkt, 1024, 0)) < 0) {
662 compress = opj_create_compress(ctx->format);
664 av_log(avctx, AV_LOG_ERROR, "Error creating the compressor\n");
665 ret = AVERROR(ENOMEM);
669 if (!opj_set_error_handler(compress, error_callback, avctx) ||
670 !opj_set_warning_handler(compress, warning_callback, avctx) ||
671 !opj_set_info_handler(compress, info_callback, avctx)) {
672 av_log(avctx, AV_LOG_ERROR, "Error setting the compressor handlers\n");
673 ret = AVERROR_EXTERNAL;
677 if (!opj_setup_encoder(compress, &ctx->enc_params, image)) {
678 av_log(avctx, AV_LOG_ERROR, "Error setting up the compressor\n");
679 ret = AVERROR_EXTERNAL;
682 stream = opj_stream_default_create(OPJ_STREAM_WRITE);
685 av_log(avctx, AV_LOG_ERROR, "Error creating the cio stream\n");
686 ret = AVERROR(ENOMEM);
691 opj_stream_set_write_function(stream, stream_write);
692 opj_stream_set_skip_function(stream, stream_skip);
693 opj_stream_set_seek_function(stream, stream_seek);
694 opj_stream_set_user_data(stream, &writer, NULL);
696 if (!opj_start_compress(compress, image, stream) ||
697 !opj_encode(compress, stream) ||
698 !opj_end_compress(compress, stream)) {
699 av_log(avctx, AV_LOG_ERROR, "Error during the opj encode\n");
700 ret = AVERROR_EXTERNAL;
704 av_shrink_packet(pkt, writer.pos);
706 pkt->flags |= AV_PKT_FLAG_KEY;
711 opj_stream_destroy(stream);
712 opj_destroy_codec(compress);
713 opj_image_destroy(image);
717 #define OFFSET(x) offsetof(LibOpenJPEGContext, x)
718 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
719 static const AVOption options[] = {
720 { "format", "Codec Format", OFFSET(format), AV_OPT_TYPE_INT, { .i64 = OPJ_CODEC_JP2 }, OPJ_CODEC_J2K, OPJ_CODEC_JP2, VE, "format" },
721 { "j2k", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CODEC_J2K }, 0, 0, VE, "format" },
722 { "jp2", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CODEC_JP2 }, 0, 0, VE, "format" },
723 { "profile", NULL, OFFSET(profile), AV_OPT_TYPE_INT, { .i64 = OPJ_STD_RSIZ }, OPJ_STD_RSIZ, OPJ_CINEMA4K, VE, "profile" },
724 { "jpeg2000", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_STD_RSIZ }, 0, 0, VE, "profile" },
725 { "cinema2k", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CINEMA2K }, 0, 0, VE, "profile" },
726 { "cinema4k", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CINEMA4K }, 0, 0, VE, "profile" },
727 { "cinema_mode", "Digital Cinema", OFFSET(cinema_mode), AV_OPT_TYPE_INT, { .i64 = OPJ_OFF }, OPJ_OFF, OPJ_CINEMA4K_24, VE, "cinema_mode" },
728 { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_OFF }, 0, 0, VE, "cinema_mode" },
729 { "2k_24", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CINEMA2K_24 }, 0, 0, VE, "cinema_mode" },
730 { "2k_48", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CINEMA2K_48 }, 0, 0, VE, "cinema_mode" },
731 { "4k_24", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CINEMA4K_24 }, 0, 0, VE, "cinema_mode" },
732 { "prog_order", "Progression Order", OFFSET(prog_order), AV_OPT_TYPE_INT, { .i64 = OPJ_LRCP }, OPJ_LRCP, OPJ_CPRL, VE, "prog_order" },
733 { "lrcp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_LRCP }, 0, 0, VE, "prog_order" },
734 { "rlcp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_RLCP }, 0, 0, VE, "prog_order" },
735 { "rpcl", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_RPCL }, 0, 0, VE, "prog_order" },
736 { "pcrl", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_PCRL }, 0, 0, VE, "prog_order" },
737 { "cprl", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = OPJ_CPRL }, 0, 0, VE, "prog_order" },
738 { "numresolution", NULL, OFFSET(numresolution), AV_OPT_TYPE_INT, { .i64 = 6 }, 0, 33, VE },
739 { "irreversible", NULL, OFFSET(irreversible), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
740 { "disto_alloc", NULL, OFFSET(disto_alloc), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE },
741 { "fixed_quality", NULL, OFFSET(fixed_quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
745 static const AVClass openjpeg_class = {
746 .class_name = "libopenjpeg",
747 .item_name = av_default_item_name,
749 .version = LIBAVUTIL_VERSION_INT,
752 AVCodec ff_libopenjpeg_encoder = {
753 .name = "libopenjpeg",
754 .long_name = NULL_IF_CONFIG_SMALL("OpenJPEG JPEG 2000"),
755 .type = AVMEDIA_TYPE_VIDEO,
756 .id = AV_CODEC_ID_JPEG2000,
757 .priv_data_size = sizeof(LibOpenJPEGContext),
758 .init = libopenjpeg_encode_init,
759 .encode2 = libopenjpeg_encode_frame,
760 .capabilities = AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_INTRA_ONLY,
761 .pix_fmts = (const enum AVPixelFormat[]) {
762 AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA, AV_PIX_FMT_RGB48,
763 AV_PIX_FMT_RGBA64, AV_PIX_FMT_GBR24P,
764 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
765 AV_PIX_FMT_GRAY8, AV_PIX_FMT_YA8, AV_PIX_FMT_GRAY16, AV_PIX_FMT_YA16,
766 AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVA420P,
767 AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVA422P,
768 AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUVA444P,
769 AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9,
770 AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA444P9,
771 AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10,
772 AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10,
773 AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12,
774 AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
775 AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
776 AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16,
780 .priv_class = &openjpeg_class,