---
libavdevice/x11grab.c | 41 +++++++++++++++++++++++++++++++----------
1 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/libavdevice/x11grab.c b/libavdevice/x11grab.c
index 0e63d09..cb643d8 100644
--- a/libavdevice/x11grab.c
+++ b/libavdevice/x11grab.c
@@ -37,6 +37,8 @@
#include "config.h"
#include "libavformat/avformat.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
#include <time.h>
#include <X11/X.h>
#include <X11/Xlib.h>
@@ -52,6 +54,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 */
int64_t time_frame; /**< Current time */
@@ -100,7 +103,12 @@ x11grab_read_header(AVFormatContext *s1,
AVFormatParameters *ap)
*offset= 0;
}
- 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, ap->width, ap->height);
+ if (ap->width > 0)
+ x11grab->width = ap->width;
+ if (ap->height > 0)
+ x11grab->height = ap->height;
+
+ 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);
dpy = XOpenDisplay(param);
if(!dpy) {
@@ -108,8 +116,8 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters
*ap)
return AVERROR(EIO);
}
- if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
- av_log(s1, AV_LOG_ERROR, "AVParameters don't have video size and/or
rate. Use -s and -r.\n");
+ if ( ap->time_base.den <= 0) {
+ av_log(s1, AV_LOG_ERROR, "AVParameters don't have video rate. Use
-r.\n");
return AVERROR(EIO);
}
@@ -130,7 +138,7 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters
*ap)
ZPixmap,
NULL,
&x11grab->shminfo,
- ap->width, ap->height);
+ x11grab->width,x11grab->height);
x11grab->shminfo.shmid = shmget(IPC_PRIVATE,
image->bytes_per_line * image->height,
IPC_CREAT|0777);
@@ -149,7 +157,7 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters
*ap)
} else {
image = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)),
x_off,y_off,
- ap->width,ap->height,
+ x11grab->width, x11grab->height,
AllPlanes, ZPixmap);
}
@@ -213,10 +221,9 @@ x11grab_read_header(AVFormatContext *s1,
AVFormatParameters *ap)
return -1;
}
- x11grab->frame_size = ap->width * ap->height * image->bits_per_pixel/8;
+
+ x11grab->frame_size = x11grab->width * x11grab->height *
image->bits_per_pixel/8;
x11grab->dpy = dpy;
- x11grab->width = ap->width;
- x11grab->height = ap->height;
x11grab->time_base = ap->time_base;
x11grab->time_frame = av_gettime() / av_q2d(ap->time_base);
x11grab->x_off = x_off;
@@ -226,8 +233,8 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters
*ap)
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->codec->codec_id = CODEC_ID_RAWVIDEO;
- st->codec->width = ap->width;
- st->codec->height = ap->height;
+ 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;
@@ -439,6 +446,19 @@ x11grab_read_close(AVFormatContext *s1)
return 0;
}
+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 },
+ { NULL },
+};
+
+static const AVClass x11_class = {
+ .class_name = "X11 grab interface",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
/** x11 grabber device demuxer declaration */
AVInputFormat ff_x11_grab_device_demuxer =
{
@@ -450,4 +470,5 @@ AVInputFormat ff_x11_grab_device_demuxer =
x11grab_read_packet,
x11grab_read_close,
.flags = AVFMT_NOFILE,
+ .priv_class = &x11_class,
};
--
1.7.5.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel