[FFmpeg-user] Slow motion ramp

Jonathan Girven jonathan.girven at trickbook.com
Mon Jun 5 17:38:30 EEST 2017


I am trying to apply slow motion to a clip with a gradual ramp into
and out of the slow motion period. I would like to apply this to both
the video and the audio. I tried to separate my clip into multiple
small sections, apply different setpts and atempo rates to each, and
then concat them back together. This almost works except that after
the slow motion period, the audio and video about 1s out of sync. The
video and audio seem reasonable on their own.

Is what I am trying to do not really possible with this method? Do you
have any other suggestions for how to do it?


ffmpeg -y -i input.mp4 -filter_complex "\
   [0:v]trim=0.0:4.0,setpts=PTS-STARTPTS[v0_trim0];\
   [0:v]trim=4.0:4.1,setpts=(PTS-STARTPTS)/0.95[v0_slomo0];\
   [0:v]trim=4.1:4.2,setpts=(PTS-STARTPTS)/0.90[v0_slomo1];\
   [0:v]trim=4.2:4.3,setpts=(PTS-STARTPTS)/0.85[v0_slomo2];\
   [0:v]trim=4.3:4.4,setpts=(PTS-STARTPTS)/0.80[v0_slomo3];\
   [0:v]trim=4.4:4.5,setpts=(PTS-STARTPTS)/0.75[v0_slomo4];\
   [0:v]trim=4.5:4.6,setpts=(PTS-STARTPTS)/0.70[v0_slomo5];\
   [0:v]trim=4.6:4.7,setpts=(PTS-STARTPTS)/0.65[v0_slomo6];\
   [0:v]trim=4.7:4.8,setpts=(PTS-STARTPTS)/0.60[v0_slomo7];\
   [0:v]trim=4.8:4.9,setpts=(PTS-STARTPTS)/0.55[v0_slomo8];\
   [0:v]trim=4.9:6.1,setpts=(PTS-STARTPTS)/0.50[v0_slomo9];\
   [0:v]trim=6.1:6.2,setpts=(PTS-STARTPTS)/0.55[v0_slomo10];\
   [0:v]trim=6.2:6.3,setpts=(PTS-STARTPTS)/0.60[v0_slomo11];\
   [0:v]trim=6.3:6.4,setpts=(PTS-STARTPTS)/0.65[v0_slomo12];\
   [0:v]trim=6.4:6.5,setpts=(PTS-STARTPTS)/0.70[v0_slomo13];\
   [0:v]trim=6.5:6.6,setpts=(PTS-STARTPTS)/0.75[v0_slomo14];\
   [0:v]trim=6.6:6.7,setpts=(PTS-STARTPTS)/0.80[v0_slomo15];\
   [0:v]trim=6.7:6.8,setpts=(PTS-STARTPTS)/0.85[v0_slomo16];\
   [0:v]trim=6.8:6.9,setpts=(PTS-STARTPTS)/0.90[v0_slomo17];\
   [0:v]trim=6.9:7.0,setpts=(PTS-STARTPTS)/0.95[v0_slomo18];\
   [0:v]trim=7.0:15.0,setpts=PTS-STARTPTS[v0_trim2];\
   \
   [0:a]atrim=0.0:4.0,asetpts=PTS-STARTPTS[a0_trim0];\
   [0:a]atrim=4.0:4.1,asetpts=PTS-STARTPTS,atempo=0.95[a0_slomo0];\
   [0:a]atrim=4.1:4.2,asetpts=PTS-STARTPTS,atempo=0.90[a0_slomo1];\
   [0:a]atrim=4.2:4.3,asetpts=PTS-STARTPTS,atempo=0.85[a0_slomo2];\
   [0:a]atrim=4.3:4.4,asetpts=PTS-STARTPTS,atempo=0.80[a0_slomo3];\
   [0:a]atrim=4.4:4.5,asetpts=PTS-STARTPTS,atempo=0.75[a0_slomo4];\
   [0:a]atrim=4.5:4.6,asetpts=PTS-STARTPTS,atempo=0.70[a0_slomo5];\
   [0:a]atrim=4.6:4.7,asetpts=PTS-STARTPTS,atempo=0.65[a0_slomo6];\
   [0:a]atrim=4.7:4.8,asetpts=PTS-STARTPTS,atempo=0.60[a0_slomo7];\
   [0:a]atrim=4.8:4.9,asetpts=PTS-STARTPTS,atempo=0.55[a0_slomo8];\
   [0:a]atrim=4.9:6.1,asetpts=PTS-STARTPTS,atempo=0.50[a0_slomo9];\
   [0:a]atrim=6.1:6.2,asetpts=PTS-STARTPTS,atempo=0.55[a0_slomo10];\
   [0:a]atrim=6.2:6.3,asetpts=PTS-STARTPTS,atempo=0.60[a0_slomo11];\
   [0:a]atrim=6.3:6.4,asetpts=PTS-STARTPTS,atempo=0.65[a0_slomo12];\
   [0:a]atrim=6.4:6.5,asetpts=PTS-STARTPTS,atempo=0.70[a0_slomo13];\
   [0:a]atrim=6.5:6.6,asetpts=PTS-STARTPTS,atempo=0.75[a0_slomo14];\
   [0:a]atrim=6.6:6.7,asetpts=PTS-STARTPTS,atempo=0.80[a0_slomo15];\
   [0:a]atrim=6.7:6.8,asetpts=PTS-STARTPTS,atempo=0.85[a0_slomo16];\
   [0:a]atrim=6.8:6.9,asetpts=PTS-STARTPTS,atempo=0.90[a0_slomo17];\
   [0:a]atrim=6.9:7.0,asetpts=PTS-STARTPTS,atempo=0.95[a0_slomo18];\
   [0:a]atrim=7.0:15.0,asetpts=PTS-STARTPTS[a0_trim2];\
   \
   [v0_trim0][v0_slomo0][v0_slomo1][v0_slomo2][v0_slomo3][v0_slomo4][v0_slomo5][v0_slomo6][v0_slomo7][v0_slomo8][v0_slomo9][v0_slomo10][v0_slomo11][v0_slomo12][v0_slomo13][v0_slomo14][v0_slomo15][v0_slomo16][v0_slomo17][v0_slomo18][v0_trim2]concat=n=21:v=1:a=0[com_v_slomo0];\
   \
   [a0_trim0][a0_slomo0][a0_slomo1][a0_slomo2][a0_slomo3][a0_slomo4][a0_slomo5][a0_slomo6][a0_slomo7][a0_slomo8][a0_slomo9][a0_slomo10][a0_slomo11][a0_slomo12][a0_slomo13][a0_slomo14][a0_slomo15][a0_slomo16][a0_slomo17][a0_slomo18][a0_trim2]concat=n=21:v=0:a=1[com_a_slomo0]\
   " -vcodec libx264 -preset ultrafast -map [com_v_slomo0] -map
[com_a_slomo0] -c:a aac -ac 2 -b:a 128k -strict -2 out.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     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-08-20T06:44:48.000000Z
  Duration: 00:00:15.02, start: 0.000000, bitrate: 2412 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661),
yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 2315 kb/s, 29.97 fps,
29.97 tbr, 90k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2016-08-20T06:44:48.000000Z
      handler_name    : ISO Media file produced by Google Inc.
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz,
mono, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2016-08-20T06:44:48.000000Z
      handler_name    : ISO Media file produced by Google Inc.
Stream mapping:
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:0 (h264) -> trim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  concat -> Stream #0:0 (libx264)
  concat -> Stream #0:1 (aac)
Press [q] to stop, [?] for help
[libx264 @ 0x215b480] using SAR=1/1
[libx264 @ 0x215b480] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x215b480] profile Constrained Baseline, level 3.1
[libx264 @ 0x215b480] 264 - core 148 - H.264/MPEG-4 AVC codec -
Copyleft 2003-2016 - http://www.videolan.org/x264.html - options:
cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1
psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0
8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0
threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1
interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0
keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0
crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to 'out.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Lavf57.71.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021),
yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 29.97 fps,
30k tbn, 29.97 tbc (default)
    Metadata:
      encoder         : Lavc57.89.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz,
stereo, fltp, 128 kb/s (default)
    Metadata:
      encoder         : Lavc57.89.100 aac
frame=  162 fps=0.0 q=21.0 size=    3209kB time=00:00:05.20
bitrate=5053.6kbits/s dup=12 drop=0 speed=10.frame=  333 fps=332
q=24.0 size=    6003kB time=00:00:10.64 bitrate=4620.0kbits/s dup=56
drop=0 speed=10.frame=  490 fps=326 q=25.0 size=   11387kB
time=00:00:15.88 bitrate=5873.2kbits/s dup=56 drop=0 speed=10.frame=
497 fps=321 q=-1.0 Lsize=   12747kB time=00:00:16.54
bitrate=6309.7kbits/s dup=56 drop=0 speed=10.7x
video:12486kB audio:247kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 0.113251%
[libx264 @ 0x215b480] frame I:2     Avg QP:19.00  size: 61007
[libx264 @ 0x215b480] frame P:495   Avg QP:23.96  size: 25582
[libx264 @ 0x215b480] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 0x215b480] mb P  I16..4: 15.8%  0.0%  0.0%  P16..4: 46.1%
0.0%  0.0%  0.0%  0.0%    skip:38.2%
[libx264 @ 0x215b480] coded y,uvDC,uvAC intra: 18.8% 31.1% 3.2% inter:
26.7% 15.7% 0.7%
[libx264 @ 0x215b480] i16 v,h,dc,p: 26% 39% 22% 13%
[libx264 @ 0x215b480] i8c dc,h,v,p: 47% 27% 18%  7%
[libx264 @ 0x215b480] kb/s:6167.78
[aac @ 0x2159a80] Qavg: 2023.994


More information about the ffmpeg-user mailing list