ffmpeg 的选择过滤器生成不需要的黑帧

ffmpeg 的选择过滤器生成不需要的黑帧

我想用 ffmpeg 按帧剪切视频。到目前为止,我想到的是

ffmpeg -i P2.mp4 -vf "fps,setpts='PTS-STARTPTS',select='gte(n\,20)*lte(n\,30)',crop='600:430:100:650',scale='280:-1'" P2o.avi

这些参数用于测试,以查看一切是否按要求执行。

我得到的是一段视频,其中有 20 个黑帧,后面跟着 10 个内容帧。虽然我想要这 10 帧,但我不知道这 20 个黑帧是怎么来的。- selectfilter 的文档明确指出,只选择表达式求值为非 0 的帧。上面的gte(n,20)应该删除它们。

如果有帮助的话,这里是 ffmpeg 的输出:

G:\>ffmpeg -i P2.mp4 -vf "fps,setpts='PTS-STARTPTS',select='gte(n\,20)*lte(n\,30)',crop='600:430:100:650',scale='280:-1'" P2o.avi
ffmpeg version N-50911-g9efcfbe Copyright (c) 2000-2013 the FFmpeg developers
  built on Mar 13 2013 21:26:48 with gcc 4.7.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 19.100 / 52. 19.100
  libavcodec     55.  0.100 / 55.  0.100
  libavformat    55.  0.100 / 55.  0.100
  libavdevice    54.  4.100 / 54.  4.100
  libavfilter     3. 45.103 /  3. 45.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[h264 @ 039a1ae0] mmco: unref short failure
    Last message repeated 5 times
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'P2.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.0.100
  Duration: 01:51:58.78, start: 0.000000, bitrate: 8479 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080
 [SAR 1:1 DAR 16:9], 8084 kb/s, 49.96 fps, 50 tbr, 90k tbn, 50 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, stereo, fltp, 384 kb/s
    Metadata:
      handler_name    : SoundHandler
File 'P2o.avi' already exists. Overwrite ? [y/N] y
Invalid pixel aspect ratio 603/602, limit is 255/255 reducing
Output #0, avi, to 'P2o.avi':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    ISFT            : Lavf55.0.100
    Stream #0:0(und): Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 280x201 [SAR 1:1 DAR 280:201], q=2-31, 200 kb/s, SAR 603:602 DAR 60:43, 25 tbn, 25 tbc
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> mpeg4)
  Stream #0:1 -> #0:1 (ac3 -> libmp3lame)
Press [q] to stop, [?] for help
[h264 @ 046f1680] mmco: unref short failure
    Last message repeated 1 times
[h264 @ 05e4a900] mmco: unref short failure
    Last message repeated 3 times
[swscaler @ 039b63e0] Warning: data is not aligned! This can lead to a speedloss

frame=    1 fps=0.0 q=4.2 size=      29kB time=00:00:01.82 bitrate= 131.8kbits/s
frame=   11 fps= 11 q=7.4 size=      71kB time=00:00:03.16 bitrate= 184.4kbits/s
frame=   11 fps=7.2 q=7.4 size=      71kB time=00:00:04.60 bitrate= 126.8kbits/s
frame=   11 fps=5.4 q=7.4 size=      71kB time=00:00:06.19 bitrate=  94.3kbits/s
frame=   11 fps=4.3 q=7.4 size=      71kB time=00:00:07.48 bitrate=  78.0kbits/s
frame=   11 fps=3.6 q=7.4 size=      71kB time=00:00:08.76 bitrate=  66.7kbits/s
frame=   11 fps=3.1 q=7.4 size=      71kB time=00:00:10.08 bitrate=  58.0kbits/s
frame=   11 fps=2.7 q=7.4 size=      71kB time=00:00:11.42 bitrate=  51.1kbits/s
frame=   11 fps=2.6 q=7.4 Lsize=     253kB time=00:00:12.04 bitrate= 171.8kbits/s
video:42kB audio:189kB subtitle:0 global headers:0kB muxing overhead 9.670474%

G:\>

有人能建议我如何去掉这 20 帧吗?我觉得在这里用不了-ss

答案1

尝试放置setpts过滤器濾器select

setpts='PTS-STARTPTS'重置每个帧的显示时间戳(因此第一帧为 0.0 秒,并且它们正确递增) - 选择过滤器会将选定的帧发送到 ffmpeg 的其余部分,但它本身不会改变显示时间戳,这可能会导致各种各样的问题 - 正如您所发现的。

相关内容