Log in

View Full Version : I'm messing with the h264 code again... project?


Matt Kirby
5th November 2024, 16:56
It seems to be the holy grail to patch / cut / change image areas without re-encoding videos. I've been interested in this topic for years.

It's a matter of principle and I don't want any loss of quality, which is not absolutely necessary in digital technology.

Now my problem. I have HD material from restored films. But the recording service has its channel logo in it. The material is even encoded in the Blu-Ray standard. Tmpeg Authoring Works (which is very strict) accepts it and doesn't want to re-encode it.

The channel logo could be covered by a subtitle track using the old trick. But not every player interprets such a track in the same way. Sometimes you have flickering and when skipping the effect that the subtitle disappears and yet the logo is still visible. Also, if you select a different subtitle track, the logo cover disappears. Not the real thing.

The logo is completely in the black border and as I strongly suspect, the logo is only saved in the I-frames. (no motion vectors are affected)

Now I have done the following manually:

I deleted the first I-frame from the h264 elementary stream using a hex editor.

I encoded an I-frame with a covered logo in the same settings (!) as the original stream.

I used the hex editor to copy the new I-frame into the place of the old one.

And what can I say: it works! The logo is gone and the stream is intact. Every player (even the very critical ones) does not display a logo until the next I-frame.

So it works manually!

The only flaw is that I have completely re-encoded the I-frame. This should also be lossless. So patch the I-frame at the position and patch the position where the logo is black.

And I can't do that. I won't understand the 300-page PDF on the h264 codec in this lifetime.

There should be an editor that can patch I-frames without loss. Limited to my special case. (Logo in the margin, only I-frames, only h264, only black)

I could offer some money for it. But I don't know how many hours a codec programmer would need. And at 50 € per hour I'll soon be poor.

What do you think of the project?

Matt Kirby
10th November 2024, 17:19
Here is a pdf for that issue


https://www.researchgate.net/publication/224200981_Replacing_picture_regions_in_H264AV...pendent_slices


The forum said this was a spam post, it is not!

So I write something on and on and on ....

Matt Kirby
10th December 2024, 11:22
Today I found this tool: “h26forge”

https://github.com/h26forge/h26forge/blob/main/docs/EDITING.md

This allows you to edit h264. A py script is also loaded when the exe is called. The given example script contains the respective logic.
With this line:

h26forge modify --input orgSR.264 --output test1.264 -t transforms/slice_0_all_blue.py

I was able to make the first I-frame completely blue. (and thus the whole first GOP)

But I would have to understand the syntax how to color a few macro blocks black from I-frames. Who can help me to code the logic in the py script for that?