Fix the clean script (again)
[mplayer/kovensky.git] / libmpcodecs / vf_tcdump.c
blob1a98ad6737ca1248511235f9b2b01e0e61cdd93d
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <inttypes.h>
7 #include "config.h"
8 #include "mp_msg.h"
9 #include "help_mp.h"
11 #include "img_format.h"
12 #include "mp_image.h"
13 #include "vf.h"
16 struct vf_priv_s {
17 char *tcv2filename;
18 FILE *tcv2file;
19 int noptswarn;
22 //===========================================================================//
23 static int config(struct vf_instance* vf,
24 int width, int height, int d_width, int d_height,
25 unsigned int flags, unsigned int outfmt){
26 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
29 static int put_image(struct vf_instance* vf, mp_image_t *mpi, double pts){
30 mp_image_t *dmpi;
31 struct vf_priv_s *priv = (struct vf_priv_s*) vf->priv;
33 // hope we'll get DR buffer:
34 if(mpi->flags&MP_IMGFLAG_DIRECT){
35 dmpi=(mp_image_t*)mpi->priv;
36 } else {
37 dmpi=vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_EXPORT, 0, mpi->w, mpi->h);
39 dmpi->planes[0]=mpi->planes[0];
40 dmpi->planes[1]=mpi->planes[1];
41 dmpi->planes[2]=mpi->planes[2];
42 dmpi->stride[0]=mpi->stride[0];
43 dmpi->stride[1]=mpi->stride[1];
44 dmpi->stride[2]=mpi->stride[2];
45 dmpi->width=mpi->width;
46 dmpi->height=mpi->height;
48 if (pts == MP_NOPTS_VALUE) {
49 if (!priv->noptswarn) {
50 priv->noptswarn = 1;
51 mp_msg(MSGT_VFILTER, MSGL_WARN, MSGTR_MPCODECS_TCDumpNoPTS);
53 } else {
54 if (!priv->tcv2file && priv->tcv2filename) {
55 priv->tcv2file = fopen(priv->tcv2filename,"w");
56 if (!priv->tcv2file) {
57 mp_msg(MSGT_VFILTER, MSGL_WARN, MSGTR_MPCODECS_TCDumpOpenFail,
58 strerror(errno));
59 free(priv->tcv2filename);
60 priv->tcv2filename = NULL;
61 } else
62 fprintf(priv->tcv2file, "# timecode format v2\n");
64 if (priv->tcv2file) {
65 fprintf(priv->tcv2file, "%.2f\n", pts*1000);
68 return vf_next_put_image(vf,dmpi, pts);
71 static void uninit(struct vf_instance *vf) {
72 struct vf_priv_s *priv = (struct vf_priv_s*) vf->priv;
73 if (priv->tcv2file)
74 fclose(priv->tcv2file);
75 if (priv->tcv2filename)
76 free (priv->tcv2filename);
77 free (priv);
80 //===========================================================================//
82 static int open(vf_instance_t *vf, char* args){
83 vf->config=config;
84 vf->put_image=put_image;
85 vf->uninit=uninit;
86 vf->priv=malloc(sizeof(struct vf_priv_s));
87 vf->priv->tcv2filename = strdup(args ? args : "timecodesv2.txt");
88 vf->priv->tcv2file = NULL;
89 vf->priv->noptswarn = 0;
90 return 1;
93 vf_info_t vf_info_tcdump = {
94 "dump frame timecodes to file",
95 "tcdump",
96 "Andrew",
97 "",
98 open,
99 NULL