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
23 #include "config_components.h"
24
32
33 #define AUDIO_FIFO_SIZE 65536
34
48
50 {
53
56 /* reserve some room for the tag */
60 } else {
62 }
63 }
64
66 {
71
80 } else {
83 }
85 }
86
88 {
89 int n;
90
92 return;
94 n = 1;
96 n++;
98 }
99 if (n > *nbits_ptr)
100 *nbits_ptr = n;
101 }
102
104 int xmin, int xmax, int ymin, int ymax)
105 {
107 uint8_t buf[256];
109
111
112 nbits = 0;
117 mask = (1 << nbits) - 1;
118
119 /* rectangle info */
125
128 }
129
131 {
133
135 put_bits(pb, 1, 1);
/* line select */
136 nbits = 2;
139
140 mask = (1 << nbits) - 1;
141 put_bits(pb, 4, nbits - 2);
/* 16 bits precision */
142 if (dx == 0) {
146 } else if (dy == 0) {
150 } else {
154 }
155 }
156
158
160 int a,
int b,
int c,
int d,
int tx,
int ty)
161 {
163 uint8_t buf[256];
164 int nbits;
165
167
168 put_bits(&p, 1, 1);
/* a, d present */
169 nbits = 1;
172 put_bits(&p, 5, nbits);
/* nb bits */
175
176 put_bits(&p, 1, 1);
/* b, c present */
177 nbits = 1;
180 put_bits(&p, 5, nbits);
/* nb bits */
183
184 nbits = 1;
187 put_bits(&p, 5, nbits);
/* nb bits */
190
193 }
194
196 {
200 uint8_t buf1[256];
203
207
208 for(
i=0;
i<
s->nb_streams;
i++) {
216 } else {
218 return -1;
219 }
220 } else {
226 } else {
227 av_log(
s,
AV_LOG_ERROR,
"SWF muxer only supports VP6, FLV, Flash Screen Video, PNG and MJPEG\n");
228 return -1;
229 }
230 }
231 }
232
234 /* currently, cannot work correctly if audio only */
237 rate = 10;
238 rate_base= 1;
239 } else {
242 // TODO: should be avg_frame_rate
245 }
246
249 else
251
253
254 if (!strcmp(
"avm2",
s->oformat->name))
259 version = 8;
/* version 8 and above support VP6 and PNG codec */
261 version = 7;
/* version 7 and above support Flash Screen Video codec */
263 version = 6;
/* version 6 and above support FLV1 codec */
264 else
265 version = 4;
/* version 4 for mpeg audio support */
267
269 (will be patched if not streamed) */
270
272 if ((rate * 256LL) / rate_base >= (1<<16)) {
275 }
276 avio_wl16(pb, (rate * 256LL) / rate_base);
/* frame rate */
279
280 /* swf v8 and later files require a file attribute tag */
285 }
286
287 /* define a shape with the jpeg inside */
290
292 /* bounding rectangle */
294 /* style info */
295 avio_w8(pb, 1);
/* one fill style */
296 avio_w8(pb, 0x41);
/* clipped bitmap fill */
298 /* position of the bitmap */
301 avio_w8(pb, 0);
/* no line style */
302
303 /* shape drawing */
305 put_bits(&p, 4, 1);
/* one fill bit */
306 put_bits(&p, 4, 0);
/* zero line bit */
307
308 put_bits(&p, 1, 0);
/* not an edge */
313 put_bits(&p, 1, 1);
/* set fill style 1 */
314
315 /* draw the rectangle ! */
320
321 /* end of shape */
322 put_bits(&p, 1, 0);
/* not an edge */
324
327
329 }
330
332 int v = 0;
333
334 /* start sound */
337 case 11025: v |= 1 << 2; break;
338 case 22050: v |= 2 << 2; break;
339 case 44100: v |= 3 << 2; break;
340 default:
341 /* not supported */
342 av_log(
s,
AV_LOG_ERROR,
"swf does not support that sample rate, choose from (44100, 22050, 11025).\n");
343 return -1;
344 }
345 v |= 0x02; /* 16 bit playback */
347 v |= 0x01; /* stereo playback */
349 v |= 0x20; /* mp3 compressed */
353
355 }
356
357 return 0;
358 }
359
361 {
363 return 0;
364 }
365
368 {
372
373 /* Flash Player limit */
376
377 if (codec_tag) {
379 /* create a new video object */
383 avio_wl16(pb, 15000);
/* hard flash player limit */
389
390 /* place the video object for the first time */
400 } else {
401 /* mark the character for update */
407 }
408
409 /* set video frame data */
414 /* FrameType and CodecId is needed here even if it is not documented correctly in the SWF specs */
417 }
422 /* remove the shape */
427
428 /* free the bitmap */
432 }
433
435
437
438 /* a dummy jpeg header seems to be required */
441 /* write the jpeg/png image */
443
445
446 /* draw the shape */
447
453 }
454
456
457 /* streaming sound always should be placed just before showframe tags */
465
466 /* update FIFO */
468 }
469
470 /* output the frame */
473
474 return 0;
475 }
476
478 const uint8_t *buf,
int size)
479 {
481
482 /* Flash Player limit */
485
488 return -1;
489 }
490
493
494 /* if audio only stream make sure we add swf frames */
497
498 return 0;
499 }
500
502 {
506 else
508 }
509
511 {
514 int file_size;
515
518
519 /* patch file size and number of frames if not streamed */
529 }
531 }
532 return 0;
533 }
534
536 {
538
540 }
541
542 #if CONFIG_SWF_MUXER
546 .p.mime_type = "application/x-shockwave-flash",
547 .p.extensions = "swf",
558 };
559 #endif
560 #if CONFIG_AVM2_MUXER
564 .p.mime_type = "application/x-shockwave-flash",
575 };
576 #endif