strukturag / libheif

libheif is an HEIF and AVIF file format decoder and encoder.
Other
1.76k stars 302 forks source link

it takes 4 seconds for 4K image HEIC to decodie #552

Open ByteYIFFF opened 3 years ago

ByteYIFFF commented 3 years ago

Is there any way to speed up decodin. e.g.:heif_decode_image 2021-10-20 112837.zip g

farindk commented 3 years ago

For me 0,8s on a 4770k CPU including writing two images to JPEG:

$ time heif-convert 2021-10-20\ 112837.heic out.jpg
File contains 1 images
Written to out.jpg
Auxiliary image written to out-urn:com:apple:photo:2020:aux:hdrgainmap.jpg

real    0m0,843s
homm commented 3 years ago

It should be at least two times faster (mobile i5-8279U). See #551 and #555.

In [1]: from HeifImagePlugin import Image, pyheif

In [2]: data = open('./2021-10-20 112837.heic', 'rb').read()

In [3]: %%time
   ...: heif_file = pyheif.read(data, apply_transformations=False)
   ...: image = Image.frombytes(
   ...:     heif_file.mode, heif_file.size, heif_file.data,
   ...:     "raw", heif_file.mode, heif_file.stride)
   ...:
CPU times: user 709 ms, sys: 79.5 ms, total: 788 ms
Wall time: 279 ms
ByteYIFFF commented 3 years ago

the problem still exists。And heif_decode_image runs slowly. Is it related to my libheif version? Are you using the master branch?

ByteYIFFF commented 3 years ago

It should be at least two times faster (mobile i5-8279U). See #551 and #555.

In [1]: from HeifImagePlugin import Image, pyheif                                                                               

In [2]: data = open('./2021-10-20 112837.heic', 'rb').read()                                                                    

In [3]: %%time 
   ...: heif_file = pyheif.read(data, apply_transformations=False) 
   ...: image = Image.frombytes( 
   ...:     heif_file.mode, heif_file.size, heif_file.data, 
   ...:     "raw", heif_file.mode, heif_file.stride) 
   ...:                                                                                                                         
CPU times: user 709 ms, sys: 79.5 ms, total: 788 ms
Wall time: 279 ms

my cpu is i7-8700K. my version is v.1.12.0. @homm

ByteYIFFF commented 3 years ago

hi.guys~ i know why it takes too much time for decoding.Because I choose to acquire RGB data.if i acquire yuv, the decoding will be qiuck.

ByteYIFFF commented 3 years ago

对于我在 4770k CPU 上的 0.8 秒,包括将两个图像写入 JPEG:

$ time heif-convert 2021-10-20\ 112837.heic out.jpg
File contains 1 images
Written to out.jpg
Auxiliary image written to out-urn:com:apple:photo:2020:aux:hdrgainmap.jpg

real  0m0,843s

please,try to transform HEIC to a PNG picture. i guess that it will need more time to decode. @farindk

homm commented 3 years ago

So it takes 4 seconds for 4K image to encode in PNG, right?

ByteYIFFF commented 3 years ago

So it takes 4 seconds for 4K image to encode in PNG, right?

"i know why it takes too much time for decoding.Because I choose to acquire RGB data.if i acquire yuv, the decoding will be qiuck."------this is my guess.

in my computer, for a 4K heic, it takes 2second to run this code (heif_decode_image(handle, &img, heif_colorspace_RGB, heif_chroma_interleaved_RGBA, nullptr) @homm

ByteYIFFF commented 2 years ago

所以 4K 图像在 PNG 中编码需要 4 秒,对吗?

in fact, when i decode image in YCBCR, the time not reduce. @homm

freemedom commented 4 months ago

Why are heic images about 10 times slower than jpg? (generate thumbnails) Because heic doesn't have hardware acceleration?