I managed to encode a video using ffmpeg and to overlay each frame with the frame number using the drawtext filter.

My problem was that using the "text=%{n}" option resulted in the first frame being 0, which is not what I need.

Then I used the code "text=%{expr\:n+1}" and the first frame is now 1 as it should be but it print out 1.000000

Does anyone know a way to remove what comes after the decimal point?


Had the same problem, took me some time to find out the answer. In the docs there is

expr_int_format, eif Evaluate the expression’s value and output as formatted integer.

The first argument is the expression to be evaluated, just as for the expr function. The second argument specifies the output format. Allowed values are ‘x’, ‘X’, ‘d’ and ‘u’. They are treated exactly as in the printf function. The third parameter is optional and sets the number of positions taken by the output. It can be used to add padding with zeros from the left.

I have e.g. :text=' == %{eif\:33\:x} ==' working fine here. Note that how much escaping (how many backslashes) you need has to do with your environment

So, for your case this does the trick:

| improve this answer | |
  • 2
    Did the trick for me - final command was: ffmpeg -i /path/to/video.mov -qscale:v 3 -vf "drawtext=fontsize=100:fontfile=/Library/Fonts/Arial.ttf:text='%{eif\:n+1\:d}':x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000099" /path/to/frames/%d.jpg – unsunghero Apr 19 '18 at 14:19

First, separate the video into individual frames, then use Multiple Image Resizer.NET to place the frame numbers into each and every frame. Then, reunite the images into a second video sequence.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.