如何用ffmpeg精确截取视频帧?

如何用ffmpeg精确截取视频帧?

我有一个视频。这是它的ffprobe输出:

> ffprobe 7347-00009\ kliksa.mp4
ffprobe version 2.6.1 Copyright (c) 2007-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libfreetype --enable-libvorbis --enable-libvpx --enable-libass --enable-ffplay --enable-libfdk-aac --enable-libopus --enable-libquvi --enable-libx265 --enable-nonfree --enable-vda
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '7347-00009 kliksa.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: avc1isommp42
    creation_time   : 2015-09-17 14:04:14
  Duration: 00:00:30.44, start: 0.000000, bitrate: 7238 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 6977 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2015-09-17 14:04:14
      handler_name    : ?Apple Video Media Handler
      encoder         : inegy Cinecoder H.264 Encoder
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 255 kb/s (default)
    Metadata:
      creation_time   : 2015-09-17 14:04:14
      handler_name    : ?Apple Sound Media Handler

所有播放器都显示持续时间为 30 秒。但确切的持续时间正如00:00:30.44显示的那样ffprobe

我想要做的是将视频时长设置为精确00:00:30.00

我尝试了这个:

ffmpeg -i 7347-00009\ kliksa.mp4 -c copy -ss 00:00:00.000 -to 30.000 test.mp4

但是我仍有持续时间00:00:30.02。这是 ffprobe 输出:

> ffprobe test.mp4
ffprobe version 2.6.1 Copyright (c) 2007-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libfreetype --enable-libvorbis --enable-libvpx --enable-libass --enable-ffplay --enable-libfdk-aac --enable-libopus --enable-libquvi --enable-libx265 --enable-nonfree --enable-vda
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.25.101
  Duration: 00:00:30.02, start: 0.000000, bitrate: 7240 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 6982 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 255 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

那么,如何才能准确地截取视频帧呢?

答案1

根据答案是,无需重新编码即可对视频进行帧精确剪切,但ffmpeg只能在 GOP 边界处进行。我不确定它是否适用于剪切视频的结尾。

顺便说一句,25 fps 的恒定帧率视频的持续时间不能为 30.02 秒。1 帧应该显示 1/25 秒,即 0.04 秒。

也许你的视频的时间戳不对?尝试重新生成时间戳:

ffmpeg -i test.mp4 -fflags +genpts output.mp4

相关内容