libheif icon indicating copy to clipboard operation
libheif copied to clipboard

Pre-encoded HEVC

Open dibbitson opened this issue 3 years ago • 1 comments

Is it possible to use libheif to write pre-encoded HEVC imagery? I'm having trouble determining from the API if it's possible or not, and if so how.

Thanks

dibbitson avatar Jul 30 '21 17:07 dibbitson

I found this eventually: https://github.com/strukturag/libheif/issues/5

And it works fine with a couple modifications, and following the other advice in the thread.

I found it necessary to fully specify an image for heif_context_encode_image()

heif_image * dummy_image = nullptr;
heif_image_create(w, h, heif_colorspace_YCbCr, heif_chroma_420, &dummy_image);
heif_image_add_plane(dummy_image, heif_channel_Y, w, h, 8);
heif_image_add_plane(dummy_image, heif_channel_Cb, (w + 1) / 2, (h + 1) / 2, 8);
heif_image_add_plane(dummy_image, heif_channel_Cr, (w + 1) / 2, (h + 1) / 2, 8);

and in the plugin dummy_encode_image() call you need to check for 3 and 4 byte nal prefix codes (at least if you are encoding with x265).

Hope this helps someone else.

dibbitson avatar Jul 31 '21 00:07 dibbitson

And it works fine with a couple modifications, and following the other advice in the thread.

I found it necessary to fully specify an image for heif_context_encode_image()

hi, bro. I tried heif_encoder_dummy plugin that you mentioned, but I cannot open that output heic file on windows. It shows message "unable to open the file, it may hanve benn corrupted". I need your help. Can you share me your input.h265 file? It would be better if the source code could also be shared.Thanks a lot.

I found this eventually: #5

And it works fine with a couple modifications, and following the other advice in the thread.

I found it necessary to fully specify an image for heif_context_encode_image()

heif_image * dummy_image = nullptr;
heif_image_create(w, h, heif_colorspace_YCbCr, heif_chroma_420, &dummy_image);
heif_image_add_plane(dummy_image, heif_channel_Y, w, h, 8);
heif_image_add_plane(dummy_image, heif_channel_Cb, (w + 1) / 2, (h + 1) / 2, 8);
heif_image_add_plane(dummy_image, heif_channel_Cr, (w + 1) / 2, (h + 1) / 2, 8);

and in the plugin dummy_encode_image() call you need to check for 3 and 4 byte nal prefix codes (at least if you are encoding with x265).

Hope this helps someone else.

hi, bro. I tried heif_encoder_dummy plugin that you mentioned, but I cannot open that output heic file on windows. It shows message "unable to open the file, it may hanve benn corrupted". I need your help. Can you share me your input.h265 file? It would be better if the source code could also be shared.Thanks a lot.

zx310 avatar Mar 01 '23 01:03 zx310