Possible Problem with PNG Output

488 views
Skip to first unread message

Fabian Russell

unread,
May 6, 2020, 1:08:51 PM5/6/20
to MathGL
Hello,

I am using MathGL to produce a series of PNG images that will be combined using
FFMPEG to create an animation.

The PNG images are produced from C code with: 

mgl_write_png(gr, "frame0000.png", "");

The PNG images can be viewed with any image viewer.  However, when I invoke
FFMPEG I get an error message:

ffmpeg -i frame0000.png -loglevel error -f null -

"Invalid PNG signature 0x49454E44.
Error while decoding stream #0:0: Invalid data found when processing input"

I can correct this by re-converting the PNG file:

convert frame0000.png frame0000-fixed.png

Is this a problem with MathGL output or is the problem with ffmpeg?


Alexey Balakin

unread,
May 6, 2020, 6:07:18 PM5/6/20
to mat...@googlegroups.com
Dear Fabian,

MathGL use the standard libpng for output. So, most probably ffmpeg don't understand some novel feature(s) of PNG format?

But. Why you don't use JPEG output? The ffmpeg convert JPEG files to video much faster with smaller blurring (as I remember).

06.05.2020 17:09, Fabian Russell пишет:
--
You received this message because you are subscribed to the Google Groups "MathGL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathgl+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathgl/33e50736-4d57-4759-833d-182156a89f7b%40googlegroups.com.


-- 
Kind regards,
Alexey Balakin

Fabian Russell

unread,
May 13, 2020, 12:57:06 PM5/13/20
to MathGL


On Wednesday, May 6, 2020 at 6:07:18 PM UTC-4, Alexey Balakin wrote:

MathGL use the standard libpng for output. So, most probably ffmpeg don't understand some novel feature(s) of PNG format? 


Libpng offers the pngcheck utility:


Using pngcheck on a PNG image created with mgl_write_png() results in an error report:

# pngcheck frame0000.png 
frame0000.png  additional data after IEND chunk
ERROR: frame0000.png

It seems that extra data is somehow erroneously written to the PNG which causes
ffmpeg to fail.

Would someone please confirm this result by writing a PNG image with mathgl
to see of the same error occurs?


 
But. Why you don't use JPEG output? The ffmpeg convert JPEG files to video much faster with smaller blurring (as I remember).



JPEG compression atrifacts will tend to distort line art images such as mathematical plots
and are not recommended.  PNG uses a different type of compression and the same
artifacts do not occur.




D Haley

unread,
May 13, 2020, 1:08:59 PM5/13/20
to Fabian Russell, mat...@googlegroups.com
I can confirm I get this error on my system - it looks like there is a
double IEND in the file.

From the PNG spec:
4.1.4. IEND Image trailer
The IEND chunk must appear LAST. It marks the end of the PNG datastream.
The chunk's data field is empty.


I think this is because png_write_png is called, and then png_write_end
- I think you only need to call png_write_png, and not both. This is in
export.cpp, mgl_png_save.

An example can be found here:

https://dev.w3.org/Amaya/libpng/example.c

where png_write_png is only called, without png_write_end.
> --
> You received this message because you are subscribed to the Google
> Groups "MathGL" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to mathgl+un...@googlegroups.com
> <mailto:mathgl+un...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mathgl/a50b7539-df87-4cc0-bf1b-64f88c62f781%40googlegroups.com
> <https://groups.google.com/d/msgid/mathgl/a50b7539-df87-4cc0-bf1b-64f88c62f781%40googlegroups.com?utm_medium=email&utm_source=footer>.

Bildschirmfoto_2020-05-13_17-54-45.png

D Haley

unread,
May 13, 2020, 6:02:55 PM5/13/20
to mat...@googlegroups.com
Dear List,

Please find a patch that removes the calls to png_write_end, I have
checked this on Revision 1652, and it applies cleanly.

The output of pngcheck indicates that once the patch is applied, the
file is OK.
patch_iend

Fabian Russell

unread,
May 13, 2020, 7:58:20 PM5/13/20
to MathGL


On Wednesday, May 13, 2020 at 6:02:55 PM UTC-4, D Haley wrote:
Dear List,

Please find a patch that removes the calls to png_write_end, I have
checked this on Revision 1652, and it applies cleanly.


Thank you very much for the patch.  I applied the patch and re-compiled
mathgl and the PNG problem is gone.

Ffmpeg no longer reports the error:

ffmpeg -i frame0000.png -loglevel error -f null -


I can now create animations without having to first convert the PNG
files.


mathgl....@gmail.com

unread,
Jun 22, 2020, 5:13:25 PM6/22/20
to mat...@googlegroups.com
Thank you for the patch. I'll add it in the recent svn commit.

чт, 14 мая 2020 г. в 02:58, Fabian Russell <fr31...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "MathGL" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathgl+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathgl/2398b97d-5a26-4c8a-ac18-fd3b05d0708c%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages