Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Announcements and Chat > General Discussion

Reply
 
Thread Tools Search this Thread Display Modes
Old 4th December 2024, 23:31   #1  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
Shutter Encoder 709 Colors

Here is a sample of my video without any colorimetry flags:
https://www.mediafire.com/file/0r160...video.mkv/file

Now use Shutter Encoder make png files and/or an apng out of it. Do they have the 709 colors or the 601 ones? Did they have the gAMA and cHRM tag issues?

You can get Shutter Encoder here:
https://www.shutterencoder.com/

Last edited by jay123210599; 5th December 2024 at 22:29.
jay123210599 is offline   Reply With Quote
Old 4th December 2024, 23:58   #2  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Posts: 359
True.
Z2697 is offline   Reply With Quote
Old 5th December 2024, 00:35   #3  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Posts: 359
Code:
"C:\Users\a\Desktop\Shutter Encoder 18.6 Windows 64bits\Library\ffmpeg.exe" -strict -2 -hide_banner -threads 0  -i "C:\Users\a\Desktop\sample tagless video.mkv" -compression_level 0 -sws_flags bicubic -an -y "C:\Users\a\Desktop\sample tagless video_%06d.png"
go figure
Z2697 is offline   Reply With Quote
Old 5th December 2024, 23:29   #4  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
Quote:
Originally Posted by Z2697 View Post
Code:
"C:\Users\a\Desktop\Shutter Encoder 18.6 Windows 64bits\Library\ffmpeg.exe" -strict -2 -hide_banner -threads 0  -i "C:\Users\a\Desktop\sample tagless video.mkv" -compression_level 0 -sws_flags bicubic -an -y "C:\Users\a\Desktop\sample tagless video_%06d.png"
go figure
What's this? What does the command mean? Did the PNGs and APNGs have the right colors? Do they have tag issues?
jay123210599 is offline   Reply With Quote
Old 9th December 2024, 14:08   #5  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Posts: 359
Quote:
Originally Posted by jay123210599 View Post
What's this? What does the command mean? Did the PNGs and APNGs have the right colors? Do they have tag issues?
This is the command that Shutter Encoder uses when converting video to PNG image sequence.
Since it calls FFmpeg CLI tool the same "limitation" applies.
Z2697 is offline   Reply With Quote
Old 9th December 2024, 15:27   #6  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
Quote:
Originally Posted by Z2697 View Post
This is the command that Shutter Encoder uses when converting video to PNG image sequence.
Since it calls FFmpeg CLI tool the same "limitation" applies.
So it would call the wrong colors and have tag issues for PNG and APNG?
jay123210599 is offline   Reply With Quote
Old 9th December 2024, 15:33   #7  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,600
Quote:
Originally Posted by jay123210599 View Post
So it would call the wrong colors and have tag issues for PNG and APNG?
No

To recap: for unflagged colorimetry input files, it uses Rec601 for the YUV=>RGB conversion. No PNG chunks written in that case.

See this thread (again)
http://forum.doom9.org/showthread.php?t=185921

I tested Shutter 18.6 - behaviour is the same as default ffmpeg . As you would expect for that command line. There is no other "logic" used in Shutter.
poisondeathray is offline   Reply With Quote
Old 9th December 2024, 17:41   #8  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Posts: 359
Quote:
Originally Posted by Z2697 View Post
The entity "Jay" (SCP-Doom9-123210599) keeps asking questions follwoing one or more of these rules:
1) The question can easily be looked up with a simple web search engine search.
2) The question can easily be answered by performing the actions involved in the question. "F*ck around and find out".
3) The question is ambiguous.
4) The question is subjective.
5) The question is a variation of previously asked question(s).
Z2697 is offline   Reply With Quote
Old 9th December 2024, 21:41   #9  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
In that case, I'm just going to add flags to my videos and convert it to lossless animated WEBP with the format being bgra, because I know by now that without flags it won't get the 709 colors I want.

Then I'll extract the frames from the WEBP using IrfanView as PNGs where it won't have any tag issues and display the right colors.
jay123210599 is offline   Reply With Quote
Old 9th December 2024, 21:58   #10  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,600
Quote:
Originally Posted by jay123210599 View Post
In that case, I'm just going to add flags to my videos and convert it to lossless animated WEBP with the format being bgra, because I know by now that without flags it won't get the 709 colors I want.

Then I'll extract the frames from the WEBP using IrfanView as PNGs where it won't have any tag issues and display the right colors.

Or you could use the zscale filter as suggested in that thread. It would be much faster, no intermediate files or extra HDD space (hard drives do break from usage eventually). 1 step instead of 3
poisondeathray is offline   Reply With Quote
Old 9th December 2024, 22:23   #11  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,600
Quote:
Originally Posted by jay123210599 View Post
In that case, I'm just going to add flags to my videos and convert it to lossless animated WEBP with the format being bgra, because I know by now that without flags it won't get the 709 colors I want...
Also, BTW that proposed 2nd step converts incorrectly. If video has 709 colorimetry flags, it uses 601 for the actual conversion for lossless webp. It even gives you a warning

Code:
[libwebp_anim @ 000000b84c414100] Using libwebp for YUV-to-RGB conversion. You may want to consider passing in RGB instead for lossless encoding.
poisondeathray is offline   Reply With Quote
Old 10th December 2024, 00:53   #12  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
Quote:
Originally Posted by poisondeathray View Post
Also, BTW that proposed 2nd step converts incorrectly. If video has 709 colorimetry flags, it uses 601 for the actual conversion for lossless webp. It even gives you a warning

Code:
[libwebp_anim @ 000000b84c414100] Using libwebp for YUV-to-RGB conversion. You may want to consider passing in RGB instead for lossless encoding.
Well, this is the command I used after adding the flags to my video, and I had not gotten a warning.
Code:
ffmpeg -i video.mkv -vf format=bgra -lossless 1 output.webp
jay123210599 is offline   Reply With Quote
Old 10th December 2024, 01:28   #13  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,600
Quote:
Originally Posted by jay123210599 View Post
Well, this is the command I used after adding the flags to my video, and I had not gotten a warning.
Code:
ffmpeg -i video.mkv -vf format=bgra -lossless 1 output.webp
Ok, that looks mostly correct for flagged input, but there are avoidable rounding errors from -vf format's use of swscale's default fast low quality conversion mode. If you look at that same thread, it mentions the swscale issue and workarounds

You decide what's best for you, but IMO it's pointless to use "lossless" if you incur avoidable rounding errors
poisondeathray is offline   Reply With Quote
Old 10th December 2024, 08:44   #14  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 254
I gave it a go this morning and the simplest way is:

Code:
ffmpeg -colorspace bt709 -i "sample tagless video.mkv" -frames:v 24 -sws_flags accurate_rnd "%%d.png"
ffmpeg -colorspace bt709 -i "sample tagless video.mkv" -frames:v 24 -sws_flags accurate_rnd "out.apng"
It converts the colours correctly, as opposed to the default BT.601 conversion, uses accurate rounding (we hope), and contains no gAMA and cHRM chunks in the resulting PNG and APNG files. Setting the transfer characteristics and primaries are what cause the gAMA and cHRM chunks to be set, respectively. Note that "-frames:v 24" merely limits the processing to 24 frames. You can remove that to process the whole file or change the value.






GIF with error-diffusion dithering

Code:
ffmpeg -colorspace bt709 -i "sample tagless video.mkv" -frames:v 1 -sws_flags accurate_rnd -sws_dither ed "out.gif"

Last edited by GeoffreyA; 10th December 2024 at 09:38.
GeoffreyA is offline   Reply With Quote
Old 10th December 2024, 10:32   #15  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Posts: 359
Quote:
Originally Posted by GeoffreyA View Post
I gave it a go this morning and the simplest way is:

Code:
ffmpeg -colorspace bt709 -i "sample tagless video.mkv" -frames:v 24 -sws_flags accurate_rnd "%%d.png"
ffmpeg -colorspace bt709 -i "sample tagless video.mkv" -frames:v 24 -sws_flags accurate_rnd "out.apng"
It converts the colours correctly, as opposed to the default BT.601 conversion, uses accurate rounding (we hope), and contains no gAMA and cHRM chunks in the resulting PNG and APNG files. Setting the transfer characteristics and primaries are what cause the gAMA and cHRM chunks to be set, respectively. Note that "-frames:v 24" merely limits the processing to 24 frames. You can remove that to process the whole file or change the value.






GIF with error-diffusion dithering

Code:
ffmpeg -colorspace bt709 -i "sample tagless video.mkv" -frames:v 1 -sws_flags accurate_rnd -sws_dither ed "out.gif"
The chroma still looks like point resized
Please use full_chroma_int flag as well
And this way the GIF is not using palette
Please use palettegen and paletteuse

Last edited by Z2697; 10th December 2024 at 10:40.
Z2697 is offline   Reply With Quote
Old 10th December 2024, 12:05   #16  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 254
Thanks, Z2697. Here's the updated script that should solve the problem, Jay:

Code:
:: Create PNG and APNG
ffmpeg -colorspace bt709 -i "src.mkv" -frames:v 1 -sws_flags accurate_rnd+full_chroma_int "%%d.png"
ffmpeg -colorspace bt709 -i "src.mkv" -frames:v 1 -sws_flags accurate_rnd+full_chroma_int "out.apng"

:: Create palette and then GIF
ffmpeg -colorspace bt709 -i "src.mkv" -vf palettegen -sws_flags accurate_rnd+full_chroma_int "palette.png"
ffmpeg -colorspace bt709 -i "src.mkv" -i "palette.png" -lavfi paletteuse -frames:v 1 -sws_flags accurate_rnd+full_chroma_int "out.gif"
PNG:


GIF made with palette and Sierra-24A dithering:


Here's a reusable way of doing it. Place this in a BAT file. Change the variables src, start, and frames and run the file.

Code:
setlocal

set src=sample tagless video.mkv
set start=2
set frames=24

:: Create PNG and APNG
ffmpeg -ss %start% -colorspace bt709 -i "%src%" -frames:v %frames% -sws_flags accurate_rnd+full_chroma_int "%%d.png"
ffmpeg -ss %start% -colorspace bt709 -i "%src%" -frames:v %frames% -sws_flags accurate_rnd+full_chroma_int "out.apng"

:: Create palette and then GIF
ffmpeg -colorspace bt709 -i "%src%" -vf palettegen -sws_flags accurate_rnd+full_chroma_int "palette.png"
ffmpeg -ss %start% -colorspace bt709 -i "%src%" -i "palette.png" -lavfi paletteuse -frames:v %frames% -sws_flags accurate_rnd+full_chroma_int "out.gif"

endlocal
pause

Last edited by GeoffreyA; 10th December 2024 at 12:46.
GeoffreyA is offline   Reply With Quote
Old 10th December 2024, 13:37   #17  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Posts: 359
Did you notice that the new GIF image is now having "jagged chroma" (well, not actual chroma 'cause it's RGB, but you get the point).
And the old GIF image is somehow not having "jagged chroma"... WTF?

swscale and auto-inserted scale filter is a huge mess.
Z2697 is offline   Reply With Quote
Old 10th December 2024, 14:21   #18  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
Wait, which one should I go with?

This?
Code:
-vf zscale=pin=2:p=2:tin=2:t=2:min=709,format=gbrp
Or this?
Code:
-colorspace bt709 -sws_flags accurate_rnd+full_chroma_int
jay123210599 is offline   Reply With Quote
Old 10th December 2024, 14:40   #19  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 254
Quote:
Originally Posted by Z2697 View Post
Did you notice that the new GIF image is now having "jagged chroma" (well, not actual chroma 'cause it's RGB, but you get the point).
And the old GIF image is somehow not having "jagged chroma"... WTF?

swscale and auto-inserted scale filter is a huge mess.
Yes, it did vaguely occur to me but I was focusing more on the skies. I'll see if I can crack this one. The auto-inserted scale filter is, indeed, one big mess; but even if we use zscale, auto-scale is still being called; therefore, it's shorter to leave out zscale.

EDIT: The problem is, for some reason in the GIF example, the sws flags aren't being set:

Code:
[auto_scale_1 @ 0000021bcef58300] w:1920 h:1080 fmt:yuv420p csp:bt709 range:unknown sar:1/1 -> w:1920 h:1080 fmt:bgra csp:gbr range:pc sar:1/1 flags:0x00000004
But in the usual case, like for the PNGs:

Code:
[auto_scale_0 @ 000001ef02b73200] w:1920 h:1080 fmt:yuv420p csp:bt709 range:unknown sar:1/1 -> w:1920 h:1080 fmt:rgb24 csp:gbr range:pc sar:1/1 flags:0x00042000

Quote:
Originally Posted by jay123210599 View Post
Wait, which one should I go with?

This?
Code:
-vf zscale=pin=2:p=2:tin=2:t=2:min=709,format=gbrp
Or this?
Code:
-colorspace bt709 -sws_flags accurate_rnd+full_chroma_int
It's up to you and which command-line is more compact or readable. Even if zscale is used, FFmpeg's auto-scale is still being called. Here are the two (unnamed) and I don't think one can ABX the difference:




Last edited by GeoffreyA; 10th December 2024 at 14:55.
GeoffreyA is offline   Reply With Quote
Old 10th December 2024, 16:42   #20  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Posts: 359
Quote:
Originally Posted by GeoffreyA View Post
Yes, it did vaguely occur to me but I was focusing more on the skies. I'll see if I can crack this one. The auto-inserted scale filter is, indeed, one big mess; but even if we use zscale, auto-scale is still being called; therefore, it's shorter to leave out zscale.

EDIT: The problem is, for some reason in the GIF example, the sws flags aren't being set:

Code:
[auto_scale_1 @ 0000021bcef58300] w:1920 h:1080 fmt:yuv420p csp:bt709 range:unknown sar:1/1 -> w:1920 h:1080 fmt:bgra csp:gbr range:pc sar:1/1 flags:0x00000004
But in the usual case, like for the PNGs:

Code:
[auto_scale_0 @ 000001ef02b73200] w:1920 h:1080 fmt:yuv420p csp:bt709 range:unknown sar:1/1 -> w:1920 h:1080 fmt:rgb24 csp:gbr range:pc sar:1/1 flags:0x00042000
If zscale is used, there's still auto-instered scale filter, true, but the actual conversion is done by zscale (if you set the parameters and format correctly), the swscale is only handling like shuffling planes or packed pixels, or whatever. Which is pretty safe. Much safer than leave it to FFmpeg to do wacky conversions (and chroma scalings).

Last edited by Z2697; 10th December 2024 at 16:44.
Z2697 is offline   Reply With Quote
Reply

Tags
colorspace, ffmpeg gui, image-quality

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:49.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.