ffmpeg 修剪连接具有 >3 个单帧条目不起作用,仅提供前 3 个

ffmpeg 修剪连接具有 >3 个单帧条目不起作用,仅提供前 3 个

我想使用 ffmpeg 从视频中剪掉特定帧(在我的情况下是黑帧)。我已经确定了正确的剩余位置,并将它们作为参数提供给修剪过滤器。特别是对于单帧的修剪命令(帧速率=25,帧持续时间=0.04),我只得到前 3 帧,然后什么都没有。知道我的命令有什么问题吗?

我的命令如下所示:

ffmpeg.exe -i MVI_6289.MOV -filter_complex "[0:v]trim=start=3.72:end=3.76,setpts=PTS-STARTPTS,format=yuvj420p[1v];[0:v]trim=start=4.04:end=4.08,setpts=PTS-STARTPTS,format=yuvj420p[2v];[0:v]trim=start=4.12:end=4.16,setpts=PTS-STARTPTS,format=yuvj420p[3v];[0:v]trim=start=4.24:end=4.28,setpts=PTS-STARTPTS,format=yuvj420p[4v];[0:v]trim=start=4.32:end=4.36,setpts=PTS-STARTPTS,format=yuvj420p[5v];[1v][2v][3v][4v][5v]concat=n=5:v=1[v]" -map [v] MVI_6289.out.MOV

输出为(输出仅 3 帧!):

ffmpeg version 5.1.2-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 12.1.0 (Rev2, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'MVI_6289.MOV':
  Metadata:
    major_brand     : qt
    minor_version   : 537331968
    compatible_brands: qt  CAEP
    creation_time   : 2022-12-08T18:17:03.000000Z
  Duration: 00:00:10.48, start: 0.000000, bitrate: 26207 kb/s
  Stream #0:0[0x1](eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuvj420p(pc, smpte170m/bt709/bt709, progressive), 1920x1080, 26204 kb/s, 25 fps, 25 tbr, 25k tbn (default)
    Metadata:
      creation_time   : 2022-12-08T18:17:03.000000Z
      vendor_id       : [0][0][0][0]
Stream mapping:
  Stream #0:0 (h264) -> trim:default
  Stream #0:0 (h264) -> trim:default
  Stream #0:0 (h264) -> trim:default
  Stream #0:0 (h264) -> trim:default
  Stream #0:0 (h264) -> trim:default
  concat:out:v0 -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
[libx264 @ 000001c1539506c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000001c1539506c0] profile High, level 4.0, 4:2:0, 8-bit
[libx264 @ 000001c1539506c0] 264 - core 164 r3099 e067ab0 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - 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, mov, to 'MVI_6289.out.MOV':
  Metadata:
    major_brand     : qt
    minor_version   : 537331968
    compatible_brands: qt  CAEP
    encoder         : Lavf59.27.100
  Stream #0:0: Video: h264 (avc1 / 0x31637661), yuvj420p(pc, smpte170m/bt709/bt709, progressive), 1920x1080, q=2-31, 25 fps, 12800 tbn
    Metadata:
      encoder         : Lavc59.37.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
frame=    3 fps=0.0 q=-1.0 Lsize=      82kB time=00:00:00.00 bitrate=8597025.6kbits/s dup=0 drop=2 speed=0.000128x
video:81kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.042721%
[libx264 @ 000001c1539506c0] frame I:1     Avg QP:23.28  size: 49746
[libx264 @ 000001c1539506c0] frame P:1     Avg QP:24.84  size: 20520
[libx264 @ 000001c1539506c0] frame B:1     Avg QP:25.37  size: 12000
[libx264 @ 000001c1539506c0] consecutive B-frames: 33.3% 66.7%  0.0%  0.0%
[libx264 @ 000001c1539506c0] mb I  I16..4: 19.1% 77.9%  3.0%
[libx264 @ 000001c1539506c0] mb P  I16..4:  6.5% 15.2%  0.2%  P16..4: 32.2%  9.9%  1.6%  0.0%  0.0%    skip:34.4%
[libx264 @ 000001c1539506c0] mb B  I16..4:  1.3%  2.1%  0.1%  B16..8: 33.6%  5.2%  0.6%  direct: 2.0%  skip:55.1%  L0:51.9% L1:45.0% BI: 3.1%
[libx264 @ 000001c1539506c0] 8x8 transform intra:76.0% inter:91.6%
[libx264 @ 000001c1539506c0] coded y,uvDC,uvAC intra: 47.4% 59.1% 21.0% inter: 14.9% 20.0% 0.0%
[libx264 @ 000001c1539506c0] i16 v,h,dc,p: 56% 24%  8% 12%
[libx264 @ 000001c1539506c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 21% 21%  3%  3%  4%  4%  5%  6%
[libx264 @ 000001c1539506c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 34% 24%  9%  4%  7%  8%  6%  5%  3%
[libx264 @ 000001c1539506c0] i8c dc,h,v,p: 61% 18% 19%  2%
[libx264 @ 000001c1539506c0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 000001c1539506c0] kb/s:5484.40

答案1

对我来说,一种解决方法是将来自修剪过滤器的每个单帧(第一帧除外)的 setpts=PTS-STARTPTS+1000 设置为 setpts=PTS-STARTPTS。多帧修剪部分只有 setpts=PTS-STARTPTS。这样我的输出就不会丢失或重复任何帧。也许必须针对其他视频源进行调整。

我的示例如下:

ffmpeg.exe -i MVI_6289.MOV -filter_complex "[0:v]trim=start=3.72:end=3.76,setpts=PTS-STARTPTS,format=yuvj420p[1v];[0:v]trim=start=4.04:end=4.08,setpts=PTS-STARTPTS+1000,format=yuvj420p[2v];[0:v]trim=start=4.12:end=4.16,setpts=PTS-STARTPTS+1000,format=yuvj420p[3v];[0:v]trim=start=4.24:end=4.28,setpts=PTS-STARTPTS+1000,format=yuvj420p[4v];[0:v]trim=start=4.32:end=4.36,setpts=PTS-STARTPTS+1000,format=yuvj420p[5v];[1v][2v][3v][4v][5v]concat=n=5:v=1[v]" -map [v] MVI_6289.out.MOV

相关内容