Setting fixed keyframes in a h265 video using FFMPEG

1.9k views Asked by At

I'm trying to cut a video and convert it into h265, but the output file isn't seekable in the same way as the original video (for example, instead of jumping to a keyframe every 1 second, the keyframes can be 15 seconds apart).

I've been trying to force keyframes every 2 seconds using the following command, but it doesn't seem to work (the input's frame rate is 25 fps):

ffmpeg -i "D:\test\example.mp4" -ss 0 -t 60 -c:v libx265 -an -x265-params "crf=25:keyint=52:min-keyint=52:no-scenecut" "D:\test\example\example_0.mp4" -hwaccel cuda -hwaccel_output_format cuda

What am I doing wrong here?

EDIT: Full run log:

ffmpeg -i "D:\test\example.mp4" -ss 0 -t 60 -c:v libx265 -an -x265-params "crf=25:keyint=52:min-keyint=52:no-scenecut" "D:\test\example\example_0.mp4" -hwaccel cuda -hwaccel_output_format cuda 
ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200523
  configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --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 --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Trailing options were found on the commandline.
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001dabdc30fc0] stream 0, timescale not set
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'D:\test\example.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    track           : 1
    comment         : www.dvdvideosoft.com
    title           : Final Four Classic, 2004: Maccabi Elite Tel Aviv-Skipper Bologna
    encoder         : Lavf55.19.104
  Duration: 01:38:43.57, start: 0.000000, bitrate: 1076 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 944 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:2: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 480x360, 90k tbr, 90k tbn, 90k tbc (attached pic)
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> hevc (libx265))
Press [q] to stop, [?] for help
x265 [info]: HEVC encoder version 3.3+29-1e3dbf09ee4f
x265 [info]: build info [Windows][GCC 9.3.1][64 bit] 8bit+10bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main profile, Level-3 (Main tier)
x265 [info]: Thread pool created using 16 threads
x265 [info]: Slices                              : 1
x265 [info]: frame threads / pool features       : 4 / wpp(8 rows)
x265 [warning]: Source height < 720p; disabling lookahead-slices
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge         : hex / 57 / 2 / 3
x265 [info]: Keyframe min / max / scenecut / bias  : 25 / 250 / 40 / 5.00 
x265 [info]: Lookahead / bframes / badapt        : 20 / 4 / 2
x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 0
x265 [info]: References / ref-limit  cu / depth  : 3 / off / on
x265 [info]: AQ: mode / str / qg-size / cu-tree  : 2 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress            : CRF-28.0 / 0.60
x265 [info]: tools: rd=3 psy-rd=2.00 early-skip rskip mode=1 signhide tmvp
x265 [info]: tools: b-intra strong-intra-smoothing deblock sao
Output #0, mp4, to 'D:\test\example\example_0.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    track           : 1
    comment         : www.dvdvideosoft.com
    title           : Final Four Classic, 2004: Maccabi Elite Tel Aviv-Skipper Bologna
    encoder         : Lavf58.29.100
    Stream #0:0(und): Video: hevc (libx265) (hev1 / 0x31766568), yuv420p, 854x480 [SAR 1:1 DAR 427:240], q=2-31, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.54.100 libx265
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 1500 fps=116 q=-0.0 Lsize=    3811kB time=00:00:59.88 bitrate= 521.4kbits/s speed=4.62x    
video:3789kB audio:0kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 0.581860%
x265 [info]: frame I:     10, Avg QP:26.67  kb/s: 3043.86 
x265 [info]: frame P:    395, Avg QP:28.57  kb/s: 1282.13 
x265 [info]: frame B:   1095, Avg QP:34.31  kb/s: 217.24  
x265 [info]: Weighted P-Frames: Y:3.8% UV:0.8%
x265 [info]: consecutive B-frames: 5.4% 5.4% 13.1% 65.4% 10.6% 

encoded 1500 frames in 12.93s (116.05 fps), 516.51 kb/s, Avg QP:32.75
0

There are 0 answers