Opened 4 years ago

Closed 3 years ago

#8857 closed defect (fixed)

ffmpeg h264_qsv force_key_frames incorret

Reported by: mikejson Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: h264_qsv
Cc: zimbler@gmail.com Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
How to reproduce:
when i user ffmpeg command line, like this:
./ffmpeg.exe -c:v mjpeg_qsv -rtbufsize 2000M -s 2560*1440 -f dshow -i video="Smart Camera" -vcodec h264_qsv -b:v 6000k -r 30 -preset veryfast -tune:v zerolatency -force_key_frames expr:gte\(t,n_forced*5\) -g 30*10 iii.h264

The key frame is generated at the fifth second; but the later is not incorret; every frame is key frame.

Change History (8)

comment:1 by Carl Eugen Hoyos, 4 years ago

Keywords: force_key_frames removed
Priority: importantnormal

Please provide the command line you tested together with the complete, uncut console output to make this a valid ticket.

comment:2 by mikejson, 4 years ago

$ ./ffmpeg.exe -c:v mjpeg_qsv -rtbufsize 2000M -s 2560*1440 -f dshow -i video="Smart Camera" -vcodec h264_qsv -b:v 6000k -r 30 -preset veryfast -tune:v zerolatency -force_key_frames expr:gte\(t,n_forced*5\) -g 30*10 iii.h264
ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers

built with gcc 10.2.1 (GCC) 20200726
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-libsrt --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-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100

[mjpeg @ 00a44500] EOI missing, emulating
Input #0, dshow, from 'video=Smart Camera':

Duration: N/A, start: 22972.029000, bitrate: N/A

Stream #0:0: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj420p(pc, bt470bg/unknown/unknown), 2560x1440 [SAR 96:96 DAR 16:9], 30 fps, 30 tbr, 10000k tbn, 10000k tbc

Codec AVOption tune (The metric that the encoder tunes for. Automatically chosen by the encoder by default) specified for output file #0 (iii.h264) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
Stream mapping:

Stream #0:0 -> #0:0 (mjpeg (mjpeg_qsv) -> h264 (h264_qsv))

Press [q] to stop, ? for help
Output #0, h264, to 'iii.h264':

Metadata:

encoder : Lavf58.45.100
Stream #0:0: Video: h264 (h264_qsv), nv12, 2560x1440 [SAR 96:96 DAR 16:9], q=-1--1, 6000 kb/s, 30 fps, 30 tbn, 30 tbc
Metadata:

encoder : Lavc58.91.100 h264_qsv

Side data:

cpb: bitrate max/min/avg: 0/0/6000000 buffer size: 0 vbv_delay: N/A

frame= 1060 fps= 30 q=51.0 size= 26112kB time=00:00:35.03 bitrate=6105.9kbits/s dup=22 drop=0 speed=0.99x

comment:3 by Sergey Tikhonov, 4 years ago

Cc: zimbler@gmail.com added
Keywords: force_key_frames added

Same problem for me, only with force_key_frames parameter present.

ffmpeg  -y -i timecode.mp4 -init_hw_device qsv=foo:/dev/dri/renderD128 -filter_hw_device foo -filter_complex "[0:v]format=nv12,hwupload=extra_hw_frames=64[v]" -map '[v]' -c:v h264_qsv -g 50 -flags +cgop -r 25 -keyint_min 49 -forced_idr 1 -force_key_frames "expr:gte(t,(n_forced*2)+ 2)" out_cgop.mp4

ffprobe -show_frames -select_streams v:0 out_cgop.mp4 | egrep '(pict_type|key_frame|pkt_pts_time)' | xargs -n 3 echo | grep I
  • without force_key_frames a key frame is set to every 50 frames.
  • with force_key_frames, first key frame is at 0:00:00.0, second at 0:02:00.0 and then randomly with average distance 2-5 frames.
  • two consequent launches produces different key frames, so there may be a race condition
  • output with or without force_key_frames is same and does not contain any warning or error.
Version 1, edited 4 years ago by Sergey Tikhonov (previous) (next) (diff)

comment:4 by Carl Eugen Hoyos, 4 years ago

Keywords: force_key_frames removed

comment:5 by Xu Guangxin, 4 years ago

Component: undeterminedavcodec

Hi mikejson, zimbler:
Thanks for reporting the issue.
It fixed at https://github.com/intel-media-ci/ffmpeg/pull/330
I will send the patch if it's passed our internal review.

thanks

comment:6 by Xu Guangxin, 4 years ago

Hi mikejson, zimbler
patch sent to maillist https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210106031234.13435-1-guangxin.xu@intel.com/

You can watch the discussion and merging process.

thanks

comment:7 by Balling, 4 years ago

Status: newopen

every frame is key frame.

Wow. Just like with VC1 decoder (in TS, not in mp4). Patch is still not applied.

Last edited 4 years ago by Balling (previous) (diff)

comment:8 by haihao, 3 years ago

Resolution: fixed
Status: openclosed
Note: See TracTickets for help on using tickets.