Opened 6 years ago

Closed 4 years ago

Last modified 4 years ago

#7272 closed defect (fixed)

encoding with hevc_amf results in video where forwarting is a mess

Reported by: Marco Pardo Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: amf
Cc: cornofear@yahoo.ca Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Hi,

I recode videos on nvidia and AMD cards in x265.

The nvidia output is nice and ok (in example for ref). The AMD output looks OK. But you can not fast forward in it. It uses 100% CPU and needs minutes.

The funny thing is that for the nvidia compile I used an old version of ffmpeg and for the amd I used the newest version.

Are there missing parameters by the AMD ffmpeg command or is it a bug with compiling with hevc_amf?

EXAMPLETIME


For example I have cut a 3 minute video and compiled it both ways.

Original clip: https://sheepchen.net/nextcloud/index.php/s/Nku5EUrTZ37BzAo
ENC NVIDIA (good): https://sheepchen.net/nextcloud/index.php/s/RJCXZzsIJBOWVK7
ENC AMD (bad): https://sheepchen.net/nextcloud/index.php/s/e61XOfrHxpghwwf

EXAMPLE NVIDIA:

\ffmpeg_20170827\bin\ffmpeg.exe -hwaccel cuvid -i "s:\temp\in_orig.mkv" -c:v hevc_nvenc -profile:v main -rc vbr_hq -qmin 18 -qmax 24 -b:v 1000k -maxrate 3000k -preset slow -rc-lookahead 32 -g 250 -c:a copy -c:s copy -map 0 "s:\temp\out_nvidia.mkv"

ffmpeg version N-87095-gef0c6d9 Copyright (c) 2000-2017 the FFmpeg developers

built with gcc 7.1.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
libavutil 55. 74.100 / 55. 74.100
libavcodec 57.103.101 / 57.103.101
libavformat 57. 78.100 / 57. 78.100
libavdevice 57. 8.100 / 57. 8.100
libavfilter 6.100.100 / 6.100.100
libswscale 4. 7.103 / 4. 7.103
libswresample 2. 8.100 / 2. 8.100
libpostproc 54. 6.100 / 54. 6.100

Input #0, matroska,webm, from 's:\temp\in_orig.mkv':

Metadata:

ENCODER : Lavf57.71.100

Duration: 00:01:00.00, start: 0.080000, bitrate: 12347 kb/s

Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
Metadata:

DURATION : 00:01:00.000000000

Stream #0:1(ger): Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s (default)
Metadata:

DURATION : 00:00:59.952000000

Stream #0:2: Audio: ac3, 48000 Hz, stereo, fltp, 448 kb/s (default)
Metadata:

DURATION : 00:00:59.952000000

Stream mapping:

Stream #0:0 -> #0:0 (h264 (native) -> hevc (hevc_nvenc))
Stream #0:1 -> #0:1 (copy)
Stream #0:2 -> #0:2 (copy)

Press [q] to stop, ? for help
Output #0, matroska, to 's:\temp\out_nvidia.mkv':

Metadata:

encoder : Lavf57.78.100
Stream #0:0: Video: hevc (hevc_nvenc) (Main), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=18-24, 1000 kb/s, 25 fps, 1k tbn, 25 tbc (default)
Metadata:

DURATION : 00:01:00.000000000
encoder : Lavc57.103.101 hevc_nvenc

Side data:

cpb: bitrate max/min/avg: 3000000/0/1000000 buffer size: 2000000 vbv_delay: -1

Stream #0:1(ger): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, fltp, 192 kb/s (default)
Metadata:

DURATION : 00:00:59.952000000

Stream #0:2: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, fltp, 448 kb/s (default)
Metadata:

DURATION : 00:00:59.952000000

%

EXAMPLE AMD:

\ffmpeg-20180619\bin\ffmpeg.exe -hwaccel dxva2 -i "s:\temp\in_orig.mkv" -c:v hevc_amf -profile:v main -qmin 18 -qmax 24 -b:v 1000k -maxrate 3000k -rc-lookahead 32 -g 250 -c:a copy -c:s copy -map 0 "s:\temp\out_amd.mkv"

ffmpeg version N-91330-ga990184007 Copyright (c) 2000-2018 the FFmpeg developers

built with gcc 7.3.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --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
libavutil 56. 18.102 / 56. 18.102
libavcodec 58. 20.103 / 58. 20.103
libavformat 58. 17.100 / 58. 17.100
libavdevice 58. 4.101 / 58. 4.101
libavfilter 7. 25.100 / 7. 25.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
libpostproc 55. 2.100 / 55. 2.100

Input #0, matroska,webm, from 's:\temp\in_orig.mkv':

Metadata:

ENCODER : Lavf57.71.100

Duration: 00:01:00.00, start: 0.080000, bitrate: 12347 kb/s

Stream #0:0: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
Metadata:

DURATION : 00:01:00.000000000

Stream #0:1(ger): Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s (default)
Metadata:

DURATION : 00:00:59.952000000

Stream #0:2: Audio: ac3, 48000 Hz, stereo, fltp, 448 kb/s (default)
Metadata:

DURATION : 00:00:59.952000000

Stream mapping:

Stream #0:0 -> #0:0 (h264 (native) -> hevc (hevc_amf))
Stream #0:1 -> #0:1 (copy)
Stream #0:2 -> #0:2 (copy)

Press [q] to stop, ? for help
Output #0, matroska, to 's:\temp\out_amd.mkv':

Metadata:

encoder : Lavf58.17.100
Stream #0:0: Video: hevc (hevc_amf), nv12, 1920x1080 [SAR 1:1 DAR 16:9], q=18-24, 1000 kb/s, 25 fps, 1k tbn, 25 tbc (default)
Metadata:

DURATION : 00:01:00.000000000
encoder : Lavc58.20.103 hevc_amf

Stream #0:1(ger): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, fltp, 192 kb/s (default)
Metadata:

DURATION : 00:00:59.952000000

Stream #0:2: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, fltp, 448 kb/s (default)
Metadata:

DURATION : 00:00:59.952000000

%

Change History (16)

comment:1 by Carl Eugen Hoyos, 6 years ago

Priority: importantnormal

comment:2 by AlexisMay, 6 years ago

hello

Fast forwarding on AMD output is slow because it is not even using gpu acceleration on latest hardware for playback that means cpu slowing everything down. Inspecting clip with ffmpeg reports : track 1: codec frame size is not set. maybe is it related to that? how can we fix this?

comment:3 by Marco Pardo, 6 years ago

Hi,

The recoding using the GPU (80% load on GPU and fast.. definily using GPU chip).

The playback from both clips is on the AMD Ryzen 5 (with internal Vega 11 GPU). The Video that was encoded using the NVIDIA has no problems (playback on AMD). The video that was encoded on the AMD has slow forwarting on AMD and Intel CPUs.

Playback in all 4 instances (INTEL, AMD CPU and NVIDIA, VEGA encoded video) was with VLC.

The problem is definitly by encoding with AMD hardware acceleration.

How can I set the codec frame size? Then I try it..

comment:4 by AlexisMay, 6 years ago

hi

thanks for the sample clips.

could you transcode the clip once again but with -c:v h264_amf parameter to see if it is h264 or just hevc related?

comment:5 by Marco Pardo, 6 years ago

Hi,

here a reupload of the x265 command: https://sheepchen.net/nextcloud/index.php/s/Fy8Kk8ZYlJgc0Br

here the x264 command: https://sheepchen.net/nextcloud/index.php/s/LH2j8ugitFw89W2

here the x264 file: https://sheepchen.net/nextcloud/index.php/s/HcYsFBBc7sO3moa

The x264 file has no problem by fast forwarting.

comment:6 by Mikhail, 6 years ago

I reproduced the problem. It appeared that AMD HEVC encoder has an additional parameter that controls frequency of IDR frames. And in turn IDRs are needed to indicate key frames used in seek. Please add "-gops_per_idr 1" to your command line. It will write IDR on every GOP. Maybe, it makes sense to change ffmpeg AMF default value from 60 to 1.

comment:7 by Mikhail, 6 years ago

I reproduced the problem. It appeared that AMD HEVC encoder has an additional parameter that controls frequency of IDR frames. And in turn IDRs are needed to indicate key frames used in seek. Please add "-gops_per_idr 1" to your command line. It will write IDR on every GOP. Maybe, it makes sense to change ffmpeg AMF default value from 60 to 1.

comment:8 by AlexisMay, 6 years ago

hi sheepchen

could you reupload hevc clip with -gops_per_idr 1 enabled?

comment:9 by Marco Pardo, 6 years ago

Resolution: fixed
Status: newclosed

Yes, this solved the problem! Thanks!

Here is the command: ffmpeg.exe -hwaccel dxva2 -i <inputfile> -c:v hevc_amf -gops_per_idr 1 -profile:v main -qmin 18 -qmax 24 -b:v 1000k -maxrate 3000k -rc-lookahead 32 -g 250 -c:a copy -c:s copy -map 0 <outputfile>

Here is the command output: https://sheepchen.net/nextcloud/index.php/s/n7Y85DfDRkotQX5
And here is the encoded videofile: https://sheepchen.net/nextcloud/index.php/s/HGoovTtsqOlJCvP

comment:10 by Carl Eugen Hoyos, 6 years ago

Resolution: fixed
Status: closedreopened

Either there never was an issue or this can still be improved, it was not fixed.

comment:11 by Marco Pardo, 6 years ago

ok, right.

It would be nice if ffmpeg use the default value "-gops_per_idr 1" if hevc_amf is used and no other value of gops_per_idr is set.

comment:12 by AlexisMay, 6 years ago

well i am on macOS High Sierra 10.13 which introduced native hardware accelerated playback of hevc media files and this clip when further transcoded with -c:v copy -c:a aac -tag:v? hvc1 out.mp4 still doesnt seek very well. so what further settings should be enabled?

Last edited 6 years ago by AlexisMay (previous) (diff)

comment:13 by Carl Eugen Hoyos, 6 years ago

Keywords: amf added; hevc_amf removed

comment:14 by Michael, 4 years ago

Cc: cornofear@yahoo.ca added

As of git-2020-05-19-74dfc88 the default gops_per_idr is still 60 rather than 1.

comment:15 by Marton Balint, 4 years ago

Resolution: fixed
Status: reopenedclosed

comment:16 by Carl Eugen Hoyos, 4 years ago

Component: undeterminedavcodec
Version: unspecifiedgit-master
Note: See TracTickets for help on using tickets.