ffmpeg:修剪/ concat结果不同长度的视频

时间:2019-05-03 13:23:03

标签: ffmpeg

我正在试验trimconcat过滤器。

我只想将视频分成 X 个块,然后再次concat。我希望结果将是具有相同 / 持续时间的视频。

所以我有一个以 1 fps 编码的视频,包含 3帧,该视频的持续时间为 3秒

我运行以下脚本

ffmpeg -y -i fps.mp4 -an -filter_complex "[0:v]trim=0:1[v1];[0:v]trim=1:2[v2];[0:v]trim=2:3[v3];[v1][v2][v3] concat=n=3:v=1 [out]" -map [out] out.mp4

结果是一段持续时间为 4秒的视频,用于检查我打过的问题:

ffprobe -print_format json -show_frames out.mp4

它表明现在有 4 个帧?? (这里是转储)

ffprobe version 4.1.3 Copyright (c) 2007-2019 the FFmpeg developers
  built with Apple LLVM version 10.0.1 (clang-1001.0.46.3)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.3 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/openjdk-12.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/openjdk-12.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
{
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'out.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
  Duration: 00:00:04.00, start: 0.000000, bitrate: 4 kb/s
    Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 100x100, 2 kb/s, 1 fps, 1 tbr, 16384 tbn, 2 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    "frames": [
        {
            "media_type": "video",
            "stream_index": 0,
            "key_frame": 1,
            "pkt_pts": 0,
            "pkt_pts_time": "0.000000",
            "pkt_dts": 0,
            "pkt_dts_time": "0.000000",
            "best_effort_timestamp": 0,
            "best_effort_timestamp_time": "0.000000",
            "pkt_duration": 16384,
            "pkt_duration_time": "1.000000",
            "pkt_pos": "48",
            "pkt_size": "857",
            "width": 100,
            "height": 100,
            "pix_fmt": "yuv444p",
            "pict_type": "I",
            "coded_picture_number": 0,
            "display_picture_number": 0,
            "interlaced_frame": 0,
            "top_field_first": 0,
            "repeat_pict": 0,
            "chroma_location": "left"
        },
        {
            "media_type": "video",
            "stream_index": 0,
            "key_frame": 0,
            "pkt_pts": 16384,
            "pkt_pts_time": "1.000000",
            "pkt_dts": 16384,
            "pkt_dts_time": "1.000000",
            "best_effort_timestamp": 16384,
            "best_effort_timestamp_time": "1.000000",
            "pkt_duration": 16384,
            "pkt_duration_time": "1.000000",
            "pkt_pos": "1053",
            "pkt_size": "146",
            "width": 100,
            "height": 100,
            "pix_fmt": "yuv444p",
            "pict_type": "B",
            "coded_picture_number": 2,
            "display_picture_number": 0,
            "interlaced_frame": 0,
            "top_field_first": 0,
            "repeat_pict": 0,
            "chroma_location": "left"
        },
        {
            "media_type": "video",
            "stream_index": 0,
            "key_frame": 0,
            "pkt_pts": 32768,
            "pkt_pts_time": "2.000000",
            "best_effort_timestamp": 32768,
            "best_effort_timestamp_time": "2.000000",
            "pkt_duration": 16384,
            "pkt_duration_time": "1.000000",
            "pkt_pos": "1199",
            "pkt_size": "19",
            "width": 100,
            "height": 100,
            "pix_fmt": "yuv444p",
            "pict_type": "B",
            "coded_picture_number": 3,
            "display_picture_number": 0,
            "interlaced_frame": 0,
            "top_field_first": 0,
            "repeat_pict": 0,
            "chroma_location": "left"
        },
        {
            "media_type": "video",
            "stream_index": 0,
            "key_frame": 0,
            "pkt_pts": 49152,
            "pkt_pts_time": "3.000000",
            "best_effort_timestamp": 49152,
            "best_effort_timestamp_time": "3.000000",
            "pkt_duration": 16384,
            "pkt_duration_time": "1.000000",
            "pkt_pos": "905",
            "pkt_size": "148",
            "width": 100,
            "height": 100,
            "pix_fmt": "yuv444p",
            "pict_type": "P",
            "coded_picture_number": 1,
            "display_picture_number": 0,
            "interlaced_frame": 0,
            "top_field_first": 0,
            "repeat_pict": 0,
            "chroma_location": "left"
        }
    ]
}

我尝试了不同的方法,如果我分割了2秒的视频(仍为1 fps)并再次连接,一切似乎都可以正常工作。但是,如果超出这一范围,就会出问题吗?

此处是ffmpeg -i fps.mp4的输出

ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple LLVM version 10.0.1 (clang-1001.0.46.3)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.3 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/openjdk-12.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/openjdk-12.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'scripts/fps.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
  Duration: 00:00:03.00, start: 0.000000, bitrate: 7 kb/s
    Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), gbrp(tv, gbr/unknown/unknown), 100x100, 4 kb/s, 1 fps, 1 tbr, 16384 tbn, 2 tbc (default)
    Metadata:
      handler_name    : VideoHandler

0 个答案:

没有答案