I'm trying to modify the motion detection part of FFMPEG. What I want to do is to extend the search space, so that whenever the macroblock hit the right most edge of the frame, I need it to still move the block towards the left-most as if they are connected (in my example videos, the right edge is actually a continue of the left edge). Can someone help me to point where exactly I can modify it within FFMPEG source code or x265, or x264?
I took H265 as an example from here. It has a motion.cpp
file which nicely specifies the possible block sizes as below. But I can't find the specific loop that traverses the frame. A help is highly appreciated.
#define SETUP_SCALE(W, H) \
sizeScale[LUMA_ ## W ## x ## H] = (H * H) >> 4;
SETUP_SCALE(4, 4);
SETUP_SCALE(8, 8);
SETUP_SCALE(8, 4);
SETUP_SCALE(4, 8);
SETUP_SCALE(16, 16);
SETUP_SCALE(16, 8);
SETUP_SCALE(8, 16);
SETUP_SCALE(16, 12);
SETUP_SCALE(12, 16);
SETUP_SCALE(4, 16);
SETUP_SCALE(16, 4);
SETUP_SCALE(32, 32);
SETUP_SCALE(32, 16);
SETUP_SCALE(16, 32);
SETUP_SCALE(32, 24);
SETUP_SCALE(24, 32);
SETUP_SCALE(32, 8);
SETUP_SCALE(8, 32);
SETUP_SCALE(64, 64);
SETUP_SCALE(64, 32);
SETUP_SCALE(32, 64);
SETUP_SCALE(64, 48);
SETUP_SCALE(48, 64);
SETUP_SCALE(64, 16);
SETUP_SCALE(16, 64);
#undef SETUP_SCALE
UPDATE:
One way to do that (in x265) is to modify the edge extension area (which is already in the code, in the frameFilter.cpp
), and do that for rightmost and fill blocks with leftmost pixels. I identified the piece of code here. Can someone help me to add this feature for right-to-left extension?
if ((col == 0) | (col == m_frameFilter->m_numCols - 1))
{
// TODO: improve by process on Left or Right only
primitives.extendRowBorder(reconPic->getLumaAddr(m_rowAddr), stride, reconPic->m_picWidth, realH, reconPic->m_lumaMarginX);
if (m_frameFilter->m_param->internalCsp != X265_CSP_I400)
{
primitives.extendRowBorder(reconPic->getCbAddr(m_rowAddr), strideC, reconPic->m_picWidth >> hChromaShift, realH >> vChromaShift, reconPic->m_chromaMarginX);
primitives.extendRowBorder(reconPic->getCrAddr(m_rowAddr), strideC, reconPic->m_picWidth >> hChromaShift, realH >> vChromaShift, reconPic->m_chromaMarginX);
}
}
// Extra Left and Right border on first and last CU
if ((col == 0) | (col == m_frameFilter->m_numCols - 1))
{
copySizeY += lumaMarginX;
copySizeC += chromaMarginX;
}
// First column need extension left padding area and first CU
if (col == 0)
{
pixY -= lumaMarginX;
pixU -= chromaMarginX;
pixV -= chromaMarginX;
}
来源:https://stackoverflow.com/questions/37849595/ffmpeg-motion-compensation-and-search