View Full Version : How to use mask information to encode all Intra frame by x264 library
l35633
9th June 2015, 20:08
hello, everyone!
Now I am using x264 library to encode a stream, I will use Intra mode for each frame of the stream. As to each frame, I can get a boolean value mask array that denotes which macro blocks are to be encoded, which macro blocks need not change (e.g. the background macro blocks).
I wonder if there is any parameters setting in x264 library to use the mask array, or I have to change souce code?
If I have to change source code, would you please give me some good ideas, then I can do less work. Because the x264 source code is too complicated.
Thank you very much!!
foxyshadis
10th June 2015, 09:04
I'm not sure I understand -- you want an intra-only stream, but you also want frames to depend on previous frames for some blocks? Those are mutually exclusive, unless you're creating your own codec that isn't AVC/H.264.
However, you could do it the other way around, where you use P-frames and force I-blocks on everything that's not background. x264 lets you set quants per-block, but not block type, so you will have to hack it in. You could modify x264_mb_analyse_init in analysis.c to first check your map of block types to see if the current block is one of the ones you want to be intra, then set a->b_force_intra = 1;. Up to you how to you plan on getting the map into the function, the call stack is:
x264_encoder_encode->x264_slices_write->x264_slice_write->x264_macroblock_analyse->x264_mb_analyse_init.
There's some logic in x264_encoder_encode for intra refresh, so maybe you could piggyback off of that, but it would be easier to just add your own extra arguments to function calls if this is just an experiment.
For all of the "background" blocks, you can just force them to be QP51 to minimize their size.
l35633
12th June 2015, 08:40
I'm not sure I understand -- you want an intra-only stream, but you also want frames to depend on previous frames for some blocks? Those are mutually exclusive, unless you're creating your own codec that isn't AVC/H.264.
However, you could do it the other way around, where you use P-frames and force I-blocks on everything that's not background. x264 lets you set quants per-block, but not block type, so you will have to hack it in. You could modify x264_mb_analyse_init in analysis.c to first check your map of block types to see if the current block is one of the ones you want to be intra, then set a->b_force_intra = 1;. Up to you how to you plan on getting the map into the function, the call stack is:
x264_encoder_encode->x264_slices_write->x264_slice_write->x264_macroblock_analyse->x264_mb_analyse_init.
There's some logic in x264_encoder_encode for intra refresh, so maybe you could piggyback off of that, but it would be easier to just add your own extra arguments to function calls if this is just an experiment.
For all of the "background" blocks, you can just force them to be QP51 to minimize their size.
Hi, first I have a image macro block mask array, "0" denotes that the macro block is useless which I don't encode, "1" denotes that the macro block is useful which I have to encode.
As what you said, I will loop all macro blocks in source code, "0" macro block is set "skip" mode or other ways? "1" macro block is processed as usual.
I have a question, each mask of frame may be different, that will affect coding performance?
Thank you very much!
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.