[FFmpeg-user] Drawtext - complex expression to show feet+frames

Mark Burton mwjburton at gmail.com
Tue Apr 11 21:36:36 EEST 2017


New here, hope this is an appropriate question layout...

I’ve been trying to learn more about expression evaluation and some of the more complex aspects of controlling drawing text. I’m trying to achieve something which is a bit far fetched, but I’d love to get any help I can and this would be a huge feature for me if we can get it working. I’ve not come across this anywhere in my numerous searches, but perhaps someone has an existing solution to this?

The idea is to write a drawtext expression which can draw a film footage counter onto my video. The 35mm 4perf counter I want to use counts 16 frames per foot, like so:

0+00
0+01
0+02
0+03
0+04
0+05
0+06
0+07
0+08
0+09
0+10
0+11
0+12
0+13
0+14
0+15
1+00
1+01
… and so on.

Although a single filter expression would be much more useful in the long run, I figured it may be easier to break the display into 3 drawtext filters to get started. One for the feet counter, one for the ‘+’ character and one for the frames counter. So far I have the feet working almost right, but I’m not getting anywhere with the third.

My source material is always going to be 24fps Avid DNx115.

Here is the basic command:

inputFile="in.mov"
outputFile="out.mov"
fontFile="/System/Library/Fonts/Helvetica.dfont"
ffmpeg \
-i $inputFile \
-y \
-c:v mjpeg -qscale:v 4 -pix_fmt yuvj422p \
-vf "
drawtext=fontsize=80:fontcolor=white:fontfile=$fontFile:text='%{eif\:0+(t/((1/24)*16))\:d}':x=(w/2)-text_w:y=(h-text_h)/2,
drawtext=fontsize=55:fontcolor=white:fontfile=$fontFile:text='+':x=(w/2)+5:y=(h-text_h)/2" \
-an \
$outputFile

The first drawtext for the feet value is 99% accurate, but sometimes it does not change to the next number of the exact frame it should. Is there a way to use a per frame value instead of ’t’? I’m guessing its this calculation is not producing an accurate enough result to calculate the exact frame each time? It needs to iterate to the next number every 16 frames exactly.

Any advice on where to begin with the frames counter. It needs to start at 0, count on every frame to 15 and then restart at 0 on the next frame.

Lastly (perhaps I’m dreaming here!) could this theoretically all be combined into a single expression with ability to set the starting counter to 12+06 for example and have it count accurately from there? Had to ask!

Thanks for your help,
Regards
Mark





More information about the ffmpeg-user mailing list