Trying to get lossless PNG -> VP9 (yuv) -> PNG

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Trying to get lossless PNG -> VP9 (yuv) -> PNG

Kirk Liberty
I'm experimenting with using video codecs for compressing still images
to reduce the size of my personal database. I'm usoing 24 bit PNGs as
the source files and everything is fine using rgb video codecs but I'm
having trouble getting yuv codecs to work. My plan is to use the YCgCo
colorspace to get lossless conversion of rgb->yuv->rgb; but my images
are coming out faded.

The commands I ran:
ffmpeg -i Ash.png -c:v  libvpx-vp9 -lossless 1 -colorspace ycgco
-color_range pc -pix_fmt yuv444p ash.ivf
ffmpeg -i ash.ivf ash.ivf.png

I've also tried it with x264 (same result):
ffmpeg -i Ash.png -c:v  libx264 -crf 0 -colorspace ycgco -color_range
pc -pix_fmt yuv444p

Uploaded files:
Ash.png         http://0x0.st/sWsV.png
ash.ivf         http://0x0.st/sWsy.ivf
ash.ivf.png     http://0x0.st/sWst.png
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Trying to get lossless PNG -> VP9 (yuv) -> PNG

Carl Eugen Hoyos-2
2018-07-29 0:16 GMT+02:00, Kirk Liberty <[hidden email]>:
> My plan is to use the YCgCo
> colorspace to get lossless conversion of rgb->yuv->rgb

This conversion (may be lossless in theory but) is not lossless
with FFmpeg, both x264 and libvpx-vp9 support encoding rgb
which can be lossless.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Trying to get lossless PNG -> VP9 (yuv) -> PNG

Kirk Liberty
On Tue, Jul 31, 2018 at 7:04 PM, Carl Eugen Hoyos <[hidden email]> wrote:
>
> 2018-07-29 0:16 GMT+02:00, Kirk Liberty <[hidden email]>:
> > My plan is to use the YCgCo
> > colorspace to get lossless conversion of rgb->yuv->rgb
>
> This conversion (may be lossless in theory but) is not lossless
> with FFmpeg, both x264 and libvpx-vp9 support encoding rgb
> which can be lossless.

Why is YCgCo not lossless in FFmpeg? Problem with using the
grba colorspace is that it is a fair bit larger than a lossless
WebP.

Someone on StackExchange pointed out that -color_range does not
affect the output. I was able to get the image to look right by
using -vf scale=out_range=pc and then -vf scale=in_range=pc for
for the reverse.

Kirk
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Trying to get lossless PNG -> VP9 (yuv) -> PNG

Carl Eugen Hoyos-2
2018-08-01 6:12 GMT+02:00, Kirk Liberty <[hidden email]>:

> On Tue, Jul 31, 2018 at 7:04 PM, Carl Eugen Hoyos <[hidden email]>
> wrote:
>>
>> 2018-07-29 0:16 GMT+02:00, Kirk Liberty <[hidden email]>:
>> > My plan is to use the YCgCo
>> > colorspace to get lossless conversion of rgb->yuv->rgb
>>
>> This conversion (may be lossless in theory but) is not lossless
>> with FFmpeg, both x264 and libvpx-vp9 support encoding rgb
>> which can be lossless.
>
> Why is YCgCo not lossless in FFmpeg?

It is / can be.
What is not lossless is the conversion from PIX_FMT_GBR* (or RGB*)
to PIX_FMT_YUV*

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Trying to get lossless PNG -> VP9 (yuv) -> PNG

Kirk Liberty
On Wed, Aug 1, 2018 at 2:00 PM, Carl Eugen Hoyos <[hidden email]> wrote:

> 2018-08-01 6:12 GMT+02:00, Kirk Liberty <[hidden email]>:
>> On Tue, Jul 31, 2018 at 7:04 PM, Carl Eugen Hoyos <[hidden email]>
>> wrote:
>>>
>>> 2018-07-29 0:16 GMT+02:00, Kirk Liberty <[hidden email]>:
>>> > My plan is to use the YCgCo
>>> > colorspace to get lossless conversion of rgb->yuv->rgb
>>>
>>> This conversion (may be lossless in theory but) is not lossless
>>> with FFmpeg, both x264 and libvpx-vp9 support encoding rgb
>>> which can be lossless.
>>
>> Why is YCgCo not lossless in FFmpeg?
>
> It is / can be.
> What is not lossless is the conversion from PIX_FMT_GBR* (or RGB*)
> to PIX_FMT_YUV*

Are you referring to rgba2ycocg() in texturedspenc.c?

574  * Convert a RGBA buffer to unscaled YCoCg.
575  * Scale is usually introduced to avoid banding over a certain
range of colors,
576  * but this version of the algorithm does not introduce it as much as other
577  * implementations, allowing for a simpler and faster conversion.
578  */
579 static void rgba2ycocg(uint8_t *dst, const uint8_t *pixel)
580 {
581  int r = pixel[0];
582  int g = (pixel[1] + 1) >> 1;
583  int b = pixel[2];
584  int t = (2 + r + b) >> 2;
585
586  dst[0] = av_clip_uint8(128 + ((r - b + 1) >> 1)); /* Co */
587  dst[1] = av_clip_uint8(128 + g - t); /* Cg */
588  dst[2] = 0;
589  dst[3] = av_clip_uint8(g + t); /* Y */
590 }

Kirk
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Trying to get lossless PNG -> VP9 (yuv) -> PNG

Carl Eugen Hoyos-2
2018-08-01 21:24 GMT+02:00, Kirk Liberty <[hidden email]>:

> On Wed, Aug 1, 2018 at 2:00 PM, Carl Eugen Hoyos <[hidden email]> wrote:
>> 2018-08-01 6:12 GMT+02:00, Kirk Liberty <[hidden email]>:
>>> On Tue, Jul 31, 2018 at 7:04 PM, Carl Eugen Hoyos <[hidden email]>
>>> wrote:
>>>>
>>>> 2018-07-29 0:16 GMT+02:00, Kirk Liberty <[hidden email]>:
>>>> > My plan is to use the YCgCo
>>>> > colorspace to get lossless conversion of rgb->yuv->rgb
>>>>
>>>> This conversion (may be lossless in theory but) is not lossless
>>>> with FFmpeg, both x264 and libvpx-vp9 support encoding rgb
>>>> which can be lossless.
>>>
>>> Why is YCgCo not lossless in FFmpeg?
>>
>> It is / can be.
>> What is not lossless is the conversion from PIX_FMT_GBR* (or RGB*)
>> to PIX_FMT_YUV*
>
> Are you referring to rgba2ycocg() in texturedspenc.c?

No.
You wrote above "lossless conversion of rgb->yuv->rgb" and i am
telling you that this is not possible with FFmpeg when using
libvpx-vp9 or x264.

Both libvpx-vp9 and x264 support rgb encoding and both can
encode in a lossless fashion.

If you have an additional question concerning FFmpeg usage,
please provide the command line you tested together with the
complete, uncut console output.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".