1 /*
2 * Flash Compatible Streaming Format muxer
3 * Copyright (c) 2000 Fabrice Bellard
4 * Copyright (c) 2003 Tinic Uro
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
27
29 {
32
35 /* reserve some room for the tag */
39 } else {
41 }
42 }
43
45 {
48 int64_t pos;
50
52 tag_len = pos - swf->
tag_pos - 2;
56 tag &= ~TAG_LONG;
59 } else {
62 }
64 }
65
67 {
69
70 if (val == 0)
71 return;
72 val = abs(val);
73 n = 1;
74 while (val != 0) {
75 n++;
76 val >>= 1;
77 }
78 if (n > *nbits_ptr)
80 }
81
83 int xmin, int xmax, int ymin, int ymax)
84 {
88
90
91 nbits = 0;
96 mask = (1 << nbits) - 1;
97
98 /* rectangle info */
104
107 }
108
110 {
112
114 put_bits(pb, 1, 1);
/* line select */
115 nbits = 2;
118
119 mask = (1 << nbits) - 1;
120 put_bits(pb, 4, nbits - 2);
/* 16 bits precision */
121 if (dx == 0) {
125 } else if (dy == 0) {
129 } else {
133 }
134 }
135
137
139 int a,
int b,
int c,
int d,
int tx,
int ty)
140 {
143 int nbits;
144
146
147 put_bits(&p, 1, 1);
/* a, d present */
148 nbits = 1;
151 put_bits(&p, 5, nbits);
/* nb bits */
154
155 put_bits(&p, 1, 1);
/* b, c present */
156 nbits = 1;
159 put_bits(&p, 5, nbits);
/* nb bits */
162
163 nbits = 1;
166 put_bits(&p, 5, nbits);
/* nb bits */
169
172 }
173
175 {
182
186
193 }
197 return -1;
198 }
203 } else {
205 return -1;
206 }
207 } else {
211 }
217 } else {
219 return -1;
220 }
221 }
222 }
223
225 /* currently, cannot work correctly if audio only */
226 width = 320;
227 height = 200;
228 rate = 10;
229 rate_base= 1;
230 } else {
233 // TODO: should be avg_frame_rate
236 }
237
240 else
242
244
246 version = 9;
248 version = 8; /* version 8 and above support VP6 codec */
250 version = 6; /* version 6 and above support FLV1 codec */
251 else
252 version = 4; /* version 4 for mpeg audio support */
254
256 (will be patched if not streamed) */
257
259 avio_wl16(pb, (rate * 256) / rate_base);
/* frame rate */
262
263 /* avm2/swf v9 (also v8?) files require a file attribute tag */
264 if (version == 9) {
266 avio_wl32(pb, 1<<3);
/* set ActionScript v3/AVM2 flag */
268 }
269
270 /* define a shape with the jpeg inside */
273
275 /* bounding rectangle */
277 /* style info */
278 avio_w8(pb, 1);
/* one fill style */
279 avio_w8(pb, 0x41);
/* clipped bitmap fill */
281 /* position of the bitmap */
284 avio_w8(pb, 0);
/* no line style */
285
286 /* shape drawing */
288 put_bits(&p, 4, 1);
/* one fill bit */
289 put_bits(&p, 4, 0);
/* zero line bit */
290
291 put_bits(&p, 1, 0);
/* not an edge */
296 put_bits(&p, 1, 1);
/* set fill style 1 */
297
298 /* draw the rectangle ! */
303
304 /* end of shape */
305 put_bits(&p, 1, 0);
/* not an edge */
307
310
312 }
313
316
317 /* start sound */
320 case 11025: v |= 1 << 2; break;
321 case 22050: v |= 2 << 2; break;
322 case 44100: v |= 3 << 2; break;
323 default:
324 /* not supported */
325 av_log(s,
AV_LOG_ERROR,
"swf does not support that sample rate, choose from (44100, 22050, 11025).\n");
326 return -1;
327 }
328 v |= 0x02; /* 16 bit playback */
330 v |= 0x01; /* stereo playback */
332 v |= 0x20; /* mp3 compressed */
336
338 }
339
341 return 0;
342 }
343
346 {
349
350 /* Flash Player limit */
352 av_log(enc,
AV_LOG_INFO,
"warning: Flash Player limit of 16000 frames reached\n");
353
357 /* create a new video object */
361 avio_wl16(pb, 15000);
/* hard flash player limit */
367
368 /* place the video object for the first time */
378 } else {
379 /* mark the character for update */
385 }
386
387 /* set video frame data */
395 /* remove the shape */
400
401 /* free the bitmap */
405 }
406
408
410
411 /* a dummy jpeg header seems to be required */
413 /* write the jpeg image */
415
417
418 /* draw the shape */
419
425 }
426
428
429 /* streaming sound always should be placed just before showframe tags */
437
438 /* update FIFO */
440 }
441
442 /* output the frame */
445
446 return 0;
447 }
448
451 {
453
454 /* Flash Player limit */
456 av_log(enc,
AV_LOG_INFO,
"warning: Flash Player limit of 16000 frames reached\n");
457
460 return -1;
461 }
462
465
466 /* if audio only stream make sure we add swf frames */
469
470 return 0;
471 }
472
474 {
478 else
480 }
481
483 {
487 int file_size, i;
488
489 video_enc = NULL;
493 video_enc = enc;
494 else {
496 }
497 }
498
501
502 /* patch file size and number of frames if not streamed */
512 }
514 }
515 return 0;
516 }
517
518 #if CONFIG_SWF_MUXER
522 .mime_type = "application/x-shockwave-flash",
523 .extensions = "swf",
531 };
532 #endif
533 #if CONFIG_AVM2_MUXER
537 .mime_type = "application/x-shockwave-flash",
545 };
546 #endif