[Ffmpeg-devel] [PATCH] Allow choosing display and screen number for x11grab device
Michael Niedermayer
michaelni
Fri Dec 15 11:05:33 CET 2006
Hi
On Thu, Dec 14, 2006 at 10:32:55PM +0100, Panagiotis Issaris wrote:
> Hi,
>
> On Thu, Dec 14, 2006 at 09:36:11PM +0100, Michael Niedermayer wrote:
> >[...]
> > > > > + if (offset) {
> > > > > + sscanf(offset, "%d,%d", &x_off, &y_off);
> > > > > + *offset = 0;
> > > >
> > > > hmm that writes into ap->device, why?
> > > To cut off the +xoffset,yoffset part to make it a valid X display name. I was
> > > not aware that ap->device would be reused or that it would be a problem for
> > > other reasons, but I can surely change it to pass a copy of a part of the string
> > > instead of a modified ("truncated") ap->device.
> >
> > i dont think its reused but changing it seems hackish ...
> I agree. I was just a bit too enthuosiastic about the x11grabbing functionality
> for creating screencasts :) And, I prefer to run a nested X server and grab all
> of its contents, which is why I hastely wrote the patch =)
>
> How about this updated version of the patch?
>
> I was wondering how to do the checking for the memalloc failing only once, but
> in the end, I figured that for the strdup case, I really did not need to check
> it, as XOpenDisplay can take NULL as a parameter, meaning that it will open a
> connection to the default display. It looks a bit bad though, which is why I
> added the comment explaining this.
>
> With friendly regards,
> Takis
> Index: doc/ffmpeg-doc.texi
> ===================================================================
> --- doc/ffmpeg-doc.texi (revision 7319)
> +++ doc/ffmpeg-doc.texi (working copy)
> @@ -50,6 +50,13 @@
> 0.0 is display.screen number of your X11 server, same as
> the DISPLAY environment variable.
>
> + at example
> +ffmpeg -f x11grab -vd x11:0.0+10,20 /tmp/out.mpg
> + at end example
> +
> +0.0 is display.screen number of your X11 server, same as the DISPLAY environment
> +variable. 10 is the x-offset and 20 the y-offset for the grabbing.
> +
> @section Video and Audio file format conversion
>
> * FFmpeg can use any supported file format and protocol as input:
> Index: libavformat/x11grab.c
> ===================================================================
> --- libavformat/x11grab.c (revision 7319)
> +++ libavformat/x11grab.c (working copy)
> @@ -94,21 +94,40 @@
> int x_off = 0;
> int y_off = 0;
> int use_shm;
> + char *param, *offset, *displayname;
>
> - dpy = XOpenDisplay(NULL);
> - if(!dpy) {
> + if (!ap->device) {
> + av_log(s1, AV_LOG_ERROR, "AVParameters don't specify any device. Use -vd.\n");
> + return AVERROR_IO;
> + }
> +
> + param = strchr(ap->device, ':');
> + if (!param) {
> av_free(st);
> return AVERROR_IO;
> }
> +
> + offset = strchr(param, '+');
> + if (offset) {
> + int len;
> + sscanf(offset, "%d,%d", &x_off, &y_off);
> + len = offset - param;
> + displayname = av_malloc(len+1);
> + if (!displayname)
> + return -ENOMEM;
> + strncpy(displayname, param, len);
> + displayname[len] = '\0';
> + } else
> + displayname = av_strdup(param); /* if displayname becomes NULL, default display will be taken */
param = av_strdup(param);
offset = strchr(param, '+');
if (offset) {
sscanf(offset, "%d,%d", &x_off, &y_off);
*offset= 0;
}
except that patch ok
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The educated differ from the uneducated as much as the living from the
dead. -- Aristotle
More information about the ffmpeg-devel
mailing list