[FFmpeg-devel] Fix for drawtext under FreeBSD

Víctor Paesa wzrlpy
Wed Jan 2 09:55:48 CET 2008

Eduardo M. Bragatto said:
> Hi there --
> I'm not a developer but I just came across an problem using drawtext
> vhook under FreeBSD that I managed to fix. Basically drawtext was
> complaining that I was not passing the parameters -t and -f, although I
> was.
> The vhook module has the following lines to parse it's command line
> parameters:
>      optind = 0;
>      while ((c = getopt(argc, argv, "f:t:T:x:y:s:c:C:bo")) > 0) {
> On FreeBSD, getopt() will return -1 when the first non-argument  is
> found. So, if optind is set to ZERO, the first string it will check will
>  be the module's filename, which of course is not considered an argument
>  (as it doesn't have "-" on the beginning). So, regardless of the
> parameters I was passing, it was always failing. See getopt() manpage
> for FreeBSD[1].
> On Linux, getopt() permutes the contents of argv during scan to make
> sure all non-argument strings are at the end, so having optind set to
> ZERO doesn't really make any difference as the module's filename would
> be shifted to the end and the parameters would be properly parsed. See
> getopt() manpage for Linux[2].
> The solution is simply change:
> optind = 1;
> That way, both Linux and FreeBSD will skip the vhook's filename and will
>  check only the parameters as we want.
> By the way, the vhook watermark.c uses this same approach I'm suggesting
>  here (setting optind=1).
> I have tested the module with this little modification both on Linux and
>  FreeBSD and it now works.

The OpenGroup says that optind shall be initialized to 1 by the system,
so optind = 1 is probably correct.

The vhook framework is deprecated but bug fixes are still accepted so
please provide one patch in diff -Naur format for *all* the vhooks that
set optind to zero.

If no developer raises his voice against, I will apply it in a week.


More information about the ffmpeg-devel mailing list