[FFmpeg-devel] Fix for drawtext under FreeBSD

Eduardo M. Bragatto eduardo
Mon Dec 31 19:44:02 CET 2007

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 

     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.

Best regards,
Eduardo M. Bragatto.

More information about the ffmpeg-devel mailing list