Go to the documentation of this file.
28 #define HOUGH_MAX_OFFSET 90
29 #define MAX_FRAMERATE 60
33 #define DIR_PREV_END 2
34 #define DIR_NEXT_END 3
37 #define STATUS_END_REACHED 1
38 #define STATUS_BEGIN_REACHED 2
52 int i, j, tmp_i, tmp_j,count;
55 for (
i = 0, count = 0;
i < 242;
i++) {
56 for (j =
i + 1; j < 243; j++, count++) {
61 dist +=
FFABS((tmp_j % 3) - (tmp_i % 3));
64 }
while (tmp_i > 0 || tmp_j > 0);
73 for (
i = 0;
i < 28;
i += 4) {
75 (
first[
i+1] & second[
i+1]) << 16 |
76 (
first[
i+2] & second[
i+2]) << 8 |
80 (
first[29] & second[29]) << 8 |
81 (
first[30] & second[30]) );
88 for (
i = 0;
i < 28;
i += 4) {
90 (
first[
i+1] | second[
i+1]) << 16 |
91 (
first[
i+2] | second[
i+2]) << 8 |
95 (
first[29] | second[29]) << 8 |
96 (
first[30] | second[30]) );
103 unsigned int dist = 0;
112 dist += sc->
l1distlut[243*242/2 - (243-
s)*(242-
s)/2 +
f -
s - 1];
114 dist += sc->
l1distlut[243*242/2 - (243-
f)*(242-
f)/2 +
s -
f - 1];
127 int jaccarddist,
i, composdist = 0, cwthcount = 0;
128 for (
i = 0;
i < 5;
i++) {
133 if (++cwthcount > 2) {
138 composdist += jaccarddist;
154 if ((*second)->next) {
155 *second = (*second)->
next;
156 }
else if ((*first)->next) {
157 *second = secondstart;
158 *
first = (*first)->next;
169 if ((*second)->next) {
170 *second = (*second)->
next;
171 }
else if ((*first)->next) {
172 *second = secondstart;
173 *
first = (*first)->next;
187 size_t i, j, k, l, hmax = 0, score;
200 typedef struct hspace_elem {
209 hspace_elem *hspaces;
220 hspace[
i][j].score = 0;
221 hspace[
i][j].dist = 99999;
228 pairs[
i].dist = 99999;
230 for (j = 0,
s = second; j <
COARSE_SIZE &&
s->next; j++,
s =
s->next) {
233 if (l1dist < sc->thl1) {
234 if (l1dist < pairs[
i].dist) {
236 pairs[
i].dist = l1dist;
237 pairs[
i].b_pos[0] = j;
239 }
else if (l1dist == pairs[
i].dist) {
240 pairs[
i].b[pairs[
i].size] =
s;
241 pairs[
i].b_pos[pairs[
i].size] = j;
248 if (
f->next ==
NULL) {
251 pairs[
i].dist = 99999;
257 for (j = 0; j < pairs[
i].size; j++) {
259 for (l = 0; l < pairs[k].size; l++) {
260 if (pairs[
i].
b[j] != pairs[k].
b[l]) {
262 m = (pairs[k].b_pos[l]-pairs[
i].b_pos[j]) / (k-
i);
267 if (pairs[
i].dist < pairs[k].dist) {
294 hmax = (
int) (0.7*hmax);
297 if (hmax < hspace[
i][j].score) {
304 c->framerateratio = (
i+1.0) / 30;
305 c->score = hspace[
i][j].score;
307 c->first = hspace[
i][j].a;
308 c->second = hspace[
i][j].b;
330 step = ((
int) 0.5 + fcount * frr)
331 -((
int) 0.5 + (fcount-1) * frr);
349 if ((*b)->next && (*b)->next->next) {
350 *
b = (*b)->next->next;
371 if ((*a)->next && (*a)->next->next) {
372 *
a = (*a)->next->next;
395 if ((*b)->prev && (*b)->prev->prev) {
396 *
b = (*b)->prev->prev;
417 if ((*a)->prev && (*a)->prev->prev) {
418 *
a = (*a)->prev->prev;
430 int dist, distsum = 0, bcount = 1, dir =
DIR_NEXT;
431 int fcount = 0, goodfcount = 0, gooda = 0, goodb = 0;
432 double meandist, minmeandist = bestmatch.
meandist;
433 int tolerancecount = 0;
437 for (; infos !=
NULL; infos = infos->
next) {
443 if (dist > sc->
thl1) {
444 if (
a->confidence >= 1 ||
b->confidence >= 1) {
449 if (tolerancecount > 2) {
470 if (
a->confidence < 1) gooda++;
471 if (
b->confidence < 1) goodb++;
489 if (sc->
thdi != 0 && bcount >= sc->
thdi) {
494 if (bcount < sc->thdi)
496 if ((
double) goodfcount / (
double) fcount < sc->thit)
498 if ((
double) goodfcount*0.5 <=
FFMAX(gooda, goodb))
501 meandist = (
double) distsum / (
double) goodfcount;
503 if (meandist < minmeandist ||
506 minmeandist = meandist;
540 cs =
first->coarsesiglist;
555 "indices of first frame: %"PRIu32
" and %"PRIu32
"\n",
561 for (
i = infos;
i !=
NULL;
i =
i->next) {
563 "ratio %f, offset %d\n",
i->first->index,
i->second->index,
564 i->framerateratio,
i->offset);
572 "ratio %f, offset %d, score %d, %d frames matching\n",
static void error(const char *err)
CoarseSignature * coarsesiglist
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
uint8_t l1distlut[243 *242/2]
static void fill_l1distlut(uint8_t lut[])
static MatchingInfo lookup_signatures(AVFilterContext *ctx, SignatureContext *sc, StreamContext *first, StreamContext *second, int mode)
static double val(void *priv, double ch)
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
static MatchingInfo evaluate_parameters(AVFilterContext *ctx, SignatureContext *sc, MatchingInfo *infos, MatchingInfo bestmatch, int mode)
#define STATUS_END_REACHED
struct FineSignature * first
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int av_log_get_level(void)
Get the current log level.
static MatchingInfo * get_matching_parameters(AVFilterContext *ctx, SignatureContext *sc, FineSignature *first, FineSignature *second)
compares framesignatures and sorts out signatures with a l1 distance above a given threshold.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static void sll_free(MatchingInfo **sll)
static int get_jaccarddist(SignatureContext *sc, CoarseSignature *first, CoarseSignature *second)
calculates the jaccard distance and evaluates a pair of coarse signatures as good
static int iterate_frame(double frr, FineSignature **a, FineSignature **b, int fcount, int *bcount, int dir)
static unsigned int union_word(const uint8_t *first, const uint8_t *second)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
static unsigned int get_l1dist(AVFilterContext *ctx, SignatureContext *sc, const uint8_t *first, const uint8_t *second)
#define i(width, name, range_min, range_max)
static int find_next_coarsecandidate(SignatureContext *sc, CoarseSignature *secondstart, CoarseSignature **first, CoarseSignature **second, int start)
step through the coarsesignatures as long as a good candidate is found
struct CoarseSignature * next
struct FineSignature * second
struct MatchingInfo * next
struct FineSignature * first
static unsigned int intersection_word(const uint8_t *first, const uint8_t *second)
#define STATUS_BEGIN_REACHED