0

I am trying to encode a RGB24 image sequence into a mathematically (not merely visually) lossless video. huffyuv was suggested on many online forums so I tried the following.

ffmpeg -i frames\%06d.png  -vcodec huffyuv test.avi

The resulting video was then decoded into frames again using ffmpeg

ffmpeg -i test.avi outframes\%06d.png

However, the input and output frames are not bit-by-bit identical as promised by huffyuv here. Any idea how I can accomplish this? My eventual goal is to read the video file using OpenCV but I am willing to cross that bridge later once I obtain a losslessly encoded video file.

This SO question mentions an attempt to obtain a lossless h264 avi and the summary of responses seems to indicate h264 cannot completely accomplish lossless encoding.

Once again, to emphasize, I am interested in bit-by-bit identical encoding, not just visually similar. Large file sizes are acceptable as is large compression/decompression time.

Community
  • 1
  • 1
curryage
  • 481
  • 1
  • 6
  • 19
  • 1
    For what purpose? - what is it you intend to accomplish with the result of this operation that you cannot accomplish with the image sequence, or a zip/tarball of the image sequence? – moonshadow Apr 25 '13 at 16:01
  • 1
    Note that the bitwise differences you see likely arise from the rgb/yuv conversion rather than the compression. If you need input and output RGB images to be bitwise identical you'll probably want a means of encoding video that works in RGB colourspace. – moonshadow Apr 25 '13 at 16:05
  • One reason is that I need the data to be copied over the network and I do not want to copy the image sequence. From what I have read, huffyuv produces a decent compression, although it obviously would not match a lossly compression size. The other reason is convenience. I would like to be able to read the file as an avi. – curryage Apr 25 '13 at 16:06
  • @moonshadow huffyuv can work with RGB colorspace as mentioned [here](http://en.wikipedia.org/wiki/Huffyuv) – curryage Apr 25 '13 at 16:09
  • ffmpeg -vcodec ffv1 -pix_fmt rgb24 is probably your best bet – moonshadow Apr 25 '13 at 16:09
  • @moonshadow I tried `ffmpeg -vcodec ffv1 -pix_fmt rgb24`. Results are visually similar but not bitwise. One suspicion I have is about the comparison process. The png image sequence was produced using OpenCV's `cvSaveImage()`. However, I use MATLAB's `imread` to load the original and decoded-from-avi frames. I am going to try using OpenCV to read the images for comparison. – curryage Apr 25 '13 at 16:17
  • 1
    Are you certain that the differences are in actual RGB values rather than how they are encoded in .png format? Different png encodes will give a different bytestream for the exact same picture. – Asik Apr 25 '13 at 18:29
  • 1
    Using the MD5 muxer in ffmpeg will probably be useful for your comparisons as shown in [How to compare two lossless media files?](http://superuser.com/a/532223/110524). – llogan Apr 28 '13 at 15:58
  • Use the approach described in the link you already added above, it actually works: http://stackoverflow.com/questions/6701805/h264-lossless-coding/12303936#18506577 – MoDJ Nov 12 '14 at 01:20

0 Answers0