38#define OFFSET(x) offsetof(SignatureContext, x)
39#define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
40#define BLOCK_LCM (int64_t) 476985600
43 {
"detectmode",
"set the detectmode",
48 {
"nb_inputs",
"number of inputs",
50 {
"filename",
"filename for output files",
52 {
"format",
"set output format",
56 {
"th_d",
"threshold to detect one word as similar",
58 {
"th_dc",
"threshold to detect all words as similar",
60 {
"th_xh",
"threshold to detect frames as similar",
62 {
"th_di",
"minimum length of matching sequence in frames",
64 {
"th_it",
"threshold for relation of good to all frames",
92 sc->
divide = (((uint64_t) inlink->
w/32) * (inlink->
w/32 + 1) * (inlink->
h/32 * inlink->
h/32 + 1) > INT64_MAX / (
BLOCK_LCM * 255));
103 return (
b->to.y -
b->up.y + 1) * (
b->to.x -
b->up.x + 1);
117 if (x0-1 >= 0 && y0-1 >= 0) {
118 sum = intpic[y1][x1] + intpic[y0-1][x0-1] - intpic[y1][x0-1] - intpic[y0-1][x1];
119 }
else if (x0-1 >= 0) {
120 sum = intpic[y1][x1] - intpic[y1][x0-1];
121 }
else if (y0-1 >= 0) {
122 sum = intpic[y1][x1] - intpic[y0-1][x1];
124 sum = intpic[y1][x1];
129static int cmp(
const void *x,
const void *y)
131 const uint64_t *
a = x, *
b = y;
132 return *
a < *
b ? -1 : ( *
a > *
b ? 1 : 0 );
151 static const uint8_t pot3[5] = { 3*3*3*3, 3*3*3, 3*3, 3, 1 };
155 static const unsigned int wordvec[25] = {44,57,70,100,101,102,103,111,175,210,217,219,233,237,269,270,273,274,275,285,295,296,334,337,354};
156 static const uint8_t s2usw[25] = { 5,10,11, 15, 20, 21, 12, 22, 6, 0, 1, 2, 7, 13, 14, 8, 9, 3, 23, 16, 17, 24, 4, 18, 19};
158 uint8_t wordt2b[5] = { 0, 0, 0, 0, 0 };
159 uint64_t intpic[32][32];
161 uint8_t *p = picref->
data[0];
166 int f = 0,
g = 0,
w = 0;
167 int32_t dh1 = 1, dh2 = 1, dw1 = 1, dw2 = 1,
a,
b;
169 int i, j, k, ternary;
190 fs->pts = picref->
pts;
193 memset(intpic, 0,
sizeof(uint64_t)*32*32);
197 for (
i = 0;
i < inlink->
w;
i++) {
198 intjlut[
i] = (
i*32)/inlink->
w;
201 for (
i = 0;
i < inlink->
h;
i++) {
202 inti = (
i*32)/inlink->
h;
203 for (j = 0; j < inlink->
w; j++) {
205 intpic[inti][intj] += p[j];
215 dh1 = inlink->
h / 32;
218 dw1 = inlink->
w / 32;
223 for (
i = 0;
i < 32;
i++) {
227 a = ((inlink->
h*(
i+1))%32 == 0) ? (inlink->
h*(
i+1))/32 - 1 : (inlink->
h*(
i+1))/32;
228 a -= ((inlink->
h*
i)%32 == 0) ? (inlink->
h*
i)/32 - 1 : (inlink->
h*
i)/32;
229 a = (
a == dh1)? dh2 : dh1;
231 for (j = 0; j < 32; j++) {
234 b = ((inlink->
w*(j+1))%32 == 0) ? (inlink->
w*(j+1))/32 - 1 : (inlink->
w*(j+1))/32;
235 b -= ((inlink->
w*j)%32 == 0) ? (inlink->
w*j)/32 - 1 : (inlink->
w*j)/32;
236 b = (
b == dw1)? dw2 : dw1;
238 rowcount += intpic[
i][j] *
a *
b * precfactor / denom;
240 intpic[
i][j] = intpic[
i-1][j] + rowcount;
242 intpic[
i][j] = rowcount;
252 uint64_t* sortsignature;
257 sortsignature = elemsignature + elemcat->
elem_count;
266 sum = blocksum / blocksize;
268 sum -= 128 * precfactor * denom;
276 sum -= blocksum / blocksize;
277 conflist[
g++] =
FFABS(sum * 8 / (precfactor * denom));
280 elemsignature[j] = sum;
281 sortsignature[j] =
FFABS(sum);
285 qsort(sortsignature, elemcat->
elem_count,
sizeof(uint64_t),
cmp);
286 th = sortsignature[(int) (elemcat->
elem_count*0.333)];
290 if (elemsignature[j] < -th) {
292 }
else if (elemsignature[j] <= th) {
297 fs->framesig[
f/5] += ternary * pot3[
f%5];
299 if (
f == wordvec[
w]) {
300 fs->words[s2usw[
w]/5] += ternary * pot3[wordt2b[s2usw[
w]/5]++];
333 for (
i = 0;
i < 5;
i++) {
339 for (
i = 0;
i < 5;
i++) {
352 for (
i = 0;
i < 5;
i++) {
355 for (j = 1; j < 5; j++)
364 for (j = 1; j < 5; j++)
381 unsigned int pot3[5] = { 3*3*3*3, 3*3*3, 3*3, 3, 1 };
394 fprintf(
f,
"<?xml version='1.0' encoding='ASCII' ?>\n");
395 fprintf(
f,
"<Mpeg7 xmlns=\"urn:mpeg:mpeg7:schema:2001\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:mpeg:mpeg7:schema:2001 schema/Mpeg7-2001.xsd\">\n");
396 fprintf(
f,
" <DescriptionUnit xsi:type=\"DescriptorCollectionType\">\n");
397 fprintf(
f,
" <Descriptor xsi:type=\"VideoSignatureType\">\n");
398 fprintf(
f,
" <VideoSignatureRegion>\n");
399 fprintf(
f,
" <VideoSignatureSpatialRegion>\n");
400 fprintf(
f,
" <Pixel>0 0 </Pixel>\n");
401 fprintf(
f,
" <Pixel>%d %d </Pixel>\n", sc->
w - 1, sc->
h - 1);
402 fprintf(
f,
" </VideoSignatureSpatialRegion>\n");
403 fprintf(
f,
" <StartFrameOfSpatialRegion>0</StartFrameOfSpatialRegion>\n");
406 fprintf(
f,
" <MediaTimeOfSpatialRegion>\n");
407 fprintf(
f,
" <StartMediaTimeOfSpatialRegion>0</StartMediaTimeOfSpatialRegion>\n");
408 fprintf(
f,
" <EndMediaTimeOfSpatialRegion>%" PRIu64
"</EndMediaTimeOfSpatialRegion>\n", sc->
coarseend->
last->
pts);
409 fprintf(
f,
" </MediaTimeOfSpatialRegion>\n");
413 fprintf(
f,
" <VSVideoSegment>\n");
414 fprintf(
f,
" <StartFrameOfSegment>%" PRIu32
"</StartFrameOfSegment>\n", cs->
first->
index);
415 fprintf(
f,
" <EndFrameOfSegment>%" PRIu32
"</EndFrameOfSegment>\n", cs->
last->
index);
416 fprintf(
f,
" <MediaTimeOfSegment>\n");
417 fprintf(
f,
" <StartMediaTimeOfSegment>%" PRIu64
"</StartMediaTimeOfSegment>\n", cs->
first->
pts);
418 fprintf(
f,
" <EndMediaTimeOfSegment>%" PRIu64
"</EndMediaTimeOfSegment>\n", cs->
last->
pts);
419 fprintf(
f,
" </MediaTimeOfSegment>\n");
420 for (
i = 0;
i < 5;
i++) {
421 fprintf(
f,
" <BagOfWords>");
422 for (j = 0; j < 31; j++) {
423 uint8_t n = cs->
data[
i][j];
425 fprintf(
f,
"%d %d %d %d %d %d %d %d ", (n & 0x80) >> 7,
435 fprintf(
f,
"%d %d %d ", (n & 0x80) >> 7,
440 fprintf(
f,
"</BagOfWords>\n");
442 fprintf(
f,
" </VSVideoSegment>\n");
447 fprintf(
f,
" <VideoFrame>\n");
448 fprintf(
f,
" <MediaTimeOfFrame>%" PRIu64
"</MediaTimeOfFrame>\n",
fs->pts);
450 fprintf(
f,
" <FrameConfidence>%d</FrameConfidence>\n",
fs->confidence);
452 fprintf(
f,
" <Word>");
453 for (
i = 0;
i < 5;
i++) {
454 fprintf(
f,
"%d ",
fs->words[
i]);
459 fprintf(
f,
"</Word>\n");
461 fprintf(
f,
" <FrameSignature>");
466 fprintf(
f,
"%d ",
fs->framesig[
i] / pot3[0]);
467 for (j = 1; j < 5; j++)
468 fprintf(
f,
" %d ",
fs->framesig[
i] % pot3[j-1] / pot3[j] );
470 fprintf(
f,
"</FrameSignature>\n");
471 fprintf(
f,
" </VideoFrame>\n");
473 fprintf(
f,
" </VideoSignatureRegion>\n");
474 fprintf(
f,
" </Descriptor>\n");
475 fprintf(
f,
" </DescriptionUnit>\n");
476 fprintf(
f,
"</Mpeg7>\n");
487 uint32_t numofsegments = (sc->
lastindex + 44)/45;
491 int len = (512 + 6 * 32 + 3*16 + 2 +
492 numofsegments * (4*32 + 1 + 5*243) +
493 sc->
lastindex * (2 + 32 + 6*8 + 608)) / 8;
528 for (
i = 0;
i < 5;
i++) {
530 for (j = 0; j < 30; j++) {
542 for (
i = 0;
i < 5;
i++) {
616 if (match.
score != 0) {
677 av_log(
ctx,
AV_LOG_ERROR,
"The filename must contain %%d or %%0nd, if you have more than one input.\n");
705 finsig = finsig->
next;
712 cousig = cousig->
next;
731 outlink->
w = inlink->
w;
732 outlink->
h = inlink->
h;
747 .p.name =
"signature",
749 .p.priv_class = &signature_class,
static int config_input(AVFilterLink *inlink)
static int request_frame(AVFilterLink *outlink)
static const char *const format[]
const FFFilter ff_vf_signature
static AVFormatContext * ctx
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_append_inpad_free_name(AVFilterContext *f, AVFilterPad *p)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Main libavfilter public API header.
char * av_asprintf(const char *fmt,...)
#define i(width, name, range_min, range_max)
#define fs(width, name, subs,...)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_log_get_level(void)
Get the current log level.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
static const char signature[]
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
#define FILTER_OUTPUTS(array)
#define FILTER_PIXFMTS_ARRAY(array)
static FilterLink * ff_filter_link(AVFilterLink *link)
#define FF_INLINK_IDX(link)
Find the index of a link.
#define AVFILTER_DEFINE_CLASS(fname)
FILE * avpriv_fopen_utf8(const char *path, const char *mode)
Open a file using a UTF-8 filename.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
static const uint16_t mask[17]
Memory handling functions.
static av_always_inline int cmp(MPVEncContext *const s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensa...
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static int put_bytes_output(const PutBitContext *s)
static av_unused void put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
MPEG-7 video signature calculation and lookup filter.
static const ElemCat * elements[ELEMENT_COUNT]
MPEG-7 video signature calculation and lookup filter.
static MatchingInfo lookup_signatures(AVFilterContext *ctx, SignatureContext *sc, StreamContext *first, StreamContext *second, int mode)
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
const char * name
Pad name.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
struct FineSignature * first
struct CoarseSignature * next
struct FineSignature * last
Link properties exposed to filter code, but not external callers.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
struct FineSignature * next
struct FineSignature * second
struct FineSignature * first
StreamContext * streamcontexts
FineSignature * finesiglist
CoarseSignature * curcoarsesig1
FineSignature * curfinesig
CoarseSignature * coarsesiglist
CoarseSignature * curcoarsesig2
CoarseSignature * coarseend
#define av_malloc_array(a, b)
static int xml_export(AVFilterContext *ctx, StreamContext *sc, const char *filename)
static int export(AVFilterContext *ctx, StreamContext *sc, int input)
static const AVOption signature_options[]
static int config_input(AVFilterLink *inlink)
static int binary_export(AVFilterContext *ctx, StreamContext *sc, const char *filename)
static int request_frame(AVFilterLink *outlink)
static void set_bit(uint8_t *data, size_t pos)
sets the bit at position pos to 1 in data
static int cmp(const void *x, const void *y)
static av_cold void uninit(AVFilterContext *ctx)
static const AVFilterPad signature_outputs[]
static int get_block_size(const Block *b)
static int config_output(AVFilterLink *outlink)
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
static uint64_t get_block_sum(StreamContext *sc, uint64_t intpic[32][32], const Block *b)