Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PNG Frame Extract Weirdness #15

Closed
bannsec opened this issue Feb 19, 2019 · 3 comments
Closed

PNG Frame Extract Weirdness #15

bannsec opened this issue Feb 19, 2019 · 3 comments

Comments

@bannsec
Copy link

bannsec commented Feb 19, 2019

Been banging my head on writing an apng extraction myself. It somewhat works, but I run into issues with this file. Looks like your method runs into issues too..

The file was manually edited by the author to set the number of frames to 1. The technique of looking at the chunks themselves obviously gets by that. However, many of the images that get pulled out are corrupt.

My knowledge of PNG isn't the greatest, so I'm not sure if they're corrupt due to some process error in extracting or if they started that way... Either way, both of our extraction approaches cause some of the output files to be errored.

p1ng

@eight04
Copy link
Owner

eight04 commented Feb 19, 2019

I think this file contains broken frames. Have you successfully extracted all frames within other tools?

@bannsec
Copy link
Author

bannsec commented Feb 19, 2019 via email

@eight04
Copy link
Owner

eight04 commented Feb 19, 2019

The decoding process in your link is not correct. They ignore the image width/height given by the APNG frame.

You can change the width/height of each frame manually by using some tools like tweakpng. After fixing each frame's width/height, you should get an identical result.

Here is a python version that will divide width/height by 10 when they are too large:

import struct
from apng import APNG, make_chunk

im = APNG.open("w.png")
i = 0
first_png = im.frames[0][0]
first_hdr = first_png.chunks[0][1]
for png, ctrl in im.frames:
    # fix header
    width = png.width
    if png.width == 1280:
        width = first_png.width
    elif png.width >= 1000:
        width = png.width // 10
        
    height = png.height
    if png.height == 768:
        height = first_png.height
    elif png.height >= 100:
        height = png.height // 10
        
    chunk_data = make_chunk("IHDR", struct.pack("!II", width, height) + first_hdr[16:-4])
    
    png.chunks[0] = ("IHDR", chunk_data)
    
    png.save("{}.png".format(i))
    i += 1

@eight04 eight04 closed this as completed Mar 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants