[FFmpeg-cvslog] avdevice/v4l2: only use average frame rate if set

Michael Niedermayer git at videolan.org
Sun Feb 2 00:21:13 CET 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sun Feb  2 00:11:16 2014 +0100| [0997c2504b25cbc2856800fc063395dcd40b2bf7] | committer: Michael Niedermayer

avdevice/v4l2: only use average frame rate if set

It might be unset on some platforms with some drivers and some input

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0997c2504b25cbc2856800fc063395dcd40b2bf7
---

 libavdevice/v4l2.c |   29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index b4f65d3..96a272c 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -447,18 +447,20 @@ static int init_convert_timestamp(AVFormatContext *ctx, int64_t ts)
         return 0;
     }
 #if HAVE_CLOCK_GETTIME && defined(CLOCK_MONOTONIC)
-    now = av_gettime_monotonic();
-    if (s->ts_mode == V4L_TS_MONO2ABS ||
-        (ts <= now + 1 * AV_TIME_BASE && ts >= now - 10 * AV_TIME_BASE)) {
-        AVRational tb = {AV_TIME_BASE, 1};
-        int64_t period = av_rescale_q(1, tb, ctx->streams[0]->avg_frame_rate);
-        av_log(ctx, AV_LOG_INFO, "Detected monotonic timestamps, converting\n");
-        /* microseconds instead of seconds, MHz instead of Hz */
-        s->timefilter = ff_timefilter_new(1, period, 1.0E-6);
-        if (!s->timefilter)
-            return AVERROR(ENOMEM);
-        s->ts_mode = V4L_TS_CONVERT_READY;
-        return 0;
+    if (ctx->streams[0]->avg_frame_rate.num) {
+        now = av_gettime_monotonic();
+        if (s->ts_mode == V4L_TS_MONO2ABS ||
+            (ts <= now + 1 * AV_TIME_BASE && ts >= now - 10 * AV_TIME_BASE)) {
+            AVRational tb = {AV_TIME_BASE, 1};
+            int64_t period = av_rescale_q(1, tb, ctx->streams[0]->avg_frame_rate);
+            av_log(ctx, AV_LOG_INFO, "Detected monotonic timestamps, converting\n");
+            /* microseconds instead of seconds, MHz instead of Hz */
+            s->timefilter = ff_timefilter_new(1, period, 1.0E-6);
+            if (!s->timefilter)
+                return AVERROR(ENOMEM);
+            s->ts_mode = V4L_TS_CONVERT_READY;
+            return 0;
+        }
     }
 #endif
     av_log(ctx, AV_LOG_ERROR, "Unknown timestamps\n");
@@ -949,7 +951,8 @@ static int v4l2_read_header(AVFormatContext *s1)
         st->codec->codec_tag = MKTAG('Y', 'V', 'U', '9');
     st->codec->width = s->width;
     st->codec->height = s->height;
-    st->codec->bit_rate = s->frame_size * av_q2d(st->avg_frame_rate) * 8;
+    if (st->avg_frame_rate.den)
+        st->codec->bit_rate = s->frame_size * av_q2d(st->avg_frame_rate) * 8;
 
     return 0;
 }



More information about the ffmpeg-cvslog mailing list