[FFmpeg-devel] [PATCH] lavc/libopenjpegenc: move opj_setup_encoder to libopenjpeg_encode_frame
if the openjpeg parameter tcp_rates is not 0 ( using the ffmpeg compression_level option ) every 2nd image per thread is badly encoded. By moving the opj_setup_encoder function from libopenjpeg_encode_init to libopenjpeg_encode_frame this can be prevented. This fixes ticket #3754. Signed-off-by: Jean First jeanfi...@gmail.com --- libavcodec/libopenjpegenc.c | 19 --- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c index 66633f4..4039663 100644 --- a/libavcodec/libopenjpegenc.c +++ b/libavcodec/libopenjpegenc.c @@ -233,14 +233,6 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx) err = AVERROR(EINVAL); goto fail; } -opj_setup_encoder(ctx-compress, ctx-enc_params, ctx-image); - -ctx-stream = opj_cio_open((opj_common_ptr) ctx-compress, NULL, 0); -if (!ctx-stream) { -av_log(avctx, AV_LOG_ERROR, Error creating the cio stream\n); -err = AVERROR(ENOMEM); -goto fail; -} avctx-coded_frame = av_frame_alloc(); if (!avctx-coded_frame) { @@ -257,8 +249,6 @@ static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx) return 0; fail: -opj_cio_close(ctx-stream); -ctx-stream = NULL; opj_destroy_compress(ctx-compress); ctx-compress = NULL; opj_image_destroy(ctx-image); @@ -569,7 +559,14 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, return -1; } -cio_seek(stream, 0); +opj_setup_encoder(compress, ctx-enc_params, image); + +stream = opj_cio_open((opj_common_ptr) compress, NULL, 0); +if (!stream) { +av_log(avctx, AV_LOG_ERROR, Error creating the cio stream\n); +return AVERROR(ENOMEM); +} + if (!opj_encode(compress, stream, image, NULL)) { av_log(avctx, AV_LOG_ERROR, Error during the opj encode\n); return -1; -- 2.2.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] lavc/libopenjpegenc: move opj_setup_encoder to libopenjpeg_encode_frame
On Fri, Jan 23, 2015 at 11:34:35PM +0100, Michael Niedermayer wrote: On Fri, Jan 23, 2015 at 09:58:41PM +0100, Jean First wrote: if the openjpeg parameter tcp_rates is not 0 ( using the ffmpeg compression_level option ) every 2nd image per thread is badly encoded. By moving the opj_setup_encoder function from libopenjpeg_encode_init to libopenjpeg_encode_frame this can be prevented. This fixes ticket #3754. how can this be reproduced ? note, ive tried: ffmpeg -i matrixbench_mpeg2.mpg -an -compression_level 1 -vframes 30 -threads 1 -compression_level 1 -vcodec libopenjpeg test.nut and that results in grayscale only output before as well as after the patch [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Into a blind darkness they enter who follow after the Ignorance, they as if into a greater darkness enter who devote themselves to the Knowledge alone. -- Isha Upanishad signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] lavc/libopenjpegenc: move opj_setup_encoder to libopenjpeg_encode_frame
On Fri, Jan 23, 2015 at 09:58:41PM +0100, Jean First wrote: if the openjpeg parameter tcp_rates is not 0 ( using the ffmpeg compression_level option ) every 2nd image per thread is badly encoded. By moving the opj_setup_encoder function from libopenjpeg_encode_init to libopenjpeg_encode_frame this can be prevented. This fixes ticket #3754. how can this be reproduced ? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB You can kill me, but you cannot change the truth. signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] lavc/libopenjpegenc: move opj_setup_encoder to libopenjpeg_encode_frame
On Fri, Jan 23, 2015 at 11:57:26PM +0100, Jean First wrote: On Fri Jan 23 2015 23:39:21 GMT+0100 (CET), Michael Niedermayer wrote: On Fri, Jan 23, 2015 at 11:34:35PM +0100, Michael Niedermayer wrote: On Fri, Jan 23, 2015 at 09:58:41PM +0100, Jean First wrote: if the openjpeg parameter tcp_rates is not 0 ( using the ffmpeg compression_level option ) every 2nd image per thread is badly encoded. By moving the opj_setup_encoder function from libopenjpeg_encode_init to libopenjpeg_encode_frame this can be prevented. This fixes ticket #3754. how can this be reproduced ? note, ive tried: ffmpeg -i matrixbench_mpeg2.mpg -an -compression_level 1 -vframes 30 -threads 1 -compression_level 1 -vcodec libopenjpeg test.nut and that results in grayscale only output before as well as after the patch you can try with: ffmpeg -i matrixbench_mpeg2.mpg -pix_fmt xyz12 -format:v jp2 -profile:v cinema2k -cinema_mode 2k_24 -prog_order cprl -numresolution 6 -numlayers 1 -compression_level 2 -threads 1 test-%05d.j2c and change the value for -compression_level ok, bugfix confirmed patch applied thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Let us carefully observe those good qualities wherein our enemies excel us and endeavor to excel them, by avoiding what is faulty, and imitating what is excellent in them. -- Plutarch signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel