---
 libavdevice/x11grab.c |   21 +++++++++------------
 1 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/libavdevice/x11grab.c b/libavdevice/x11grab.c
index d48478b..1ef4bbd 100644
--- a/libavdevice/x11grab.c
+++ b/libavdevice/x11grab.c
@@ -56,7 +56,7 @@ struct x11_grab
 {
     AVClass *class;          /**< Class for private options. */
     int frame_size;          /**< Size in bytes of a grabbed frame */
-    AVRational time_base;    /**< Time base */
+    AVRational fps;          /**< Framerate, set by a private option. */
     int64_t time_frame;      /**< Current time */
 
     int height;              /**< Height of the grab frame */
@@ -108,6 +108,8 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters 
*ap)
         x11grab->width = ap->width;
     if (ap->height > 0)
         x11grab->height = ap->height;
+    if (ap->time_base.num)
+        x11grab->fps = (AVRational){ap->time_base.den, ap->time_base.num};
 #endif
 
     av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d 
height: %d\n", s1->filename, param, x_off, y_off, x11grab->width, 
x11grab->height);
@@ -118,11 +120,6 @@ x11grab_read_header(AVFormatContext *s1, 
AVFormatParameters *ap)
         return AVERROR(EIO);
     }
 
-    if ( ap->time_base.den <= 0) {
-        av_log(s1, AV_LOG_ERROR, "AVParameters don't have video rate. Use 
-r.\n");
-        return AVERROR(EIO);
-    }
-
     st = av_new_stream(s1, 0);
     if (!st) {
         return AVERROR(ENOMEM);
@@ -226,8 +223,7 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters 
*ap)
 
     x11grab->frame_size = x11grab->width * x11grab->height * 
image->bits_per_pixel/8;
     x11grab->dpy = dpy;
-    x11grab->time_base  = ap->time_base;
-    x11grab->time_frame = av_gettime() / av_q2d(ap->time_base);
+    x11grab->time_frame = av_gettime() * av_q2d(x11grab->fps);
     x11grab->x_off = x_off;
     x11grab->y_off = y_off;
     x11grab->image = image;
@@ -238,8 +234,8 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters 
*ap)
     st->codec->width  = x11grab->width;
     st->codec->height = x11grab->height;
     st->codec->pix_fmt = input_pixfmt;
-    st->codec->time_base = ap->time_base;
-    st->codec->bit_rate = x11grab->frame_size * 1/av_q2d(ap->time_base) * 8;
+    st->codec->time_base = (AVRational){x11grab->fps.den, x11grab->fps.num};
+    st->codec->bit_rate = x11grab->frame_size * av_q2d(x11grab->fps) * 8;
 
     return 0;
 }
@@ -381,9 +377,9 @@ x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
     /* wait based on the frame rate */
     for(;;) {
         curtime = av_gettime();
-        delay = s->time_frame * av_q2d(s->time_base) - curtime;
+        delay = s->time_frame / av_q2d(s->fps) - curtime;
         if (delay <= 0) {
-            if (delay < INT64_C(-1000000) * av_q2d(s->time_base)) {
+            if (delay < INT64_C(-1000000) / av_q2d(s->fps)) {
                 s->time_frame += INT64_C(1000000);
             }
             break;
@@ -451,6 +447,7 @@ x11grab_read_close(AVFormatContext *s1)
 static const AVOption options[] = {
     { "width",    "", offsetof(struct x11_grab, width),  FF_OPT_TYPE_INT, 
{.dbl = 640}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
     { "height",   "", offsetof(struct x11_grab, height), FF_OPT_TYPE_INT, 
{.dbl = 480}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+    { "framerate","", offsetof(struct x11_grab, fps),    FF_OPT_TYPE_RATIONAL, 
{.dbl = 25}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
     { NULL },
 };
 
-- 
1.7.5.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to