2

I'm trying to test the amount of information lost with some different video codecs. I've got a python script which uses PyPNG to write a series of 8 bit RGB images. I then encode it using avconv, for instance

avconv -r 1 -i ../frames/data%03d.png -c:v ffv1 -qscale:v 0 -r 1 

outffv1.avi

I then decode this back into pngs like so

avconv -r 1 -i outffv1.avi -r 1 ./outffv1/frame%03d.png

But when I compare the images before and after the video compression, they are different (mean absolute error of ~~15%). The thing that is confusing me is that this is true (give or take) independent of the codec.

For instance, I get similar answers for libtheora for a range of qscale values.

The png encoding i.e. write to png, and immediately load back in without and video compression step, is lossless.

UPDATE - more precise worked example:

Single input frame here: https://www.dropbox.com/s/2utk1xs2t8heai9/data001.png?dl=0 Encoded to video like this: avconv -r 1 -i ./frames/data%03d.png -c:v ffv1 -qscale:v 0 -r 1 outffv1.avi resultant video here: https://www.dropbox.com/s/g1babae2a41v914/outffv1.avi?dl=0 decoded to a png again here: https://www.dropbox.com/s/8i8zg1qn7dxsgat/out001.png?dl=0 using this command: avconv -r 1 -i outffv1.avi -qscale:v 31 -r 1 out%03d.png and image magick differenced like this compare out001.png ./frames/data001.png diff.png to give this (non-zero) diff https://www.dropbox.com/s/vpouk54p0dieqif/diff.png?dl=0

llogan
  • 121,796
  • 28
  • 232
  • 243
nrob
  • 861
  • 1
  • 8
  • 22
  • Your question is not very clear. Do you mean to say that you didn't expect png encoding to be lossless? PNG supports loss-less coding – ARK Dec 15 '15 at 14:32
  • I expect/want the avconv encoding from video to png to be lossless. Do you know if it is, or how to make it so? – nrob Dec 15 '15 at 14:56
  • @nrob Can you share a sample png? How are you comparing? – aergistal Dec 15 '15 at 15:16
  • I'm loading them into python using pypng and then comparing using numpy. Here's a sample png https://www.dropbox.com/s/9qc0809kyqm4pi5/data000.png?dl=0 – nrob Dec 15 '15 at 15:21
  • @nrob Using the original 4K image with `ffmpeg` and `ffv1` failed for me due to int limits, I have to see what's wrong since I'm on x64. Encoding the provided PNG scaled to 2048x2048 to `ffv1` (which is lossless) in `AVI` and extracting the frames showed no differences with imagemagick's `compare`. Theora is lossy AFAIK. – aergistal Dec 15 '15 at 16:05
  • Im confused then - because that's not what happened when I did it. I'll update the question with a more precise, stripped down example with data. btw I mentioned the Theora because it was apparently the same data loss as ffv1, which suggested that the data wasn't lost in the video compression, but somewhere else – nrob Dec 15 '15 at 16:49

1 Answers1

2

Your video file most likely uses the YUV color format. PNG uses RGB. The conversion of the color is not a lossless process.

szatmary
  • 29,969
  • 8
  • 44
  • 57