37 #if HAVE_OPENJPEG_1_5_OPENJPEG_H
38 # include <openjpeg-1.5/openjpeg.h>
40 # include <openjpeg.h>
78 opj_image_cmptparm_t *cmptparm;
84 OPJ_COLOR_SPACE color_space = CLRSPC_UNKNOWN;
86 sub_dx[0] = sub_dx[3] = 1;
87 sub_dy[0] = sub_dy[3] = 1;
97 color_space = CLRSPC_GRAY;
103 color_space = CLRSPC_SRGB;
138 color_space = CLRSPC_SYCC;
142 "The requested pixel format '%s' is not supported\n",
147 cmptparm =
av_mallocz(numcomps *
sizeof(*cmptparm));
152 for (i = 0; i < numcomps; i++) {
155 cmptparm[i].sgnd = 0;
156 cmptparm[i].dx = sub_dx[i];
157 cmptparm[i].dy = sub_dy[i];
158 cmptparm[i].w = avctx->
width / sub_dx[i];
159 cmptparm[i].h = avctx->
height / sub_dy[i];
162 img = opj_image_create(numcomps, cmptparm, color_space);
172 opj_set_default_encoder_parameters(&ctx->
enc_params);
204 memset(&ctx->
event_mgr, 0,
sizeof(opj_event_mgr_t));
225 const int numcomps = image->numcomps;
227 for (compno = 0; compno < numcomps; ++compno) {
228 if (image->comps[compno].w > frame->
linesize[0] / numcomps) {
234 for (compno = 0; compno < numcomps; ++compno) {
235 for (y = 0; y < avctx->
height; ++y) {
236 image_index = y * avctx->
width;
237 frame_index = y * frame->
linesize[0] + compno;
238 for (x = 0; x < avctx->
width; ++x) {
239 image->comps[compno].data[image_index++] = frame->
data[0][frame_index];
240 frame_index += numcomps;
255 const int numcomps = image->numcomps;
256 uint16_t *frame_ptr = (uint16_t*)frame->
data[0];
258 for (compno = 0; compno < numcomps; ++compno) {
259 if (image->comps[compno].w > frame->
linesize[0] / numcomps) {
265 for (compno = 0; compno < numcomps; ++compno) {
266 for (y = 0; y < avctx->
height; ++y) {
267 image_index = y * avctx->
width;
268 frame_index = y * (frame->
linesize[0] / 2) + compno;
269 for (x = 0; x < avctx->
width; ++x) {
270 image->comps[compno].data[image_index++] = frame_ptr[frame_index];
271 frame_index += numcomps;
288 const int numcomps = image->numcomps;
290 for (compno = 0; compno < numcomps; ++compno) {
291 if (image->comps[compno].w > frame->
linesize[compno]) {
297 for (compno = 0; compno < numcomps; ++compno) {
298 width = avctx->
width / image->comps[compno].dx;
299 height = avctx->
height / image->comps[compno].dy;
300 for (y = 0; y <
height; ++y) {
301 image_index = y *
width;
302 frame_index = y * frame->
linesize[compno];
303 for (x = 0; x <
width; ++x)
304 image->comps[compno].data[image_index++] = frame->
data[compno][frame_index++];
320 const int numcomps = image->numcomps;
323 for (compno = 0; compno < numcomps; ++compno) {
324 if (image->comps[compno].w > frame->
linesize[compno]) {
330 for (compno = 0; compno < numcomps; ++compno) {
331 width = avctx->
width / image->comps[compno].dx;
332 height = avctx->
height / image->comps[compno].dy;
333 frame_ptr = (uint16_t*)frame->
data[compno];
335 image_index = y *
width;
336 frame_index = y * (frame->
linesize[compno] / 2);
337 for (x = 0; x <
width; ++x)
338 image->comps[compno].data[image_index++] = frame_ptr[frame_index++];
349 opj_cinfo_t *compress = ctx->
compress;
350 opj_image_t *image = ctx->
image;
413 "The frame's pixel format '%s' is not supported\n",
421 "Could not copy the frame data to the internal image buffer\n");
425 opj_setup_encoder(compress, &ctx->
enc_params, image);
426 stream = opj_cio_open((opj_common_ptr)compress,
NULL, 0);
432 if (!opj_encode(compress, stream, image,
NULL)) {
433 opj_cio_close(stream);
438 len = cio_tell(stream);
440 opj_cio_close(stream);
444 memcpy(pkt->
data, stream->buffer, len);
447 opj_cio_close(stream);
455 opj_destroy_compress(ctx->
compress);
456 opj_image_destroy(ctx->
image);
461 #define OFFSET(x) offsetof(LibOpenJPEGContext, x)
462 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
464 {
"format",
"Codec Format",
OFFSET(format),
AV_OPT_TYPE_INT, { .i64 = CODEC_JP2 }, CODEC_J2K, CODEC_JP2,
VE,
"format" },
471 {
"cinema_mode",
"Digital Cinema",
OFFSET(cinema_mode),
AV_OPT_TYPE_INT, { .i64 = OFF }, OFF, CINEMA4K_24,
VE,
"cinema_mode" },
476 {
"prog_order",
"Progression Order",
OFFSET(prog_order),
AV_OPT_TYPE_INT, { .i64 = LRCP }, LRCP, CPRL,
VE,
"prog_order" },
498 .
name =
"libopenjpeg",
523 .priv_class = &
class,