View Full Version : How to implement ROI(region of interest) encoding through ffmpeg/x264


jerry30121
23rd April 2014, 09:31
Hi, I was doing a project that needs to encode video with ROI method.
And as I checked the information on Internet, still can't find how to write the command to do that.

1. Should I check "Flexible Macroblock Ordering"? and how to implement this in ffmpeg/x264?

many thanks!
:confused:

LoRd_MuldeR
23rd April 2014, 12:56
x264 does not support ROI encoding "out of the box", in the sense that it detects the ROI (whatever that may be) for you and then adjusts the quantizers accordingly. In other words: You can not enable ROI encoding with a simple commannd! But there is an API provided by x264 that allows for implementing ROI encoding yourself, i.e. in the calling application.

See here:
http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=a6c6afa85053443dc459e096e8e681dc21d43ade

jerry30121
24th April 2014, 16:42
so... in that case, I should try compile these files over original x264 and make it to my version?
Can I have more detail about ho do turn it on? sorry if this bothers you, cuz I've been stuck on this issue for a while.

this API offers me to control quant_offsets by giving what parameter? or can you bring me any example?

many many thanks!

LoRd_MuldeR
24th April 2014, 20:12
so... in that case, I should try compile these files over original x264 and make it to my version?
Can I have more detail about ho do turn it on? sorry if this bothers you, cuz I've been stuck on this issue for a while.

As explained before, you can not simply "turn it on", because there is no such thing as region of interest encoding in x264. But there is an API that allows you, optionally, to set a quantizer offset for each individual block in the frame. This way, the calling application might implement a form of "region of interest encoding" when using x264. In other words, you will have to write your own program that uses x264, as a library, and that adjusts the quantizer offsets as desired.

this API offers me to control quant_offsets...?

Yes.

can you bring me any example?

I have no complete example, but see "x264.h" for details.

The interesting part is highlighted in the commit that I already linked above:
http://git.videolan.org/gitweb.cgi/x264.git/?p=x264.git;a=commitdiff;h=a6c6afa85053443dc459e096e8e681dc21d43ade;hp=6dc1217f510ece46166376dcca1d6b19d088a3b5#patch5

jerry30121
7th May 2014, 07:00
it seems that the latest version of x264 has already included this API. What I should do is writing my program directly call such function and pass related data, am I on the right direction?

thanks again

jerry30121
7th May 2014, 08:04
What I am trying to do is: encoding a video file by x264, and the outcome video should content a part of area that has higher quality than the other area.

let's say a 1280x720 mp4 format file for input.
and output should hold the same resolution and left part area (640*720) has the better quality than the right one.

Is it possible to encode that way by x264?
Can you give me some suggestion?

thanks!

LoRd_MuldeR
7th May 2014, 11:56
it seems that the latest version of x264 has already included this API.

It does so since Fri, 28 May 2010, as you can see in the commit log (see link above).

What I should do is writing my program directly call such function and pass related data, am I on the right direction?

Exactly.

Is it possible to encode that way by x264?

Yes. By setting the quantizer offsets accordingly.

Can you give me some suggestion?

See here:
https://forum.doom9.org/showpost.php?p=1678686&postcount=2
https://forum.doom9.org/showpost.php?p=1678860&postcount=4

jerry30121
7th May 2014, 17:19
What I am trying to do is: encoding a video file by x264, and the outcome video should content a part of area that has higher quality than the other area.

let's say a 1280x720 mp4 format file for input.
and output should hold the same resolution and left part area (640*720) has the better quality than the right one.

Is it possible to encode that way by x264?
Can you give me some suggestion?

thanks!

and...what about this one?
can this be done by the API you mentioned?

LoRd_MuldeR
7th May 2014, 18:20
YES. How many times do you want to hear that it is possible? You just have to code it :sly:

(If you can control the quantizers on a per-marcoblock basis, why it shouldn't be possible to increase/decrease compression for one half of the frame?)