Add rules to install gmplayer manual pages.
[mplayer/glamo.git] / libmpcodecs / vf_framestep.c
blob9f6d331d8728a0e77520082ac4ea6e04851b2d18
1 /*
2 * filter to ouput only 1 every n frame, or only the I (key)frame
4 * The parameters are:
6 * [I] | [i]num
8 * if you call the filter with I (uppercase) as the parameter
9 * ... -vf framestep=I ...
10 * then ONLY the keyframes are outputted.
11 * For DVD it means, generally, one every 15 frames (IBBPBBPBBPBBPBB), for avi it means
12 * every scene change or every keyint value (see -lavcopts).
14 * if you call the filter with the i (lowercase)
15 * ... -vf framestep=i ...
16 * then a I! followed by a cr is printed when a key frame (eg Intra frame) is
17 * found, leaving the current line of mplayer/mencoder, where you got the
18 * time, in seconds, and frame of the key. Use this information to split the
19 * AVI.
21 * After the i or alone you can put a positive number and only one frame every
22 * x (the number you set) is passed on the filter chain, limiting the output
23 * of the frame.
25 * Example
26 * ... -vf framestep=i20 ...
27 * Dump one every 20 frames, printing on the console when a I-Frame is encounter.
29 * ... -vf framestep=25
30 * Dump one every 25 frames.
32 * If you call the filter without parameter it does nothing (except using memory
33 * and resource of your system,. of course).
35 * This filter doesn' t work like the option -sstep seconds.
37 * The -sstep seek to the new position, without decoding all frames but,
38 * expecially on avi file coded whith mpeg4 (lavc or xvid or divx), the
39 * seek is not always too much precise.
41 * This filter simply discard the unwanted frames, so you are very precise in
42 * counting the frame but sometime you use a lot of CPU for nothing.
44 * As usual it depends on what you're doing.
46 * Daniele Forghieri ( guru@digitalfantasy.it )
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <string.h>
53 #include "config.h"
54 #include "mp_msg.h"
55 #include "help_mp.h"
56 #include "cpudetect.h"
58 #include "img_format.h"
59 #include "mp_image.h"
60 #include "vf.h"
62 /* Uncomment if you want to print some info on the format */
63 // #define DUMP_FORMAT_DATA
65 /* Private data */
66 struct vf_priv_s {
67 /* Current frame */
68 int frame_cur;
69 /* Frame output step, 0 = all */
70 int frame_step;
71 /* Only I-Frame (2), print on I-Frame (1) */
72 int dump_iframe;
75 /* Filter handler */
76 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts)
78 mp_image_t *dmpi;
79 struct vf_priv_s *priv;
80 int skip;
82 priv = vf->priv;
84 /* Print the 'I' if is a intra frame. The \n advance the current line so you got the
85 * current file time (in second) and the frame number on the console ;-)
87 if (priv->dump_iframe) {
88 if (mpi->pict_type == 1) {
89 mp_msg(MSGT_VFILTER, MSGL_INFO, "I!\n");
93 /* decide if frame must be shown */
94 if (priv->dump_iframe == 2) {
95 /* Only key frame */
96 skip = mpi->pict_type == 1 ? 0 : 1;
98 else {
99 /* Only 1 every frame_step */
100 skip = 0;
101 if ((priv->frame_step != 0) && ((priv->frame_cur % priv->frame_step) != 0)) {
102 skip = 1;
105 /* Increment current frame */
106 ++priv->frame_cur;
108 if (skip == 0) {
109 /* Get image, export type (we don't modify tghe image) */
110 dmpi=vf_get_image(vf->next, mpi->imgfmt,
111 MP_IMGTYPE_EXPORT, 0,
112 mpi->w, mpi->h);
113 /* Copy only the pointer ( MP_IMGTYPE_EXPORT ! ) */
114 dmpi->planes[0] = mpi->planes[0];
115 dmpi->planes[1] = mpi->planes[1];
116 dmpi->planes[2] = mpi->planes[2];
118 dmpi->stride[0] = mpi->stride[0];
119 dmpi->stride[1] = mpi->stride[1];
120 dmpi->stride[2] = mpi->stride[2];
122 dmpi->width = mpi->width;
123 dmpi->height = mpi->height;
125 /* Chain to next filter / output ... */
126 return vf_next_put_image(vf, dmpi, pts);
129 /* Skip the frame */
130 return 0;
133 static void uninit(struct vf_instance_s* vf)
135 /* Free private data */
136 free(vf->priv);
139 /* Main entry funct for the filter */
140 static int open(vf_instance_t *vf, char* args)
142 struct vf_priv_s *p;
144 vf->put_image = put_image;
145 vf->uninit = uninit;
146 vf->default_reqs = VFCAP_ACCEPT_STRIDE;
147 vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
148 if (p == NULL) {
149 return 0;
152 if (args != NULL) {
153 #ifdef DUMP_FORMAT_DATA
154 if (*args == 'd') {
155 p->dump_iframe = 3;
157 else
158 #endif
159 if (*args == 'I') {
160 /* Dump only KEY (ie INTRA) frame */
161 p->dump_iframe = 2;
163 else {
164 if (*args == 'i') {
165 /* Print a 'I!' when a i-frame is encounter */
166 p->dump_iframe = 1;
167 ++args;
170 if (*args != '\0') {
171 p->frame_step = atoi(args);
172 if (p->frame_step <= 0) {
173 mp_msg(MSGT_VFILTER, MSGL_WARN, MSGTR_MPCODECS_ErrorParsingArgument);
174 return 0;
179 return 1;
182 const vf_info_t vf_info_framestep = {
183 "Dump one every n / key frames",
184 "framestep",
185 "Daniele Forghieri",
187 open,
188 NULL