2 * filter to ouput only 1 every n frame, or only the I (key)frame
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
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
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 )
56 #include "cpudetect.h"
58 #include "img_format.h"
62 /* Uncomment if you want to print some info on the format */
63 // #define DUMP_FORMAT_DATA
69 /* Frame output step, 0 = all */
71 /* Only I-Frame (2), print on I-Frame (1) */
76 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
)
79 struct vf_priv_s
*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) {
96 skip
= mpi
->pict_type
== 1 ? 0 : 1;
99 /* Only 1 every frame_step */
101 if ((priv
->frame_step
!= 0) && ((priv
->frame_cur
% priv
->frame_step
) != 0)) {
105 /* Increment current frame */
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,
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
);
133 static void uninit(struct vf_instance_s
* vf
)
135 /* Free private data */
139 /* Main entry funct for the filter */
140 static int open(vf_instance_t
*vf
, char* args
)
144 vf
->put_image
= put_image
;
146 vf
->default_reqs
= VFCAP_ACCEPT_STRIDE
;
147 vf
->priv
= p
= calloc(1, sizeof(struct vf_priv_s
));
153 #ifdef DUMP_FORMAT_DATA
160 /* Dump only KEY (ie INTRA) frame */
165 /* Print a 'I!' when a i-frame is encounter */
171 p
->frame_step
= atoi(args
);
172 if (p
->frame_step
<= 0) {
173 mp_msg(MSGT_VFILTER
, MSGL_WARN
, MSGTR_MPCODECS_ErrorParsingArgument
);
182 const vf_info_t vf_info_framestep
= {
183 "Dump one every n / key frames",