diff options
Diffstat (limited to 'ffmpeg/libavdevice/x11grab.c')
| -rw-r--r-- | ffmpeg/libavdevice/x11grab.c | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/ffmpeg/libavdevice/x11grab.c b/ffmpeg/libavdevice/x11grab.c index 6124006..0e7b6ae 100644 --- a/ffmpeg/libavdevice/x11grab.c +++ b/ffmpeg/libavdevice/x11grab.c @@ -76,8 +76,11 @@ struct x11grab { int draw_mouse; /**< Set by a private option. */ int follow_mouse; /**< Set by a private option. */ int show_region; /**< set by a private option. */ - char *framerate; /**< Set by a private option. */ + AVRational framerate; /**< Set by a private option. */ + int palette_changed; + uint32_t palette[256]; + Cursor c; Window region_win; /**< This is used by show_region option. */ }; @@ -166,7 +169,9 @@ x11grab_read_header(AVFormatContext *s1) int use_shm; char *dpyname, *offset; int ret = 0; - AVRational framerate; + Colormap color_map; + XColor color[256]; + int i; dpyname = av_strdup(s1->filename); if (!dpyname) @@ -184,10 +189,6 @@ x11grab_read_header(AVFormatContext *s1) *offset= 0; } - if ((ret = av_parse_video_rate(&framerate, x11grab->framerate)) < 0) { - av_log(s1, AV_LOG_ERROR, "Could not parse framerate: %s.\n", x11grab->framerate); - goto out; - } av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n", s1->filename, dpyname, x_off, y_off, x11grab->width, x11grab->height); @@ -262,6 +263,15 @@ x11grab_read_header(AVFormatContext *s1) case 8: av_log (s1, AV_LOG_DEBUG, "8 bit palette\n"); input_pixfmt = AV_PIX_FMT_PAL8; + color_map = DefaultColormap(dpy, screen); + for (i = 0; i < 256; ++i) + color[i].pixel = i; + XQueryColors(dpy, color_map, color, 256); + for (i = 0; i < 256; ++i) + x11grab->palette[i] = (color[i].red & 0xFF00) << 8 | + (color[i].green & 0xFF00) | + (color[i].blue & 0xFF00) >> 8; + x11grab->palette_changed = 1; break; case 16: if ( image->red_mask == 0xf800 && @@ -308,7 +318,7 @@ x11grab_read_header(AVFormatContext *s1) x11grab->frame_size = x11grab->width * x11grab->height * image->bits_per_pixel/8; x11grab->dpy = dpy; - x11grab->time_base = av_inv_q(framerate); + x11grab->time_base = av_inv_q(x11grab->framerate); x11grab->time_frame = av_gettime() / av_q2d(x11grab->time_base); x11grab->x_off = x_off; x11grab->y_off = y_off; @@ -353,7 +363,6 @@ paint_mouse_pointer(XImage *image, struct x11grab *s) * Anyone who performs further investigation of the xlib API likely risks * permanent brain damage. */ uint8_t *pix = image->data; - Cursor c; Window w; XSetWindowAttributes attr; @@ -361,9 +370,10 @@ paint_mouse_pointer(XImage *image, struct x11grab *s) if (image->bits_per_pixel != 24 && image->bits_per_pixel != 32) return; - c = XCreateFontCursor(dpy, XC_left_ptr); + if(!s->c) + s->c = XCreateFontCursor(dpy, XC_left_ptr); w = DefaultRootWindow(dpy); - attr.cursor = c; + attr.cursor = s->c; XChangeWindowAttributes(dpy, w, CWCursor, &attr); xcim = XFixesGetCursorImage(dpy); @@ -493,6 +503,16 @@ x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt) pkt->data = image->data; pkt->size = s->frame_size; pkt->pts = curtime; + if (s->palette_changed) { + uint8_t *pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, + AVPALETTE_SIZE); + if (!pal) { + av_log(s, AV_LOG_ERROR, "Cannot append palette to packet\n"); + } else { + memcpy(pal, s->palette, AVPALETTE_SIZE); + s->palette_changed = 0; + } + } screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); @@ -602,7 +622,7 @@ static const AVOption options[] = { { "centered", "keep the mouse pointer at the center of grabbing region when following", 0, AV_OPT_TYPE_CONST, {.i64 = -1}, INT_MIN, INT_MAX, DEC, "follow_mouse" }, - { "framerate", "set video frame rate", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "ntsc"}, 0, 0, DEC }, + { "framerate", "set video frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "ntsc"}, 0, 0, DEC }, { "show_region", "show the grabbing region", OFFSET(show_region), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC }, { "video_size", "set video frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = "vga"}, 0, 0, DEC }, { NULL }, |
