gl_common: do not call glXGetClientString() and glXGetServerString()
[mplayer.git] / libmpcodecs / vf_framestep.c
blobd6aad9a90ae9d1f84d54cad190e477029c5e0bfa
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, where you got the time, in
18 * seconds, and frame of the key. Use this information to split the AVI.
20 * After the i or alone you can put a positive number and only one frame every
21 * x (the number you set) is passed on the filter chain, limiting the output
22 * of the frame.
24 * Example
25 * ... -vf framestep=i20 ...
26 * Dump one every 20 frames, printing on the console when a I-Frame is encounter.
28 * ... -vf framestep=25
29 * Dump one every 25 frames.
31 * If you call the filter without parameter it does nothing (except using memory
32 * and resource of your system,. of course).
34 * This filter doesn' t work like the option -sstep seconds.
36 * The -sstep seek to the new position, without decoding all frames but,
37 * expecially on avi file coded whith mpeg4 (lavc or xvid or divx), the
38 * seek is not always too much precise.
40 * This filter simply discard the unwanted frames, so you are very precise in
41 * counting the frame but sometime you use a lot of CPU for nothing.
43 * As usual it depends on what you're doing.
45 * copyright (c) 2003 Daniele Forghieri ( guru@digitalfantasy.it )
47 * This file is part of MPlayer.
49 * MPlayer is free software; you can redistribute it and/or modify
50 * it under the terms of the GNU General Public License as published by
51 * the Free Software Foundation; either version 2 of the License, or
52 * (at your option) any later version.
54 * MPlayer is distributed in the hope that it will be useful,
55 * but WITHOUT ANY WARRANTY; without even the implied warranty of
56 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57 * GNU General Public License for more details.
59 * You should have received a copy of the GNU General Public License along
60 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
61 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
64 #include <stdio.h>
65 #include <stdlib.h>
66 #include <string.h>
68 #include "config.h"
69 #include "mp_msg.h"
70 #include "cpudetect.h"
72 #include "img_format.h"
73 #include "mp_image.h"
74 #include "vf.h"
76 /* Uncomment if you want to print some info on the format */
77 // #define DUMP_FORMAT_DATA
79 /* Private data */
80 struct vf_priv_s {
81 /* Current frame */
82 int frame_cur;
83 /* Frame output step, 0 = all */
84 int frame_step;
85 /* Only I-Frame (2), print on I-Frame (1) */
86 int dump_iframe;
89 /* Filter handler */
90 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
92 mp_image_t *dmpi;
93 struct vf_priv_s *priv;
94 int skip;
96 priv = vf->priv;
98 /* Print the 'I' if is a intra frame. The \n advance the current line so you got the
99 * current file time (in second) and the frame number on the console ;-)
101 if (priv->dump_iframe) {
102 if (mpi->pict_type == 1) {
103 mp_msg(MSGT_VFILTER, MSGL_INFO, "I!\n");
107 /* decide if frame must be shown */
108 if (priv->dump_iframe == 2) {
109 /* Only key frame */
110 skip = mpi->pict_type == 1 ? 0 : 1;
112 else {
113 /* Only 1 every frame_step */
114 skip = 0;
115 if ((priv->frame_step != 0) && ((priv->frame_cur % priv->frame_step) != 0)) {
116 skip = 1;
119 /* Increment current frame */
120 ++priv->frame_cur;
122 if (skip == 0) {
123 /* Get image, export type (we don't modify tghe image) */
124 dmpi=vf_get_image(vf->next, mpi->imgfmt,
125 MP_IMGTYPE_EXPORT, 0,
126 mpi->w, mpi->h);
127 /* Copy only the pointer ( MP_IMGTYPE_EXPORT ! ) */
128 dmpi->planes[0] = mpi->planes[0];
129 dmpi->planes[1] = mpi->planes[1];
130 dmpi->planes[2] = mpi->planes[2];
132 dmpi->stride[0] = mpi->stride[0];
133 dmpi->stride[1] = mpi->stride[1];
134 dmpi->stride[2] = mpi->stride[2];
136 dmpi->width = mpi->width;
137 dmpi->height = mpi->height;
139 /* Chain to next filter / output ... */
140 return vf_next_put_image(vf, dmpi, pts);
143 /* Skip the frame */
144 return 0;
147 static void uninit(struct vf_instance *vf)
149 /* Free private data */
150 free(vf->priv);
153 /* Main entry funct for the filter */
154 static int vf_open(vf_instance_t *vf, char *args)
156 struct vf_priv_s *p;
158 vf->put_image = put_image;
159 vf->uninit = uninit;
160 vf->default_reqs = VFCAP_ACCEPT_STRIDE;
161 vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
162 if (p == NULL) {
163 return 0;
166 if (args != NULL) {
167 #ifdef DUMP_FORMAT_DATA
168 if (*args == 'd') {
169 p->dump_iframe = 3;
171 else
172 #endif
173 if (*args == 'I') {
174 /* Dump only KEY (ie INTRA) frame */
175 p->dump_iframe = 2;
177 else {
178 if (*args == 'i') {
179 /* Print a 'I!' when a i-frame is encounter */
180 p->dump_iframe = 1;
181 ++args;
184 if (*args != '\0') {
185 p->frame_step = atoi(args);
186 if (p->frame_step <= 0) {
187 mp_tmsg(MSGT_VFILTER, MSGL_WARN, "[VF_FRAMESTEP] Error parsing argument.\n");
188 return 0;
193 return 1;
196 const vf_info_t vf_info_framestep = {
197 "Dump one every n / key frames",
198 "framestep",
199 "Daniele Forghieri",
201 vf_open,
202 NULL