annotate libmpcodecs/vf_screenshot.c @ 29445:3e9db1ac8cf1

Map IMGFMT_RGB48xE to PIX_FMT_RGB48xE.
author cehoyos
date Tue, 11 Aug 2009 17:52:01 +0000
parents 67c256364220
children 28fb967d78d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16874
diff changeset
1 #include "config.h"
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
2
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
3 #include <stdio.h>
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
4 #include <stdlib.h>
28594
df67d03dde3b Convert HAVE_MALLOC_H into a 0/1 definition, fixes the warning:
diego
parents: 27949
diff changeset
5 #if HAVE_MALLOC_H
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
6 #include <malloc.h>
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
7 #endif
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
8 #include <string.h>
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
9 #include <inttypes.h>
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
10
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
11 #include <sys/types.h>
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
12 #include <sys/stat.h>
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
13 #include <unistd.h>
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
14
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16874
diff changeset
15 #include "mp_msg.h"
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
16
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
17 #include "img_format.h"
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
18 #include "mp_image.h"
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
19 #include "vf.h"
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
20 #include "vf_scale.h"
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
21
18861
8579acff875e Move postproc ---> libswscale
lucabe
parents: 18771
diff changeset
22 #include "libswscale/swscale.h"
24731
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
23 #include "libavcodec/avcodec.h"
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
24
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
25 struct vf_priv_s {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
26 int frameno;
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
27 char fname[102];
19833
10f36060390a Add repeated screenshot mode to vf_screenshot.
eugeni
parents: 18879
diff changeset
28 /// shot stores current screenshot mode:
10f36060390a Add repeated screenshot mode to vf_screenshot.
eugeni
parents: 18879
diff changeset
29 /// 0: don't take screenshots
10f36060390a Add repeated screenshot mode to vf_screenshot.
eugeni
parents: 18879
diff changeset
30 /// 1: take single screenshot, reset to 0 afterwards
10f36060390a Add repeated screenshot mode to vf_screenshot.
eugeni
parents: 18879
diff changeset
31 /// 2: take screenshots of each frame
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
32 int shot, store_slices;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
33 int dw, dh, stride;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
34 uint8_t *buffer;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
35 struct SwsContext *ctx;
24731
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
36 AVCodecContext *avctx;
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
37 uint8_t *outbuffer;
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
38 int outbuffer_size;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
39 };
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
40
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
41 //===========================================================================//
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
42
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
43 static int config(struct vf_instance_s* vf,
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
44 int width, int height, int d_width, int d_height,
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
45 unsigned int flags, unsigned int outfmt)
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
46 {
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
47 vf->priv->ctx=sws_getContextFromCmdLine(width, height, outfmt,
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
48 d_width, d_height, IMGFMT_RGB24);
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
49
24731
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
50 vf->priv->outbuffer_size = d_width * d_height * 3 * 2;
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
51 vf->priv->outbuffer = realloc(vf->priv->outbuffer, vf->priv->outbuffer_size);
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
52 vf->priv->avctx->width = d_width;
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
53 vf->priv->avctx->height = d_height;
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
54 vf->priv->avctx->pix_fmt = PIX_FMT_RGB24;
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
55 vf->priv->avctx->compression_level = 0;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
56 vf->priv->dw = d_width;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
57 vf->priv->dh = d_height;
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
58 vf->priv->stride = (3*vf->priv->dw+15)&~15;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
59
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
60 if (vf->priv->buffer) free(vf->priv->buffer); // probably reconfigured
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
61 vf->priv->buffer = NULL;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
62
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
63 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
64 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
65
24731
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
66 static void write_png(struct vf_priv_s *priv)
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
67 {
24731
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
68 char *fname = priv->fname;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
69 FILE * fp;
24731
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
70 AVFrame pic;
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
71 int size;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
72
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
73 fp = fopen (fname, "wb");
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
74 if (fp == NULL) {
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
75 mp_msg(MSGT_VFILTER,MSGL_ERR,"\nPNG Error opening %s for writing!\n", fname);
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
76 return;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
77 }
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
78
24731
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
79 pic.data[0] = priv->buffer;
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
80 pic.linesize[0] = priv->stride;
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
81 size = avcodec_encode_video(priv->avctx, priv->outbuffer, priv->outbuffer_size, &pic);
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
82 if (size > 0)
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
83 fwrite(priv->outbuffer, size, 1, fp);
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
84
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
85 fclose (fp);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
86 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
87
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
88 static int fexists(char *fname)
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
89 {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
90 struct stat dummy;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
91 if (stat(fname, &dummy) == 0) return 1;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
92 else return 0;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
93 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
94
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
95 static void gen_fname(struct vf_priv_s* priv)
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
96 {
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
97 do {
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
98 snprintf (priv->fname, 100, "shot%04d.png", ++priv->frameno);
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
99 } while (fexists(priv->fname) && priv->frameno < 100000);
16457
5ab14fa7a019 do nothing if no free filenames are available
henry
parents: 16456
diff changeset
100 if (fexists(priv->fname)) {
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
101 priv->fname[0] = '\0';
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
102 return;
16457
5ab14fa7a019 do nothing if no free filenames are available
henry
parents: 16456
diff changeset
103 }
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
104
40222952440f DR and slice support
henry
parents: 16446
diff changeset
105 mp_msg(MSGT_VFILTER,MSGL_INFO,"*** screenshot '%s' ***\n",priv->fname);
40222952440f DR and slice support
henry
parents: 16446
diff changeset
106
40222952440f DR and slice support
henry
parents: 16446
diff changeset
107 }
40222952440f DR and slice support
henry
parents: 16446
diff changeset
108
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
109 static void scale_image(struct vf_priv_s* priv, mp_image_t *mpi)
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
110 {
29064
67c256364220 Consistently use MP_MAX_PLANES as size for plane pointer/stride arrays in libmpcodecs.
reimar
parents: 28594
diff changeset
111 uint8_t *dst[MP_MAX_PLANES] = {NULL};
67c256364220 Consistently use MP_MAX_PLANES as size for plane pointer/stride arrays in libmpcodecs.
reimar
parents: 28594
diff changeset
112 int dst_stride[MP_MAX_PLANES] = {0};
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
113
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
114 dst_stride[0] = priv->stride;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
115 if (!priv->buffer)
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
116 priv->buffer = memalign(16, dst_stride[0]*priv->dh);
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
117
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
118 dst[0] = priv->buffer;
20930
29c478a2483f Fix segfault with videos with unusual resolution, patch by Stanislav Maslovski % stanislav P maslovski A gmail P com %
gpoirier
parents: 19833
diff changeset
119 sws_scale_ordered(priv->ctx, mpi->planes, mpi->stride, 0, priv->dh, dst, dst_stride);
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
120 }
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
121
27948
6e485d467cfe cosmetics: consistent function declarations.
diego
parents: 27947
diff changeset
122 static void start_slice(struct vf_instance_s* vf, mp_image_t *mpi)
6e485d467cfe cosmetics: consistent function declarations.
diego
parents: 27947
diff changeset
123 {
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
124 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
125 mpi->type, mpi->flags, mpi->width, mpi->height);
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
126 if (vf->priv->shot) {
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
127 vf->priv->store_slices = 1;
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
128 if (!vf->priv->buffer)
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
129 vf->priv->buffer = memalign(16, vf->priv->stride*vf->priv->dh);
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
130 }
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
131
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
132 }
40222952440f DR and slice support
henry
parents: 16446
diff changeset
133
27948
6e485d467cfe cosmetics: consistent function declarations.
diego
parents: 27947
diff changeset
134 static void draw_slice(struct vf_instance_s* vf, unsigned char** src,
6e485d467cfe cosmetics: consistent function declarations.
diego
parents: 27947
diff changeset
135 int* stride, int w,int h, int x, int y)
6e485d467cfe cosmetics: consistent function declarations.
diego
parents: 27947
diff changeset
136 {
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
137 if (vf->priv->store_slices) {
29064
67c256364220 Consistently use MP_MAX_PLANES as size for plane pointer/stride arrays in libmpcodecs.
reimar
parents: 28594
diff changeset
138 uint8_t *dst[MP_MAX_PLANES] = {NULL};
67c256364220 Consistently use MP_MAX_PLANES as size for plane pointer/stride arrays in libmpcodecs.
reimar
parents: 28594
diff changeset
139 int dst_stride[MP_MAX_PLANES] = {0};
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
140 dst_stride[0] = vf->priv->stride;
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
141 dst[0] = vf->priv->buffer;
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
142 sws_scale_ordered(vf->priv->ctx, src, stride, y, h, dst, dst_stride);
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
143 }
40222952440f DR and slice support
henry
parents: 16446
diff changeset
144 vf_next_draw_slice(vf,src,stride,w,h,x,y);
40222952440f DR and slice support
henry
parents: 16446
diff changeset
145 }
40222952440f DR and slice support
henry
parents: 16446
diff changeset
146
27948
6e485d467cfe cosmetics: consistent function declarations.
diego
parents: 27947
diff changeset
147 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi)
6e485d467cfe cosmetics: consistent function declarations.
diego
parents: 27947
diff changeset
148 {
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
149 // FIXME: should vf.c really call get_image when using slices??
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
150 if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
151 return;
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
152 vf->dmpi= vf_get_image(vf->next, mpi->imgfmt,
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
153 mpi->type, mpi->flags/* | MP_IMGFLAG_READABLE*/, mpi->width, mpi->height);
16456
34eb986b7e4a use slices if DR isn't available
henry
parents: 16452
diff changeset
154
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
155 mpi->planes[0]=vf->dmpi->planes[0];
40222952440f DR and slice support
henry
parents: 16446
diff changeset
156 mpi->stride[0]=vf->dmpi->stride[0];
40222952440f DR and slice support
henry
parents: 16446
diff changeset
157 if(mpi->flags&MP_IMGFLAG_PLANAR){
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
158 mpi->planes[1]=vf->dmpi->planes[1];
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
159 mpi->planes[2]=vf->dmpi->planes[2];
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
160 mpi->stride[1]=vf->dmpi->stride[1];
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
161 mpi->stride[2]=vf->dmpi->stride[2];
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
162 }
40222952440f DR and slice support
henry
parents: 16446
diff changeset
163 mpi->width=vf->dmpi->width;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
164
40222952440f DR and slice support
henry
parents: 16446
diff changeset
165 mpi->flags|=MP_IMGFLAG_DIRECT;
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
166
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
167 mpi->priv=(void*)vf->dmpi;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
168 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
169
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
170 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts)
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
171 {
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
172 mp_image_t *dmpi = (mp_image_t *)mpi->priv;
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
173
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
174 if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
175 dmpi = vf->dmpi;
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
176 else
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
177 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
178 dmpi=vf_get_image(vf->next,mpi->imgfmt,
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
179 MP_IMGTYPE_EXPORT, 0,
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
180 mpi->width, mpi->height);
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
181 vf_clone_mpi_attributes(dmpi, mpi);
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
182 dmpi->planes[0]=mpi->planes[0];
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
183 dmpi->planes[1]=mpi->planes[1];
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
184 dmpi->planes[2]=mpi->planes[2];
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
185 dmpi->stride[0]=mpi->stride[0];
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
186 dmpi->stride[1]=mpi->stride[1];
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
187 dmpi->stride[2]=mpi->stride[2];
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
188 dmpi->width=mpi->width;
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
189 dmpi->height=mpi->height;
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
190 }
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
191
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
192 if(vf->priv->shot) {
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
193 if (vf->priv->shot==1)
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
194 vf->priv->shot=0;
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
195 gen_fname(vf->priv);
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
196 if (vf->priv->fname[0]) {
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
197 if (!vf->priv->store_slices)
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
198 scale_image(vf->priv, dmpi);
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
199 write_png(vf->priv);
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
200 }
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
201 vf->priv->store_slices = 0;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
202 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
203
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
204 return vf_next_put_image(vf, dmpi, pts);
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
205 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
206
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
207 int control (vf_instance_t *vf, int request, void *data)
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
208 {
19833
10f36060390a Add repeated screenshot mode to vf_screenshot.
eugeni
parents: 18879
diff changeset
209 /** data contains an integer argument
10f36060390a Add repeated screenshot mode to vf_screenshot.
eugeni
parents: 18879
diff changeset
210 * 0: take screenshot with the next frame
10f36060390a Add repeated screenshot mode to vf_screenshot.
eugeni
parents: 18879
diff changeset
211 * 1: take screenshots with each frame until the same command is given once again
10f36060390a Add repeated screenshot mode to vf_screenshot.
eugeni
parents: 18879
diff changeset
212 **/
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
213 if(request==VFCTRL_SCREENSHOT) {
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
214 if (data && *(int*)data) { // repeated screenshot mode
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
215 if (vf->priv->shot==2)
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
216 vf->priv->shot=0;
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
217 else
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
218 vf->priv->shot=2;
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
219 } else { // single screenshot
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
220 if (!vf->priv->shot)
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
221 vf->priv->shot=1;
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
222 }
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
223 return CONTROL_TRUE;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
224 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
225 return vf_next_control (vf, request, data);
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
226 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
227
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
228
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
229 //===========================================================================//
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
230
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
231 static int query_format(struct vf_instance_s* vf, unsigned int fmt)
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
232 {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
233 switch(fmt){
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
234 case IMGFMT_YV12:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
235 case IMGFMT_I420:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
236 case IMGFMT_IYUV:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
237 case IMGFMT_UYVY:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
238 case IMGFMT_YUY2:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
239 case IMGFMT_BGR32:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
240 case IMGFMT_BGR24:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
241 case IMGFMT_BGR16:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
242 case IMGFMT_BGR15:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
243 case IMGFMT_RGB32:
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
244 case IMGFMT_RGB24:
27947
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
245 case IMGFMT_Y800:
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
246 case IMGFMT_Y8:
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
247 case IMGFMT_YVU9:
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
248 case IMGFMT_IF09:
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
249 case IMGFMT_444P:
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
250 case IMGFMT_422P:
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
251 case IMGFMT_411P:
4681b6303443 cosmetics: Remove tabs and trailing whitespace.
diego
parents: 26069
diff changeset
252 return vf_next_query_format(vf, fmt);
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
253 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
254 return 0;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
255 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
256
27949
88d793e52bd9 cosmetics: Move up uninit() to avoid a forward declaration.
diego
parents: 27948
diff changeset
257 static void uninit(vf_instance_t *vf)
88d793e52bd9 cosmetics: Move up uninit() to avoid a forward declaration.
diego
parents: 27948
diff changeset
258 {
88d793e52bd9 cosmetics: Move up uninit() to avoid a forward declaration.
diego
parents: 27948
diff changeset
259 av_freep(&vf->priv->avctx);
88d793e52bd9 cosmetics: Move up uninit() to avoid a forward declaration.
diego
parents: 27948
diff changeset
260 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
88d793e52bd9 cosmetics: Move up uninit() to avoid a forward declaration.
diego
parents: 27948
diff changeset
261 if (vf->priv->buffer) free(vf->priv->buffer);
88d793e52bd9 cosmetics: Move up uninit() to avoid a forward declaration.
diego
parents: 27948
diff changeset
262 free(vf->priv->outbuffer);
88d793e52bd9 cosmetics: Move up uninit() to avoid a forward declaration.
diego
parents: 27948
diff changeset
263 free(vf->priv);
88d793e52bd9 cosmetics: Move up uninit() to avoid a forward declaration.
diego
parents: 27948
diff changeset
264 }
88d793e52bd9 cosmetics: Move up uninit() to avoid a forward declaration.
diego
parents: 27948
diff changeset
265
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
266 // open conflicts with stdio.h at least under MinGW
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
267 static int screenshot_open(vf_instance_t *vf, char* args)
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
268 {
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
269 vf->config=config;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
270 vf->control=control;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
271 vf->put_image=put_image;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
272 vf->query_format=query_format;
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
273 vf->start_slice=start_slice;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
274 vf->draw_slice=draw_slice;
40222952440f DR and slice support
henry
parents: 16446
diff changeset
275 vf->get_image=get_image;
16874
debd99a161e0 10l, uninit() was not used, fixes bug #401
reimar
parents: 16464
diff changeset
276 vf->uninit=uninit;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
277 vf->priv=malloc(sizeof(struct vf_priv_s));
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
278 vf->priv->frameno=0;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
279 vf->priv->shot=0;
16450
40222952440f DR and slice support
henry
parents: 16446
diff changeset
280 vf->priv->store_slices=0;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
281 vf->priv->buffer=0;
24731
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
282 vf->priv->outbuffer=0;
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
283 vf->priv->ctx=0;
24731
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
284 vf->priv->avctx = avcodec_alloc_context();
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
285 avcodec_register_all();
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
286 if (avcodec_open(vf->priv->avctx, avcodec_find_encoder(CODEC_ID_PNG))) {
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
287 mp_msg(MSGT_VFILTER, MSGL_FATAL, "Could not open libavcodec PNG encoder\n");
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
288 return 0;
1d9ea74f79a0 Make vf_screenshot use the libavcodec PNG encoder
reimar
parents: 23373
diff changeset
289 }
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
290 return 1;
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
291 }
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
292
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
293
25221
00fff9a3b735 Make all vf_info_t structs const
reimar
parents: 24731
diff changeset
294 const vf_info_t vf_info_screenshot = {
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
295 "screenshot to file",
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
296 "screenshot",
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
297 "A'rpi, Jindrich Makovicka",
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
298 "",
16464
0a828abf1f0f Fix multiple issues: No picture at all, broken pictures, only every second
reimar
parents: 16457
diff changeset
299 screenshot_open,
16446
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
300 NULL
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
301 };
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
302
c82c0d407ec9 screenshot filter
henry
parents:
diff changeset
303 //===========================================================================//