Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > High Efficiency Video Coding (HEVC)

Reply
 
Thread Tools Search this Thread Display Modes
Old 8th May 2019, 08:27   #1  |  Link
TEB
Registered User
 
Join Date: Feb 2003
Location: Palmcoast of Norway
Posts: 363
x265 not honoring slice config

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:
Code:
./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 :
Code:
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?

Last edited by TEB; 8th May 2019 at 11:34.
TEB is offline   Reply With Quote
Old 9th May 2019, 05:44   #2  |  Link
Blue_MiSfit
Derek Prestegard IRL
 
Blue_MiSfit's Avatar
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,988
-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.
Blue_MiSfit is offline   Reply With Quote
Old 9th May 2019, 10:44   #3  |  Link
TEB
Registered User
 
Join Date: Feb 2003
Location: Palmcoast of Norway
Posts: 363
Quote:
Originally Posted by Blue_MiSfit View Post
-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..

Quote:
Originally Posted by Blue_MiSfit View Post
Just set keyint equal to min-keyint
Ok, ive done this now and removed the rest

Quote:
Originally Posted by Blue_MiSfit View Post
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:

Code:
./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 :

Code:
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

Last edited by TEB; 9th May 2019 at 10:52.
TEB is offline   Reply With Quote
Old 9th May 2019, 12:37   #4  |  Link
excellentswordfight
Lost my old account :(
 
Join Date: Jul 2017
Posts: 322
Quote:
Originally Posted by TEB View Post
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.

Last edited by excellentswordfight; 9th May 2019 at 12:41.
excellentswordfight is offline   Reply With Quote
Old 9th May 2019, 19:07   #5  |  Link
TEB
Registered User
 
Join Date: Feb 2003
Location: Palmcoast of Norway
Posts: 363
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
TEB is offline   Reply With Quote
Old 9th May 2019, 19:51   #6  |  Link
Blue_MiSfit
Derek Prestegard IRL
 
Blue_MiSfit's Avatar
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,988
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.
Blue_MiSfit is offline   Reply With Quote
Old 9th May 2019, 20:13   #7  |  Link
TEB
Registered User
 
Join Date: Feb 2003
Location: Palmcoast of Norway
Posts: 363
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..
TEB is offline   Reply With Quote
Old 10th May 2019, 08:07   #8  |  Link
excellentswordfight
Lost my old account :(
 
Join Date: Jul 2017
Posts: 322
Quote:
Originally Posted by TEB View Post
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?

Last edited by excellentswordfight; 10th May 2019 at 08:27.
excellentswordfight is offline   Reply With Quote
Old 10th May 2019, 15:34   #9  |  Link
TEB
Registered User
 
Join Date: Feb 2003
Location: Palmcoast of Norway
Posts: 363
Quote:
Originally Posted by excellentswordfight View Post
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..
TEB is offline   Reply With Quote
Old 10th May 2019, 15:50   #10  |  Link
excellentswordfight
Lost my old account :(
 
Join Date: Jul 2017
Posts: 322
Quote:
Originally Posted by TEB View Post
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.
excellentswordfight is offline   Reply With Quote
Old 10th May 2019, 18:48   #11  |  Link
TEB
Registered User
 
Join Date: Feb 2003
Location: Palmcoast of Norway
Posts: 363
Quote:
Originally Posted by excellentswordfight View Post
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:

Code:
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:

Code:
yuv4mpegpipe @ 00000207a4021140] Warning: generating non standard YUV stream. Mjpegtools will not work.
Code:
av_interleaved_write_frame(): Invalid argument
Error writing trailer of pipe:: Invalid argument
TEB is offline   Reply With Quote
Old 10th May 2019, 22:34   #12  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
Code:
-y test.mp4
?
Try
Code:
-o test.265
Always post complete ffmpeg+x265 logs so it's easier to spot such problems.
sneaker_ger is offline   Reply With Quote
Old 10th May 2019, 23:29   #13  |  Link
TEB
Registered User
 
Join Date: Feb 2003
Location: Palmcoast of Norway
Posts: 363
Quote:
Originally Posted by sneaker_ger View Post
Code:
-y test.mp4
?
Try
Code:
-o test.265
Always post complete ffmpeg+x265 logs so it's easier to spot such problems.
thx! worked
TEB is offline   Reply With Quote
Old 11th May 2019, 07:54   #14  |  Link
TEB
Registered User
 
Join Date: Feb 2003
Location: Palmcoast of Norway
Posts: 363
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.

Code:
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:

Code:
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:
Code:
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

Last edited by TEB; 11th May 2019 at 08:08.
TEB is offline   Reply With Quote
Old 12th May 2019, 14:26   #15  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,718
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.
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Old 14th May 2019, 16:59   #16  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 4,750
My preferred syntax for this is

Code:
--keyint 100 --no-scenecut --no-open-gop
That works in both x265 and x264, as x264 doesn't allow keyint=min-keyint
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 15th May 2019, 20:17   #17  |  Link
TEB
Registered User
 
Join Date: Feb 2003
Location: Palmcoast of Norway
Posts: 363
Quote:
Originally Posted by benwaggoner View Post
My preferred syntax for this is

Code:
--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

Last edited by TEB; 16th May 2019 at 09:53.
TEB is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:59.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.