Log in

View Full Version : From PNGs to APNGs


jay123210599
6th January 2025, 07:31
I have 227 PNGs. I want to make APNGs out of them where each APNG has 50 frames in them. I also want to make all of the APNGs in one setting. How do I do that using ffmpeg?

StainlessS
6th January 2025, 09:02
"From APNGs from PNGs",

Typo ?, Maybe "To APNGs from PNGs", or "From PNGs to APNGs".

Select EDIT, Advanced EDIT, on first post to edit thread title.

Balling
6th January 2025, 09:56
APNG implementaion in ffmpeg is subpar. You use https://apngasm.sourceforge.net/

GeoffreyA
6th January 2025, 10:00
Here's a working method for the time being. I tried to do it all automatically, but nested FOR loops are problematic in Windows batch files. So, you will have to change the "start" and "end" variables each time. The first time would be "start=1" and "end=50" and the second time, "start=51" and "end=100" and so on. Your filenames will have to be in the format of "1.png" and so forth, starting from 1. Please run this on a copy of your original folder in case something gets accidentally overwritten. I'll see if I can improve to do everything automatically.

setlocal EnableDelayedExpansion

set start=1
set end=50

mkdir "OUT"

(for /l %%i in (!start!, 1, !end!) do @echo file %%i.png) > "Jay2025.txt"

ffmpeg -f concat -r 23.976 -i "Jay2025.txt" "OUT\FINAL_%RANDOM%.apng"

pause

GeoffreyA
6th January 2025, 10:03
APNG implementaion in ffmpeg is subpar. You use https://apngasm.sourceforge.net/

Seeing this now, Balling's solution would be the way to go and looks far simpler.

jay123210599
6th January 2025, 15:24
APNG implementaion in ffmpeg is subpar. You use https://apngasm.sourceforge.net/

I don't want any delays between my frames.

huhn
6th January 2025, 15:33
APNG without a delay makes no sense the delay is just a different word for FPS calculated differently.

GeoffreyA
6th January 2025, 16:21
I don't want any delays between my frames.

As huhn points out, you can use a delay (0,041708375 should == 23.976 fps). Alternatively, my method works but requires editing the start and end variables.

jay123210599
6th January 2025, 20:07
Well, the default frame delay is 1/10 sec. How do I adjust it so my output APNG has 23.976 fps?

Also, which compressions for the tools are lossless, zlib, 7zip, or Zopfli? How does the number of iterations affect the compression/speed/quality? If I choose to optimize the palette and/or original color type of the PNGs, will it affect the quality of the APNG?

Z2697
6th January 2025, 20:12
they are lossless

GeoffreyA
6th January 2025, 21:03
Well, the default frame delay is 1/10 sec. How do I adjust it so my output APNG has 23.976 fps?

Also, which compressions for the tools are lossless, zlib, 7zip, or Zopfli? How does the number of iterations affect the compression/speed/quality? If I choose to optimize the palette and/or original color type of the PNGs, will it affect the quality of the APNG?

I'm not at the computer now to test it, but put in that value I posted, 0,041708375, and I reckon it should give 23.976 fps. As for the compression, try a few PNGs to convert to APNG, seeing which gives the better size; 7zip or Zopfli might have the edge. More iterations should yield better compression, but beyond some level, it will be diminishing returns.

Z2697
6th January 2025, 21:30
Shouldn't it be 1001/24000 = 0.0417833333333333333...?

GeoffreyA
6th January 2025, 21:39
Shouldn't it be 1001/24000 = 0.0417833333333333333...?

You are correct. I took the lazy option of dividing by 23.976.

jay123210599
7th January 2025, 16:07
I'm not at the computer now to test it, but put in that value I posted, 0,041708375, and I reckon it should give 23.976 fps. As for the compression, try a few PNGs to convert to APNG, seeing which gives the better size; 7zip or Zopfli might have the edge. More iterations should yield better compression, but beyond some level, it will be diminishing returns.

What if I optimize the palette and/or original color type of the PNGs? Are you at your computer so you can test it now?

Z2697
7th January 2025, 17:14
Why not test yourself?
You have no computer?

poisondeathray
7th January 2025, 17:32
What if I optimize the palette and/or original color type of the PNGs?

"optimize the palette" for PNG implies a lossy transform for most "video" scenarios - you decide which colors to discard . The more you discard, the more quality loss . The lossy transform is applied before the lossless PNG compression is applied

Palette optimization for PNG can be lossless if it's a very simple source with a few colors . This technique is typically used for simple graphics / logos with a few colors

jay123210599
7th January 2025, 17:37
"optimize the palette" for PNG implies a lossy transform for most "video" scenarios - you decide which colors to discard . The more you discard, the more quality loss . The lossy transform is applied before the lossless PNG compression is applied

Palette optimization for PNG can be lossless if it's a very simple source with a few colors . This technique is typically used for simple graphics / logos with a few colors

My PNGs are all 24bit, and optimizing the palette will get rid of some colors?

poisondeathray
7th January 2025, 17:58
My PNGs are all 24bit, and optimizing the palette will get rid of some colors?

In most "video" cases , yes .

In simple cases (e.g. simple logo with 6 colors) you might not get rid of any colors


You can test it yourself. If you cannot "see" the quality loss, measure it with an objective metric such as PSNR. This method was shown to you in other threads.

Another indirect way is to count the number of unique colors e.g. imagemagick. If you start with say 6,467,433 . But you optimize the pallette and now you have 1,234,453. You've lost millions of colors => quality loss

"mathematically lossless" means the decoded data is the same - or bit for bit identical

GeoffreyA
7th January 2025, 18:25
What if I optimize the palette and/or original color type of the PNGs? Are you at your computer so you can test it now?

Testing 24 PNGs made from your anime video, the size of the APNG was roughly the same regardless of the compression method. Zopfli was considerably slower, though, so use either zlib or 7zip, the former being a little bit faster. Increasing the number of iterations, at least for 7zip, made no real difference, so leave it at the default or use even 1, which is faster. Optimising the colour palette and type also made no difference in size, so turn it off, since, as poisondeathray notes, they may lead to loss of colour. As an anchor, FFmpeg created a much bigger file.

These are my findings; but you've got to test it out yourself because your files may yield different results.

Regarding the delay, use the ratio of 1001/24000. It yields 23.976 fps. Yesterday, I was under the impression that one could add a decimal number to the program, but actually, it has to be in the form of a fraction.

poisondeathray
7th January 2025, 18:37
My comments for "pallete optimization" for PNG were "in general" . It's a commonly used lossy technique for web graphics

If you're referring to apngasm specifically , the optimizations used there should be lossless according to the instructions.



Some optimizations used in APNG Assembler might re-sort the
palette, or change the color type from RGBA and RGB modes
to RGB and indexed modes. Those optimizations are only performed
when they are lossless, but if you want to avoid changing the
palette or colortype, use those switches to turn them off:

/kp : keep palette
/kc : keep color type


As usual, just read the instructions and/or test it yourself

GeoffreyA
7th January 2025, 20:06
My comments for "pallete optimization" for PNG were "in general" . It's a commonly used lossy technique for web graphics

If you're referring to apngasm specifically , the optimizations used there should be lossless according to the instructions.

Noted. I didn't read the Readme.

jay123210599
8th January 2025, 16:52
Here are my test files: https://www.mediafire.com/file/2ootywokyv2fkjt/Test_APNGs.7z/file

1-1 and 2-1 uses both color and palette optimization.

1-2 and 2-2 does use color nor palette optimization.

1-3 and 2-3 only uses palette optimization.

1-4 and 2-4 only uses color optimization.

All of them use zlib for compression.

GeoffreyA
8th January 2025, 17:29
Here are my test files: https://www.mediafire.com/file/2ootywokyv2fkjt/Test_APNGs.7z/file

1-1 and 2-1 uses both color and palette optimization.

1-2 and 2-2 does use color nor palette optimization.

1-3 and 2-3 only uses palette optimization.

1-4 and 2-4 only uses color optimization.

All of them use zlib for compression.

Good job on the testing, and well organised. Looks like it's of no use turning on those settings because the files are exactly the same size; even the hashes are identical.

I must say, Jay, I couldn't help but smile seeing the second set of APNGs. Thanks for bringing a bit of humour to the evening. What anime is that?

Z2697
8th January 2025, 17:32
Keijo, perhaps

jay123210599
8th January 2025, 17:57
Good job on the testing, and well organised. Looks like it's of no use turning on those settings because the files are exactly the same size; even the hashes are identical.

You mean the colors? How did you prove they were the same?

Z2697
8th January 2025, 18:53
cmp
md5sum
sha1sum
sha256sum
b3sum

Or even just look crc32 already in the 7z archive LOL

GeoffreyA
8th January 2025, 18:55
You mean the colors? How did you prove they were the same?

I didn't test the colours. I just looked at the file sizes and hashes in 7-Zip. Whether they are the same as the PNGs, I do not know, but they, the APNGs, are identical to each other.

GeoffreyA
8th January 2025, 18:59
Keijo, perhaps

Okay, I haven't seen that one, or indeed, any of this genre.

Z2697
8th January 2025, 19:52
Okay, I haven't seen that one, or indeed, any of this genre.

Me neither :p
Wait it's a genre?:eek:

GeoffreyA
8th January 2025, 20:23
Me neither :p
Wait it's a genre?:eek:

Well, I wouldn't be surprised. It's an out-of-the-ordinary concept ;)

jay123210599
8th January 2025, 21:59
How do I check the hashes of the APNGs?

GeoffreyA
9th January 2025, 07:17
How do I check the hashes of the APNGs?

For my part, the easiest way is with 7-Zip. Inside its file explorer, right click on a file, then CRC, and select the hash method, or "*" to calculate all methods. Also, in archives, the CRC32 of each file is listed in one of the columns.