[libav-devel] Need help to binarize an image

Théo LAVAUX lavauxtheo at gmail.com
Wed Dec 13 12:19:56 CET 2017

Hello everyone,

I've read the ffmpeg tutorial and I'm trying to figure out how to access to
a precise pixel instead of a line of data. I would like to store all the
pixels in something like a memory buffer and then binarize and save my
frame to the ppm file. The frame is already converted to an RGB format as
you can see here;
Can someone help me out (I'm pretty new to ffmpeg) ?

This is the function we need to modify.

void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame) {
  FILE *pFile;
  char szFilename[32];
  int  y;

  // Open file
  sprintf(szFilename, "frame%d.ppm", iFrame);
  pFile=fopen(szFilename, "wb");

  // Write header
  fprintf(pFile, "P6\n%d %d\n255\n", width, height);

  // Write pixel data
  for(y=0; y<height; y++)
    fwrite(pFrame->data[0]+y*pFrame->linesize[0], 1, width*3, pFile);

  // Close file

More information about the libav-devel mailing list