[FFmpeg-user] Slow motion setpts equation

Jonathan Girven jonathan.girven at trickbook.com
Tue May 30 11:57:06 EEST 2017


I know that it is possible to apply slow motion to a section of video
using a combination of splitting the video into the relevant sections,
using setpts to adjust the rate and then concat'ing them back
together. E.g:

ffmpeg -i input.mp4 -filter_complex
"[0:v]trim=0:2,setpts=expr=PTS-STARTPTS[v0];[0:v]trim=2:3,setpts=expr=PTS-STARTPTS[v1];[0:v]trim=3:5,setpts=expr=PTS-STARTPTS[v2];[v1]setpts=PTS/0.5[v1_slowmo];[v0][v1_slowmo][v2]concat=n=3:v=1:a=0[out]"
-map [out] output.mp4

I wondered if it is also possible to do this with an equation in
setpts (and might be easier to read)? E.g:

ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=if(between(T\, 2\,
3)\, 0.5\, 1)*PTS[out]" -map [out] output.mp4

This command doesn't adjust the times correctly though, I guess
because each segment of time doesn't account for the previous shifts.
Therefore t=0--2 and t=2-3 (with slowmo) actually end up overlapping
in PTS.

Is the equation I am going to have to write going to end up more
complicated that my first example? / Just impossible.

Full output:

$ ffmpeg -y -i input.mp4 -filter_complex "[0:v]setpts=if(between(T\,
2\, 3)\, 0.5\, 1)*PTS[out]" -map [out] output.mp4
ffmpeg version 3.3 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --prefix=/usr/local
--extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib
--bindir=/usr/local/bin --disable-doc --disable-static --enable-shared
--disable-ffplay --extra-libs=-ldl --enable-version3
--enable-libfreetype --enable-libx264 --enable-gpl --enable-openssl
--enable-nonfree --disable-debug
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.19.100
  Duration: 00:00:11.05, start: 0.000000, bitrate: 5584 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 /
0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 5473 kb/s, 25 fps,
25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz,
stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 (h264) -> setpts
  setpts -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
[libx264 @ 0xd89820] using SAR=1/1
[libx264 @ 0xd89820] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0xd89820] profile High, level 3.1
[libx264 @ 0xd89820] 264 - core 148 - H.264/MPEG-4 AVC codec -
Copyleft 2003-2016 - http://www.videolan.org/x264.html - options:
cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1
psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1
8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2
threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1
interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2
b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250
keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf
mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40
aq=1:1.00
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.71.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021),
yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 12800 tbn, 25
tbc (default)
    Metadata:
      encoder         : Lavc57.89.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=   78 fps=0.0 q=28.0 size=     403kB time=00:00:00.76
bitrate=4346.3kbits/s dup=25 drop=25 speed= 1frame=  122 fps=112
q=28.0 size=    1085kB time=00:00:02.52 bitrate=3525.7kbits/s dup=25
drop=25 speed=2.frame=  158 fps= 99 q=28.0 size=    1568kB
time=00:00:03.96 bitrate=3243.6kbits/s dup=25 drop=25 speed=2.frame=
191 fps= 91 q=28.0 size=    2210kB time=00:00:05.28
bitrate=3428.1kbits/s dup=25 drop=25 speed=2.frame=  224 fps= 86
q=28.0 size=    2859kB time=00:00:06.60 bitrate=3549.2kbits/s dup=25
drop=25 speed=2.frame=  254 fps= 81 q=28.0 size=    3402kB
time=00:00:07.80 bitrate=3572.8kbits/s dup=25 drop=25 speed= 2frame=
275 fps= 68 q=-1.0 Lsize=    4877kB time=00:00:10.88
bitrate=3672.0kbits/s dup=25 drop=25 speed=2.68x
video:4875kB audio:0kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 0.046016%
[libx264 @ 0xd89820] frame I:4     Avg QP:18.22  size: 89324
[libx264 @ 0xd89820] frame P:250   Avg QP:23.73  size: 18427
[libx264 @ 0xd89820] frame B:21    Avg QP:27.84  size:  1288
[libx264 @ 0xd89820] consecutive B-frames: 89.1%  2.2%  0.0%  8.7%
[libx264 @ 0xd89820] mb I  I16..4: 45.8% 20.2% 34.1%
[libx264 @ 0xd89820] mb P  I16..4:  6.4%  1.2%  1.2%  P16..4: 53.7%
8.4%  4.7%  0.0%  0.0%    skip:24.4%
[libx264 @ 0xd89820] mb B  I16..4:  0.5%  0.1%  0.0%  B16..8:  5.0%
0.7%  0.1%  direct: 0.3%  skip:93.2%  L0:53.8% L1:32.6% BI:13.5%
[libx264 @ 0xd89820] 8x8 transform intra:14.6% inter:37.3%
[libx264 @ 0xd89820] coded y,uvDC,uvAC intra: 53.2% 65.0% 12.8% inter:
27.7% 19.0% 0.1%
[libx264 @ 0xd89820] i16 v,h,dc,p: 10% 46% 34%  9%
[libx264 @ 0xd89820] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu:  8% 55% 24%  2%
1%  1%  3%  1%  6%
[libx264 @ 0xd89820] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 13% 51% 22%  2%
2%  1%  3%  1%  5%
[libx264 @ 0xd89820] i8c dc,h,v,p: 43% 40%  9%  8%
[libx264 @ 0xd89820] Weighted P-Frames: Y:0.4% UV:0.4%
[libx264 @ 0xd89820] ref P L0: 83.6% 14.8%  1.3%  0.2%  0.0%
[libx264 @ 0xd89820] ref B L0: 84.2% 15.6%  0.2%
[libx264 @ 0xd89820] ref B L1: 99.9%  0.1%
[libx264 @ 0xd89820] kb/s:3629.85


More information about the ffmpeg-user mailing list