[FFmpeg-devel] [PATCH] libopenjpegenc: recreate image data buffer after encoding frame

Michael Bradshaw mjbshaw at gmail.com
Wed Oct 12 04:42:45 EEST 2016


On Tue, Oct 11, 2016 at 9:57 AM, Andreas Cadhalpun <
andreas.cadhalpun at googlemail.com> wrote:

> openjpeg 2 sets the data pointers of the image components to NULL,
> causing segfaults if the image is reused.
>

I've never seen this issue. Is there a particular version of OpenJPEG or
reproduction steps available? Where are the data pointers being set to NULL
here?

Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun at googlemail.com>
> ---
>
> The relevant openjpeg2 code is:
> https://sources.debian.net/src/openjpeg2/2.1.2-1/src/lib/
> openjp2/j2k.c/?hl=10253#L10247
>
> ---
>  libavcodec/libopenjpegenc.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/libavcodec/libopenjpegenc.c b/libavcodec/libopenjpegenc.c
> index 023fdf4..2f0ab20 100644
> --- a/libavcodec/libopenjpegenc.c
> +++ b/libavcodec/libopenjpegenc.c
> @@ -776,6 +776,16 @@ static int libopenjpeg_encode_frame(AVCodecContext
> *avctx, AVPacket *pkt,
>          goto done;
>      }
>
> +    // openjpeg 2 sets the data pointers of the image components to NULL.
> +    // Thus the image can't be reused.
> +    opj_image_destroy(ctx->image);
> +    ctx->image = mj2_create_image(avctx, &ctx->enc_params);
> +    if (!ctx->image) {
> +        av_log(avctx, AV_LOG_ERROR, "Error creating the mj2 image\n");
> +        ret = AVERROR(EINVAL);
> +        goto done;
> +    }
> +
>      av_shrink_packet(pkt, writer.pos);
>  #endif // OPENJPEG_MAJOR_VERSION == 1
>
> --
> 2.9.3
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


More information about the ffmpeg-devel mailing list