Log in

View Full Version : Reencoding middle part of an x265 stream / mkv - artifacts at 2nd cut point


katzenjoghurt
26th October 2023, 23:16
Hello,

So sometimes I‘m not completely happy with my x265 encoding and want to only replace certain segments of its stream in the mkv container.

But I fail to achieve this without getting artifacts after merging the new part in. While the transition to the START of the inserted segment seems to be always fine, I‘ll see artifacts for a few frames right where the inserted segment ENDS.

So, if we have
Start----A----B----End
and I replace A to B by a new encoding, point A will be fine but I‘ll see artifacts at B.

That means, if I want to replace a segment, I can always only keep the first part of the video, up to start of the segment I want to replace….and reencode from there up to the end of the ENTIRE video. At least if I‘m not willing to accept artifact glitches.

If I would encode 3 parts (Start to A, A to B, B to End) and merge them together its also fine.
The problem seems to occur when cutting and adding a new clip IN FRONT OF a cut-off point.

A known issue?
Can I do something about it?

Tools:

StaxRip v2.29.0
x265 (Patman‘s build contained in StaxRip 2.29.0)
Current MKVToolnix
Current VLC

Selur
27th October 2023, 15:03
2cents from me:
Not much data to go on, no info how you split, merge and what settings you use for reencoding, what settings the rest was encoded with or what artifacts you see,...
a. do you use compatible x265 parameters?
b. do you enable https://x265.readthedocs.io/en/stable/cli.html#cmdoption-repeat-headers
c. do you only cut on IDR frames?
if not, look into those.

Cu Selur

katzenjoghurt
22nd November 2023, 14:50
2cents from me:
Not much data to go on, no info how you split, merge and what settings you use for reencoding, what settings the rest was encoded with or what artifacts you see,...
a. do you use compatible x265 parameters?
b. do you enable https://x265.readthedocs.io/en/stable/cli.html#cmdoption-repeat-headers
c. do you only cut on IDR frames?
if not, look into those.

Cu Selur

Hey Selur,

sorry for replying so lately.
I read it immediately, read your suggestion with repeat headers, added it to my encoding and it didn't help.
I took some more time now to go back to the basics.

Here are the details.
1) I grabbed a 1min20s clip

2) x265 build used:
http://msystem.waw.pl/x265/x265-3.5+110-8ee01d4_vs2022-AVX2.7z

3) I used StaxRip for reencoding.
Under the hood it's using this basic command line for reencoding:


"E:\StaxRip\x265\Apps\avs2pipemod\avs2pipemod64.exe" -y4mp "C:\Temp\VID1 Lorem ipsu..._temp\base_reenc.avs"
| "E:\StaxRip\x265\Apps\x265\x265.exe" --crf 20 --frames 4000 --y4m --output "C:\Temp\VID1 Lorem ipsu..._temp\base_reenc_out.hevc" -

3) I opened MKVToolnix 79.0.0 and added the .hevc stream

4) In MKVToolnixes output settings I chose
Split mode: "After output duration"
Duration: 00:00:30

5) The output were 3 mkv files and I reencoded the middle part with the same x265 settings:
"E:\StaxRip\Apps\avs2pipemod\avs2pipemod64.exe" -y4mp "C:\Temp\VID1 Lorem ipsu..._temp\base_reenc_out-002_new.avs"
| "E:\StaxRip\Apps\x265\x265.exe" --crf 20 --frames 1734 --y4m --output "base_reenc_out-002_new_out.hevc"


What I observe:
After splitting I have 3 parts (A, B, C)

- If I check the first few frames of the original split part B in Staxrip they are duplicates

- These duplicates are also in the reencoded B

- After merging A, B_new and C I see the duplicate frames at the transition from A to B and erratic frame jumps between B_new & C.
In Staxrip's frame preview I even see a huge artifact at the transition point from B_new to C. It's not visible in VLC though.

- If I reencode the resulted merge file once more, all the errors are still there


edit: The problem doesn't occur with x264
edit2: double checked it: "--repeat headers" for x265 makes no difference