0

Say I have 5 images that are quite similar. I'd like to compress images 2, 3, 4 and 5 based on the first image, somewhat similar to the way P frames are generated from an I frame.

  • In general, what's the best way/tool to do so?
  • For instance, using FFMPEG, is it possible to generate P frames and store them in a separate file?

Edit: Although similar, I am not looking for simply generating a diff between the two images. My goal is to somehow use the information in the first image to make the consecutive images much smaller. If I simply do a diff, the diff itself is about the same size (about 10% reduced) which is not as much as I expect. If I generate a mp4 video including these 5 frames, the video size is much less than putting 5 frames in a file, which probably has to with frame predications based on the I frames. Is there a way to generate those predicted frames one by one and store them individually?

  • You could use the blend filter in ffmpeg in difference mode and store the result. This won't strictly be P frames but you can generate the original by performing addition mode blend. – Gyan Oct 11 '16 at 02:22
  • I checked the blend filter. It seems to be used for overlaying frames, not consecutive frames. Can you please give an example? – Navid Ahmadi Oct 11 '16 at 16:38
  • Overlaying frames is one utility of the blend filter. Computing pixel differences is another. It's late here so I'll supply an example tomorrow. – Gyan Oct 11 '16 at 17:11
  • I will wait till tomorrow. I appreciate it :) – Navid Ahmadi Oct 11 '16 at 17:42

1 Answers1

1

Here's the basic syntax:

Let's say I.png is your base frame and P1.png is the frame which you wish to reduce to its difference from I.png

Then

ffmpeg -i P1.png -i I.png -lavfi blend=all_expr='A-B' D1.png

produces the difference frame D1.png.

To reconstruct P1 from I and D1, run

ffmpeg -i D1.png -i I.png -lavfi blend=all_expr='A+B' P1-r.png

PI-r.png will be identical to P1.png.

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Thanks for the code, but this seems to be a simple diff of images, that I could also achieve using ImageMagick. I will edit the question to explain what I am looking for. – Navid Ahmadi Oct 11 '16 at 19:41
  • Yes. Did you also want intra+inter prediction? – Gyan Oct 12 '16 at 02:04
  • Probably yes, if intra+inter predictions is what causes the video files to be much smaller than just putting a number of frames together. Is there a way to achieve this with ffmpeg? I edited the question to explain this better. Thanks. – Navid Ahmadi Oct 17 '16 at 17:38
  • I will keep the first frame, which is basically the I Frame. Then everytime I receive a P frame data, I'd like to calculate the actual frame using the P frame and the I frame it was coded with. My problem is that I don't have all the frames in hand when encoding them. I received them one by one on a regular time interval, and I don't want to wait to receive all of them to encode the whole movie and pass them on. Rather, I want to encode an individual frame and pass it on immediately. – Navid Ahmadi Oct 17 '16 at 19:00
  • So, you will write the code to decode, using ffmpeg APIs? – Gyan Oct 18 '16 at 03:27
  • Ideally not. But if it's possible to decode it with ffmpeg, I'd like to know about it. At this point, I just want to know if this is possible at all, in any ways, through ffmpeg or any other API. And if not, what's the right way to go about it? – Navid Ahmadi Oct 18 '16 at 15:43