Helmut Tessarek
2012-Aug-26 20:26 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
Hello, How can I make fontconfig look for the config files in the local directory? Here is the background: I''m compiling a static ffmpeg binary with libass and fontconfig. Now ffmpeg (or actually the library which was statically linked to ffmpeg) is looking for the configuration files in a directory which does not exist on other systems. I need to have the library looking for the config files relative to the static binary. e.g.: binary: /path/to/binary/my_static_binary config files: /path/to/binary/conf.d /path/to/binary/fonts.conf or /path/to/binary/cfg/conf.d /path/to/binary/cfg/fonts.conf Any ideas how I can do this? Would --sysconfdir=. do this? Is this valid? Cheers, Helmut
Raimund Steger
2012-Aug-26 21:50 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
Helmut Tessarek wrote:> [...] > > Would --sysconfdir=. do this? Is this valid?No, this must resolve to an absolute path at compile time. But you can set FONTCONFIG_PATH to a non-default configuration root at runtime, i. e. FONTCONFIG_PATH=/path/to/binary/cfg. Raimund -- Worringer Str 31, Duesseldorf 40211 Germany home: <rs at mytum.de> +49-179-2981632 icq 16845346 work: <rs at interface-ag.de>
Helmut Tessarek
2012-Aug-26 23:27 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
Hi Raimund, On 26.08.12 17:50 , Raimund Steger wrote:> No, this must resolve to an absolute path at compile time.What about these 2 configuration parameters: --with-baseconfigdir=DIR Use DIR to store the base configuration files [default=SYSCONFDIR/fonts] --with-configdir=DIR Use DIR to store active configuration files [default=BASECONFIGDIR/conf.d] Do they have to be absolute paths as well?> But you can set FONTCONFIG_PATH to a non-default configuration root at > runtime, i. e. FONTCONFIG_PATH=/path/to/binary/cfg.I don''t want to use ENV vars, otherwise I''d have to use a wrapper script to start the binary. There are binaries available that search in the same or relative directory for the font configuration files. It must be possible somehow. Cheers, Helmut
Akira TAGOH
2012-Aug-27 07:16 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
On Mon, Aug 27, 2012 at 8:27 AM, Helmut Tessarek <ml at evermeet.cx> wrote:> Hi Raimund, > > On 26.08.12 17:50 , Raimund Steger wrote: >> No, this must resolve to an absolute path at compile time. > > What about these 2 configuration parameters: > > --with-baseconfigdir=DIR > Use DIR to store the base configuration files > [default=SYSCONFDIR/fonts] > --with-configdir=DIR Use DIR to store active configuration files > [default=BASECONFIGDIR/conf.d] > > Do they have to be absolute paths as well?Yes.>> But you can set FONTCONFIG_PATH to a non-default configuration root at >> runtime, i. e. FONTCONFIG_PATH=/path/to/binary/cfg. > > I don''t want to use ENV vars, otherwise I''d have to use a wrapper script to > start the binary. > There are binaries available that search in the same or relative directory for > the font configuration files.that would be only way to go to read the configuration from _current path_ so far. if it''s the fixed path for the specific application, you can use --with-baseconfigdir=/path/to/binary/cfg and put your rules on /path/to/binary/cfg/conf.d or simply use --with-configdir=/path/to/binary/cfg. Regards, -- Akira TAGOH
Helmut Tessarek
2012-Aug-27 17:26 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
On 27.08.12 3:16 , Akira TAGOH wrote:>> I don''t want to use ENV vars, otherwise I''d have to use a wrapper script to >> start the binary. >> There are binaries available that search in the same or relative directory for >> the font configuration files. > > that would be only way to go to read the configuration from _current > path_ so far. if it''s the fixed path for the specific application, you > can use --with-baseconfigdir=/path/to/binary/cfg and put your rules on > /path/to/binary/cfg/conf.d or simply use > --with-configdir=/path/to/binary/cfg.Well, that''s the thing. Static binaries are seldomly in a specific path. People put them wherever they want. Anyway, I understand that using the ENV var is the only way to manipulate the config path. But here''s the next problem. a) fontconfig linked statically b) some binary using fontconfig also linked statically I use setenv in b) to set the FONTCONFIG_PATH variable, but a) ignores it. Any ideas? Cheers, Helmut
Raimund Steger
2012-Aug-27 23:26 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
Helmut Tessarek wrote:> [...] > > Anyway, I understand that using the ENV var is the only way to manipulate the > config path. But here''s the next problem. > > a) fontconfig linked statically > b) some binary using fontconfig also linked statically > > I use setenv in b) to set the FONTCONFIG_PATH variable, but a) ignores it.Should work: /* ... * no FcInit*() before this point */ char cfgpath[PATH_MAX]; /* need to add "." if relative paths are involved: */ snprintf(cfgpath,PATH_MAX,"%s/cfg:.",dirname(argv[0])); setenv("FONTCONFIG_PATH",cfgpath,1); FcInit(); Then, if ./cfg is a valid configuration: FC_DEBUG=1024 ./the-binary shows: Loading config file ./cfg/fonts.conf Scanning config dir ./cfg/conf.d Loading config file ././cfg/conf.d/20-fix-globaladvance.conf [...] Note that binaries on Windows have different defaults than UNIX. Raimund -- Worringer Str 31, Duesseldorf 40211 Germany home: <rs at mytum.de> +49-179-2981632 icq 16845346 work: <rs at interface-ag.de>
Helmut Tessarek
2012-Aug-28 00:48 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
On 27.08.12 19:26 , Raimund Steger wrote:> Should work: > > /* ... > * no FcInit*() before this point */ > char cfgpath[PATH_MAX]; > /* need to add "." if relative paths are involved: */ > snprintf(cfgpath,PATH_MAX,"%s/cfg:.",dirname(argv[0])); > setenv("FONTCONFIG_PATH",cfgpath,1); > FcInit(); > > Then, if ./cfg is a valid configuration: > > FC_DEBUG=1024 ./the-binary > > shows: > > Loading config file ./cfg/fonts.conf > Scanning config dir ./cfg/conf.d > Loading config file ././cfg/conf.d/20-fix-globaladvance.conf > [...]The problem is that it does not work. I tried in ffmpeg.c, as well as in libavfilter/vf_drawtext.c and it is just not working. There is apparently no way to get ffmpeg to use ./cfg/ as the config path for fontconfig. The only way seems to be to set the env variable _before_ starting ffmpeg. If you set it in ffmpeg, it is ignored. Very weird, since it does not make any sense. IMO it is logical to use a relative config dir, when working with static binaries... Anyway, I guess I have to patch fontconfig and use the patched fontconfig library. This seems to be the only solution for this problem. Helmut
Akira TAGOH
2012-Aug-28 01:15 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
On Tue, Aug 28, 2012 at 9:48 AM, Helmut Tessarek <ml at evermeet.cx> wrote:> The problem is that it does not work. I tried in ffmpeg.c, as well as in > libavfilter/vf_drawtext.c and it is just not working. > > There is apparently no way to get ffmpeg to use ./cfg/ as the config path for > fontconfig. > The only way seems to be to set the env variable _before_ starting ffmpeg. > If you set it in ffmpeg, it is ignored. > > Very weird, since it does not make any sense.Not that weird if it''s a separate process and it''s not on parent-child relationship, because the env vars that is set on the child process isn''t reflected to the parent nor another child processes. you have to do it on the parent process before starting a child process or wrap it up with the shell script or the batch file. -- Akira TAGOH
Helmut Tessarek
2012-Aug-28 04:17 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
On 27.08.12 21:15 , Akira TAGOH wrote:> Not that weird if it''s a separate process and it''s not on parent-child > relationship, because the env vars that is set on the child process > isn''t reflected to the parent nor another child processes. you have to > do it on the parent process before starting a child process or wrap it > up with the shell script or the batch file.Well, ffmpeg calls the fontconfig functions so it has the same environment. Even, if a sub-process was spawned or a thread created it would still have the same environment. But this is not the case. FFmpeg is just calling fontconfig functions. Thus setting an env var in ffmpeg should get picked up by the fontconfig lib. And this is exactly my point. I have no idea why it does not get picked up. Cheers, Helmut
Akira TAGOH
2012-Aug-28 05:13 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
On Tue, Aug 28, 2012 at 1:17 PM, Helmut Tessarek <ml at evermeet.cx> wrote:> Well, ffmpeg calls the fontconfig functions so it has the same environment. > > Even, if a sub-process was spawned or a thread created it would still have the > same environment. But this is not the case. FFmpeg is just calling fontconfig > functions. Thus setting an env var in ffmpeg should get picked up by the > fontconfig lib. And this is exactly my point. I have no idea why it does not > get picked up.Other than that, those setenv thing has to be called before FcInit(). if it''s written in C++ say and FcInit() is called in any constructors, it may not work as expected unless you are sure you did it before calling FcInit(). -- Akira TAGOH
Helmut Tessarek
2012-Aug-28 05:58 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
On 28.08.12 1:13 , Akira TAGOH wrote:> Other than that, those setenv thing has to be called before FcInit(). > if it''s written in C++ say and FcInit() is called in any constructors, > it may not work as expected unless you are sure you did it before > calling FcInit().Thanks, this is useful information for the future. wrt ffmpeg, it is written in C and I made sure I called the stenv before the FcInit. But no worries. I will patch fontconfig to use a relative directory. Since I''m compiling fontconfig as a static lib and ffmpeg as a static binary, there is no harm in doing this. Cheers, Helmut
Raimund Steger
2012-Aug-28 08:53 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
Helmut Tessarek wrote:> [...] > The only way seems to be to set the env variable _before_ starting ffmpeg. > If you set it in ffmpeg, it is ignored. > > Very weird, since it does not make any sense.Is this against current ffmpeg git head? Can you send me the patch you''re trying?> IMO it is logical to use a relative config dir, when working with static > binaries...NB. This has nothing to do with static vs. dynamic. A lot of portable apps are linked dynamically with relative runpaths. Raimund -- Worringer Str 31, Duesseldorf 40211 Germany home: <rs at mytum.de> +49-179-2981632 icq 16845346 work: <rs at interface-ag.de>
Helmut Tessarek
2012-Aug-28 18:46 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
On 28.08.12 4:53 , Raimund Steger wrote:> Is this against current ffmpeg git head? > Can you send me the patch you''re trying?Yes, it is ffmpeg git head. I''ve tried to add it in the main function and also in the avfilter code that initializes fontconfig. (see patches.tar) Cheers, Helmut -------------- next part -------------- A non-text attachment was scrubbed... Name: patches.tar Type: application/x-tar Size: 4608 bytes Desc: not available URL: <http://lists.freedesktop.org/archives/fontconfig/attachments/20120828/ea4a5ae8/attachment.tar>
Raimund Steger
2012-Aug-28 23:47 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
Helmut Tessarek wrote:> On 28.08.12 4:53 , Raimund Steger wrote: >> Is this against current ffmpeg git head? >> Can you send me the patch you''re trying? > > Yes, it is ffmpeg git head. > > I''ve tried to add it in the main function and also in the avfilter code that > initializes fontconfig. (see patches.tar)OK, I tried your ffmpeg.c.patch, with a configuration in the directory ./fontconfig; (1) with vf_ass -- seems OK: sun2:video_encoding)truss \ -topen -ulibc,libfontconfig:setenv,Fc\* \ ffmpeg -i in.avi -vf ass=$HOME/tmp/test.ass out.avi [...] /1 at 1: -> libc:setenv() /1 at 1: <- libc:setenv() = 0 [...] ffmpeg version N-43970-g6c06b56 Copyright (c) 2000-2012 the FFmpeg developers built on Aug 28 2012 23:39:01 with gcc 4.5.2 (GCC) [...] /1 at 1: -> libfontconfig:FcConfigCreate() /1 at 1: <- libfontconfig:FcConfigCreate() = 0x80a0da8 /1 at 1: -> libfontconfig:FcConfigParseAndLoad() /1: open("/home/rs/tmp/video_encoding/fontconfig/fonts.conf", O_RDONLY) = 5 /1: open("/home/rs/tmp/video_encoding/fontconfig/conf.d/20-fix-globaladvance [...] (2) with vf_drawtext -- seems OK as well: sun2:video_encoding)truss \ -topen -ulibc,libfontconfig:setenv,Fc\* \ ffmpeg -i in.avi -vf \ drawtext=''text=foo:r=25:x=(w-tw)/2:y=h-(2*lh):fontcolor=white'' \ out.avi [...] /1 at 1: -> libc:setenv() /1 at 1: <- libc:setenv() = 0 [...] /1 at 1: -> libfontconfig:FcInitLoadConfigAndFonts() /1: open("/home/rs/tmp/video_encoding/fontconfig/fonts.conf", O_RDONLY) = 5 /1: open("/home/rs/tmp/video_encoding/fontconfig/conf.d/20-fix-globaladvance.conf", O_RDONLY) = 7 [...] I also checked (2) with some bogus config file in ./fontconfig that mapped all requests to a single very recognizable font to be sure, and it worked. So I think your patch is OK. I have to say that I didn''t link statically, but I''d be surprised if that made a difference. I trust you have checked that ffmpeg enabled fontconfig for vf_drawtext with "egrep ''FONTCONFIG|FREETYPE'' config.mak"? Raimund -- Worringer Str 31, Duesseldorf 40211 Germany home: <rs at mytum.de> +49-179-2981632 icq 16845346 work: <rs at interface-ag.de>
Helmut Tessarek
2012-Aug-29 01:48 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
On 28.08.12 19:47 , Raimund Steger wrote:> So I think your patch is OK. I have to say that I didn''t link statically, but > I''d be surprised if that made a difference.Hmm, interesting. My patch obviously only works on your system. On mine it does not help, nor does it read the config in ./fontconfig It seems that it has something to do with linking it statically, otherwise it would work on my system as well. I''m using MacOSX (not Linux), but this shouldn''t matter.> I trust you have checked that ffmpeg enabled fontconfig for vf_drawtext with > "egrep ''FONTCONFIG|FREETYPE'' config.mak"?Yes, I did. Cheers, Helmut
Helmut Tessarek
2012-Aug-29 01:53 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
On 28.08.12 19:47 , Raimund Steger wrote:> So I think your patch is OK. I have to say that I didn''t link statically, but > I''d be surprised if that made a difference.I''m just wondering. How can my patch work, if you didn''t link it statically? The entire setenv thingy is conditional: #if CONFIG_STATIC Cheers, Helmut
Raimund Steger
2012-Aug-29 08:41 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
Helmut Tessarek wrote:> [...] > > I''m just wondering. How can my patch work, if you didn''t link it statically? > The entire setenv thingy is conditional: > > #if CONFIG_STATICI believe this only indicates whether libav*.a files are generated and is always enabled unless ''--disable-static'' was specified. It does not reflect the linkage of the ffmpeg binary and/or its prerequisites. Raimund -- Worringer Str 31, Duesseldorf 40211 Germany home: <rs at mytum.de> +49-179-2981632 icq 16845346 work: <rs at interface-ag.de>
Raimund Steger
2012-Aug-29 11:27 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
On Wed, August 29, 2012 03:48, Helmut Tessarek wrote:> On 28.08.12 19:47 , Raimund Steger wrote: >> So I think your patch is OK. I have to say that I didn''t link >> statically, but >> I''d be surprised if that made a difference. > > Hmm, interesting. My patch obviously only works on your system. On mine it > does not help, nor does it read the config in ./fontconfig > > It seems that it has something to do with linking it statically, otherwise > it > would work on my system as well. I''m using MacOSX (not Linux), but this > shouldn''t matter.I suppose the only way to be sure what''s going on is to open your ffmpeg build in a debugger and set a breakpoint before getenv("FONTCONFIG_PATH") in fccfg.c and trace from there. (Configure ffmpeg with --disable-stripping) Raimund -- Worringer Str 31 Duesseldorf 40211 Germany +49-179-2981632 icq 16845346
Helmut Tessarek
2012-Aug-30 22:11 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
On 29.08.12 4:41 , Raimund Steger wrote:> Helmut Tessarek wrote: >> [...] >> >> I''m just wondering. How can my patch work, if you didn''t link it statically? >> The entire setenv thingy is conditional: >> >> #if CONFIG_STATIC > > I believe this only indicates whether libav*.a files are generated and is > always enabled unless ''--disable-static'' was specified. It does not reflect > the linkage of the ffmpeg binary and/or its prerequisites.If you use --enable-static in the configure script of ffmpeg, then CONFIG_STATIC is 1, otherwise it is 0. Cheers, Helmut
Helmut Tessarek
2012-Aug-30 22:13 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
On 29.08.12 7:27 , Raimund Steger wrote:> I suppose the only way to be sure what''s going on is to open your ffmpeg > build in a debugger and set a breakpoint before getenv("FONTCONFIG_PATH") > in fccfg.c and trace from there. (Configure ffmpeg with > --disable-stripping)It looks that way. Because it makes no sense that my patch works on your system, but not on mine... Cheers, Helmut
Helmut Tessarek
2012-Aug-31 02:18 UTC
[Fontconfig] how to read config file from current dir (relative to a binary using the lib)
On 29.08.12 7:27 , Raimund Steger wrote:> I suppose the only way to be sure what''s going on is to open your ffmpeg > build in a debugger and set a breakpoint before getenv("FONTCONFIG_PATH") > in fccfg.c and trace from there. (Configure ffmpeg with > --disable-stripping)It got stuck in one of the directories defined in fonts.conf. Or maybe I just have too many fonts installed... I removed some of the dirs in the configuration file, then it worked right away. Thanks again for your help.... Cheers, Helmut