Opened 5 years ago

Closed 5 years ago

#3329 closed defect (fixed)

fps filter bug

Reported by: Krieger 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 Krieger 5 years ago.
arrow_1.png
arrow_2.png (1.3 KB) - added by Krieger 5 years ago.
arrow_2.png
arrow_3.png (1.3 KB) - added by Krieger 5 years ago.
arrow_3.png

Download all attachments as: .zip

Change History (6)

Changed 5 years ago by Krieger

arrow_1.png

Changed 5 years ago by Krieger

arrow_2.png

Changed 5 years ago by Krieger

arrow_3.png

comment:1 Changed 5 years ago by cehoyos

  • Keywords fps added
  • Reproduced by developer set
  • Status changed from new to open

comment:2 Changed 5 years ago by Cigaes

  • 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 Changed 5 years ago by cehoyos

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

Fixed by Michael in 8f33810e

Note: See TracTickets for help on using tickets.