mpv icon indicating copy to clipboard operation
mpv copied to clipboard

encoding with mpv(libx265) produces higher levels (compared to ffmpeg)

Open monarc99 opened this issue 6 years ago • 4 comments

mpv/ffmpeg version and platform

mpv 0.29.0-106-g5bcac8580d Copyright © 2000-2018 mpv/MPlayer/mplayer2 projects built on UNKNOWN ffmpeg library versions: libavutil 56.24.101 libavcodec 58.41.101 libavformat 58.23.102 libswscale 5.4.100 libavfilter 7.46.101 libswresample 3.4.100 ffmpeg version: N-92622-g6ea3cf1b6f

ffmpeg version n4.1 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 8.2.1 (GCC) 20180831 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 libswscale 5. 3.100 / 5. 3.100 libswresample 3. 3.100 / 3. 3.100 libpostproc 55. 3.100 / 55. 3.100

Reproduction steps

encoding with mpv produces a file with Main@L6.1@Main and a bitrate 6 097 kb/s:

mpv -v -no-config https://media.xiph.org/video/derf/webm/Netflix_Aerial_4096x2160_60fps_10bit_420.webm -o mpvout.mkv -ovc libx265

encoding with ffmpeg creates a file with Main@L5.1@Main and a bitrate 8 029 kb/s:

ffmpeg -i https://media.xiph.org/video/derf/webm/Netflix_Aerial_4096x2160_60fps_10bit_420.webm -vcodec libx265 ffmpegout.mkv

Expected behavior

ffmpeg and mpv should create nearly the same encodings with default values. Most important is the level of the file, because many players (e.g. firetv stick) only support L5.1 for hevc.

Actual behavior

encodings with mpv always have a higher level (e.g. L6.2) than ffmpeg (e.g. L4.2) and cannot be played on devices (e.g. firevtv)

i tried to limit the level with x265 parameters, but than the encoder aborts with a error message:

mpv -v -no-config https://media.xiph.org/video/derf/webm/vidyo1_720p_60fps.webm -o outfile.mkv --vf=fps=60 -ovc libx265 -ovcopts x265-params="level-idc=51"

... x265 [error]: frame rate is out of range for specified level [ffmpeg] libx265: Cannot open libx265 encoder. ...

Log file

encoding with mpv: https://paste.pound-python.org/show/oMTkSdAnAzxsrRx9bEnL/ mediainfo of the mpv result: https://paste.pound-python.org/show/sPyA985377T5HIwzbZUf/

encoding with ffmpeg: https://paste.pound-python.org/show/8WiK1RNcWXjJMIJJJwtQ/ mediainfo of ffmpeg result: https://paste.pound-python.org/show/NiJZiRGYpDNOH2YSByie/

encoding with mpv and x265-params="level-idc=51": https://paste.pound-python.org/show/dm04FPlnwHuqVoZFg9hw/

Sample files

source file for encoding tests: https://media.xiph.org/video/derf/webm/Netflix_Aerial_4096x2160_60fps_10bit_420.webm

monarc99 avatar Dec 05 '18 22:12 monarc99

Instead of -ovcopts x265-params="level-idc=51" can you try -ovcopts 'x265-params="level-idc=51"'?

CounterPillow avatar Dec 05 '18 22:12 CounterPillow

Same result:

mpv -v -no-config https://media.xiph.org/video/derf/webm/vidyo1_720p_60fps.webm -o outfile.mkv --vf=fps=60 -ovc libx265 -ovcopts 'x265-params="level-idc=51"'

[vo/lavc] Opening encoder: libx265 H.265 / HEVC [libx265] x265 [info]: HEVC encoder version 2.9 x265 [info]: build info [Linux][GCC 8.2.1][64 bit] 8bit+10bit+12bit x265 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX x265 [error]: frame rate is out of range for specified level [ffmpeg] libx265: Cannot open libx265 encoder. [vo/lavc] Could not initialize encoder. [cplayer] Could not initialize video chain.

Log: https://paste.pound-python.org/show/AwWVU3ENI79fX0uG3zPQ/

monarc99 avatar Dec 05 '18 22:12 monarc99

Happens even with lower frame rates in both libx265 and hevc_nvenv. I tried with 1920x1080 23.967fps files which should be able to go as low as L4.0 but MPV still sets the level to L6.2. I'm getting the same error as monarc99 when setting level-idc in libx265. Setting the level for hevc_nvenc gives me the error "[ffmpeg] hevc_nvenc: InitializeEncoder failed: invalid param (8): Unsupported Level."

GatesDA avatar Sep 29 '21 16:09 GatesDA

I have the same issue - when I set level-idc=51 or 41, or anything below 62 in x265-params, it complains that FPS is too high.

One observation that I made is that when I let it use profile 6.2, and then check the file with mediainfo, it says

Original frame rate                      : 24 000.000 FPS

Which is certainly not true

Reproducing

I run it as

mpv input.mkv --profile=tvenc --aid=1 --o=out.mkv

With the following profile in mpv.conf

[tvenc]
ovc = libx265
ovcopts-add = preset=fast
ovcopts-add = crf=18
# breaks encoder
# ovcopts-add = x265-params=level-idc=41

oac = libopus
oacopts-add = ab=96K

Output

When ovcopts-add = x265-params=level-idc=41 is enabled

...
x265 [info]: HEVC encoder version 3.5
x265 [info]: build info [Linux][GCC 10.2.0][64 bit] 10bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [error]: frame rate is out of range for specified level
[ffmpeg] libx265: Cannot open libx265 encoder.
[vo/lavc] Could not initialize encoder.
Could not initialize video chain.
Video: no video
...

dreambottle avatar Oct 17 '21 00:10 dreambottle

fixed by 4bcefa5be3b776c68b689b8009759390c2eb62de

sfan5 avatar May 08 '23 10:05 sfan5