Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#1949 closed enhancement (fixed)

Display frame number on each frame

Reported by: igorg Owned by:
Priority: wish Component: avfilter
Version: git-master Keywords: drawtext
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: yes

Description

Summary of the bug: The drawtext filter understands the n variable in the "y=h-(2*lh)-n", but if I want to display the frame number on each frame as text, then it does not work. Putting n there displays the letter itself and %n is the new line symbol.
How to reproduce:

% fmpeg -i in.mov -vf "drawtext=fontfile=/usr/share/fonts/ttf-bitstream-vera/Vera.ttf: x=(w-tw)/2: y=h-(2*lh)-n: fontcolor=white: fontsize=40: box=1: boxcolor=0x00000000@1: text=" -an -y out.mov
ffmpeg version 0.10.6
built on Nov 21 2012

Change History (17)

comment:1 Changed 4 years ago by cehoyos

Please test current git head and please add the complete, uncut console output.

comment:2 Changed 4 years ago by igorg

  • Version 0.10.5 deleted

Current git tested. Full console output:

ffmpeg version N-46986-gdcbf728 Copyright (c) 2000-2012 the FFmpeg developers

built on Nov 22 2012 14:13:43 with gcc 4.5.4 (Gentoo 4.5.4 p1.0, pie-0.4.7)
configuration: --enable-libfreetype
libavutil 52. 8.100 / 52. 8.100
libavcodec 54. 75.100 / 54. 75.100
libavformat 54. 37.100 / 54. 37.100
libavdevice 54. 3.100 / 54. 3.100
libavfilter 3. 23.101 / 3. 23.101
libswscale 2. 1.102 / 2. 1.102
libswresample 0. 17.101 / 0. 17.101

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out.mov':

Metadata:

major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf53.32.100

Duration: 00:00:10.92, start: 0.000000, bitrate: 30881 kb/s

Stream #0:0(eng): Video: mjpeg (jpeg / 0x6765706A), yuvj420p, 800x600 [SAR 4:3 DAR 16:9], 30880 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
Metadata:

handler_name : DataHandler?

[Parsed_drawtext_0 @ 0x2f95ee0] expansion=strftime is deprecated.
Output #0, mp4, to 'out.mp4':

Metadata:

major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf54.37.100
Stream #0:0(eng): Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 800x600 [SAR 4:3 DAR 16:9], q=2-31, 200 kb/s, 12800 tbn, 25 tbc
Metadata:

handler_name : DataHandler?

Stream mapping:

Stream #0:0 -> #0:0 (mjpeg -> mpeg4)

Press [q] to stop, ? for help
frame= 273 fps=109 q=31.0 Lsize= 1835kB time=00:00:10.92 bitrate=1376.3kbits/s
video:1833kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.107959%

Version 0, edited 4 years ago by igorg (next)

comment:3 Changed 4 years ago by cehoyos

  • Component changed from FFmpeg to avfilter
  • Version set to git-master

comment:4 Changed 4 years ago by Cigaes

Why do you want the frame number for? The frame number is a fragile thing: remuxing to a format that does not support variable frame rate or encoding to a codec that aggressively drops frames may change it.

Since last week, the drawtext filter can be used to print the exact timestamp of each frame. Timestamps are the correct way of addressing frames.

comment:5 Changed 4 years ago by igorg

I am actually converting pictures to mov, and I really need the frame numbers. Another solution would be numbering the pictures themselves, but I was aiming at a faster solution.

comment:6 Changed 4 years ago by saste

  • Analyzed by developer set
  • Keywords drawtext added
  • Reproduced by developer set
  • Resolution set to fixed
  • Status changed from new to closed

Should be fixed in:

commit eb87b340e8c8ad3902e9dc0857724c8f659a113f
Author: Stefano Sabatini <stefasab@gmail.com>
Date:   Thu Nov 22 12:08:45 2012 +0100

    lavfi/drawtext: add support for printing frame numbers
    
    Fix trac ticket #1949.

comment:7 follow-up: Changed 4 years ago by igorg

Thanks! Could you though specify how exactly printing frame numbers is achieved and what version is it going to be available in?

comment:8 in reply to: ↑ 7 ; follow-up: Changed 4 years ago by saste

Replying to igorg:

Thanks! Could you though specify how exactly printing frame numbers is achieved and what version is it going to be available in?

You need a git repository updated to this morning. The syntax is specified in the updated manual, it will be something like:

drawtext=text=%{n}:other_options...

comment:9 in reply to: ↑ 8 ; follow-up: Changed 4 years ago by igorg

Replying to saste:

Replying to igorg:

Thanks! Could you though specify how exactly printing frame numbers is achieved and what version is it going to be available in?

You need a git repository updated to this morning. The syntax is specified in the updated manual, it will be something like:

drawtext=text=%{n}:other_options...

One quick question still - how to start numbering the frames from 1 and not 0? I tried the regular math expressions like %{n+1}, but that did not work

comment:10 in reply to: ↑ 9 ; follow-up: Changed 4 years ago by saste

Replying to igorg:
[...]

One quick question still - how to start numbering the frames from 1 and not 0? I tried the regular math expressions like %{n+1}, but that did not work

Because there is no such feature. Question, why do you need frame count from 1?

comment:11 in reply to: ↑ 10 ; follow-up: Changed 4 years ago by igorg

Replying to saste:

Replying to igorg:
[...]

One quick question still - how to start numbering the frames from 1 and not 0? I tried the regular math expressions like %{n+1}, but that did not work

Because there is no such feature. Question, why do you need frame count from 1?

Well, because it is more comprehensible and people usually count starting from 1. Moreover, when I add the extra frame before the actual sequence (containing the info on that particular sequence), its number is also 0. Therefore, shifting all the frame numbers by a given number (in my case 1) would work perfectly fine.

comment:12 in reply to: ↑ 11 ; follow-up: Changed 4 years ago by saste

Replying to igorg:
[...]

Because there is no such feature. Question, why do you need frame count from 1?

Well, because it is more comprehensible and people usually count starting from 1. Moreover, when I add the extra frame before the actual sequence (containing the info on that particular sequence), its number is also 0. Therefore, shifting all the frame numbers by a given number (in my case 1) would work perfectly fine.

Try the new expansion function %{expr\\:n+1} (note the double escaping), it prints a double value, no formatting control is still provided.

comment:13 follow-up: Changed 4 years ago by jenini

Hello,
I am also interested to know how to count from frame 1.
I have trouble understand the new expansion function ( %{expr
:n+1} ) or maybe it doesn't works.
If someone know how to do that, it will be really helpfull.

comment:14 in reply to: ↑ 13 Changed 4 years ago by igorg

Replying to jenini:

Hello,
I am also interested to know how to count from frame 1.
I have trouble understand the new expansion function ( %{expr
:n+1} ) or maybe it doesn't works.
If someone know how to do that, it will be really helpfull.

Hi!
I tried the expansion function, except it needed more than two escapings in my example (something like five worked). But the value is in the format '1.0000000' (the double value), which is not really nice. However, it works.

comment:15 in reply to: ↑ 12 Changed 4 years ago by igorg

Replying to saste:

Replying to igorg:
[...]

Because there is no such feature. Question, why do you need frame count from 1?

Well, because it is more comprehensible and people usually count starting from 1. Moreover, when I add the extra frame before the actual sequence (containing the info on that particular sequence), its number is also 0. Therefore, shifting all the frame numbers by a given number (in my case 1) would work perfectly fine.

Try the new expansion function %{expr\\:n+1} (note the double escaping), it prints a double value, no formatting control is still provided.

Not sure if I should create a new wish ticket... But will the simple formatting be supported? Something like displaying the frames as 1, 2, 3...

comment:16 Changed 3 years ago by Charlie

Hi,
in my case, I needed five escapings:

Code highlighting:

text=%{expr\\\\\:n+1}

And, not sure if this has been answered elsewhere ? but it would be great indeed to have some formatting control and display the frame number as int (1,2,3,..) instead of double (1.000000, 2.000000, ...)
Thanks !

Last edited 3 years ago by Charlie (previous) (diff)

comment:17 Changed 3 years ago by Charlie

also, is it possible to use a variable in this expansion function ?
I need to display a frame number with an integer offset I calculate before:

text=%{expr\\\\\:n-' + offset + '}
'text=%{expr\\\\\:n-%d}' % offset

Both lines above display the plain expression 'n-offset', but don't calculate it.
Thanks in advance

Note: See TracTickets for help on using tickets.