annotate libvo/vo_png.c @ 36920:40ad45360c8a

Replace old item 'potmeter' by new item 'pimage'. Recent versions of the X11/GTK GUI didn't allow to control a potmeter, because that didn't seem to make any sense. In order to get rid of the confusing potmeter that doesn't distinguish from a hpotmeter and in order to allow the more useful behaviour recent versions of the X11/GTK GUI have been utilized (and because we're still supporting item 'potmeter' for reasons of compatibility with old skins), introduce new item 'pimage' that reuses most of the current potmeter code. Additionally, remove remaining code and documentation of 'potmeter'.
author ib
date Mon, 17 Mar 2014 12:29:46 +0000
parents 5d3f93051de9
children 88b4aa330150
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28446
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
1 /*
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
2 * Portable Network Graphics renderer
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
3 *
530
670d47b4ce10 changed copyroght message to correct stuff :)
atmosfear
parents: 527
diff changeset
4 * Copyright 2001 by Felix Buenemann <atmosfear@users.sourceforge.net>
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
5 *
530
670d47b4ce10 changed copyroght message to correct stuff :)
atmosfear
parents: 527
diff changeset
6 * Uses libpng (which uses zlib), so see according licenses.
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
7 *
28446
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
8 * This file is part of MPlayer.
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
9 *
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
10 * MPlayer is free software; you can redistribute it and/or modify
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
11 * it under the terms of the GNU General Public License as published by
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
13 * (at your option) any later version.
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
14 *
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
15 * MPlayer is distributed in the hope that it will be useful,
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
18 * GNU General Public License for more details.
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
19 *
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
20 * You should have received a copy of the GNU General Public License along
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
21 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
7681eab10aea Add standard license headers, unify header formatting.
diego
parents: 28092
diff changeset
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
23 */
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
24
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
25 #include <stdio.h>
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
26 #include <stdlib.h>
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
27 #include <string.h>
612
77e0094f0cce some warnings killed
szabii
parents: 530
diff changeset
28 #include <errno.h>
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
29 #include <sys/stat.h>
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
30 #include <sys/types.h>
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
31 #include <unistd.h>
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
32
26203
0d255d03016f #include config.h before all other headers.
diego
parents: 25220
diff changeset
33 #include "config.h"
30427
946629f9b239 Add missing #include, fixes the warning:
diego
parents: 30144
diff changeset
34 #include "fmt-conversion.h"
30516
f4e017b6921a Fix exit_player() usage throughout the codebase.
diego
parents: 30427
diff changeset
35 #include "mp_core.h"
18234
a107276371a8 Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents: 17932
diff changeset
36 #include "mp_msg.h"
a107276371a8 Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents: 17932
diff changeset
37 #include "help_mp.h"
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
38 #include "video_out.h"
36517
5d3f93051de9 Remove empty draw_slice and draw_frame stubs.
reimar
parents: 36374
diff changeset
39 #define NO_DRAW_FRAME
5d3f93051de9 Remove empty draw_slice and draw_frame stubs.
reimar
parents: 36374
diff changeset
40 #define NO_DRAW_SLICE
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
41 #include "video_out_internal.h"
14451
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
42 #include "subopt-helper.h"
30144
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
43 #include "libavcodec/avcodec.h"
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
44
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
45 #define BUFLENGTH 512
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
46
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28922
diff changeset
47 static const vo_info_t info =
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
48 {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
49 "PNG file",
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
50 "png",
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
51 "Felix Buenemann <atmosfear@users.sourceforge.net>",
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
52 ""
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
53 };
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
54
25220
c9e9ac2008c2 Mark the vo_functions_t definitions as const where possible.
reimar
parents: 25216
diff changeset
55 const LIBVO_EXTERN (png)
8148
5b39e79af5fe removed get_info, using the same sheme as in libmpcodecs instead
alex
parents: 7926
diff changeset
56
30144
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
57 static int z_compression;
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
58 static char *png_outdir;
32755
f03a237a8d26 Add prefix filename option for PNG video output.
cboesch
parents: 32537
diff changeset
59 static char *png_outfile_prefix;
34635
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
60 static uint32_t png_format;
30144
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
61 static int framenum;
28092
77c7b422a49d Add support for writing PNG files with alpha channel in -vo png
reimar
parents: 27873
diff changeset
62 static int use_alpha;
30144
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
63 static AVCodecContext *avctx;
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
64 static uint8_t *outbuffer;
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
65 int outbuffer_size;
3950
e92653caf5d7 osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 2732
diff changeset
66
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28922
diff changeset
67 static void png_mkdir(char *buf, int verbose) {
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
68 struct stat stat_p;
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
69
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28922
diff changeset
70 #ifndef __MINGW32__
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
71 if ( mkdir(buf, 0755) < 0 ) {
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
72 #else
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
73 if ( mkdir(buf) < 0 ) {
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
74 #endif
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
75 switch (errno) { /* use switch in case other errors need to be caught
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
76 and handled in the future */
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
77 case EEXIST:
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
78 if ( stat(buf, &stat_p ) < 0 ) {
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
79 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
80 MSGTR_VO_GenericError, strerror(errno) );
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
81 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
82 MSGTR_VO_UnableToAccess,buf);
30516
f4e017b6921a Fix exit_player() usage throughout the codebase.
diego
parents: 30427
diff changeset
83 exit_player(EXIT_ERROR);
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
84 }
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
85 if ( !S_ISDIR(stat_p.st_mode) ) {
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
86 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
87 buf, MSGTR_VO_ExistsButNoDirectory);
30516
f4e017b6921a Fix exit_player() usage throughout the codebase.
diego
parents: 30427
diff changeset
88 exit_player(EXIT_ERROR);
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
89 }
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
90 if ( !(stat_p.st_mode & S_IWUSR) ) {
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
91 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
92 buf, MSGTR_VO_DirExistsButNotWritable);
30516
f4e017b6921a Fix exit_player() usage throughout the codebase.
diego
parents: 30427
diff changeset
93 exit_player(EXIT_ERROR);
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
94 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28922
diff changeset
95
36374
cd83754e4f3a vo jpeg, png, pnm: Make output directory message less confusing
al
parents: 36328
diff changeset
96 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s: %s\n", info.short_name, MSGTR_VO_OutputDirectory, buf);
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
97 break;
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
98
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
99 default:
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
100 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
101 MSGTR_VO_GenericError, strerror(errno) );
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
102 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
103 buf, MSGTR_VO_CantCreateDirectory);
30516
f4e017b6921a Fix exit_player() usage throughout the codebase.
diego
parents: 30427
diff changeset
104 exit_player(EXIT_ERROR);
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
105 } /* end switch */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28922
diff changeset
106 } else if ( verbose ) {
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
107 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
108 buf, MSGTR_VO_DirectoryCreateSuccess);
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
109 } /* end if */
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
110 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28922
diff changeset
111
16171
fd51fd1ff231 Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents: 15212
diff changeset
112 static int
15212
05aa13cdf92f replace VO and VF numeric flags with #defined identifiers
henry
parents: 14451
diff changeset
113 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
114 {
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
115 char buf[BUFLENGTH];
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28922
diff changeset
116
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
117 if(z_compression == 0) {
18234
a107276371a8 Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents: 17932
diff changeset
118 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning1);
a107276371a8 Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents: 17932
diff changeset
119 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning2);
a107276371a8 Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents: 17932
diff changeset
120 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning3);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28922
diff changeset
121 }
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28922
diff changeset
122
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
123 snprintf(buf, BUFLENGTH, "%s", png_outdir);
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
124 png_mkdir(buf, 1);
24671
fbcd9dcb0daf Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents: 24670
diff changeset
125 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Compression level %i\n", z_compression);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28922
diff changeset
126
34635
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
127
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
128 if (avctx && png_format != format) {
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
129 avcodec_close(avctx);
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
130 av_freep(&avctx);
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
131 }
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
132
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
133 if (!avctx) {
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
134 avctx = avcodec_alloc_context3(NULL);
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
135 avctx->compression_level = z_compression;
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
136 avctx->pix_fmt = imgfmt2pixfmt(format);
35715
8517826b0dbd Replace CODEC_IDs their modern AV_-prefixed counterparts.
diego
parents: 34804
diff changeset
137 if (avcodec_open2(avctx, avcodec_find_encoder(AV_CODEC_ID_PNG), NULL) < 0) {
34635
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
138 uninit();
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
139 return -1;
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
140 }
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
141 png_format = format;
7e0f50b4921c Fix vo_png after FFmpeg merge.
iive
parents: 34566
diff changeset
142 }
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
143 return 0;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
144 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
145
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
146
7693
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
147 static uint32_t draw_image(mp_image_t* mpi){
30144
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
148 AVFrame pic;
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
149 int buffersize;
36327
797bbffdd112 vo png: Switch to avcodec_encode_video2
al
parents: 35715
diff changeset
150 int res, got_pkt;
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
151 char buf[100];
30144
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
152 FILE *outfile;
36327
797bbffdd112 vo png: Switch to avcodec_encode_video2
al
parents: 35715
diff changeset
153 AVPacket pkt;
7693
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
154
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
155 // if -dr or -slices then do nothing:
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
156 if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28922
diff changeset
157
32755
f03a237a8d26 Add prefix filename option for PNG video output.
cboesch
parents: 32537
diff changeset
158 snprintf (buf, 100, "%s/%s%08d.png", png_outdir, png_outfile_prefix, ++framenum);
30144
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
159 outfile = fopen(buf, "wb");
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
160 if (!outfile) {
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
161 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorOpeningForWriting, strerror(errno));
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
162 return 1;
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
163 }
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
164
30144
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
165 avctx->width = mpi->w;
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
166 avctx->height = mpi->h;
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
167 pic.data[0] = mpi->planes[0];
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
168 pic.linesize[0] = mpi->stride[0];
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
169 buffersize = mpi->w * mpi->h * 8;
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
170 if (outbuffer_size < buffersize) {
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
171 av_freep(&outbuffer);
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
172 outbuffer = av_malloc(buffersize);
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
173 outbuffer_size = buffersize;
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
174 }
36327
797bbffdd112 vo png: Switch to avcodec_encode_video2
al
parents: 35715
diff changeset
175 av_init_packet(&pkt);
797bbffdd112 vo png: Switch to avcodec_encode_video2
al
parents: 35715
diff changeset
176 pkt.data = outbuffer;
797bbffdd112 vo png: Switch to avcodec_encode_video2
al
parents: 35715
diff changeset
177 pkt.size = outbuffer_size;
797bbffdd112 vo png: Switch to avcodec_encode_video2
al
parents: 35715
diff changeset
178 res = avcodec_encode_video2(avctx, &pkt, &pic, &got_pkt);
30144
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
179
36328
9af6f39eab61 vo png: Error handling and clean up
al
parents: 36327
diff changeset
180 if (res < 0 || !got_pkt) {
18234
a107276371a8 Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents: 17932
diff changeset
181 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorInCreatePng);
36328
9af6f39eab61 vo png: Error handling and clean up
al
parents: 36327
diff changeset
182 } else {
9af6f39eab61 vo png: Error handling and clean up
al
parents: 36327
diff changeset
183 fwrite(outbuffer, pkt.size, 1, outfile);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28922
diff changeset
184 }
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
185
30144
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
186 fclose(outfile);
36328
9af6f39eab61 vo png: Error handling and clean up
al
parents: 36327
diff changeset
187 av_free_packet(&pkt);
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
188
7693
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
189 return VO_TRUE;
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
190 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
191
7926
7d2542838d24 - removed YV12 support (builtin yv12->rgb conversion)
arpi
parents: 7694
diff changeset
192 static void draw_osd(void){}
1501
d40f2b686846 changes according to -utf8 option, draw_osd() function added
atlka
parents: 1078
diff changeset
193
7926
7d2542838d24 - removed YV12 support (builtin yv12->rgb conversion)
arpi
parents: 7694
diff changeset
194 static void flip_page (void){}
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
195
16171
fd51fd1ff231 Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents: 15212
diff changeset
196 static int
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
197 query_format(uint32_t format)
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
198 {
28092
77c7b422a49d Add support for writing PNG files with alpha channel in -vo png
reimar
parents: 27873
diff changeset
199 const int supported_flags = VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE;
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
200 switch(format){
27873
80a16d26acda Use the proper IMGFMT_RGB24 and IMGFMT_BGR24 defines instead of
reimar
parents: 27655
diff changeset
201 case IMGFMT_RGB24:
28092
77c7b422a49d Add support for writing PNG files with alpha channel in -vo png
reimar
parents: 27873
diff changeset
202 return use_alpha ? 0 : supported_flags;
34804
664152973dbc Fix -vo png:alpha with newer FFmpeg.
cehoyos
parents: 34635
diff changeset
203 case IMGFMT_RGBA:
28092
77c7b422a49d Add support for writing PNG files with alpha channel in -vo png
reimar
parents: 27873
diff changeset
204 return use_alpha ? supported_flags : 0;
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
205 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
206 return 0;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
207 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
208
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
209 static void uninit(void){
30144
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
210 avcodec_close(avctx);
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
211 av_freep(&avctx);
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
212 av_freep(&outbuffer);
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
213 outbuffer_size = 0;
32537
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 30516
diff changeset
214 free(png_outdir);
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 30516
diff changeset
215 png_outdir = NULL;
32755
f03a237a8d26 Add prefix filename option for PNG video output.
cboesch
parents: 32537
diff changeset
216 free(png_outfile_prefix);
f03a237a8d26 Add prefix filename option for PNG video output.
cboesch
parents: 32537
diff changeset
217 png_outfile_prefix = NULL;
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
218 }
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
219
7926
7d2542838d24 - removed YV12 support (builtin yv12->rgb conversion)
arpi
parents: 7694
diff changeset
220 static void check_events(void){}
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
221
30122
1772a5171ac7 Fix function declarations to avoid casting function pointers.
reimar
parents: 29263
diff changeset
222 static int int_zero_to_nine(void *value)
14451
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
223 {
30122
1772a5171ac7 Fix function declarations to avoid casting function pointers.
reimar
parents: 29263
diff changeset
224 int *sh = value;
30123
0f5f75b4a015 Simplify range-checking functions for subopt parsing.
reimar
parents: 30122
diff changeset
225 return *sh >= 0 && *sh <= 9;
14451
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
226 }
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
227
28828
56eee6ffba9b Make data related to suboption parsing const in libvo
reimar
parents: 28446
diff changeset
228 static const opt_t subopts[] = {
28922
9dd905e52639 Remove obsolete extra elements from opt_t struct initialization.
diego
parents: 28828
diff changeset
229 {"alpha", OPT_ARG_BOOL, &use_alpha, NULL},
30122
1772a5171ac7 Fix function declarations to avoid casting function pointers.
reimar
parents: 29263
diff changeset
230 {"z", OPT_ARG_INT, &z_compression, int_zero_to_nine},
28922
9dd905e52639 Remove obsolete extra elements from opt_t struct initialization.
diego
parents: 28828
diff changeset
231 {"outdir", OPT_ARG_MSTRZ, &png_outdir, NULL},
32755
f03a237a8d26 Add prefix filename option for PNG video output.
cboesch
parents: 32537
diff changeset
232 {"prefix", OPT_ARG_MSTRZ, &png_outfile_prefix, NULL },
14451
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
233 {NULL}
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
234 };
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
235
16171
fd51fd1ff231 Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents: 15212
diff changeset
236 static int preinit(const char *arg)
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
237 {
14451
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
238 z_compression = 0;
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
239 png_outdir = strdup(".");
32755
f03a237a8d26 Add prefix filename option for PNG video output.
cboesch
parents: 32537
diff changeset
240 png_outfile_prefix = strdup("");
28092
77c7b422a49d Add support for writing PNG files with alpha channel in -vo png
reimar
parents: 27873
diff changeset
241 use_alpha = 0;
14451
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
242 if (subopt_parse(arg, subopts) != 0) {
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
243 return -1;
4737
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
244 }
30144
0a92a14ced38 Change vo_png to use FFmpeg's png encoder instead of libpng.
reimar
parents: 30123
diff changeset
245 avcodec_register_all();
4737
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
246 return 0;
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
247 }
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
248
33305
ddb45e9443ec Remove the variable arguments from the libvo control() functions.
iive
parents: 32755
diff changeset
249 static int control(uint32_t request, void *data)
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
250 {
4592
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
251 switch (request) {
7693
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
252 case VOCTRL_DRAW_IMAGE:
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
253 return draw_image(data);
4592
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
254 case VOCTRL_QUERY_FORMAT:
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
255 return query_format(*((uint32_t*)data));
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
256 }
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
257 return VO_NOTIMPL;
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
258 }