annotate libmpcodecs/vf_framestep.c @ 17874:1973600f8f3e

Small fix with object list (-vf) help. Tell the user when an object have no option description instead of falling back to the "normal" help, like with -vf pp=help. Don't display a useless error message when querying the help of an object option (as in -vf scale=presize=help).
author albeu
date Wed, 15 Mar 2006 17:16:13 +0000
parents 6ff3379a0862
children 20aca9baf5d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10751
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
1 /*
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
2 * vf_fstep.c - filter to ouput only 1 every n frame, or only the I (key)
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
3 * frame
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
4 *
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
5 * The parameters are:
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
6 *
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
7 * [I] | [i]num
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
8 *
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
9 * if you call the filter with I (uppercase) as the parameter
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
10 * ... -vf framestep=I ...
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
11 * then ONLY the keyframes are outputted.
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
12 * For DVD it means, generally, one every 15 frames (IBBPBBPBBPBBPBB), for avi it means
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
13 * every scene change or every keyint value (see -lavcopts).
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
14 *
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
15 * if you call the filter with the i (lowercase)
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
16 * ... -vf framestep=i ...
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
17 * then a I! followed by a cr is printed when a key frame (eg Intra frame) is
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
18 * found, leaving the current line of mplayer/mencoder, where you got the
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
19 * time, in seconds, and frame of the key. Use this information to split the
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
20 * AVI.
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
21 *
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
22 * After the i or alone you can put a positive number and only one frame every
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
23 * x (the number you set) is passed on the filter chain, limiting the output
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
24 * of the frame.
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
25 *
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
26 * Example
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
27 * ... -vf framestep=i20 ...
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
28 * Dump one every 20 frames, printing on the console when a I-Frame is encounter.
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
29 *
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
30 * ... -vf framestep=25
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
31 * Dump one every 25 frames.
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
32 *
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
33 * If you call the filter without parameter it does nothing (except using memory
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
34 * and resource of your system,. of course).
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
35 *
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
36 * This filter doesn' t work like the option -sstep seconds.
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
37 *
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
38 * The -sstep seek to the new position, without decoding all frames but,
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
39 * expecially on avi file coded whith mpeg4 (lavc or xvid or divx), the
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
40 * seek is not always too much precise.
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
41 *
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
42 * This filter simply discard the unwanted frames, so you are very precise in
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
43 * counting the frame but sometime you use a lot of CPU for nothing.
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
44 *
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
45 * As usual it depends on what you're doing.
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
46 *
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
47 * Daniele Forghieri ( guru@digitalfantasy.it )
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
48 */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
49
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
50 #include <stdio.h>
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
51 #include <stdlib.h>
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
52 #include <string.h>
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
53
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 10751
diff changeset
54 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 10751
diff changeset
55 #include "mp_msg.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 10751
diff changeset
56 #include "cpudetect.h"
10751
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
57
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
58 #include "img_format.h"
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
59 #include "mp_image.h"
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
60 #include "vf.h"
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
61
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 10751
diff changeset
62 #include "libvo/fastmemcpy.h"
10751
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
63
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
64 /* Uncomment if you want to print some info on the format */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
65 // #define DUMP_FORMAT_DATA
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
66
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
67 /* Private data */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
68 struct vf_priv_s {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
69 /* Current frame */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
70 int frame_cur;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
71 /* Frame output step, 0 = all */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
72 int frame_step;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
73 /* Only I-Frame (2), print on I-Frame (1) */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
74 int dump_iframe;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
75 };
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
76
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
77 /* Filter handler */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
78 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi)
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
79 {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
80 mp_image_t *dmpi;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
81 struct vf_priv_s *priv;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
82 int skip;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
83
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
84 priv = vf->priv;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
85
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
86 /* Print the 'I' if is a intra frame. The \n advance the current line so you got the
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
87 * current file time (in second) and the frame number on the console ;-)
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
88 */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
89 if (priv->dump_iframe) {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
90 if (mpi->pict_type == 1) {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
91 printf("I!\n");
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
92 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
93 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
94
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
95 /* decide if frame must be shown */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
96 if (priv->dump_iframe == 2) {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
97 /* Only key frame */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
98 skip = mpi->pict_type == 1 ? 0 : 1;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
99 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
100 else {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
101 /* Only 1 every frame_step */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
102 skip = 0;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
103 if ((priv->frame_step != 0) && ((priv->frame_cur % priv->frame_step) != 0)) {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
104 skip = 1;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
105 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
106 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
107 /* Increment current frame */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
108 ++priv->frame_cur;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
109
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
110 if (skip == 0) {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
111 /* Get image, export type (we don't modify tghe image) */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
112 dmpi=vf_get_image(vf->next, mpi->imgfmt,
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
113 MP_IMGTYPE_EXPORT, 0,
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
114 mpi->w, mpi->h);
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
115 /* Copy only the pointer ( MP_IMGTYPE_EXPORT ! ) */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
116 dmpi->planes[0] = mpi->planes[0];
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
117 dmpi->planes[1] = mpi->planes[1];
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
118 dmpi->planes[2] = mpi->planes[2];
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
119
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
120 dmpi->stride[0] = mpi->stride[0];
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
121 dmpi->stride[1] = mpi->stride[1];
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
122 dmpi->stride[2] = mpi->stride[2];
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
123
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
124 dmpi->width = mpi->width;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
125 dmpi->height = mpi->height;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
126
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
127 /* Chain to next filter / output ... */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
128 return vf_next_put_image(vf, dmpi);
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
129 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
130
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
131 /* Skip the frame */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
132 return 0;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
133 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
134
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
135 static void uninit(struct vf_instance_s* vf)
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
136 {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
137 /* Free private data */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
138 free(vf->priv);
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
139 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
140
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
141 /* Main entry funct for the filter */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
142 static int open(vf_instance_t *vf, char* args)
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
143 {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
144 struct vf_priv_s *p;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
145
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
146 vf->put_image = put_image;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
147 vf->uninit = uninit;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
148 vf->default_reqs = VFCAP_ACCEPT_STRIDE;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
149 vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
150 if (p == NULL) {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
151 return(0);
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
152 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
153
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
154 if (args != NULL) {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
155 #ifdef DUMP_FORMAT_DATA
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
156 if (*args == 'd') {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
157 p->dump_iframe = 3;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
158 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
159 else
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
160 #endif
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
161 if (*args == 'I') {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
162 /* Dump only KEY (ie INTRA) frame */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
163 p->dump_iframe = 2;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
164 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
165 else {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
166 if (*args == 'i') {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
167 /* Print a 'I!' when a i-frame is encounter */
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
168 p->dump_iframe = 1;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
169 ++args;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
170 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
171
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
172 if (*args != '\0') {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
173 p->frame_step = atoi(args);
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
174 if (p->frame_step <= 0) {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
175 printf("Error parsing argument\n");
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
176 return(0);
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
177 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
178 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
179 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
180 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
181 return 1;
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
182 }
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
183
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
184 vf_info_t vf_info_framestep = {
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
185 "Dump one every n / key frames",
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
186 "framestep",
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
187 "Daniele Forghieri",
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
188 "",
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
189 open,
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
190 NULL
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
191 };
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
192
81d03cb2cd64 2 new filters: tile & framestep
arpi
parents:
diff changeset
193