Parser for NAL units

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Xico Amorim
    Junior Member
    Junior Member
    • Oct 2009
    • 1

    Parser for NAL units

    Hello,

    Im a student from Brazil and I'm trying to do a program, using C,
    that opens a .264 video and split the NAL units that are inside it...
    im trying to write the bytes of the file in a .txt file...
    but I am having some troubles...
    First of all, i cant find the end or the beginning of the nal unit...
    second, the first byte of the file is already different from the nal header that i was waiting for... the first 3 bytes always are 0 0 1.... and i dont know what it means....

    my program is this:
    (im not an expert when the subject is programming....)

    #include <cstdlib>
    #include <iostream>
    #include <fstream>
    #include <stdio.h>
    #include <string>

    int main()
    {

    char filein[30], fileout[30];
    unsigned char nalu[500000];
    int nframes,n, luma_only, j, i, bl, upsample, a,b,c,d, m,p,nfr, wi, hi,w,h, nnalu, endofnal;
    float prov;

    printf("file name in: \n");
    scanf("%s",filein);
    FILE * pFile;
    long lSize;
    size_t result;
    pFile = fopen ( filein , "rb" );

    printf("file name out: \n");
    scanf("%s",fileout);
    FILE *fileopen;
    fileopen = fopen ( fileout , "w" );


    char ch; //Para a leitura dos caracteres
    bl = 0; //count the num of bytes - not working
    while ( fscanf(pFile, "%c", &ch) != EOF )
    {
    printf ("\n TESTE!\n");
    i=0;
    endofnal = 0;
    while(endofnal==0)
    {
    i=i+1;
    nalu[i] = fgetc(pFile);
    fprintf (fileopen, "%d ", nalu[i]);
    // if (i>4) {
    if (nalu[i] == '3' || fscanf(pFile, "%c", &ch) == EOF)
    {
    endofnal = 1;
    fprintf (fileopen, "\n Numero de bytes desta nal: %d\n", i);
    bl = bl + i;
    printf ("\n Numero de bytes desta nal: %d\n", i);
    }

    // }

    }

    }
    fprintf (fileopen, "\n Num of bytes in file: %d\n", bl);
    fclose(pFile);
    fclose(fileopen);

    printf("done!");
    return 0;

    }

    someone have another way to do this??

    is lika a parser for the nal units...

    thanks anyway..

    Xico
Working...