Created
July 1, 2021 19:08
-
-
Save kuzux/d3531f080bdb01d909f429648ebe6b70 to your computer and use it in GitHub Desktop.
anal_annexb.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdbool.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
FILE* fp; | |
size_t N; | |
uint8_t* buf; | |
int main(int argc, char** argv) { | |
if(argc < 2) { | |
printf("USAGE: anal_annexb filename"); | |
return 1; | |
} | |
fp = fopen(argv[1], "rb"); | |
assert(fp); | |
int rc; | |
rc = fseek(fp, 0, SEEK_END); | |
assert(!rc); | |
N = ftell(fp); | |
rc = fseek(fp, 0, SEEK_SET); | |
assert(!rc); | |
buf = malloc(N); | |
assert(buf); | |
rc = fread(buf, 1, N, fp); | |
assert(rc == N); | |
int prev_nalu = -1; | |
for(int i=0; i<N-3; i++) { | |
bool found = false; | |
int start = i; | |
if(buf[i]==0 && buf[i+1] == 0 && buf[i+2] == 0 && buf[i+3] == 1) { | |
found = true; | |
start += 4; | |
} else if (buf[i]==0 && buf[i+1] == 0 && buf[i+2] == 1) { | |
found = true; | |
start += 3; | |
} | |
if(found && start != prev_nalu) { | |
prev_nalu = start; | |
uint8_t header = buf[start]; | |
printf("nal unit at offset %d header 0x%02x\n", start, header); | |
} | |
} | |
fclose(fp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment