From 59eddb17ffad8595804cfc7d6a25f644b042fc54 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 23 Jan 2011 02:06:19 +0100 Subject: Display the instant frame rate for each frame during capture This helps debugging framerate related problems. Thanks to Martin Hostettler for submitting a first version of this patch. Signed-off-by: Laurent Pinchart --- yavta.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/yavta.c b/yavta.c index e25013b..d6fd3b2 100644 --- a/yavta.c +++ b/yavta.c @@ -815,6 +815,7 @@ static int video_do_capture(struct device *dev, unsigned int nframes, { char *filename = NULL; struct timeval start; + struct timeval last; struct timeval ts; struct v4l2_buffer buf; unsigned int size; @@ -835,6 +836,7 @@ static int video_do_capture(struct device *dev, unsigned int nframes, size = 0; gettimeofday(&start, NULL); + last = start; for (i = 0; i < nframes; ++i) { /* Dequeue a buffer. */ @@ -860,11 +862,17 @@ static int video_do_capture(struct device *dev, unsigned int nframes, size += buf.bytesused; + fps = (buf.timestamp.tv_sec - last.tv_sec) * 1000000 + + buf.timestamp.tv_usec - last.tv_usec; + fps = fps ? 1000000.0 / fps : 0.0; + gettimeofday(&ts, NULL); - printf("%u (%u) [%c] %u %u bytes %ld.%06ld %ld.%06ld\n", i, buf.index, + printf("%u (%u) [%c] %u %u bytes %ld.%06ld %ld.%06ld %.3f fps\n", i, buf.index, (buf.flags & V4L2_BUF_FLAG_ERROR) ? 'E' : '-', buf.sequence, buf.bytesused, buf.timestamp.tv_sec, - buf.timestamp.tv_usec, ts.tv_sec, ts.tv_usec); + buf.timestamp.tv_usec, ts.tv_sec, ts.tv_usec, fps); + + last = buf.timestamp; /* Save the image. */ if (dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && filename_prefix && !skip) { -- cgit v1.2.3