[FFmpeg-devel] [PATCH] libopenjpegenc: add 9-15 bit RGB output

Jean First jeanfirst at gmail.com
Fri Feb 1 11:25:38 CET 2013


>> I think your diff is backwards ;)
> very true, sorry. Here is a corrected diff.
>> Now that Michael Neidermayer has added gbrp* support in swscale, I think
>> you could just use
>> my 0001-libopenjpegenc-add-support-for-pix-fmt-gbrp-8-16-bit.patch patch
>> and do the following (for 12-bit output):
>>
>> ffmpeg -i input_image -vcodec libopenjpeg -pix_fmt gbrp12 output_image.jp2
>>
>> To get 10 bit, use gbrp10, etc.
>>
>> It wouldn't have your cinema_mode changes, but see if this works for you
>> (it would be useful to know if it didn't!)
> I would most probably make valid 12 bpcc j2c files, but I don't think they would be DCI compliant. The options specified in the patch are necessary to get valid DCI compliant output. The most important change in the patch, the one that made me do 6 round-trips with the Cinema (hey thank you l'Aventure, Bruxelles), was  "ctx->enc_params.tcp_mct = 1;"
>
--

> diff --git a/FFmpeg_stock/libavcodec/libopenjpegenc.c 
> b/FFmpeg/libavcodec/libopenjpegenc.c index 13e8ef9..6f6686b 100644 --- 
> a/FFmpeg_stock/libavcodec/libopenjpegenc.c +++ 
> b/FFmpeg/libavcodec/libopenjpegenc.c @@ -55,6 +55,7 @@ typedef struct 
> { int disto_alloc; int fixed_alloc; int fixed_quality; + int shr; } 
> LibOpenJPEGContext; static void error_callback(const char *msg, void 
> *data) @@ -74,6 +75,7 @@ static void info_callback(const char *msg, 
> void *data) static opj_image_t *mj2_create_image(AVCodecContext 
> *avctx, opj_cparameters_t *parameters) { + LibOpenJPEGContext *ctx = 
> avctx->priv_data; const AVPixFmtDescriptor *desc = 
> av_pix_fmt_desc_get(avctx->pix_fmt); opj_image_cmptparm_t *cmptparm; 
> opj_image_t *img; @@ -150,8 +152,8 @@ static opj_image_t 
> *mj2_create_image(AVCodecContext *avctx, opj_cparameters_t *p return 
> NULL; } for (i = 0; i < numcomps; i++) { - cmptparm[i].prec = 
> desc->comp[i].depth_minus1 + 1; - cmptparm[i].bpp = 
> desc->comp[i].depth_minus1 + 1; + cmptparm[i].prec = 
> desc->comp[i].depth_minus1 + 1 - ctx->shr; + cmptparm[i].bpp = 
> desc->comp[i].depth_minus1 + 1 - ctx->shr; cmptparm[i].sgnd = 0; 
> cmptparm[i].dx = sub_dx[i]; cmptparm[i].dy = sub_dy[i]; @@ -182,6 
> +184,37 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext 
> *avctx) ctx->enc_params.tcp_numlayers = ctx->numlayers; 
> ctx->enc_params.tcp_rates[0] = FFMAX(avctx->compression_level, 0) * 2; 
> + if(ctx->cinema_mode>0){ 

please a a space around >

> + av_log(avctx, AV_LOG_DEBUG, "cinema-mode\n"); 

I think this can be dropped.

> + ctx->enc_params.irreversible = 1; + ctx->enc_params.tcp_mct = 1; 

after a quick look at https://github.com/tmeiczin/OpenDCP/blob/master/libopendcp/codecs/opendcp_encoder_openjpeg.c
it seemsthat: tcp_mct  =  opj_image->numcomps  ==  3  ?  1  :  0;


> + ctx->enc_params.tile_size_on = 0; + /* no subsampling*/ + 
> ctx->enc_params.cp_tdx=1; + ctx->enc_params.cp_tdy=1; 

spaces (also in the comment before */)

> + ctx->enc_params.subsampling_dx = 1; + ctx->enc_params.subsampling_dy 
> = 1; + /*Tile and Image shall be at (0,0)*/ + ctx->enc_params.cp_tx0 = 
> 0; + ctx->enc_params.cp_ty0 = 0; + ctx->enc_params.image_offset_x0 = 
> 0; + ctx->enc_params.image_offset_y0 = 0; + /*Codeblock size= 32*32*/ 
> + ctx->enc_params.cblockw_init = 32; + ctx->enc_params.cblockh_init = 
> 32; + ctx->enc_params.csty |= 0x01; + /* No ROI */ + 
> ctx->enc_params.roi_compno = -1; + + 
> if(ctx->enc_params.prog_order!=CPRL){ 

spaces

> + av_log(avctx, AV_LOG_ERROR, "Prog_order forced to CPRL\n"); + 
> ctx->enc_params.prog_order = CPRL; + } + ctx->enc_params.tp_flag = 
> 'C'; + ctx->enc_params.tp_on = 1; + } + 

> ctx->compress = opj_create_compress(ctx->format); if (!ctx->compress) 
> { av_log(avctx, AV_LOG_ERROR, "Error creating the compressor\n"); @@ 
> -245,7 +278,7 @@ static int libopenjpeg_copy_packed8(AVCodecContext 
> *avctx, const AVFrame *frame, return 1; } -static int 
> libopenjpeg_copy_packed16(AVCodecContext *avctx, const AVFrame *frame, 
> opj_image_t *image) +static int 
> libopenjpeg_copy_packed16(AVCodecContext *avctx, const AVFrame *frame, 
> opj_image_t *image, int shr) { int compno; int x; @@ -267,7 +300,7 @@ 
> static int libopenjpeg_copy_packed16(AVCodecContext *avctx, const 
> AVFrame *frame image_index = y * avctx->width; frame_index = y * 
> (frame->linesize[0] / 2) + compno; for (x = 0; x < avctx->width; ++x) 
> { - image->comps[compno].data[image_index++] = frame_ptr[frame_index]; 
> + image->comps[compno].data[image_index++] = frame_ptr[frame_index] >> 
> shr; frame_index += numcomps; } } @@ -367,7 +400,7 @@ static int 
> libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, break; 
> case AV_PIX_FMT_RGB48: case AV_PIX_FMT_RGBA64: - cpyresult = 
> libopenjpeg_copy_packed16(avctx, frame, image); + cpyresult = 
> libopenjpeg_copy_packed16(avctx, frame, image, ctx->shr); break; case 
> AV_PIX_FMT_GRAY8: case AV_PIX_FMT_YUV410P: @@ -484,6 +517,7 @@ static 
> const AVOption options[] = { { "disto_alloc", NULL, 
> OFFSET(disto_alloc), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, VE }, { 
> "fixed_alloc", NULL, OFFSET(fixed_alloc), AV_OPT_TYPE_INT, { .i64 = 0 
> }, 0, 1, VE }, { "fixed_quality", NULL, OFFSET(fixed_quality), 
> AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE }, + { "shr", NULL, 
> OFFSET(shr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 7, VE }, { NULL }, }; 

jean



More information about the ffmpeg-devel mailing list