Log in

View Full Version : x265 not honoring slice config


TEB
8th May 2019, 08:27
hi, im trying to encode some hevc files for use in an ABR stack where the config is:

4 sec GOP
IDR at the start on each GOP
I-frames on scenecut

Syntax:
./ffmpeg -loglevel verbose -i test.mov -codec:v libx265 -x265-params keyint=100:min-keyint=100:no-open-gop=1:nal-hrd=VBR:force-cfr -preset fast -crf 23 -maxrate 15M -bufsize 15M -force_key_frames "expr:eq(mod(n,100),0)" -c:a:0 aac -ac:a:0 2 -ab:a:0 128k -y hevc.mp4

Still i notice when ffmpeg starts :
x265 [info]: Keyframe min / max / scenecut / bias: 25 / 250 / 40 / 5.00
both 25 as minimum is wrong, and 250 as max is wrong.. as i locked them both at 100 (25fps x 4sec)

Harmonic's AV analyzer tells me that x265 is actually encoding IDRs as CRA slices instead.. with some Iframes mixed in here an there..
in X264, this is all correct, but x265 this fails..

Anyone have any idea whats going on here?

Blue_MiSfit
9th May 2019, 05:44
-force_key_frames "expr:eq(mod(n,100),0)"

don't use this. It's a BAD idea.

Just set keyint equal to min-keyint

Also, your x265-params is likely not being parsed because you have force-cfr, which isn't a thing for x265.

Fix those two things and you should get correct keyframe config.

TEB
9th May 2019, 10:44
-force_key_frames "expr:eq(mod(n,100),0)"

don't use this. It's a BAD idea.

OK, it was the only way i could get this to work in X264, with forced IDR at the start on each gop.. I just imagined that would work in x265..

Just set keyint equal to min-keyint

Ok, ive done this now and removed the rest

Also, your x265-params is likely not being parsed because you have force-cfr, which isn't a thing for x265.

Yes, trying with a clean config to see how it goes.

Fix those two things and you should get correct keyframe config.

Ok.

Updated "clean" x265 config:

./ffmpeg -loglevel verbose -i test.mov -codec:v libx265 -x265-params keyint=100:min-keyint=100:no-open-gop=1:nal-hrd=VBR -preset slow -crf 23 -maxrate 5M -bufsize 5M -c:a:0 aac -ac:a:0 2 -ab:a:0 128k -y test.mp4

Result:

Now atleast X265 is behaving from a syntax level :

x265 [info]: Keyframe min / max / scenecut / bias: 100 / 100 / 40 / 5.00

But when analysing the ouput in Harmonic AV Analyser:

1. It starts of with an IDR frame, but then its all over..
2. At frame 100, there should be an IDR, but thats a B frame..
3. All scenecut iframes are CRA frames not regular I-frames..
4. And at frame 100,200,300,400, etc there should be an IDR..

Any idea whats going on ?

TEB

excellentswordfight
9th May 2019, 12:37
But when analysing the ouput in Harmonic AV Analyser:

1. It starts of with an IDR frame, but then its all over..
2. At frame 100, there should be an IDR, but thats a B frame..
3. All scenecut iframes are CRA frames not regular I-frames..
4. And at frame 100,200,300,400, etc there should be an IDR..

Any idea whats going on ?

TEB
What do you mean with regular i-frames? If you dont allow open-gop, and they cant reference any other frame, shoudlnt they be CRA frames?

Your syntax should work, according to the .log file x265 creates I get an I-frame every 100 frame with --keyint 100 --min-keyint 100 --no-open-gop (At least I think "I" with a captial letter is IDR frames), and scenecuts get an "i".

What is the "nal-hrd" command? Cant find it in the x265 documentation.

TEB
9th May 2019, 19:07
I must admit my knowledge at the frame level in HEVC is somewhat lacking. So please excuse my ignorance ;) but in my understanding there are 4 types of I-frames in HEVC:

IDR, CRA, BLA and normal I-frames.. Well thats what Harmonics AV Analyser is saying..
ffprobe´s parse just say capital I and non- capital I.
IDR is the only one that actually enforces a full flush of the decoders buffer, hence beeing used in a ABR ladders cross points.

The main problem here is that Shaka Packager is getting the segment length wrong due to this as it expects an IDR frame at the start of every segment

Blue_MiSfit
9th May 2019, 19:51
Hm... that's odd.

I'd expect frame 100 to be an IDR for sure.

I use very similar GOP config for ABR just fine - admittedly with a different packager.

You could try disabling scenecut, but it should still work without that.

TEB
9th May 2019, 20:13
Well.. from my perspective theres multiple bugs here in x265.. cannot explain more than that..
In x264, it all works fine, with IDR at every GOP start and Iframes "inside" the gop on scenecut
Packagers work good with the bitstreams also..

excellentswordfight
10th May 2019, 08:07
Well.. from my perspective theres multiple bugs here in x265.. cannot explain more than that..
In x264, it all works fine, with IDR at every GOP start and Iframes "inside" the gop on scenecut
Packagers work good with the bitstreams also..
Well, as I said, it works fine for me so I dont really see the multiple bugs. Could be an ffmpeg issue, could be an syntax issue, could be an build issue. I get a similar behavior when i use open gop, so could be that the command is not parsing.

How is it behaving if you're piping it to and standalone x265 executable?

TEB
10th May 2019, 15:34
Well, as I said, it works fine for me so I dont really see the multiple bugs. Could be an ffmpeg issue, could be an syntax issue, could be an build issue. I get a similar behavior when i use open gop, so could be that the command is not parsing.

How is it behaving if you're piping it to and standalone x265 executable?

Yea.. using FFmpeg 4.1.x.
I can try to disable Open-gop, but i really cant use open-gop in a ABR domain..
I was just thinking about trying x265 standalone with piping yes..

excellentswordfight
10th May 2019, 15:50
Yea.. using FFmpeg 4.1.x.
I can try to disable Open-gop, but i really cant use open-gop in a ABR domain..
No no, what I was trying to say is that I get the same I-frame structure that you are having issues with when I use/enable open-gop, so I was thinking that your no-open-gop switch might not be working properly.

TEB
10th May 2019, 18:48
No no, what I was trying to say is that I get the same I-frame structure that you are having issues with when I use/enable open-gop, so I was thinking that your no-open-gop switch might not be working properly.

hehe ok! i gotcha.. but it wasnt..

So, its a long time since ive tried piping from ffmpeg to x265, but i cannot the world get it to work now:

ffmpeg -i "output.mov" -strict -1 -vf format=yuv420p10 -f yuv4mpegpipe - | "x265.exe" --y4m - --output-depth 10 --input-res 1920x1080 --fps 25 --preset slow --no-open-gop --keyint 100 --min-keyint 100 --profile main10 --sar 1:1 --vbv-bufsize 15000 --crf 19 --vbv-maxrate 15000 -y test.mp4

It ends up with 3 errors before exiting:

yuv4mpegpipe @ 00000207a4021140] Warning: generating non standard YUV stream. Mjpegtools will not work.

av_interleaved_write_frame(): Invalid argument
Error writing trailer of pipe:: Invalid argument

sneaker_ger
10th May 2019, 22:34
-y test.mp4
?
Try
-o test.265

Always post complete ffmpeg+x265 logs so it's easier to spot such problems.

TEB
10th May 2019, 23:29
-y test.mp4
?
Try
-o test.265

Always post complete ffmpeg+x265 logs so it's easier to spot such problems.

thx! worked

TEB
11th May 2019, 07:54
Good news! It works as intended by using ffmpeg pipe to x265!
Every 4 sec, IDR, and normal I-frames inbetween on scenecut
Besides 2 errors repported by AV Analyser most seem fine.

Error Buffer Analysis Missing parameter 0 0 Info appearance: Picture Timing SEI message not found, NAL index [0]. SPS Id [0]
Error Buffer Analysis Missing parameter 0 0 Info appearance: Buffering Period SEI message not found, NAL index [0]. SPS Id [0]


Syntax used:

ffmpeg -i "output.mov" -strict -1 -vf format=yuv420p10 -f yuv4mpegpipe - | "x265.exe" --y4m - --output-depth 10 --input-res 1920x1080 --fps 25 --preset fast --no-open-gop --keyint 100 --min-keyint 100 --profile main10 --sar 1:1 --vbv-bufsize 15000 --crf 19 --vbv-maxrate 15000 -o test2.hevc

x265 output:
y4m [info]: 1920x1080 fps 25000/1000 i420p10 sar 1:1 unknown frame count
raw [info]: output file: AiB_GOT_test2.hevc
x265 [info]: HEVC encoder version 3.0_Au+22-feec4bdf9866
x265 [info]: build info [Windows][GCC 6.3.0][64 bit] 10bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [info]: Main 10 profile, Level-4 (High tier)
x265 [info]: Thread pool created using 16 threads
x265 [info]: Slices : 1
x265 [info]: frame threads / pool features : 4 / wpp(17 rows)
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 / 2
x265 [info]: Keyframe min / max / scenecut / bias: 100 / 100 / 40 / 5.00
x265 [info]: Lookahead / bframes / badapt : 15 / 4 / 0
x265 [info]: b-pyramid / weightp / weightb : 1 / 1 / 0
x265 [info]: References / ref-limit cu / depth : 3 / on / on
x265 [info]: AQ: mode / str / qg-size / cu-tree : 2 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress : CRF-19.0 / 0.60
x265 [info]: VBV/HRD buffer / max-rate / init : 15000 / 15000 / 0.900
x265 [info]: tools: rd=2 psy-rd=2.00 rskip signhide tmvp fast-intra
x265 [info]: tools: strong-intra-smoothing lslices=6 deblock sao

Now, any suggestions how to optimize the quality?
*preset = slow
*Any tips on reducing banding in dark scenes? Please note that i have a 10bit source and using main10 outbound..


PS! Thx for all the help!
/TEB

Boulder
12th May 2019, 14:26
You could try aq-mode 3 to boost the dark areas. The bitrate will be a lot higher though. And add --no-sao to keep more details intact.

benwaggoner
14th May 2019, 16:59
My preferred syntax for this is

--keyint 100 --no-scenecut --no-open-gop

That works in both x265 and x264, as x264 doesn't allow keyint=min-keyint

TEB
15th May 2019, 20:17
My preferred syntax for this is

--keyint 100 --no-scenecut --no-open-gop

That works in both x265 and x264, as x264 doesn't allow keyint=min-keyint

hmm thx!, mind telling me why you arent min-keyint on x265?
Ive been using min-keyint with x264 (maybe it just ignores it ;))

and no-scenecut basically disables auto-iframe insertion.. Im doing the opposite since we have 4 sec segments.. Any reason why u turn it off?

UPDATE: I did 3 tests and analysed them all with Harmonics AV Analyser:

1. x265 --keyint 100 --no-scenecut = Gives an IDR pr 4 sec as expected, but no Iframes inside the GOP on scenechange
2. x265 --keyint 100 = Gives an IDR pr 4 sec as expected, but keyframes between the 4 sec boundries formatted as IDR (mostly) and some I frames on scenechange
3. x265 --keyint 100 --min-keyint 100 = Gives an IDR pr 4 sec as expected, and keyframes formatted as regular I-frames dynamically inserted on scenechange