Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#4008 closed defect (fixed)

"main_w" value unrecognized with the new "enable" option in Drawtext

Reported by: beloko Owned by:
Priority: important Component: avfilter
Version: unspecified Keywords: drawtext
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Hello,

Here is the Drawtext command I used early for write a text onto video output only when video input resolution width is between 700p and 1200p :

-filter_complex 
"drawtext=fontfile='/Windows/Fonts/arial.ttf':text='HELLO TEXT':fontsize=47:fontcolor=yellow:x=(main_w/2-text_w/2):y=(main_h/2-
text_h/2):draw=gte(main_w\,700)*lte(main_w\,1200)"

Since "draw" option is deprecated, we have to used "enable" option instead :

-filter_complex 
"drawtext=fontfile='/Windows/Fonts/arial.ttf':text='HELLO TEXT':fontsize=47:fontcolor=yellow:x=(main_w/2-text_w/2):y=(main_h/2-
text_h/2):enable=gte(main_w\,700)*lte(main_w\,1200)"

But now with the "enable" option I get this error :

[drawtext @ 0000000002be6c00] [Eval @ 000000000022ec20] Undefined constant or mi
ssing '(' in 'main_w,1200)'

[drawtext @ 0000000002be6c00] Error when evaluating the expression 'gte(main_w,7
00)*lte(main_w,1200)' for enable

[AVFilterGraph @ 0000000002b42be0] Error initializing filter 'drawtext' with arg
s 'fontfile=/Windows/Fonts/arial.ttf:text=HELLO TEXT:fontsize=47:fontcolor=yello
w:x=(main_w/2-text_w/2):y=(main_h/2-text_h/2):enable=gte(main_w,700)*lte(main_w,
1200)'
Error configuring filters.

After looking what's wrong with this new syntax, I understand that "main_w" value isn't available with the new "enable" option. I think it's the same problem with all defined values.

In my /libavfilter/version.h file I replaced this :
LIBAVFILTER_VERSION_MAJOR < 5 to LIBAVFILTER_VERSION_MAJOR < 6

... and rebuild my FFMPEG.
Now "draw" option is coming back in my binary.

While "enable" option isn't its equivalent, the deprecated "draw" option musn't be disabled.

Change History (11)

comment:1 Changed 5 years ago by cehoyos

  • Keywords drawtext added; main_w main_h draw enable removed
  • Version changed from 2.4.2 to unspecified

To make this a valid ticket, please test current FFmpeg git head and please provide your failing command line together with the complete, uncut console output.

comment:2 Changed 5 years ago by beloko

Hello Cehoyos,

To build my binary I get the FFMPEG source code from this URL :
https://github.com/FFmpeg/FFmpeg.git

Should I use another repositery to get a fresh FFmpeg source code ?

Here is my complete command with the full failling command :

C:\Users\Beloko\Desktop\FFMPEG>ffmpeg.exe -i "C:\Users\BelokoZ\Desktop\bunny.avi" -threads 0 -vcodec libx264 -s 1
920x1080 -b:v 4096k -maxrate 4096k -bufsize 4096k -r 25 -filter:v "drawtext=font
file='/Users/Beloko/Desktop/FFMPEG/arial.ttf':text
='HELLO TEXT':fontsize=47:fontcolor=yellow:x=(main_w/2-text_w/2):y=(main_h/2-tex
t_h/2):enable=gte(main_w\,700)*lte(main_w\,1200)*lt(mod(t\,8)\,6)" -vprofile bas
eline -f mpegts big_bunny.ts
ffmpeg version N-66568-g81cee70 Copyright (c) 2000-2014 the FFmpeg developers
  built on Sep 04 2014 15:37:25 with gcc 4.7.2 (GCC)
  configuration: --arch=x86_64 --target-os=mingw32 --cross-prefix=/home/beloko/s
andbox/mingw-w64-x86_64/bin/x86_64-w64-mingw32- --pkg-config=pkg-config --enable
-gpl --enable-libx264 --enable-avisynth --enable-libxvid --enable-libmp3lame --e
nable-version3 --enable-zlib --enable-librtmp --enable-libvorbis --enable-libthe
ora --enable-libspeex --enable-libopenjpeg --enable-gnutls --enable-libgsm --ena
ble-libfreetype --enable-libopus --disable-w32threads --enable-frei0r --enable-f
ilter=frei0r --enable-libvo-aacenc --enable-bzlib --enable-libxavs --extra-cflag
s=-DPTW32_STATIC_LIB --enable-libopencore-amrnb --enable-libopencore-amrwb --ena
ble-libvo-amrwbenc --enable-libschroedinger --enable-libvpx --enable-libilbc --p
refix=/home/beloko/sandbox/mingw-w64-x86_64/x86_64-w64-mingw32 --enable-static -
-disable-shared --enable-libsoxr --enable-fontconfig --enable-libass --enable-li
butvideo --enable-libbluray --enable-iconv --enable-libtwolame --extra-cflags=-D
LIBTWOLAME_STATIC --enable-libzvbi --enable-libcaca --enable-libmodplug -
-enable-runtime-cpudetect
  libavutil      54.  7.101 / 54.  7.101
  libavcodec     56.  1.102 / 56.  1.102
  libavformat    56.  7.102 / 56.  7.102
  libavdevice    56.  1.100 / 56.  1.100
  libavfilter     5.  1.102 /  5.  1.102
  libswscale      3.  1.100 /  3.  1.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  1.100 / 53.  1.100
Input #0, avi, from 'C:\Users\Beloko\Desktop\bunny.avi':
  Metadata:
    encoder         : AVI-Mux GUI 1.17.7, Aug  8 2006  20:59:17
    JUNK            :
  Duration: 00:09:56.46, start: 0.000000, bitrate: 12455 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 192
0x1080 [SAR 1:1 DAR 16:9], 12001 kb/s, 24 fps, 24 tbr, 24 tbn, 24 tbc
    Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 44
8 kb/s
[drawtext @ 00000000003b6c00] [Eval @ 000000000022ac90] Unknown function in 'mai
n_w,1200)*lt(mod(t,8),6)'
[drawtext @ 00000000003b6c00] Error when evaluating the expression 'gte(main_w,7
00)*lte(main_w,1200)*lt(mod(t,8),6)' for enable
[AVFilterGraph @ 000000000031af20] Error initializing filter 'drawtext' with arg
s 'fontfile=/Users/Beloko/FFMPEG/arial.ttf
:text=HELLO TEXT:fontsize=47:fontcolor=yellow:x=(main_w/2-text_w/2):y=(main_h/2-
text_h/2):enable=gte(main_w,700)*lte(main_w,1200)*lt(mod(t,8),6)'
Error opening filters!

In my FFMPEG command, you can replace "main_w" with another value like 800 for the "enable" option and you'll see my FFMPEG command works perfectly. Problem is "enable" option doesn't support all "draw" option values like "main_w" or "main_h".

:enable=gte(main_w\,700)*lte(main_w\,1200)*lt(mod(t\,8)\,6)
becomes
:enable=gte(800\,700)*lte(800\,1200)*lt(mod(t\,8)\,6)

Last edited 5 years ago by beloko (previous) (diff)

comment:3 Changed 5 years ago by ubitux

So you want to enable the filter only based on the resolution size?

I guess we could add these variables to the timeline eval, but maybe what you are actually looking for is a text being displayed only if it fits into the frame, and so an option for that specific purpose could be added to drawtext?

comment:4 follow-up: Changed 5 years ago by beloko

Hello Ubitux,

Yes exactly. I use this command to enable the "drawtext" filter only when video input resolution has a specific width.

In the past, I was able to used the "draw" option available in the "drawtext" filter. But now, the "draw" option is discontinued and we have to use the "enable" option to replace it.

Finally the "draw" option was more efficient and usefull than this new "enable" option. So I don't understand why the "draw" option is definitively deprecated so early.

In my opinion : if the old "draw" option can do the job, we should keep it longer in "libavfilter" library as a nice "drawtext" filter option. Until the new "enable" option can do the same job. It's not to late, because yesterday I built my new binary with the "draw" option and it works like before. We just have to reprecated the old "draw" option instead of the new "enable" option.

I suppose, add a new option to retrieve the same purpose with "Drawtext" filter will require more job time.

comment:5 in reply to: ↑ 4 Changed 5 years ago by ubitux

Replying to beloko:

Hello Ubitux,

Yes exactly. I use this command to enable the "drawtext" filter only when video input resolution has a specific width.

In the past, I was able to used the "draw" option available in the "drawtext" filter. But now, the "draw" option is discontinued and we have to use the "enable" option to replace it.

Finally the "draw" option was more efficient and usefull than this new "enable" option. So I don't understand why the "draw" option is definitively deprecated so early.

"enable" is a system shared between a lot of other filters, it avoids having the same logic duplicated in every filter. "draw" wasn't kept in drawtext because no one thought main_w and main_h would actually be useful for enabling/disabling the filter. It seems we were wrong.

Now this use case looks very specific to drawtext, so I'm not yet sure between simply adding variable names in the timeline system ("enable"), or adding an option in drawtext to say "don't draw the text if it doesn't fit into the frame".

[...]

comment:6 Changed 5 years ago by ubitux

Patch on the mailing-list implementing the timeline version: http://ffmpeg.org/pipermail/ffmpeg-devel/2014-October/163833.html

Using "w" and "h" with "enable" would be possible after this patch.

comment:7 follow-up: Changed 5 years ago by beloko

Shared the "enable" option filters with others is a nice goal, FFmpeg can solve many use cases.

Ex: With "draw" option, I can make a text readable on any high resolution video file in just one FFmpeg command line. Otherwise, I have to detect the input video resolution width before call a specific FFmpeg command for each width.

I prefer switch between different font sizes than having an auto-scale text I can't size properly.

For now, I built a new FFmpeg binary by merging your patch. "Drawtext" error messages are left after the command line, but the text content doesn't appear on the output video file.

Version 0, edited 5 years ago by beloko (next)

comment:8 in reply to: ↑ 7 Changed 5 years ago by ubitux

  • Resolution set to fixed
  • Status changed from new to closed

Replying to beloko:

Shared the "enable" option filters with others is a nice goal, FFmpeg can solve many use cases.

Note that it's not a "goal", it actually is the case:

☭ ./ffmpeg -v error -filters|grep -c '^ T'
49

Ex: With "draw" option, I can make a text readable on any high resolution video file in just one FFmpeg command line. Otherwise, I have to detect the input video resolution width before call a specific FFmpeg command for each width.

I prefer switch between different font sizes than having an auto-scale text I can't size properly.

Sorry, I have no idea what you are talking about here, but I'm probably very tired.

For now, I built a new FFmpeg binary by merging your patch. "Drawtext" error messages are left after the command line, but the text content doesn't appear in the output video file.

That patch is now applied. I don't like that solution much because I believe we should add a "display-the-text-only-if-it-fits-in" in drawtext, but since it's somehow a regression, I applied that version.

What error messages are you talking about?

comment:9 follow-up: Changed 5 years ago by beloko

Hello Ubitux,

I'm skeptical about your patch but I hope I'm wrong.

Please, where should I download your patch to build a fresh FFmpeg binary and try it properly ?

Usually I use this GIT repository, but now it doesn't seems up to date :
https://github.com/FFmpeg/FFmpeg.git

Having the "draw" option reprecated or the same capacity via another option name supported in next FFmepg realeases is just perfect for me. Your "if-text-fit-size-area" proposition is really more than I could expect.

comment:10 in reply to: ↑ 9 Changed 5 years ago by ubitux

Replying to beloko:

Hello Ubitux,

I'm skeptical about your patch but I hope I'm wrong.

It doesn't restore draw, but it makes possible for you to use the "w" and "h" variables in the "enable" option.

Please, where should I download your patch to build a fresh FFmpeg binary and try it properly ?

You just checkout git/master.

Usually I use this GIT repository, but now it doesn't seems up to date :
https://github.com/FFmpeg/FFmpeg.git

This is a mirror, see ffmpeg.org for the correct URL.

Having the "draw" option reprecated or the same capacity via another option name supported in next FFmepg realeases is just perfect for me.

Won't happen, but since you needed it for the main_w/main_h access, it was added to the timeline system.

Your "if-text-fit-size-area" proposition is really more than I could expect.

I don't have time to implement that correctly unfortunately.

comment:11 Changed 5 years ago by beloko

Hello Ubitux,

Finally I built a fresh FFmpeg binary from main repositery :
git://source.ffmpeg.org/ffmpeg.git

I just tried it now on a video file and yes ... I confirm your patch works like a charm. Thank you very much, accept my apologies !

We don't need to develop a new function to do the same job.

Note: See TracTickets for help on using tickets.