PDA

View Full Version : fseeking to first I frame


ozzzy
25th March 2006, 15:55
Hello (Ladies and) Gentlemen

I wish to find and seek to the first found I frame (GOP ?) that exists in a video file, the beginning will most likely to be incomplete and may be anywhere in a encoded feed (that has been saved to a file).

I have some C experience and found some clues for standard mpeg files (in ffmpeg) that there was a tag for each GOP start that said

#define GOP_START_CODE 0x000001b8

so the code searched for this code and stopped, and voila you were at a start..

i know your business is not to do my coding for me but could you possibly point me in the right direction ?

Is there a tag for h.264 avc to search for in order to find the first I frame?

I have searched for a week now for a clue but i dont seem to find what i'm looking for (or i'm missing it)

what is the proper winding procedure for h.264 avc ?
(or where should i look for it ?)


thank you very much,

oz

drmpeg
26th March 2006, 13:00
Here's a good starting point. For a larger and more useful program based on the simple loop below, see:

http://www.w6rz.net/xport.zip

Ron


/*
Bitstream Parser
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define TRUE 1
#define FALSE 0

#define GOP_START_CODE 0x000001b8

int main(int argc, char **argv)
{
FILE *fp;
static unsigned char buffer[16384];
int i, length;
static unsigned int parse = 0;

if (argc != 2) {
fprintf(stderr, "usage: parse <infile>\n");
exit(-1);
}

/*--- open binary file (for parsing) ---*/
fp = fopen(argv[1], "rb");
if (fp == 0) {
fprintf(stderr, "Cannot open bitstream file <%s>\n", argv[1]);
exit(-1);
}

while(!feof(fp)) {
length = fread(&buffer[0], 1, 16384, fp);
for(i = 0; i < length; i++) {
parse = (parse << 8) + buffer[i];
if (parse == GOP_START_CODE) {
printf("GOP startcode found\n");
}
}
}
fclose(fp);
return 0;
}

ozzzy
28th March 2006, 20:52
thank you sooooo very much!