FFmpeg
swfenc.c
Go to the documentation of this file.
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 
25 #include "libavcodec/put_bits.h"
26 #include "libavutil/avassert.h"
27 #include "libavutil/fifo.h"
28 #include "avformat.h"
29 #include "flv.h"
30 #include "mux.h"
31 #include "swf.h"
32 
33 #define AUDIO_FIFO_SIZE 65536
34 
35 typedef struct SWFEncContext {
36  int64_t duration_pos;
37  int64_t tag_pos;
38  int64_t vframes_pos;
43  int tag;
48 
49 static void put_swf_tag(AVFormatContext *s, int tag)
50 {
51  SWFEncContext *swf = s->priv_data;
52  AVIOContext *pb = s->pb;
53 
54  swf->tag_pos = avio_tell(pb);
55  swf->tag = tag;
56  /* reserve some room for the tag */
57  if (tag & TAG_LONG) {
58  avio_wl16(pb, 0);
59  avio_wl32(pb, 0);
60  } else {
61  avio_wl16(pb, 0);
62  }
63 }
64 
66 {
67  SWFEncContext *swf = s->priv_data;
68  AVIOContext *pb = s->pb;
69  int64_t pos;
70  int tag_len, tag;
71 
72  pos = avio_tell(pb);
73  tag_len = pos - swf->tag_pos - 2;
74  tag = swf->tag;
75  avio_seek(pb, swf->tag_pos, SEEK_SET);
76  if (tag & TAG_LONG) {
77  tag &= ~TAG_LONG;
78  avio_wl16(pb, (tag << 6) | 0x3f);
79  avio_wl32(pb, tag_len - 4);
80  } else {
81  av_assert0(tag_len < 0x3f);
82  avio_wl16(pb, (tag << 6) | tag_len);
83  }
84  avio_seek(pb, pos, SEEK_SET);
85 }
86 
87 static inline void max_nbits(int *nbits_ptr, int val)
88 {
89  int n;
90 
91  if (val == 0)
92  return;
93  val = FFABS(val);
94  n = 1;
95  while (val != 0) {
96  n++;
97  val >>= 1;
98  }
99  if (n > *nbits_ptr)
100  *nbits_ptr = n;
101 }
102 
103 static void put_swf_rect(AVIOContext *pb,
104  int xmin, int xmax, int ymin, int ymax)
105 {
106  PutBitContext p;
107  uint8_t buf[256];
108  int nbits, mask;
109 
110  init_put_bits(&p, buf, sizeof(buf));
111 
112  nbits = 0;
113  max_nbits(&nbits, xmin);
114  max_nbits(&nbits, xmax);
115  max_nbits(&nbits, ymin);
116  max_nbits(&nbits, ymax);
117  mask = (1 << nbits) - 1;
118 
119  /* rectangle info */
120  put_bits(&p, 5, nbits);
121  put_bits(&p, nbits, xmin & mask);
122  put_bits(&p, nbits, xmax & mask);
123  put_bits(&p, nbits, ymin & mask);
124  put_bits(&p, nbits, ymax & mask);
125 
126  flush_put_bits(&p);
127  avio_write(pb, buf, put_bits_ptr(&p) - p.buf);
128 }
129 
130 static void put_swf_line_edge(PutBitContext *pb, int dx, int dy)
131 {
132  int nbits, mask;
133 
134  put_bits(pb, 1, 1); /* edge */
135  put_bits(pb, 1, 1); /* line select */
136  nbits = 2;
137  max_nbits(&nbits, dx);
138  max_nbits(&nbits, dy);
139 
140  mask = (1 << nbits) - 1;
141  put_bits(pb, 4, nbits - 2); /* 16 bits precision */
142  if (dx == 0) {
143  put_bits(pb, 1, 0);
144  put_bits(pb, 1, 1);
145  put_bits(pb, nbits, dy & mask);
146  } else if (dy == 0) {
147  put_bits(pb, 1, 0);
148  put_bits(pb, 1, 0);
149  put_bits(pb, nbits, dx & mask);
150  } else {
151  put_bits(pb, 1, 1);
152  put_bits(pb, nbits, dx & mask);
153  put_bits(pb, nbits, dy & mask);
154  }
155 }
156 
157 #define FRAC_BITS 16
158 
159 static void put_swf_matrix(AVIOContext *pb,
160  int a, int b, int c, int d, int tx, int ty)
161 {
162  PutBitContext p;
163  uint8_t buf[256];
164  int nbits;
165 
166  init_put_bits(&p, buf, sizeof(buf));
167 
168  put_bits(&p, 1, 1); /* a, d present */
169  nbits = 1;
170  max_nbits(&nbits, a);
171  max_nbits(&nbits, d);
172  put_bits(&p, 5, nbits); /* nb bits */
173  put_bits(&p, nbits, a);
174  put_bits(&p, nbits, d);
175 
176  put_bits(&p, 1, 1); /* b, c present */
177  nbits = 1;
178  max_nbits(&nbits, c);
179  max_nbits(&nbits, b);
180  put_bits(&p, 5, nbits); /* nb bits */
181  put_bits(&p, nbits, c);
182  put_bits(&p, nbits, b);
183 
184  nbits = 1;
185  max_nbits(&nbits, tx);
186  max_nbits(&nbits, ty);
187  put_bits(&p, 5, nbits); /* nb bits */
188  put_bits(&p, nbits, tx);
189  put_bits(&p, nbits, ty);
190 
191  flush_put_bits(&p);
192  avio_write(pb, buf, put_bits_ptr(&p) - p.buf);
193 }
194 
196 {
197  SWFEncContext *swf = s->priv_data;
198  AVIOContext *pb = s->pb;
199  PutBitContext p;
200  uint8_t buf1[256];
201  int i, width, height, rate, rate_base;
202  int version;
203 
204  swf->sound_samples = 0;
205  swf->swf_frame_number = 0;
206  swf->video_frame_number = 0;
207 
208  for(i=0;i<s->nb_streams;i++) {
209  AVCodecParameters *par = s->streams[i]->codecpar;
210  if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
211  if (swf->audio_par) {
212  av_log(s, AV_LOG_ERROR, "SWF muxer only supports 1 audio stream\n");
213  return AVERROR_INVALIDDATA;
214  }
215  if (par->codec_id == AV_CODEC_ID_MP3) {
216  swf->audio_par = par;
218  if (!swf->audio_fifo)
219  return AVERROR(ENOMEM);
220  } else {
221  av_log(s, AV_LOG_ERROR, "SWF muxer only supports MP3\n");
222  return -1;
223  }
224  } else {
225  if (swf->video_par) {
226  av_log(s, AV_LOG_ERROR, "SWF muxer only supports 1 video stream\n");
227  return AVERROR_INVALIDDATA;
228  }
230  par->codec_id == AV_CODEC_ID_PNG ||
231  par->codec_id == AV_CODEC_ID_MJPEG) {
232  swf->video_st = s->streams[i];
233  swf->video_par = par;
234  } else {
235  av_log(s, AV_LOG_ERROR, "SWF muxer only supports VP6, FLV, Flash Screen Video, PNG and MJPEG\n");
236  return -1;
237  }
238  }
239  }
240 
241  if (!swf->video_par) {
242  /* currently, cannot work correctly if audio only */
243  width = 320;
244  height = 200;
245  rate = 10;
246  rate_base= 1;
247  } else {
248  width = swf->video_par->width;
249  height = swf->video_par->height;
250  // TODO: should be avg_frame_rate
251  rate = swf->video_st->time_base.den;
252  rate_base = swf->video_st->time_base.num;
253  }
254 
255  if (!swf->audio_par)
256  swf->samples_per_frame = (44100LL * rate_base) / rate;
257  else
258  swf->samples_per_frame = (swf->audio_par->sample_rate * rate_base) / rate;
259 
260  avio_write(pb, "FWS", 3);
261 
262  if (!strcmp("avm2", s->oformat->name))
263  version = 9;
264  else if (swf->video_par && (swf->video_par->codec_id == AV_CODEC_ID_VP6A ||
267  version = 8; /* version 8 and above support VP6 and PNG codec */
268  else if (swf->video_par && swf->video_par->codec_id == AV_CODEC_ID_FLASHSV)
269  version = 7; /* version 7 and above support Flash Screen Video codec */
270  else if (swf->video_par && swf->video_par->codec_id == AV_CODEC_ID_FLV1)
271  version = 6; /* version 6 and above support FLV1 codec */
272  else
273  version = 4; /* version 4 for mpeg audio support */
274  avio_w8(pb, version);
275 
276  avio_wl32(pb, DUMMY_FILE_SIZE); /* dummy size
277  (will be patched if not streamed) */
278 
279  put_swf_rect(pb, 0, width * 20, 0, height * 20);
280  if ((rate * 256LL) / rate_base >= (1<<16)) {
281  av_log(s, AV_LOG_ERROR, "Invalid (too large) frame rate %d/%d\n", rate, rate_base);
282  return AVERROR(EINVAL);
283  }
284  avio_wl16(pb, (rate * 256LL) / rate_base); /* frame rate */
285  swf->duration_pos = avio_tell(pb);
286  avio_wl16(pb, (uint16_t)(DUMMY_DURATION * (int64_t)rate / rate_base)); /* frame count */
287 
288  /* swf v8 and later files require a file attribute tag */
289  if (version >= 8) {
291  avio_wl32(pb, (version >= 9) << 3); /* set ActionScript v3/AVM2 flag */
293  }
294 
295  /* define a shape with the jpeg inside */
296  if (swf->video_par && (swf->video_par->codec_id == AV_CODEC_ID_MJPEG || swf->video_par->codec_id == AV_CODEC_ID_PNG)) {
298 
299  avio_wl16(pb, SHAPE_ID); /* ID of shape */
300  /* bounding rectangle */
301  put_swf_rect(pb, 0, width, 0, height);
302  /* style info */
303  avio_w8(pb, 1); /* one fill style */
304  avio_w8(pb, 0x41); /* clipped bitmap fill */
305  avio_wl16(pb, BITMAP_ID); /* bitmap ID */
306  /* position of the bitmap */
307  put_swf_matrix(pb, 1 << FRAC_BITS, 0,
308  0, 1 << FRAC_BITS, 0, 0);
309  avio_w8(pb, 0); /* no line style */
310 
311  /* shape drawing */
312  init_put_bits(&p, buf1, sizeof(buf1));
313  put_bits(&p, 4, 1); /* one fill bit */
314  put_bits(&p, 4, 0); /* zero line bit */
315 
316  put_bits(&p, 1, 0); /* not an edge */
318  put_bits(&p, 5, 1); /* nbits */
319  put_bits(&p, 1, 0); /* X */
320  put_bits(&p, 1, 0); /* Y */
321  put_bits(&p, 1, 1); /* set fill style 1 */
322 
323  /* draw the rectangle ! */
324  put_swf_line_edge(&p, width, 0);
325  put_swf_line_edge(&p, 0, height);
326  put_swf_line_edge(&p, -width, 0);
327  put_swf_line_edge(&p, 0, -height);
328 
329  /* end of shape */
330  put_bits(&p, 1, 0); /* not an edge */
331  put_bits(&p, 5, 0);
332 
333  flush_put_bits(&p);
334  avio_write(pb, buf1, put_bits_ptr(&p) - p.buf);
335 
337  }
338 
339  if (swf->audio_par && swf->audio_par->codec_id == AV_CODEC_ID_MP3) {
340  int v = 0;
341 
342  /* start sound */
344  switch(swf->audio_par->sample_rate) {
345  case 11025: v |= 1 << 2; break;
346  case 22050: v |= 2 << 2; break;
347  case 44100: v |= 3 << 2; break;
348  default:
349  /* not supported */
350  av_log(s, AV_LOG_ERROR, "swf does not support that sample rate, choose from (44100, 22050, 11025).\n");
351  return -1;
352  }
353  v |= 0x02; /* 16 bit playback */
354  if (swf->audio_par->ch_layout.nb_channels == 2)
355  v |= 0x01; /* stereo playback */
356  avio_w8(s->pb, v);
357  v |= 0x20; /* mp3 compressed */
358  avio_w8(s->pb, v);
359  avio_wl16(s->pb, swf->samples_per_frame); /* avg samples per frame */
360  avio_wl16(s->pb, 0);
361 
363  }
364 
365  return 0;
366 }
367 
368 static int fifo_avio_wrapper(void *opaque, void *buf, size_t *nb_elems)
369 {
370  avio_write(opaque, buf, *nb_elems);
371  return 0;
372 }
373 
375  AVCodecParameters *par, const uint8_t *buf, int size, unsigned pkt_flags)
376 {
377  SWFEncContext *swf = s->priv_data;
378  AVIOContext *pb = s->pb;
379  unsigned codec_tag = ff_codec_get_tag(ff_swf_codec_tags, par->codec_id);
380 
381  /* Flash Player limit */
382  if (swf->swf_frame_number == 16000)
383  av_log(s, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
384 
385  if (codec_tag) {
386  if (swf->video_frame_number == 0) {
387  /* create a new video object */
389  avio_wl16(pb, VIDEO_ID);
390  swf->vframes_pos = avio_tell(pb);
391  avio_wl16(pb, 15000); /* hard flash player limit */
392  avio_wl16(pb, par->width);
393  avio_wl16(pb, par->height);
394  avio_w8(pb, 0);
395  avio_w8(pb, codec_tag);
397 
398  /* place the video object for the first time */
400  avio_w8(pb, 0x36);
401  avio_wl16(pb, 1);
402  avio_wl16(pb, VIDEO_ID);
403  put_swf_matrix(pb, 1 << FRAC_BITS, 0, 0, 1 << FRAC_BITS, 0, 0);
404  avio_wl16(pb, swf->video_frame_number);
405  avio_write(pb, "video", 5);
406  avio_w8(pb, 0x00);
408  } else {
409  /* mark the character for update */
411  avio_w8(pb, 0x11);
412  avio_wl16(pb, 1);
413  avio_wl16(pb, swf->video_frame_number);
415  }
416 
417  /* set video frame data */
419  avio_wl16(pb, VIDEO_ID);
420  avio_wl16(pb, swf->video_frame_number++);
421  if (par->codec_id == AV_CODEC_ID_FLASHSV) {
422  /* FrameType and CodecId is needed here even if it is not documented correctly in the SWF specs */
423  int flags = codec_tag | (pkt_flags & AV_PKT_FLAG_KEY ? FLV_FRAME_KEY : FLV_FRAME_INTER);
424  avio_w8(pb, flags);
425  }
426  avio_write(pb, buf, size);
428  } else if (par->codec_id == AV_CODEC_ID_MJPEG || par->codec_id == AV_CODEC_ID_PNG) {
429  if (swf->swf_frame_number > 0) {
430  /* remove the shape */
432  avio_wl16(pb, SHAPE_ID); /* shape ID */
433  avio_wl16(pb, 1); /* depth */
435 
436  /* free the bitmap */
438  avio_wl16(pb, BITMAP_ID);
440  }
441 
443 
444  avio_wl16(pb, BITMAP_ID); /* ID of the image */
445 
446  /* a dummy jpeg header seems to be required */
447  if (par->codec_id == AV_CODEC_ID_MJPEG)
448  avio_wb32(pb, 0xffd8ffd9);
449  /* write the jpeg/png image */
450  avio_write(pb, buf, size);
451 
453 
454  /* draw the shape */
455 
457  avio_wl16(pb, SHAPE_ID); /* shape ID */
458  avio_wl16(pb, 1); /* depth */
459  put_swf_matrix(pb, 20 << FRAC_BITS, 0, 0, 20 << FRAC_BITS, 0, 0);
461  }
462 
463  swf->swf_frame_number++;
464 
465  /* streaming sound always should be placed just before showframe tags */
466  if (swf->audio_par && av_fifo_can_read(swf->audio_fifo)) {
467  size_t frame_size = av_fifo_can_read(swf->audio_fifo);
469  avio_wl16(pb, swf->sound_samples);
470  avio_wl16(pb, 0); // seek samples
473 
474  /* update FIFO */
475  swf->sound_samples = 0;
476  }
477 
478  /* output the frame */
481 
482  return 0;
483 }
484 
486  const uint8_t *buf, int size)
487 {
488  SWFEncContext *swf = s->priv_data;
489 
490  /* Flash Player limit */
491  if (swf->swf_frame_number == 16000)
492  av_log(s, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
493 
494  if (av_fifo_can_write(swf->audio_fifo) < size) {
495  av_log(s, AV_LOG_ERROR, "audio fifo too small to mux audio essence\n");
496  return -1;
497  }
498 
499  av_fifo_write(swf->audio_fifo, buf, size);
501 
502  /* if audio only stream make sure we add swf frames */
503  if (!swf->video_par)
504  swf_write_video(s, par, 0, 0, 0);
505 
506  return 0;
507 }
508 
510 {
511  AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar;
512  if (par->codec_type == AVMEDIA_TYPE_AUDIO)
513  return swf_write_audio(s, par, pkt->data, pkt->size);
514  else
515  return swf_write_video(s, par, pkt->data, pkt->size, pkt->flags);
516 }
517 
519 {
520  SWFEncContext *swf = s->priv_data;
521  AVIOContext *pb = s->pb;
522  int file_size;
523 
526 
527  /* patch file size and number of frames if not streamed */
528  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && swf->video_par) {
529  file_size = avio_tell(pb);
530  avio_seek(pb, 4, SEEK_SET);
531  avio_wl32(pb, file_size);
532  avio_seek(pb, swf->duration_pos, SEEK_SET);
533  avio_wl16(pb, swf->video_frame_number);
534  if (swf->vframes_pos) {
535  avio_seek(pb, swf->vframes_pos, SEEK_SET);
536  avio_wl16(pb, swf->video_frame_number);
537  }
538  avio_seek(pb, file_size, SEEK_SET);
539  }
540  return 0;
541 }
542 
544 {
545  SWFEncContext *swf = s->priv_data;
546 
547  av_fifo_freep2(&swf->audio_fifo);
548 }
549 
550 #if CONFIG_SWF_MUXER
552  .p.name = "swf",
553  .p.long_name = NULL_IF_CONFIG_SMALL("SWF (ShockWave Flash)"),
554  .p.mime_type = "application/x-shockwave-flash",
555  .p.extensions = "swf",
556  .priv_data_size = sizeof(SWFEncContext),
557  .p.audio_codec = AV_CODEC_ID_MP3,
558  .p.video_codec = AV_CODEC_ID_FLV1,
559  .write_header = swf_write_header,
560  .write_packet = swf_write_packet,
561  .write_trailer = swf_write_trailer,
562  .deinit = swf_deinit,
563  .p.flags = AVFMT_TS_NONSTRICT,
564 };
565 #endif
566 #if CONFIG_AVM2_MUXER
568  .p.name = "avm2",
569  .p.long_name = NULL_IF_CONFIG_SMALL("SWF (ShockWave Flash) (AVM2)"),
570  .p.mime_type = "application/x-shockwave-flash",
571  .priv_data_size = sizeof(SWFEncContext),
572  .p.audio_codec = AV_CODEC_ID_MP3,
573  .p.video_codec = AV_CODEC_ID_FLV1,
574  .write_header = swf_write_header,
575  .write_packet = swf_write_packet,
576  .write_trailer = swf_write_trailer,
577  .deinit = swf_deinit,
578  .p.flags = AVFMT_TS_NONSTRICT,
579 };
580 #endif
AV_CODEC_ID_VP6F
@ AV_CODEC_ID_VP6F
Definition: codec_id.h:144
av_fifo_can_write
size_t av_fifo_can_write(const AVFifo *f)
Definition: fifo.c:94
SWFEncContext
Definition: swfenc.c:35
AVOutputFormat::name
const char * name
Definition: avformat.h:508
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:58
max_nbits
static void max_nbits(int *nbits_ptr, int val)
Definition: swfenc.c:87
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:54
swf_write_header
static int swf_write_header(AVFormatContext *s)
Definition: swfenc.c:195
put_swf_end_tag
static void put_swf_end_tag(AVFormatContext *s)
Definition: swfenc.c:65
init_put_bits
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:62
TAG_VIDEOSTREAM
@ TAG_VIDEOSTREAM
Definition: swf.h:74
swf_write_audio
static int swf_write_audio(AVFormatContext *s, AVCodecParameters *par, const uint8_t *buf, int size)
Definition: swfenc.c:485
DUMMY_FILE_SIZE
#define DUMMY_FILE_SIZE
Definition: swf.h:29
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:221
AVPacket::data
uint8_t * data
Definition: packet.h:374
TAG_JPEG2
@ TAG_JPEG2
Definition: swf.h:53
SWFEncContext::tag_pos
int64_t tag_pos
Definition: swfenc.c:37
AUDIO_FIFO_SIZE
#define AUDIO_FIFO_SIZE
Definition: swfenc.c:33
b
#define b
Definition: input.c:41
TAG_STREAMBLOCK
@ TAG_STREAMBLOCK
Definition: swf.h:51
SWFEncContext::tag
int tag
Definition: swfenc.c:43
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:429
swf_deinit
static void swf_deinit(AVFormatContext *s)
Definition: swfenc.c:543
TAG_END
@ TAG_END
Definition: swf.h:33
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:34
avio_wl16
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:458
fifo.h
av_fifo_write
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
Definition: fifo.c:188
SHAPE_ID
#define SHAPE_ID
Definition: swf.h:110
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:500
val
static double val(void *priv, double ch)
Definition: aeval.c:77
SWFEncContext::video_st
AVStream * video_st
Definition: swfenc.c:46
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:439
AVRational::num
int num
Numerator.
Definition: rational.h:59
FLAG_SETFILL0
#define FLAG_SETFILL0
Definition: swf.h:104
avassert.h
put_swf_matrix
static void put_swf_matrix(AVIOContext *pb, int a, int b, int c, int d, int tx, int ty)
Definition: swfenc.c:159
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
swf.h
mask
static const uint16_t mask[17]
Definition: lzw.c:38
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:256
ff_swf_codec_tags
const AVCodecTag ff_swf_codec_tags[]
Definition: swf.c:25
ff_avm2_muxer
const FFOutputFormat ff_avm2_muxer
frame_size
int frame_size
Definition: mxfenc.c:2205
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:128
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
DUMMY_DURATION
#define DUMMY_DURATION
Definition: swf.h:30
TAG_PLACEOBJECT
@ TAG_PLACEOBJECT
Definition: swf.h:37
swf_write_trailer
static int swf_write_trailer(AVFormatContext *s)
Definition: swfenc.c:518
TAG_REMOVEOBJECT
@ TAG_REMOVEOBJECT
Definition: swf.h:38
PutBitContext
Definition: put_bits.h:50
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:64
AV_CODEC_ID_PNG
@ AV_CODEC_ID_PNG
Definition: codec_id.h:113
AVFormatContext
Format I/O context.
Definition: avformat.h:1104
PutBitContext::buf
uint8_t * buf
Definition: put_bits.h:53
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:877
SWFEncContext::vframes_pos
int64_t vframes_pos
Definition: swfenc.c:38
SWFEncContext::swf_frame_number
int swf_frame_number
Definition: swfenc.c:41
av_fifo_can_read
size_t av_fifo_can_read(const AVFifo *f)
Definition: fifo.c:87
FFOutputFormat
Definition: mux.h:30
flv.h
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:200
AV_CODEC_ID_FLASHSV
@ AV_CODEC_ID_FLASHSV
Definition: codec_id.h:138
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:213
AV_CODEC_ID_VP6A
@ AV_CODEC_ID_VP6A
Definition: codec_id.h:158
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:178
BITMAP_ID
#define BITMAP_ID
Definition: swf.h:108
SWFEncContext::audio_fifo
AVFifo * audio_fifo
Definition: swfenc.c:44
FLAG_MOVETO
#define FLAG_MOVETO
Definition: swf.h:103
SWFEncContext::sound_samples
int sound_samples
Definition: swfenc.c:40
AVIOContext
Bytestream IO Context.
Definition: avio.h:166
av_fifo_read_to_cb
int av_fifo_read_to_cb(AVFifo *f, AVFifoCB write_cb, void *opaque, size_t *nb_elems)
Feed data from a FIFO into a user-provided callback.
Definition: fifo.c:247
AVPacket::size
int size
Definition: packet.h:375
AVFifo
Definition: fifo.c:35
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:115
TAG_SHOWFRAME
@ TAG_SHOWFRAME
Definition: swf.h:34
size
int size
Definition: twinvq_data.h:10344
av_get_audio_frame_duration2
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
Definition: utils.c:837
TAG_LONG
#define TAG_LONG
Definition: swf.h:100
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:222
avio_wb32
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:386
height
#define height
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
avio_wl32
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:378
FLV_FRAME_KEY
@ FLV_FRAME_KEY
key frame (for AVC, a seekable frame)
Definition: flv.h:116
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:380
version
version
Definition: libkvazaar.c:313
FLV_FRAME_INTER
@ FLV_FRAME_INTER
inter frame (for AVC, a non-seekable frame)
Definition: flv.h:117
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
swf_write_video
static int swf_write_video(AVFormatContext *s, AVCodecParameters *par, const uint8_t *buf, int size, unsigned pkt_flags)
Definition: swfenc.c:374
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:59
SWFEncContext::samples_per_frame
int samples_per_frame
Definition: swfenc.c:39
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
ff_swf_muxer
const FFOutputFormat ff_swf_muxer
AVCodecParameters::height
int height
Definition: codec_par.h:129
swf_write_packet
static int swf_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: swfenc.c:509
AVFMT_TS_NONSTRICT
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:489
SWFEncContext::audio_par
AVCodecParameters * audio_par
Definition: swfenc.c:45
tag
uint32_t tag
Definition: movenc.c:1641
SWFEncContext::video_par
AVCodecParameters * video_par
Definition: swfenc.c:45
put_swf_rect
static void put_swf_rect(AVIOContext *pb, int xmin, int xmax, int ymin, int ymax)
Definition: swfenc.c:103
AVStream
Stream structure.
Definition: avformat.h:838
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:252
pos
unsigned int pos
Definition: spdifenc.c:413
avformat.h
av_fifo_alloc2
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
Definition: fifo.c:47
VIDEO_ID
#define VIDEO_ID
Definition: mpeg.h:42
put_bits_ptr
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
Definition: put_bits.h:377
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:41
AVRational::den
int den
Denominator.
Definition: rational.h:60
SWFEncContext::duration_pos
int64_t duration_pos
Definition: swfenc.c:36
TAG_STREAMHEAD2
@ TAG_STREAMHEAD2
Definition: swf.h:67
ff_codec_get_tag
unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
Definition: utils.c:134
TAG_PLACEOBJECT2
@ TAG_PLACEOBJECT2
Definition: swf.h:57
AVPacket::stream_index
int stream_index
Definition: packet.h:376
fifo_avio_wrapper
static int fifo_avio_wrapper(void *opaque, void *buf, size_t *nb_elems)
Definition: swfenc.c:368
SWFEncContext::video_frame_number
int video_frame_number
Definition: swfenc.c:42
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:143
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:62
AVPacket
This structure stores compressed data.
Definition: packet.h:351
put_swf_line_edge
static void put_swf_line_edge(PutBitContext *pb, int dx, int dy)
Definition: swfenc.c:130
d
d
Definition: ffmpeg_filter.c:156
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
av_fifo_freep2
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
Definition: fifo.c:286
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
TAG_VIDEOFRAME
@ TAG_VIDEOFRAME
Definition: swf.h:75
TAG_DEFINESHAPE
@ TAG_DEFINESHAPE
Definition: swf.h:35
AV_CODEC_ID_FLV1
@ AV_CODEC_ID_FLV1
Definition: codec_id.h:73
put_bits.h
TAG_FILEATTRIBUTES
@ TAG_FILEATTRIBUTES
Definition: swf.h:80
put_swf_tag
static void put_swf_tag(AVFormatContext *s, int tag)
Definition: swfenc.c:49
TAG_FREECHARACTER
@ TAG_FREECHARACTER
Definition: swf.h:36
FRAC_BITS
#define FRAC_BITS
Definition: swfenc.c:157
mux.h