This:
for(y=0; y<height; y++){
fwrite(pFrame->data[0]+y*pFrame->linesize[0], 1, width*3, pFile);
can be done with this:
fwrite(pFrame->data[0], 1, width*height*3, pFile);
which is easier to understand, at least for me, since I'm not acknowledged with ffmpeg.