Я пытаюсь замедлить видео до половины скорости, начиная с кадра 100 с помощью фильтра setpts. Это работает, но из кадра 100 я получаю 100 дополнительных замороженных пропущенных кадров, прежде чем видео продолжается с половинной скоростью. Моя команда неверна или есть проблема с фильтром setpts?

Команда:

ffmpeg -i ball.mp4 -vf "setpts = 'if(gte(N, 100), 2,1)' * PTS" ball_slow.mp4

Вывод командной строки:

ffmpeg version N-91592-g87cc7e8d4e Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 8.2.1 (GCC) 20180808
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
  libavutil      56. 18.102 / 56. 18.102
  libavcodec     58. 22.101 / 58. 22.101
  libavformat    58. 17.101 / 58. 17.101
  libavdevice    58.  4.101 / 58.  4.101
  libavfilter     7. 26.100 /  7. 26.100
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'ball.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.17.100
  Duration: 00:00:10.00, start: 0.066016, bitrate: 412 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 409 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 000001ceb370b4c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000001ceb370b4c0] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 000001ceb370b4c0] 264 - core 157 r2932 303c484 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - 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=6 lookahead_threads=1 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 'ball_slow.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.17.101
    Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1280x720, q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.22.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=   47 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x
frame=   52 fps= 40 q=29.0 size=       0kB time=-00:00:00.03 bitrate=N/A speed=N/A
frame=   97 fps= 53 q=29.0 size=       0kB time=00:00:01.46 bitrate=   0.3kbits/s speed=0.805x
frame=  203 fps= 74 q=29.0 size=       0kB time=00:00:05.00 bitrate=   0.1kbits/s dup=101 drop=0 speed=1.81x
frame=  261 fps= 80 q=29.0 size=       0kB time=00:00:06.93 bitrate=   0.1kbits/s dup=130 drop=0 speed=2.13x
frame=  303 fps= 80 q=29.0 size=       0kB time=00:00:08.33 bitrate=   0.0kbits/s dup=151 drop=0 speed=2.19x
frame=  351 fps= 82 q=29.0 size=     256kB time=00:00:09.93 bitrate= 211.2kbits/s dup=175 drop=0 speed=2.31x
frame=  395 fps= 82 q=29.0 size=     256kB time=00:00:11.40 bitrate= 184.0kbits/s dup=197 drop=0 speed=2.37x
frame=  431 fps= 81 q=29.0 size=     256kB time=00:00:12.60 bitrate= 166.5kbits/s dup=215 drop=0 speed=2.38x
frame=  469 fps= 81 q=29.0 size=     256kB time=00:00:13.86 bitrate= 151.3kbits/s dup=234 drop=0 speed=2.39x
frame=  515 fps= 81 q=29.0 size=     256kB time=00:00:15.40 bitrate= 136.2kbits/s dup=257 drop=0 speed=2.43x
frame=  559 fps= 82 q=29.0 size=     512kB time=00:00:16.86 bitrate= 248.7kbits/s dup=279 drop=0 speed=2.47x
frame=  599 fps= 81 q=-1.0 Lsize=     578kB time=00:00:19.86 bitrate= 238.3kbits/s dup=299 drop=0 speed=2.68x    
video:570kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.370572%
[libx264 @ 000001ceb370b4c0] frame I:3     Avg QP:10.25  size:  3598
[libx264 @ 000001ceb370b4c0] frame P:154   Avg QP:20.98  size:  2032
[libx264 @ 000001ceb370b4c0] frame B:442   Avg QP:19.73  size:   587
[libx264 @ 000001ceb370b4c0] consecutive B-frames:  0.7%  2.3%  1.5% 95.5%
[libx264 @ 000001ceb370b4c0] mb I  I16..4: 67.9% 28.6%  3.5%
[libx264 @ 000001ceb370b4c0] mb P  I16..4:  0.2%  1.1%  0.7%  P16..4:  2.0%  1.6%  0.6%  0.0%  0.0%    skip:93.8%
[libx264 @ 000001ceb370b4c0] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  3.3%  1.0%  0.2%  direct: 0.1%  skip:95.4%  L0:43.3% L1:48.9% BI: 7.8%
[libx264 @ 000001ceb370b4c0] 8x8 transform intra:41.2% inter:7.4%
[libx264 @ 000001ceb370b4c0] coded y,uvDC,uvAC intra: 12.1% 0.6% 0.0% inter: 0.5% 0.0% 0.0%
[libx264 @ 000001ceb370b4c0] i16 v,h,dc,p: 87%  7%  6%  0%
[libx264 @ 000001ceb370b4c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16%  9% 74%  0%  0%  0%  0%  0%  0%
[libx264 @ 000001ceb370b4c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 18% 39%  4%  4%  3%  4%  3%  2%
[libx264 @ 000001ceb370b4c0] i8c dc,h,v,p: 94%  4%  3%  0%
[libx264 @ 000001ceb370b4c0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 000001ceb370b4c0] ref P L0: 72.5%  2.9% 18.0%  6.6%
[libx264 @ 000001ceb370b4c0] ref B L0: 65.4% 28.1%  6.5%
[libx264 @ 000001ceb370b4c0] ref B L1: 94.2%  5.8%
[libx264 @ 000001ceb370b4c0] kb/s:233.59

1 ответ1

0

Допустим, ваша временная база обратна частоте кадров.

Согласно вашему выражению setpts,

кадр 99 будет иметь новый PTS 99 = 99/30 = 3,30 и
кадр 100 будет иметь новый PTS 200 = 200/30 = 6,67 с; 101 будет иметь 6,73 с.

PTS кадра можно рассматривать как

timestamp of previous frame + inter-frame interval

Для половинной скорости вам нужно только удвоить межкадровый интервал.

Итак, используйте вместо этого,

setpts='if(eq(N,0),0,PREV_OUTPTS+if(gte(N,100),2,1)*(PTS-PREV_INPTS))'

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .