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 "swf.h"
31 
32 #define AUDIO_FIFO_SIZE 65536
33 
34 typedef struct SWFEncContext {
35  int64_t duration_pos;
36  int64_t tag_pos;
37  int64_t vframes_pos;
42  int tag;
47 
48 static void put_swf_tag(AVFormatContext *s, int tag)
49 {
50  SWFEncContext *swf = s->priv_data;
51  AVIOContext *pb = s->pb;
52 
53  swf->tag_pos = avio_tell(pb);
54  swf->tag = tag;
55  /* reserve some room for the tag */
56  if (tag & TAG_LONG) {
57  avio_wl16(pb, 0);
58  avio_wl32(pb, 0);
59  } else {
60  avio_wl16(pb, 0);
61  }
62 }
63 
65 {
66  SWFEncContext *swf = s->priv_data;
67  AVIOContext *pb = s->pb;
68  int64_t pos;
69  int tag_len, tag;
70 
71  pos = avio_tell(pb);
72  tag_len = pos - swf->tag_pos - 2;
73  tag = swf->tag;
74  avio_seek(pb, swf->tag_pos, SEEK_SET);
75  if (tag & TAG_LONG) {
76  tag &= ~TAG_LONG;
77  avio_wl16(pb, (tag << 6) | 0x3f);
78  avio_wl32(pb, tag_len - 4);
79  } else {
80  av_assert0(tag_len < 0x3f);
81  avio_wl16(pb, (tag << 6) | tag_len);
82  }
83  avio_seek(pb, pos, SEEK_SET);
84 }
85 
86 static inline void max_nbits(int *nbits_ptr, int val)
87 {
88  int n;
89 
90  if (val == 0)
91  return;
92  val = FFABS(val);
93  n = 1;
94  while (val != 0) {
95  n++;
96  val >>= 1;
97  }
98  if (n > *nbits_ptr)
99  *nbits_ptr = n;
100 }
101 
102 static void put_swf_rect(AVIOContext *pb,
103  int xmin, int xmax, int ymin, int ymax)
104 {
105  PutBitContext p;
106  uint8_t buf[256];
107  int nbits, mask;
108 
109  init_put_bits(&p, buf, sizeof(buf));
110 
111  nbits = 0;
112  max_nbits(&nbits, xmin);
113  max_nbits(&nbits, xmax);
114  max_nbits(&nbits, ymin);
115  max_nbits(&nbits, ymax);
116  mask = (1 << nbits) - 1;
117 
118  /* rectangle info */
119  put_bits(&p, 5, nbits);
120  put_bits(&p, nbits, xmin & mask);
121  put_bits(&p, nbits, xmax & mask);
122  put_bits(&p, nbits, ymin & mask);
123  put_bits(&p, nbits, ymax & mask);
124 
125  flush_put_bits(&p);
126  avio_write(pb, buf, put_bits_ptr(&p) - p.buf);
127 }
128 
129 static void put_swf_line_edge(PutBitContext *pb, int dx, int dy)
130 {
131  int nbits, mask;
132 
133  put_bits(pb, 1, 1); /* edge */
134  put_bits(pb, 1, 1); /* line select */
135  nbits = 2;
136  max_nbits(&nbits, dx);
137  max_nbits(&nbits, dy);
138 
139  mask = (1 << nbits) - 1;
140  put_bits(pb, 4, nbits - 2); /* 16 bits precision */
141  if (dx == 0) {
142  put_bits(pb, 1, 0);
143  put_bits(pb, 1, 1);
144  put_bits(pb, nbits, dy & mask);
145  } else if (dy == 0) {
146  put_bits(pb, 1, 0);
147  put_bits(pb, 1, 0);
148  put_bits(pb, nbits, dx & mask);
149  } else {
150  put_bits(pb, 1, 1);
151  put_bits(pb, nbits, dx & mask);
152  put_bits(pb, nbits, dy & mask);
153  }
154 }
155 
156 #define FRAC_BITS 16
157 
158 static void put_swf_matrix(AVIOContext *pb,
159  int a, int b, int c, int d, int tx, int ty)
160 {
161  PutBitContext p;
162  uint8_t buf[256];
163  int nbits;
164 
165  init_put_bits(&p, buf, sizeof(buf));
166 
167  put_bits(&p, 1, 1); /* a, d present */
168  nbits = 1;
169  max_nbits(&nbits, a);
170  max_nbits(&nbits, d);
171  put_bits(&p, 5, nbits); /* nb bits */
172  put_bits(&p, nbits, a);
173  put_bits(&p, nbits, d);
174 
175  put_bits(&p, 1, 1); /* b, c present */
176  nbits = 1;
177  max_nbits(&nbits, c);
178  max_nbits(&nbits, b);
179  put_bits(&p, 5, nbits); /* nb bits */
180  put_bits(&p, nbits, c);
181  put_bits(&p, nbits, b);
182 
183  nbits = 1;
184  max_nbits(&nbits, tx);
185  max_nbits(&nbits, ty);
186  put_bits(&p, 5, nbits); /* nb bits */
187  put_bits(&p, nbits, tx);
188  put_bits(&p, nbits, ty);
189 
190  flush_put_bits(&p);
191  avio_write(pb, buf, put_bits_ptr(&p) - p.buf);
192 }
193 
195 {
196  SWFEncContext *swf = s->priv_data;
197  AVIOContext *pb = s->pb;
198  PutBitContext p;
199  uint8_t buf1[256];
200  int i, width, height, rate, rate_base;
201  int version;
202 
203  swf->sound_samples = 0;
204  swf->swf_frame_number = 0;
205  swf->video_frame_number = 0;
206 
207  for(i=0;i<s->nb_streams;i++) {
208  AVCodecParameters *par = s->streams[i]->codecpar;
209  if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
210  if (swf->audio_par) {
211  av_log(s, AV_LOG_ERROR, "SWF muxer only supports 1 audio stream\n");
212  return AVERROR_INVALIDDATA;
213  }
214  if (par->codec_id == AV_CODEC_ID_MP3) {
215  swf->audio_par = par;
217  if (!swf->audio_fifo)
218  return AVERROR(ENOMEM);
219  } else {
220  av_log(s, AV_LOG_ERROR, "SWF muxer only supports MP3\n");
221  return -1;
222  }
223  } else {
224  if (swf->video_par) {
225  av_log(s, AV_LOG_ERROR, "SWF muxer only supports 1 video stream\n");
226  return AVERROR_INVALIDDATA;
227  }
229  par->codec_id == AV_CODEC_ID_PNG ||
230  par->codec_id == AV_CODEC_ID_MJPEG) {
231  swf->video_st = s->streams[i];
232  swf->video_par = par;
233  } else {
234  av_log(s, AV_LOG_ERROR, "SWF muxer only supports VP6, FLV, Flash Screen Video, PNG and MJPEG\n");
235  return -1;
236  }
237  }
238  }
239 
240  if (!swf->video_par) {
241  /* currently, cannot work correctly if audio only */
242  width = 320;
243  height = 200;
244  rate = 10;
245  rate_base= 1;
246  } else {
247  width = swf->video_par->width;
248  height = swf->video_par->height;
249  // TODO: should be avg_frame_rate
250  rate = swf->video_st->time_base.den;
251  rate_base = swf->video_st->time_base.num;
252  }
253 
254  if (!swf->audio_par)
255  swf->samples_per_frame = (44100LL * rate_base) / rate;
256  else
257  swf->samples_per_frame = (swf->audio_par->sample_rate * rate_base) / rate;
258 
259  avio_write(pb, "FWS", 3);
260 
261  if (!strcmp("avm2", s->oformat->name))
262  version = 9;
263  else if (swf->video_par && (swf->video_par->codec_id == AV_CODEC_ID_VP6A ||
266  version = 8; /* version 8 and above support VP6 and PNG codec */
267  else if (swf->video_par && swf->video_par->codec_id == AV_CODEC_ID_FLASHSV)
268  version = 7; /* version 7 and above support Flash Screen Video codec */
269  else if (swf->video_par && swf->video_par->codec_id == AV_CODEC_ID_FLV1)
270  version = 6; /* version 6 and above support FLV1 codec */
271  else
272  version = 4; /* version 4 for mpeg audio support */
273  avio_w8(pb, version);
274 
275  avio_wl32(pb, DUMMY_FILE_SIZE); /* dummy size
276  (will be patched if not streamed) */
277 
278  put_swf_rect(pb, 0, width * 20, 0, height * 20);
279  if ((rate * 256LL) / rate_base >= (1<<16)) {
280  av_log(s, AV_LOG_ERROR, "Invalid (too large) frame rate %d/%d\n", rate, rate_base);
281  return AVERROR(EINVAL);
282  }
283  avio_wl16(pb, (rate * 256LL) / rate_base); /* frame rate */
284  swf->duration_pos = avio_tell(pb);
285  avio_wl16(pb, (uint16_t)(DUMMY_DURATION * (int64_t)rate / rate_base)); /* frame count */
286 
287  /* swf v8 and later files require a file attribute tag */
288  if (version >= 8) {
290  avio_wl32(pb, (version >= 9) << 3); /* set ActionScript v3/AVM2 flag */
292  }
293 
294  /* define a shape with the jpeg inside */
295  if (swf->video_par && (swf->video_par->codec_id == AV_CODEC_ID_MJPEG || swf->video_par->codec_id == AV_CODEC_ID_PNG)) {
297 
298  avio_wl16(pb, SHAPE_ID); /* ID of shape */
299  /* bounding rectangle */
300  put_swf_rect(pb, 0, width, 0, height);
301  /* style info */
302  avio_w8(pb, 1); /* one fill style */
303  avio_w8(pb, 0x41); /* clipped bitmap fill */
304  avio_wl16(pb, BITMAP_ID); /* bitmap ID */
305  /* position of the bitmap */
306  put_swf_matrix(pb, 1 << FRAC_BITS, 0,
307  0, 1 << FRAC_BITS, 0, 0);
308  avio_w8(pb, 0); /* no line style */
309 
310  /* shape drawing */
311  init_put_bits(&p, buf1, sizeof(buf1));
312  put_bits(&p, 4, 1); /* one fill bit */
313  put_bits(&p, 4, 0); /* zero line bit */
314 
315  put_bits(&p, 1, 0); /* not an edge */
317  put_bits(&p, 5, 1); /* nbits */
318  put_bits(&p, 1, 0); /* X */
319  put_bits(&p, 1, 0); /* Y */
320  put_bits(&p, 1, 1); /* set fill style 1 */
321 
322  /* draw the rectangle ! */
323  put_swf_line_edge(&p, width, 0);
324  put_swf_line_edge(&p, 0, height);
325  put_swf_line_edge(&p, -width, 0);
326  put_swf_line_edge(&p, 0, -height);
327 
328  /* end of shape */
329  put_bits(&p, 1, 0); /* not an edge */
330  put_bits(&p, 5, 0);
331 
332  flush_put_bits(&p);
333  avio_write(pb, buf1, put_bits_ptr(&p) - p.buf);
334 
336  }
337 
338  if (swf->audio_par && swf->audio_par->codec_id == AV_CODEC_ID_MP3) {
339  int v = 0;
340 
341  /* start sound */
343  switch(swf->audio_par->sample_rate) {
344  case 11025: v |= 1 << 2; break;
345  case 22050: v |= 2 << 2; break;
346  case 44100: v |= 3 << 2; break;
347  default:
348  /* not supported */
349  av_log(s, AV_LOG_ERROR, "swf does not support that sample rate, choose from (44100, 22050, 11025).\n");
350  return -1;
351  }
352  v |= 0x02; /* 16 bit playback */
353  if (swf->audio_par->ch_layout.nb_channels == 2)
354  v |= 0x01; /* stereo playback */
355  avio_w8(s->pb, v);
356  v |= 0x20; /* mp3 compressed */
357  avio_w8(s->pb, v);
358  avio_wl16(s->pb, swf->samples_per_frame); /* avg samples per frame */
359  avio_wl16(s->pb, 0);
360 
362  }
363 
364  return 0;
365 }
366 
367 static int fifo_avio_wrapper(void *opaque, void *buf, size_t *nb_elems)
368 {
369  avio_write(opaque, buf, *nb_elems);
370  return 0;
371 }
372 
374  AVCodecParameters *par, const uint8_t *buf, int size, unsigned pkt_flags)
375 {
376  SWFEncContext *swf = s->priv_data;
377  AVIOContext *pb = s->pb;
378  unsigned codec_tag = ff_codec_get_tag(ff_swf_codec_tags, par->codec_id);
379 
380  /* Flash Player limit */
381  if (swf->swf_frame_number == 16000)
382  av_log(s, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
383 
384  if (codec_tag) {
385  if (swf->video_frame_number == 0) {
386  /* create a new video object */
388  avio_wl16(pb, VIDEO_ID);
389  swf->vframes_pos = avio_tell(pb);
390  avio_wl16(pb, 15000); /* hard flash player limit */
391  avio_wl16(pb, par->width);
392  avio_wl16(pb, par->height);
393  avio_w8(pb, 0);
394  avio_w8(pb, codec_tag);
396 
397  /* place the video object for the first time */
399  avio_w8(pb, 0x36);
400  avio_wl16(pb, 1);
401  avio_wl16(pb, VIDEO_ID);
402  put_swf_matrix(pb, 1 << FRAC_BITS, 0, 0, 1 << FRAC_BITS, 0, 0);
403  avio_wl16(pb, swf->video_frame_number);
404  avio_write(pb, "video", 5);
405  avio_w8(pb, 0x00);
407  } else {
408  /* mark the character for update */
410  avio_w8(pb, 0x11);
411  avio_wl16(pb, 1);
412  avio_wl16(pb, swf->video_frame_number);
414  }
415 
416  /* set video frame data */
418  avio_wl16(pb, VIDEO_ID);
419  avio_wl16(pb, swf->video_frame_number++);
420  if (par->codec_id == AV_CODEC_ID_FLASHSV) {
421  /* FrameType and CodecId is needed here even if it is not documented correctly in the SWF specs */
422  int flags = codec_tag | (pkt_flags & AV_PKT_FLAG_KEY ? FLV_FRAME_KEY : FLV_FRAME_INTER);
423  avio_w8(pb, flags);
424  }
425  avio_write(pb, buf, size);
427  } else if (par->codec_id == AV_CODEC_ID_MJPEG || par->codec_id == AV_CODEC_ID_PNG) {
428  if (swf->swf_frame_number > 0) {
429  /* remove the shape */
431  avio_wl16(pb, SHAPE_ID); /* shape ID */
432  avio_wl16(pb, 1); /* depth */
434 
435  /* free the bitmap */
437  avio_wl16(pb, BITMAP_ID);
439  }
440 
442 
443  avio_wl16(pb, BITMAP_ID); /* ID of the image */
444 
445  /* a dummy jpeg header seems to be required */
446  if (par->codec_id == AV_CODEC_ID_MJPEG)
447  avio_wb32(pb, 0xffd8ffd9);
448  /* write the jpeg/png image */
449  avio_write(pb, buf, size);
450 
452 
453  /* draw the shape */
454 
456  avio_wl16(pb, SHAPE_ID); /* shape ID */
457  avio_wl16(pb, 1); /* depth */
458  put_swf_matrix(pb, 20 << FRAC_BITS, 0, 0, 20 << FRAC_BITS, 0, 0);
460  }
461 
462  swf->swf_frame_number++;
463 
464  /* streaming sound always should be placed just before showframe tags */
465  if (swf->audio_par && av_fifo_can_read(swf->audio_fifo)) {
466  size_t frame_size = av_fifo_can_read(swf->audio_fifo);
468  avio_wl16(pb, swf->sound_samples);
469  avio_wl16(pb, 0); // seek samples
472 
473  /* update FIFO */
474  swf->sound_samples = 0;
475  }
476 
477  /* output the frame */
480 
481  return 0;
482 }
483 
485  const uint8_t *buf, int size)
486 {
487  SWFEncContext *swf = s->priv_data;
488 
489  /* Flash Player limit */
490  if (swf->swf_frame_number == 16000)
491  av_log(s, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
492 
493  if (av_fifo_can_write(swf->audio_fifo) < size) {
494  av_log(s, AV_LOG_ERROR, "audio fifo too small to mux audio essence\n");
495  return -1;
496  }
497 
498  av_fifo_write(swf->audio_fifo, buf, size);
500 
501  /* if audio only stream make sure we add swf frames */
502  if (!swf->video_par)
503  swf_write_video(s, par, 0, 0, 0);
504 
505  return 0;
506 }
507 
509 {
510  AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar;
511  if (par->codec_type == AVMEDIA_TYPE_AUDIO)
512  return swf_write_audio(s, par, pkt->data, pkt->size);
513  else
514  return swf_write_video(s, par, pkt->data, pkt->size, pkt->flags);
515 }
516 
518 {
519  SWFEncContext *swf = s->priv_data;
520  AVIOContext *pb = s->pb;
521  int file_size;
522 
525 
526  /* patch file size and number of frames if not streamed */
527  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && swf->video_par) {
528  file_size = avio_tell(pb);
529  avio_seek(pb, 4, SEEK_SET);
530  avio_wl32(pb, file_size);
531  avio_seek(pb, swf->duration_pos, SEEK_SET);
532  avio_wl16(pb, swf->video_frame_number);
533  if (swf->vframes_pos) {
534  avio_seek(pb, swf->vframes_pos, SEEK_SET);
535  avio_wl16(pb, swf->video_frame_number);
536  }
537  avio_seek(pb, file_size, SEEK_SET);
538  }
539  return 0;
540 }
541 
543 {
544  SWFEncContext *swf = s->priv_data;
545 
546  av_fifo_freep2(&swf->audio_fifo);
547 }
548 
549 #if CONFIG_SWF_MUXER
551  .name = "swf",
552  .long_name = NULL_IF_CONFIG_SMALL("SWF (ShockWave Flash)"),
553  .mime_type = "application/x-shockwave-flash",
554  .extensions = "swf",
555  .priv_data_size = sizeof(SWFEncContext),
556  .audio_codec = AV_CODEC_ID_MP3,
557  .video_codec = AV_CODEC_ID_FLV1,
561  .deinit = swf_deinit,
563 };
564 #endif
565 #if CONFIG_AVM2_MUXER
567  .name = "avm2",
568  .long_name = NULL_IF_CONFIG_SMALL("SWF (ShockWave Flash) (AVM2)"),
569  .mime_type = "application/x-shockwave-flash",
570  .priv_data_size = sizeof(SWFEncContext),
571  .audio_codec = AV_CODEC_ID_MP3,
572  .video_codec = AV_CODEC_ID_FLV1,
576  .deinit = swf_deinit,
578 };
579 #endif
AV_CODEC_ID_VP6F
@ AV_CODEC_ID_VP6F
Definition: codec_id.h:142
SWFEncContext
Definition: swfenc.c:34
AVOutputFormat::name
const char * name
Definition: avformat.h:510
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:57
max_nbits
static void max_nbits(int *nbits_ptr, int val)
Definition: swfenc.c:86
TAG_PLACEOBJECT2
@ TAG_PLACEOBJECT2
Definition: swf.h:57
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:53
swf_write_header
static int swf_write_header(AVFormatContext *s)
Definition: swfenc.c:194
put_swf_end_tag
static void put_swf_end_tag(AVFormatContext *s)
Definition: swfenc.c:64
ff_swf_muxer
const AVOutputFormat ff_swf_muxer
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
swf_write_audio
static int swf_write_audio(AVFormatContext *s, AVCodecParameters *par, const uint8_t *buf, int size)
Definition: swfenc.c:484
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
deinit
static void deinit(AVFormatContext *s)
Definition: chromaprint.c:49
AVPacket::data
uint8_t * data
Definition: packet.h:374
av_fifo_can_read
size_t av_fifo_can_read(const AVFifo *f)
Definition: fifo.c:87
SWFEncContext::tag_pos
int64_t tag_pos
Definition: swfenc.c:36
AUDIO_FIFO_SIZE
#define AUDIO_FIFO_SIZE
Definition: swfenc.c:32
b
#define b
Definition: input.c:34
FLV_FRAME_KEY
@ FLV_FRAME_KEY
key frame (for AVC, a seekable frame)
Definition: flv.h:116
SWFEncContext::tag
int tag
Definition: swfenc.c:42
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:300
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:542
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:832
avio_wl16
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:466
fifo.h
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:505
val
static double val(void *priv, double ch)
Definition: aeval.c:77
SWFEncContext::video_st
AVStream * video_st
Definition: swfenc.c:45
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:428
AVRational::num
int num
Numerator.
Definition: rational.h:59
TAG_REMOVEOBJECT
@ TAG_REMOVEOBJECT
Definition: swf.h:38
FLAG_SETFILL0
#define FLAG_SETFILL0
Definition: swf.h:104
TAG_PLACEOBJECT
@ TAG_PLACEOBJECT
Definition: swf.h:37
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:158
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
FLV_FRAME_INTER
@ FLV_FRAME_INTER
inter frame (for AVC, a non-seekable frame)
Definition: flv.h:117
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
frame_size
int frame_size
Definition: mxfenc.c:2201
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:127
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_VIDEOFRAME
@ TAG_VIDEOFRAME
Definition: swf.h:75
swf_write_trailer
static int swf_write_trailer(AVFormatContext *s)
Definition: swfenc.c:517
av_fifo_can_write
size_t av_fifo_can_write(const AVFifo *f)
Definition: fifo.c:94
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:111
TAG_FILEATTRIBUTES
@ TAG_FILEATTRIBUTES
Definition: swf.h:80
AVFormatContext
Format I/O context.
Definition: avformat.h:1213
TAG_END
@ TAG_END
Definition: swf.h:33
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:978
SWFEncContext::vframes_pos
int64_t vframes_pos
Definition: swfenc.c:37
write_trailer
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:100
SWFEncContext::swf_frame_number
int swf_frame_number
Definition: swfenc.c:40
TAG_JPEG2
@ TAG_JPEG2
Definition: swf.h:53
flv.h
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:210
AV_CODEC_ID_FLASHSV
@ AV_CODEC_ID_FLASHSV
Definition: codec_id.h:136
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:212
AV_CODEC_ID_VP6A
@ AV_CODEC_ID_VP6A
Definition: codec_id.h:156
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:177
BITMAP_ID
#define BITMAP_ID
Definition: swf.h:108
SWFEncContext::audio_fifo
AVFifo * audio_fifo
Definition: swfenc.c:43
TAG_STREAMBLOCK
@ TAG_STREAMBLOCK
Definition: swf.h:51
FLAG_MOVETO
#define FLAG_MOVETO
Definition: swf.h:103
SWFEncContext::sound_samples
int sound_samples
Definition: swfenc.c:39
AVIOContext
Bytestream IO Context.
Definition: avio.h:162
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:117
TAG_STREAMHEAD2
@ TAG_STREAMHEAD2
Definition: swf.h:67
size
int size
Definition: twinvq_data.h:10344
ff_avm2_muxer
const AVOutputFormat ff_avm2_muxer
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:232
avio_wb32
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:394
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:386
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:380
version
version
Definition: libkvazaar.c:313
TAG_DEFINESHAPE
@ TAG_DEFINESHAPE
Definition: swf.h:35
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
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
swf_write_video
static int swf_write_video(AVFormatContext *s, AVCodecParameters *par, const uint8_t *buf, int size, unsigned pkt_flags)
Definition: swfenc.c:373
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:57
SWFEncContext::samples_per_frame
int samples_per_frame
Definition: swfenc.c:38
AVOutputFormat
Definition: avformat.h:509
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
AVCodecParameters::height
int height
Definition: codec_par.h:128
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
av_fifo_freep2
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
Definition: fifo.c:286
swf_write_packet
static int swf_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: swfenc.c:508
AVFMT_TS_NONSTRICT
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:491
SWFEncContext::audio_par
AVCodecParameters * audio_par
Definition: swfenc.c:44
tag
uint32_t tag
Definition: movenc.c:1646
SWFEncContext::video_par
AVCodecParameters * video_par
Definition: swfenc.c:44
put_swf_rect
static void put_swf_rect(AVIOContext *pb, int xmin, int xmax, int ymin, int ymax)
Definition: swfenc.c:102
AVStream
Stream structure.
Definition: avformat.h:948
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:260
pos
unsigned int pos
Definition: spdifenc.c:412
avformat.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
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:370
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:35
ff_codec_get_tag
unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
Definition: utils.c:134
TAG_VIDEOSTREAM
@ TAG_VIDEOSTREAM
Definition: swf.h:74
AVPacket::stream_index
int stream_index
Definition: packet.h:376
TAG_SHOWFRAME
@ TAG_SHOWFRAME
Definition: swf.h:34
fifo_avio_wrapper
static int fifo_avio_wrapper(void *opaque, void *buf, size_t *nb_elems)
Definition: swfenc.c:367
SWFEncContext::video_frame_number
int video_frame_number
Definition: swfenc.c:41
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:61
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:129
d
d
Definition: ffmpeg_filter.c:153
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
write_packet
static int write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: v4l2enc.c:92
write_header
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:346
AV_CODEC_ID_FLV1
@ AV_CODEC_ID_FLV1
Definition: codec_id.h:71
put_bits.h
TAG_FREECHARACTER
@ TAG_FREECHARACTER
Definition: swf.h:36
put_swf_tag
static void put_swf_tag(AVFormatContext *s, int tag)
Definition: swfenc.c:48
FRAC_BITS
#define FRAC_BITS
Definition: swfenc.c:156