[FFmpeg-user] Changing video speed, overlay filter and video length.

Oleg Afanasyev oafanasiev at gmail.com
Tue May 16 01:56:20 EEST 2023

Hey friends!

I'm trying to make timelapse of video with images overlaid on top of it.
The ultimate command that I use is:
ffmpeg -hide_banner -y -v trace \
       -f concat -safe 0 -i "fragments.txt" -i frames/frame-%05d.png \
       -filter_complex "[0:v]scale=1280x720[camera]; \


       -vcodec libx264 -an tamplapse.mp4 2>ffmpeg.log
It picks videos from fragments.txt and overlays images from frames
directory over it. Then it scales pts to be 0.025 of original making
video faster and then dropping all intermediate frames to 30 fps
before reencoding.
Frames are prepared by other program and are generated with 10 fps, so
after combining them pts is adjusted from default image merging 25fps
by just using frame id.

Unfortunately it doesn't work as expected.Resulting video runs with
desired speed and combined correctly but resulting length equals to
the original full length so when playing it reaches the end of the
timelapse and then keeps a blank image till it reaches full time.

I tried to verify timelapse approach in general by making just a
timelapse of video:
ffmpeg -hide_banner -y -v trace \
  -f concat -safe 0 -i "fragments.txt" \
  -filter_complex "[0:v]scale=1280x720[camera]; \
                   [camera]setpts=expr=PTS*0.025,fps=30" \
  -vcodec libx264 -an timelapse.mp4 2>ffmpeg.log

And also timelapse of image sequence:
ffmpeg -hide_banner -y -v trace \
  -i frames/frame-%05d.png \
                   [camera]setpts=expr=PTS*0.025,fps=30" \
  -vcodec libx264 -an timelapse.mp4 2>ffmpeg.log

And they successfully produce videos of identical short length. So I
assume there's some specifics of how overlay combines streams. I tried
various combinations of shortest, repeatlast, eof_action to see if it
makes any difference, but to no avail. But since combined streams have
identical length with just difference of pts rounding of last frame it
should be irrelevant.

I would appreciate any pointers to what to poke on. I looked briefly
on setpts trace as it logs generated values, and I think it always
stops at the expected timelapse end time (short) so I suspect it must
be some metadata that is generated that sets full length of the video
incorrectly. While it might be possible to just set -t to the new
length, it might be tricky for me as I'll have to estimate the length
as I'm making some pts fiddling using commands and resulting length is
not easy to predict.

with best regards
Oleg Afanasyev

More information about the ffmpeg-user mailing list