strukturag / libheif

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

VVC/H.266 support #519

Open rafael2k opened 3 years ago

rafael2k commented 3 years ago

Hi, Do you think it is in the scope of libheif the support for VVC/H.266 still image format? There is already a pretty decent free software implementation of VVC here: https://github.com/fraunhoferhhi/vvenc https://github.com/fraunhoferhhi/vvdec/

farindk commented 3 years ago

Hi, sure. It should be pretty easy to add VVC as encoder/decoder plugin to libheif. I don't have the HEIF DAmd2 text yet, so I don't know the prospective ID values for VVC. Once I have that information, VVC can be added.

rafael2k commented 3 years ago

Thanks! Can you point me the exact ISO standard you are mentioning? I can try to get through the university.

farindk commented 3 years ago

ISO/IEC 23008-12:2017/DAmd 2 Information technology — High efficiency coding and media delivery in heterogeneous environments — Part 12: Image File Format — Amendment 2: Support for VVC, EVC, slideshows and other improvements

https://www.iso.org/standard/81688.html

rafael2k commented 3 years ago

I dropped you an email. Please confirm. ; )

Jamaika1 commented 3 years ago

I was unsuccessfully trying in libbpg. https://github.com/Jamaika1/libbpg_vvc Reduce Complexity for intra coding of VVC https://github.com/llsurreal919/Reduce-Complexity-for-intra-coding-of-VVC The evc codecs are here. https://github.com/mpeg5/xeve https://github.com/mpeg5/xevd Currently, I advise against using the fraunhoferhhi codecs. I only support certain frame sizes 1280x720, 1920x1080 VVC codec can already be used in MP4 GPAC container. Strange that not in the MP5.

rafael2k commented 3 years ago

Hi Jamaika1,

It seems you suggested the use of the ISO reference code (in both "libbpg_vvc" and "Reduce-Complexity-for-intra-coding-of-VVC"), which is way slower than FhG implementation (and of course have some extra features). IMHO, FhG VVC are the best VVC open-source codec implementations, by far.

Jamaika1 commented 3 years ago

Hi rafael2k

FhG VVC v1.0.0 doesn`t currently have lossless function. It's still long way.

rafael2k commented 3 years ago

The purpose of such encoders are to have high compression rate, not to be bit-per-bit lossless. You are missing the point - higher coding efficiency at lower rates is the focus of these series of encoders (H.261, H.262, H.263, H.264, H.265, H.266 - and twin MPEG counter-parts). Indeed, at higher rates you get "lossless" compression considering the human visual system (HVS) - as you can verify in the psychovisual experiments in the literature. If you want to understand more about the FhG VVC codec, please read: J. Brandenburg, A. Wieckowski, T. Hinz , A. Henkel , V. George , I. Zupancic, C. Stoffers, B. Bross, H. Schwarz, D. Marpe, “Towards Fast and Efficient VVC Encoding,” IEEE 22nd Workshop on Multimedia Signal Processing (MMSP 2020), Tampere, Finland, 2020. and: A. Wieckowski, G. Hege, C. Bartnik, C. Lehmann, C. Stoffers, B. Bross, D. Marpe, “Towards a Live Software Decoder Implementation for the Upcoming Versatile Video Coding (VVC) Codec,” IEEE International Conference on Image Processing (ICIP 2020), Virtual Conference, 2020.

farindk commented 3 years ago

Both is correct. Of course, usually the lossy codec is used, but since h.264, there is also a lossless coding mode, which can actually be quite handy has a replacement alternative for PNG.

rafael2k commented 2 years ago

I'm impressed by EVC (thanks @Jamaika1), which performs a bit worse than VVC, but better then HEIF and AVIF, so I'm changing the title to VVC and EVC support.

Jamaika1 commented 1 year ago

I recommend GPAC HEIF link from VVC. MP4Box -add-image "image_21447_24bit.266":time=-1:@@reframer:frames=1 -ab heic "image.heic"

Track Importing VVC - Width 1563 Height 1558 FPS 25000/1000
VVC Import results: 1 samples (5 NALUs) - Slices: 1 I 0 P 0 B - 0 SEI - 1 IDR - 0 CRA
Adding sample at time 0.000 as item 3

Unfortunately. Demuxer isn't B-frame decompression. I am added link to nokia heif vvc. Unfortunately, I don't know how to use it. The decoder should already be vvdec thread and not jvet. https://github.com/nokiatech/heif/tree/VVC_MP4

rafael2k commented 1 year ago

I recommend GPAC HEIF link from VVC. MP4Box -add-image "image_21447_24bit.266":time=-1:@@reframer:frames=1 -ab heic "image.heic"

Track Importing VVC - Width 1563 Height 1558 FPS 25000/1000
VVC Import results: 1 samples (5 NALUs) - Slices: 1 I 0 P 0 B - 0 SEI - 1 IDR - 0 CRA
Adding sample at time 0.000 as item 3

Unfortunately. Demuxer isn't B-frame decompression. I am added link to nokia heif vvc. Unfortunately, I don't know how to use it. The decoder should already be vvdec thread and not jvet. https://github.com/nokiatech/heif/tree/VVC_MP4

Unfortunately, this implementation uses the VTM reference VVC for decoding, which is pretty buggy and slow. :(

rafael2k commented 1 year ago

Any news on VVC support?

Jamaika1 commented 1 year ago

Maybe use this: https://github.com/ffvvc/FFmpeg/commits/main

farindk commented 1 year ago

The main blocker for this at the moment is that in the current code, I would have to copy-paste a large part of it for each new compression format. I'd like to refactor this first so that there is less copied code.

farindk commented 1 year ago

Are there any example images using VVC? Adding the decoder would be a first step.

Jamaika1 commented 1 year ago

Hi farindk Here is example of heif VVC. https://www.sendspace.com/file/kuiwvw

farindk commented 1 year ago

@Jamaika1 Thank you. That will be very helpful.

rafael2k commented 1 year ago

That support would be really wonderful. Any help I can provide, let me know.

farindk commented 1 year ago

I started with the decoder. @Jamaika1 The example image you prepared has no "pitm" box. Would it be easy for you to add this? Otherwise, I have to patch it in a hex editor somehow.

farindk commented 1 year ago

The example image does not look correct to me. I started implementing decoding the vvcC box, but what I get does not match the specification:

| | | Box: vvcC -----
| | | size: 124   (header size: 8)
| | | version: 0
| | | frame-rate: 0
| | | constant frame rate: unknown
| | | num temporal layers: 0
| | | length size: 1
| | | chroma-format: 4:4:4
| | | bit-depth: 15

version should definitely by 1. I checked the file in a hex editor and skipped some bytes to that version=1, but then, everything else (bit-depth, chroma-format) is still incorrect. Moreover, the box is either much too long, or it contains config NALs, in which case, `num of arrays' should be >0.

farindk commented 1 day ago

There is now an experimental VVC encoding plugin in the master branch. We don't have any way to decode those images yet, though. Thus, I'm not sure it is written correctly.

rafael2k commented 1 day ago

This is wonderful. I'll give it a try and report back.

rafael2k commented 1 day ago

Do you plan to also support VVEnc [1]?

Last time I compared both VVEnc and Kvazaar, VVEnc provided better quality.

[1] https://github.com/fraunhoferhhi/vvenc

farindk commented 1 day ago

First having a decoder would be nice. Do you know any program than can read vvic images?

rafael2k commented 1 day ago

MP4Box can. I'm just finishing compiling libheif with uvg266.

farindk commented 1 day ago

MP4Box can. I'm just finishing compiling libheif with uvg266.

Maybe you can give it a try.

I've just written a decoder plugin based on vvdec. That was very easy, but it doesn't work yet because I'm not sure what data format to push in.

rafael2k commented 1 day ago

Just to confirm, the flags to compile are these ones, right: -DWITH_UVG266=ON \ -DWITH_UVG266_PLUGIN=ON \

farindk commented 1 day ago

Yes. WITH_UVG266_PLUGIN can also be OFF. Then you don't have to install anything.

PS: vvdec plugin works :-) I'll cleanup and the commit it.

rafael2k commented 1 day ago

Yay! Btw, I'm missing a "cmake/modules/FindUVG266.cmake". : )

farindk commented 1 day ago

Btw, I'm missing a "cmake/modules/FindUVG266.cmake".

Right. Now it's there.

rafael2k commented 1 day ago

I'll try with the git version. But the one I have installed (GPAC 2.2.1) gives me this

MP4Box t2fd.vvic -raw t2fd.vvc
[VVC] Invalid NALU type 9 in vvcC - ignoring
[VVC] Wrong param set size 39948
[isom] not enough bytes in box vvcC: 2 left, reading 469 (file isomedia/avc_ext.c, line 3087)
[iso file] Read Box "vvcC" (start 204) failed (Invalid IsoMedia File) - skipping
[iso file] Read Box "ipco" (start 196) failed (Invalid IsoMedia File) - skipping
[iso file] Read Box "iprp" (start 188) failed (Invalid IsoMedia File) - skipping
[iso file] Read Box type 000000! (0x00000021) at position 36 has size 0 but is not at root/file level. Forbidden, skipping end of parent box !
[iso file] Box "meta" (start 28) has 293 extra bytes
[iso file] Missing handler in META!
Error opening file t2fd.vvic: Invalid IsoMedia File
rafael2k commented 1 day ago

I'm compiling GPAC 2.5. I report back soon.

rafael2k commented 1 day ago

MP4Box from git:

$ MP4Box -stats t2fd.vvic
[VVC] Invalid NALU type 9 in vvcC - ignoring
[VVC] Wrong param set size 39948
[isom] not enough bytes in box vvcC: 2 left, reading 469 (file isomedia/avc_ext.c, line 3096) - try specifying -no-check (might crash)
[iso file] Read Box "vvcC" (start 204) failed (Invalid IsoMedia File) - skipping
[iso file] Read Box "ipco" (start 196) failed (Invalid IsoMedia File) - skipping
[iso file] Read Box "iprp" (start 188) failed (Invalid IsoMedia File) - skipping
[iso file] Read Box type 000000! (0x00000021) at position 36 has size 0 but is not at root/file level. Forbidden, skipping end of parent box !
[iso file] Box "meta" (start 28) has 293 extra bytes
[iso file] Missing handler in META!
Error opening file /home/rafael2k/files/images/t2fd.vvic: Invalid IsoMedia File
$ MP4Box -stats -no-check t2fd.vvic
[VVC] Invalid NALU type 9 in vvcC - ignoring
[VVC] Wrong param set size 39948
[isom] not enough bytes in box vvcC: 2 left, reading 469 (file isomedia/avc_ext.c, line 3096) - try specifying -no-check (might crash)
[iso file] Box "vvcC" size 14 (start 204) invalid (read 481)
rafael2k commented 1 day ago

Got the right command line - it can read, but with errors:

MP4Box t2fd.vvic -info -no-check
[VVC] Invalid NALU type 9 in vvcC - ignoring
[VVC] Wrong param set size 39948
[isom] not enough bytes in box vvcC: 2 left, reading 469 (file isomedia/avc_ext.c, line 3087)
[iso file] Box "vvcC" size 14 (start 204) invalid (read 481)
# File Meta type: "pict" - 2 resource item(s)
Primary Item - ID 1
Item #1: ID 1 type vvc1 size 760x480 3 channels (8 bpc) Clap 758/1,480/1,-2/2,0/2

File has no movie (moov) - static data container
rafael2k commented 1 day ago

Full log:

./MP4Box -info -v -no-check t2fd.vvic
[iso file] Parsing a top-level box at position 0
[iso file] Read Box type ftyp size 28 start 0
[iso file] Parsing a top-level box at position 28
[iso file] Read Box type meta size 309 start 28
[iso file] Read Box type hdlr size 33 start 40
[iso file] Read Box type pitm size 14 start 73
[iso file] Read Box type iloc size 66 start 87
[iso file] Read Box type iinf size 35 start 153
[iso file] Read Box type infe size 21 start 167
[iso file] Read Box type iprp size 149 start 188
[iso file] Read Box type ipco size 117 start 196
[iso file] Read Box type vvcC size 14 start 204
[VVC] Invalid NALU type 9 in vvcC - ignoring
[VVC] Wrong param set size 39948
[isom] not enough bytes in box vvcC: 2 left, reading 469 (file isomedia/avc_ext.c, line 3096) - try specifying -no-check (might crash)
[iso file] Box "vvcC" size 14 (start 204) invalid (read 481)
[iso file] Read Box type ispe size 20 start 218
[iso file] Read Box type clap size 40 start 238
[iso file] Read Box type colr size 19 start 278
[iso file] Read Box type pixi size 16 start 297
[iso file] Read Box type ipma size 24 start 313
[iso file] Parsing a top-level box at position 337
[iso file] Read Box type mdat size 38144 start 337
# File Meta type: "pict" - 2 resource item(s)
Primary Item - ID 1
Item #1: ID 1 type vvc1 size 760x480 3 channels (8 bpc) Clap 758/1,480/1,-2/2,0/2

File has no movie (moov) - static data container
farindk commented 1 day ago

I have checked the GPAC source code. Reading vvcC header is in gpac/src/odf/descriptors.c, function gf_odf_vvc_cfg_read_bs(). That function does not match the vvcC specification (gpac source from 27/06/2024). There are a few fields after ptl_present = false that are not read by GPAC.

rafael2k commented 1 day ago

Thanks @farindk. Can I open a ticket in GPAC issues page, or you open it?

rafael2k commented 1 day ago

ps: I think it is good to have another implementation interoperable with libheif VVC. I tested MP4Box with hevc heif created libheif image file and it worked fine. : )

rafael2k commented 17 hours ago

Managed to decode with vvdec-enabled libheif. Yay! I'm maintaining "debian dirs" to uvg266, vvdec (and vvenc) and libheif all ready to create packages with VVC-enabled libheif in Debian. https://github.com/Rhizomatica/libheif https://github.com/Rhizomatica/uvg266 https://github.com/Rhizomatica/vvdec https://github.com/Rhizomatica/vvenc

VVEnc support for encoding would be wonderful, as quality is better.