Skip to content

Instantly share code, notes, and snippets.

@DRMacIver
Created December 28, 2010 10:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DRMacIver/757116 to your computer and use it in GitHub Desktop.
Save DRMacIver/757116 to your computer and use it in GitHub Desktop.
ppm-reader.c
#include <netpbm/pam.h>
#include <stdbool.h>
#include <stdint.h>
int main(int argc, char **argv){
int c;
while((c = getc(stdin)) != EOF){
ungetc(c, stdin);
struct pam inpam;
tuple *tuplerow;
unsigned int row;
pm_init(argv[0], 0);
pnm_readpaminit(stdin, &inpam, PAM_STRUCT_SIZE(tuple_type));
tuplerow = pnm_allocpamrow(&inpam);
for(row = 0; row < inpam.height; row++){
unsigned int column;
pnm_readpamrow(&inpam, tuplerow);
for(column = 0; column < inpam.width; ++column){
// Process pixels in here however you want.
// This is a pointer to inpam.depth many long values
// inpam.depth seems to always be 3 for ffmpeg output, but I wouldn't swear that's always true
unsigned long *pixel = tuplerow[column];
}
}
pnm_freepamrow(tuplerow);
}
}
ffmpeg -i $1 -f image2pipe -vcodec ppm pipe:1 | ppm-reader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment