initial commit
[goodguy/history.git] / cinelerra-5.0 / db / utils / clip_frames.C
1 #include<stdio.h>
2 #include<stdarg.h>
3 #include<time.h>
4
5 #include "tdb.h"
6 #include "s.C"
7
8 void write_pbm(uint8_t *tp, int w, int h, const char *fmt, ...)
9 {
10   va_list ap;    va_start(ap, fmt);
11   char fn[256];  vsnprintf(fn, sizeof(fn), fmt, ap);
12   va_end(ap);
13   FILE *fp = !strcmp(fn,"-") ? stdout : fopen(fn,"w");
14   if( fp ) {
15     fprintf(fp,"P5\n%d %d\n255\n",w,h);
16     fwrite(tp,w,h,fp);
17     fclose(fp);
18   }
19 }
20
21 int main(int ac, char **av)
22 {
23   int ret;  setbuf(stdout,0);
24   theDb db;
25   db.open(av[1]);
26   //db.access(av[1], 34543, 0);
27   if( !db.opened() || db.error() ) exit(1);
28
29   if( !(ret=db.clip_set.FindId(atoi(av[2]))) ) {
30     int cid = db.clip_set.id();
31 //    printf("clip_set %d, frames %d", cid, db.clip_set.Frames());
32 //    printf(" prefix %d/suffix %d\n", db.clip_set.Prefix_size(),db.clip_set.Suffix_size());
33     TimelineLoc::ikey_Sequences ikey(db.timeline,cid,0);
34     if( (ret=ikey.Locate()) || (int)db.timeline.Clip_id() != cid ) {
35       printf("missed seq for clip_set %d\n",cid);
36       exit(1);
37     }
38     const char *apath =  db.clip_set._Asset_path();
39     const char *cp = strrchr(apath,'/');
40     if( cp ) apath = cp+1;
41     int fid = -1, n = 0;
42     TimelineLoc::rkey_Sequences rkey(db.timeline);
43     do {
44       if( (int)db.timeline.Clip_id() != cid ) break;
45       //if( fid == (int)db.timeline.Frame_id() ) continue;
46       int seq = db.timeline.Sequence_no();
47       fid = db.timeline.Frame_id();
48       if( (ret=db.video_frame.FindId(fid)) ) {
49         printf("missed frame %d(%d) in clip_set %d\n", seq,fid,cid);
50       }
51       printf("%4d %4d %6d %f %f %f %f %f\n", n, seq, db.video_frame.id(),
52         db.video_frame.Frame_mean(), db.video_frame.Frame_std_dev(),
53         db.video_frame.Frame_cx(), db.video_frame.Frame_cy(),
54         db.video_frame.Frame_moment());
55       if( ac > 3 ) {
56         int w = 80, h = 45;
57         uint8_t *dat = db.video_frame._Frame_data();
58         write_pbm(dat,w,h,"%s/c%04df%03d.pbm",av[3],cid,n);
59       }
60       ++n;
61     } while( !(ret=rkey.Next()) );
62   }
63
64   db.close();
65   return 0;
66 }
67