MB Probe
This article contains mere code.
/*
* It is a standalone console application that reveals macroblock
* level information for YUV 4:2:0 QCIF raw video stream only.
* It is generally used as a small tool for video development and
* associated debugging.
*
* The interface of the application will guide those who use it.
*
*/
#include <stdio.h>
typedef unsigned char BYTE;
int filelength (FILE *f)
{
int len;
int cur = ftell(f);
fseek(f, 0, SEEK_END);
len = ftell(f);
fseek(f, cur, SEEK_SET);
return len;
}
int main (int argc, char **argv)
{
FILE *fIn = NULL;
int picNr;
int mbNr;
int flen;
int strideY = 176;
int strideUv = 176/2;
int picBits = 38016;
int picBitsY = strideY * 144;
int picBitsUv = strideUv * 72;
int picTotal = flen / picBits;
int mbTotal = 99;
int i;
if (argc < 1)
{
printf(": Video file not specified./n");
return 0;
}
printf("file = %s/n", argv[1]);
fIn = fopen(argv[1], "rb");
if (fIn == NULL)
{
printf(": Error opening video file./n");
return 0;
}
flen = filelength(fIn);
while (1)
{
int mbVert, mbHori;
BYTE mbY[16*16], mbU[8*8], mbV[8*8];
BYTE *dst;
printf("Input pic number>");
scanf("%d", &picNr);
if (picNr >= picTotal)
{
printf("Error, the frame number you input exceeds the total
number of pics./n");
printf("Take the maximum number allowed./n");
picNr = picTotal - 1;
}
printf("Input macroblock number>");
scanf("%d", &mbNr);
if (mbNr >= mbTotal)
{
printf("Error, the macroblock number you input exceeds the total
number of macroblocks./n");
printf("Take the maximum number allowed./n");
mbNr = mbNr - 1;
}
mbVert = mbNr / 11;
mbHori = mbNr % 11;
// read Y
dst = mbY;
printf("offset = %d/n", picNr*picBits + mbVert*16*strideY +
mbHori*16);
fseek(fIn, picNr*picBits + mbVert*16*strideY + mbHori*16,
SEEK_SET);
for (i = 0; i < 16; i++)
{
fread(dst, 1, 16, fIn);
fseek(fIn, strideY - 16, SEEK_CUR);
dst += 16;
}
// read U
dst = mbU;
fseek(fIn, picNr*picBits + picBitsY + mbVert*8*strideUv +
mbHori*8, SEEK_SET);
for (i = 0; i < 8; i++)
{
fread(dst, 1, 8, fIn);
fseek(fIn, strideUv - 8, SEEK_CUR);
dst += 8;
}
// read V
dst = mbV;
fseek(fIn, picNr*picBits + picBitsY + strideUv +
mbVert*8*strideUv + mbHori*8, SEEK_SET);
for (i = 0; i < 8; i++)
{
fread(dst, 1, 8, fIn);
fseek(fIn, strideUv - 8, SEEK_CUR);
dst += 8;
}
printf("== Y ==/n");
for (i = 0; i < 256; i++)
{
printf("%3d ", mbY[i]);
if (i % 16 == 15)
{
printf("/n");
}
}
printf("/n== U ==/n");
for (i = 0; i < 64; i++)
{
printf("%3d ", mbU[i]);
if (i % 8 == 7)
{
printf("/n");
}
}
printf("/n== V ==/n");
for (i = 0; i < 64; i++)
{
printf("%3d ", mbV[i]);
if (i % 8 == 7)
{
printf("/n");
}
}
printf("Press 'q' to quit or others to do once more./n");
if (getch() == 'q')
{
break;
}
}
bail:
fclose(fIn);
return 0;
}
enjoy every minute of an appless, googless and oracless life