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;
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值