Opened 11 years ago

Closed 11 years ago

#3329 closed defect (fixed)

fps filter bug

Reported by: Andrey Utkin Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords: fps
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: yes

Description

Summary of the bug:
Trying to make looped animation from several source images, raising framerate from 2 FPS to 25 FPS.
After several loops, order of frames was wrong in some places.

How to reproduce:

Take png files from attach.

 ffmpeg -f image2 -loop 1 -framerate 2 -i '/tmp/arrow_%1d.png' -frames 1000 -vf fps=fps=25 /tmp/tmp.ts -y
ffmpeg version N-59981-g9d13432 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jan 19 2014 22:00:02 with gcc 4.6.3 (Gentoo 4.6.3 p1.13, pie-0.5.2)
  configuration: --enable-gpl --enable-libx264 --enable-encoder=libx264 --disable-stripping --enable-debug --extra-cflags='-O0 -g -ggdb' --enable-libopus --enable-libvpx --enable-x11grab --enable-libfreetype --enable-filter=drawtext --enable-libzvbi
  libavutil      52. 63.100 / 52. 63.100
  libavcodec     55. 48.101 / 55. 48.101
  libavformat    55. 24.100 / 55. 24.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  1.100 /  4.  1.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, image2, from '/tmp/arrow_%1d.png':
  Duration: 00:00:01.50, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, rgba, 44x12, 2 fps, 2 tbr, 2 tbn, 2 tbc
Output #0, mpegts, to '/tmp/tmp.ts':
  Metadata:
    encoder         : Lavf55.24.100
    Stream #0:0: Video: mpeg2video, yuv420p, 44x12, q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (png -> mpeg2video)
Press [q] to stop, [?] for help
frame=32188 fps=25692 q=2.0 Lsize=    9816kB time=00:21:27.48 bitrate=  62.5kbits/s}}}

Attachments (3)

arrow_1.png (1.3 KB ) - added by Andrey Utkin 11 years ago.
arrow_1.png
arrow_2.png (1.3 KB ) - added by Andrey Utkin 11 years ago.
arrow_2.png
arrow_3.png (1.3 KB ) - added by Andrey Utkin 11 years ago.
arrow_3.png

Download all attachments as: .zip

Change History (6)

by Andrey Utkin, 11 years ago

Attachment: arrow_1.png added

arrow_1.png

by Andrey Utkin, 11 years ago

Attachment: arrow_2.png added

arrow_2.png

by Andrey Utkin, 11 years ago

Attachment: arrow_3.png added

arrow_3.png

comment:1 by Carl Eugen Hoyos, 11 years ago

Keywords: fps added
Reproduced by developer: set
Status: newopen

comment:2 by Cigaes, 11 years ago

Analyzed by developer: set

The timestamp logic in vf_fps is wrong. The major culprit is this hunk:

    /* number of output frames */
    delta = av_rescale_q_rnd(buf->pts - s->pts, inlink->time_base,
                             outlink->time_base, s->rounding);

As you can see, it means: number of frames to output = (time of next frame) - (time of current frame) rescaled to output frame rate. In this particular case (2 FPS -> 25 FPS, it is 12.5, rounded to 13. Rounded to 13 every time. That means a 0.5/25 error for every input frame.

The in this case fix would be to convert all timestamps to the output time base immediately, but it must be tested also when decreasing the frame rate and other corner cases.

As a temporary workaround, I suggest: -vf fps=50,framestep=2: 2→50 is exact, and framestep is easy.

comment:3 by Carl Eugen Hoyos, 11 years ago

Resolution: fixed
Status: openclosed

Fixed by Michael in 8f33810e

Note: See TracTickets for help on using tickets.