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 if ((rate * 256LL) / rate_base >= (1<<16)) {
262 }
263 avio_wl16(pb, (rate * 256) / rate_base);
/* frame rate */
266
267 /* avm2/swf v9 (also v8?) files require a file attribute tag */
268 if (version == 9) {
270 avio_wl32(pb, 1<<3);
/* set ActionScript v3/AVM2 flag */
272 }
273
274 /* define a shape with the jpeg inside */
277
279 /* bounding rectangle */
281 /* style info */
282 avio_w8(pb, 1);
/* one fill style */
283 avio_w8(pb, 0x41);
/* clipped bitmap fill */
285 /* position of the bitmap */
288 avio_w8(pb, 0);
/* no line style */
289
290 /* shape drawing */
292 put_bits(&p, 4, 1);
/* one fill bit */
293 put_bits(&p, 4, 0);
/* zero line bit */
294
295 put_bits(&p, 1, 0);
/* not an edge */
300 put_bits(&p, 1, 1);
/* set fill style 1 */
301
302 /* draw the rectangle ! */
307
308 /* end of shape */
309 put_bits(&p, 1, 0);
/* not an edge */
311
314
316 }
317
319 int v = 0;
320
321 /* start sound */
324 case 11025: v |= 1 << 2; break;
325 case 22050: v |= 2 << 2; break;
326 case 44100: v |= 3 << 2; break;
327 default:
328 /* not supported */
329 av_log(s,
AV_LOG_ERROR,
"swf does not support that sample rate, choose from (44100, 22050, 11025).\n");
330 return -1;
331 }
332 v |= 0x02; /* 16 bit playback */
334 v |= 0x01; /* stereo playback */
336 v |= 0x20; /* mp3 compressed */
340
342 }
343
345 return 0;
346 }
347
350 {
353
354 /* Flash Player limit */
356 av_log(enc,
AV_LOG_INFO,
"warning: Flash Player limit of 16000 frames reached\n");
357
361 /* create a new video object */
365 avio_wl16(pb, 15000);
/* hard flash player limit */
371
372 /* place the video object for the first time */
382 } else {
383 /* mark the character for update */
389 }
390
391 /* set video frame data */
399 /* remove the shape */
404
405 /* free the bitmap */
409 }
410
412
414
415 /* a dummy jpeg header seems to be required */
417 /* write the jpeg image */
419
421
422 /* draw the shape */
423
429 }
430
432
433 /* streaming sound always should be placed just before showframe tags */
441
442 /* update FIFO */
444 }
445
446 /* output the frame */
449
450 return 0;
451 }
452
455 {
457
458 /* Flash Player limit */
460 av_log(enc,
AV_LOG_INFO,
"warning: Flash Player limit of 16000 frames reached\n");
461
464 return -1;
465 }
466
469
470 /* if audio only stream make sure we add swf frames */
473
474 return 0;
475 }
476
478 {
482 else
484 }
485
487 {
491 int file_size, i;
492
497 video_enc = enc;
498 else {
500 }
501 }
502
505
506 /* patch file size and number of frames if not streamed */
516 }
518 }
519 return 0;
520 }
521
522 #if CONFIG_SWF_MUXER
526 .mime_type = "application/x-shockwave-flash",
527 .extensions = "swf",
535 };
536 #endif
537 #if CONFIG_AVM2_MUXER
541 .mime_type = "application/x-shockwave-flash",
549 };
550 #endif
const AVCodecTag ff_swf_codec_tags[]
const char const char void * val
void avio_wl16(AVIOContext *s, unsigned int val)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void avio_wl32(AVIOContext *s, unsigned int val)
AVStream ** streams
A list of all streams in the file.
static void put_swf_rect(AVIOContext *pb, int xmin, int xmax, int ymin, int ymax)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
static void put_swf_line_edge(PutBitContext *pb, int dx, int dy)
struct AVOutputFormat * oformat
The output container format.
static int swf_write_video(AVFormatContext *s, AVCodecContext *enc, const uint8_t *buf, int size)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
static const uint16_t mask[17]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
preferred ID for decoding MPEG audio layer 1, 2 or 3
simple assert() macros that are a bit more flexible than ISO C assert().
AVCodecContext * codec
Codec context associated with this stream.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int void avio_flush(AVIOContext *s)
Force flushing of buffered data.
static void put_swf_tag(AVFormatContext *s, int tag)
static void max_nbits(int *nbits_ptr, int val)
static int swf_write_audio(AVFormatContext *s, AVCodecContext *enc, uint8_t *buf, int size)
int width
picture width / height.
static int write_trailer(AVFormatContext *s1)
AVCodecContext * audio_enc
static int swf_write_packet(AVFormatContext *s, AVPacket *pkt)
int frame_size
Number of samples per channel in an audio frame.
#define AV_LOG_INFO
Standard information.
static int swf_write_header(AVFormatContext *s)
enum AVMediaType codec_type
int av_fifo_size(const AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
int sample_rate
samples per second
AVIOContext * pb
I/O context.
void avio_w8(AVIOContext *s, int b)
main external API structure.
BYTE int const BYTE int int int height
AVCodecContext * video_enc
static void put_swf_end_tag(AVFormatContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
int channels
number of audio channels
void * priv_data
Format private data.
static void write_header(FFV1Context *f)
void avio_wb32(AVIOContext *s, unsigned int val)
void av_fifo_freep(AVFifoBuffer **f)
Free an AVFifoBuffer and reset pointer to NULL.
AVFifoBuffer * audio_fifo
static int swf_write_trailer(AVFormatContext *s)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
static void put_swf_matrix(AVIOContext *pb, int a, int b, int c, int d, int tx, int ty)
This structure stores compressed data.
static int write_packet(AVFormatContext *s1, AVPacket *pkt)