1 /*
2 * WebP encoding support via libwebp
3 * Copyright (c) 2015 Urvang Joshi
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * WebP encoder using libwebp (WebPAnimEncoder API)
25 */
26
29
33
34 #include <webp/mux.h>
35
38 WebPAnimEncoder *
enc;
// the main AnimEncoder object
41
44
45 int done;
// If true, we have assembled the bitstream already
47
49 {
53 WebPAnimEncoderOptions enc_options = { { 0 } };
54 WebPAnimEncoderOptionsInit(&enc_options);
56 // TODO(urvang): Expose some options on command-line perhaps.
57 s->enc = WebPAnimEncoderNew(avctx->
width, avctx->
height, &enc_options);
62 }
64 }
65
70
72 if (
s->done) {
// Second flush: return empty package to denote finish.
73 *got_packet = 0;
74 return 0;
75 } else { // First flush: assemble bitstream and return it.
76 WebPData assembled_data = { 0 };
77 ret = WebPAnimEncoderAssemble(
s->enc, &assembled_data);
81 WebPDataClear(&assembled_data);
83 }
84 memcpy(
pkt->
data, assembled_data.bytes, assembled_data.size);
85 WebPDataClear(&assembled_data);
88
91
95 s->first_frame_opaque_ref =
NULL;
96 }
97
98 *got_packet = 1;
99 return 0;
100 } else {
101 WebPDataClear(&assembled_data);
103 "WebPAnimEncoderAssemble() failed with error: %d\n",
104 VP8_ENC_ERROR_OUT_OF_MEMORY);
106 }
107 }
108 } else {
109 int timestamp_ms;
110 WebPPicture *pic =
NULL;
114 goto end;
115
116 timestamp_ms =
118 ret = WebPAnimEncoderAdd(
s->enc, pic, timestamp_ms, &
s->cc.config);
121 "Encoding WebP frame failed with error: %d\n",
122 pic->error_code);
124 goto end;
125 }
126
128 s->first_frame_pts =
frame->pts;
129
131 s->first_frame_opaque =
frame->opaque;
134 goto end;
135 }
136 }
137
140
142 *got_packet = 0;
143
144 end:
145 WebPPictureFree(pic);
149 }
150 }
151
153 {
156 WebPAnimEncoderDelete(
s->enc);
157
159
160 return 0;
161 }
162
164 .
p.
name =
"libwebp_anim",
173 .p.wrapper_name = "libwebp",
180 };