Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve accuracy of frame rate calculation. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions yamdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ typedef struct {

// Calculated values
size_t ntags; // # of video tags
size_t nframetags; // # of actual frame tags (not sequence headers)
double framerate; // ntags / duration
double datarate; // datasize / duration
uint64_t datasize; // Size of the video data
Expand Down Expand Up @@ -709,6 +710,7 @@ int freeFLV(FLV_t *flv) {
int analyzeFLV(FLV_t *flv, FILE *fp) {
int rv;
size_t i, index;
unsigned char flagBytes[2];
unsigned char flags;
FLVTag_t *flvtag;

Expand Down Expand Up @@ -767,7 +769,13 @@ int analyzeFLV(FLV_t *flv, FILE *fp) {
flv->video.lasttimestamp = flvtag->timestamp;
flv->video.lastframeindex = i;

readFLVTagData(&flags, 1, flvtag, fp);
readFLVTagData(flagBytes, 2, flvtag, fp);
flags = flagBytes[0];

// All non-H.264 video tags, and all H.264 NALU tags, should be actual video frames.
if (((flags & 0xf) != 7) || (flagBytes[1] == 1)) {
flv->video.nframetags++;
}

// Keyframes
flvtag->keyframe = (flags >> 4) & 0xf;
Expand Down Expand Up @@ -862,8 +870,8 @@ int analyzeFLV(FLV_t *flv, FILE *fp) {
#endif

// Calculate video framerate
if(flv->video.ntags != 0)
flv->video.framerate = (double)flv->video.ntags / (double)flv->video.lasttimestamp * 1000.0;
if(flv->video.nframetags > 1)
flv->video.framerate = ((double)flv->video.nframetags - 1) / (double)flv->video.lasttimestamp * 1000.0;

// Calculate video datarate
if(flv->video.datasize != 0)
Expand All @@ -874,6 +882,7 @@ int analyzeFLV(FLV_t *flv, FILE *fp) {
fprintf(stderr, "[FLV] video.lasttimestamp = %d ms\n", flv->video.lasttimestamp);
fprintf(stderr, "[FLV] video.lastframeindex = %d\n", flv->video.lastframeindex);
fprintf(stderr, "[FLV] video.ntags = %d\n", flv->video.ntags);
fprintf(stderr, "[FLV] video.nframetags = %d\n", flv->video.nframetags);
fprintf(stderr, "[FLV] video.framerate = %f fps\n", flv->video.framerate);
fprintf(stderr, "[FLV] video.datasize = %" PRIu64 " kb\n", flv->video.datasize);
fprintf(stderr, "[FLV] video.datarate = %f kbit/s\n", flv->video.datarate);
Expand Down