huzi96 / Coarse2Fine-PyTorch

70 stars 6 forks source link

H266, 265 codec #1

Closed jinxixiang closed 3 years ago

jinxixiang commented 3 years ago

Thank you for your seminal work! Which H266 and 265 codec are used in your paper? Could you please leave the web links for reference?

huzi96 commented 3 years ago

We compare with BPG 4:4:4 (based on HEVC intra) and VTM-8 4:4:4 in the paper. The links are as follows: BPG: https://bellard.org/bpg/ VTM: https://vcgit.hhi.fraunhofer.de/jvet/VVCSoftware_VTM/-/tree/VTM-8.0

jinxixiang commented 3 years ago

cheers! thank you for your help.

jinxixiang commented 3 years ago

The VTM software accepts inputs in YUV format. I use 'ffmpeg' to convert PNG to YUV before carrying out the compression experiment. I am not sure whether this additional conversion process would introduce unexceptional losses. How do you deal with the format compatibility problem, please?

huzi96 commented 3 years ago

I convert PNG files to YUV (specifically YUV 4:4:4) with the following function. cv2.cvtColor(img, cv2.COLOR_BGR2YUV) And I convert it back with, cv2.cvtColor(nyuv, cv2.COLOR_YUV2BGR) PSNR is calculated in the RGB color space.

jinxixiang commented 3 years ago

Thank you!

liuty10 commented 2 years ago

Thanks! I have similar questions. How did you save the YUV image using cv2? It seems cv2 can't write xxx.yuv file. Right?

img = cv2.imread(sys.argv[1])
yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
cv2.imwrite(sys.argv[2], yuv)

And what commands parameters did you use for VTM encoding and decoding? I only find the following example and wonder what args did you use?

./EncoderAppStatic -i vicue_test_432x240_420_8_500.yuv -wdt 432 -hgt 240 -c encoder_randomaccess_vtm.cfg -f 5 -fr 30

huzi96 commented 2 years ago

Yes. You need to follow the YUV file format to read and write the YUV files. I did that by converting the numpy array to byte strings and writing it to a binary file. For YUV4:2:0 you can follow the format defined in https://www.fourcc.org/pixel-format/yuv-i420/. For YUV 4:4:4 you just change the resampling rate accordingly.

To use VTM you need to use the ALL INTRA configuration to encode an image. The configuration file is available in the VTM repository, specifically the cfg folder. You need to additionally specify the height (hgt), width (wdt) and QP in the command line.

liuty10 commented 2 years ago

Thanks! I tried ffmpeg and used the config file: cfg/encoder_intra_vtm.cfg (But, I am not sure where to set the ALL INTRA configuration).

After making the following changes to the configuration file,

=========== Misc. ============

InternalBitDepth : 8 # codec operating bit-depth

I used the following commands for YUV420, and the reconstructed image seems good.

ffmpeg -i ../datasets/105.png -pix_fmt yuv420p output.yuv
./bin/EncoderAppStatic -i output.yuv -wdt 1920 -hgt 1080 -c ./cfg/encoder_intra_vtm.cfg -f 1 -fr 1 -q 50 -cf 420 -b output.vtm
./bin/DecoderAppStatic -d 8 -b output.vtm -o dec.yuv
ffmpeg -pixel_format yuv420p -video_size 1920x1080 -framerate 1 -i dec.yuv dec.png

But, when I try YUV444 with the following commands, the reconstructed image seems weird (the image is covered with pink color). I am not sure which parameter is wrong. It might be alignment or YUV data structure, I think. Do you have any ideas?

ffmpeg -i ../datasets/105.png -pix_fmt yuv444p output.yuv
./bin/EncoderAppStatic -i output.yuv -wdt 1920 -hgt 1080 -c ./cfg/encoder_intra_vtm.cfg -f 1 -fr 1 -q 50 -cf 444 -b output.vtm
./bin/DecoderAppStatic -d 8 -b output.vtm -o dec.yuv
ffmpeg -pixel_format yuv444p -video_size 1920x1080 -framerate 1 -i dec.yuv dec.png
huzi96 commented 2 years ago

This encoder_intra_vtm.cfg is what I meant. You might need to be careful when using ffmpeg because you need to make sure the yuv file it generates is in the right form. Sometimes ffmpeg does not do 'yuv444p' in the right way (and not in the way vtm processes it). For now, I am not sure what went wrong but you may want to check whether the yuv files are in the right form for each step, as a start of your debugging.

liuty10 commented 2 years ago

OK, Thanks! I appreciate it. I can debug further.