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 "libavcodec/put_bits.h"
24 #include "libavutil/avassert.h"
25 #include "libavutil/fifo.h"
26 #include "avformat.h"
27 #include "swf.h"
28 
29 #define AUDIO_FIFO_SIZE 65536
30 
31 typedef struct SWFEncContext {
32  int64_t duration_pos;
33  int64_t tag_pos;
34  int64_t vframes_pos;
39  int tag;
44 
45 static void put_swf_tag(AVFormatContext *s, int tag)
46 {
47  SWFEncContext *swf = s->priv_data;
48  AVIOContext *pb = s->pb;
49 
50  swf->tag_pos = avio_tell(pb);
51  swf->tag = tag;
52  /* reserve some room for the tag */
53  if (tag & TAG_LONG) {
54  avio_wl16(pb, 0);
55  avio_wl32(pb, 0);
56  } else {
57  avio_wl16(pb, 0);
58  }
59 }
60 
62 {
63  SWFEncContext *swf = s->priv_data;
64  AVIOContext *pb = s->pb;
65  int64_t pos;
66  int tag_len, tag;
67 
68  pos = avio_tell(pb);
69  tag_len = pos - swf->tag_pos - 2;
70  tag = swf->tag;
71  avio_seek(pb, swf->tag_pos, SEEK_SET);
72  if (tag & TAG_LONG) {
73  tag &= ~TAG_LONG;
74  avio_wl16(pb, (tag << 6) | 0x3f);
75  avio_wl32(pb, tag_len - 4);
76  } else {
77  av_assert0(tag_len < 0x3f);
78  avio_wl16(pb, (tag << 6) | tag_len);
79  }
80  avio_seek(pb, pos, SEEK_SET);
81 }
82 
83 static inline void max_nbits(int *nbits_ptr, int val)
84 {
85  int n;
86 
87  if (val == 0)
88  return;
89  val = FFABS(val);
90  n = 1;
91  while (val != 0) {
92  n++;
93  val >>= 1;
94  }
95  if (n > *nbits_ptr)
96  *nbits_ptr = n;
97 }
98 
99 static void put_swf_rect(AVIOContext *pb,
100  int xmin, int xmax, int ymin, int ymax)
101 {
102  PutBitContext p;
103  uint8_t buf[256];
104  int nbits, mask;
105 
106  init_put_bits(&p, buf, sizeof(buf));
107 
108  nbits = 0;
109  max_nbits(&nbits, xmin);
110  max_nbits(&nbits, xmax);
111  max_nbits(&nbits, ymin);
112  max_nbits(&nbits, ymax);
113  mask = (1 << nbits) - 1;
114 
115  /* rectangle info */
116  put_bits(&p, 5, nbits);
117  put_bits(&p, nbits, xmin & mask);
118  put_bits(&p, nbits, xmax & mask);
119  put_bits(&p, nbits, ymin & mask);
120  put_bits(&p, nbits, ymax & mask);
121 
122  flush_put_bits(&p);
123  avio_write(pb, buf, put_bits_ptr(&p) - p.buf);
124 }
125 
126 static void put_swf_line_edge(PutBitContext *pb, int dx, int dy)
127 {
128  int nbits, mask;
129 
130  put_bits(pb, 1, 1); /* edge */
131  put_bits(pb, 1, 1); /* line select */
132  nbits = 2;
133  max_nbits(&nbits, dx);
134  max_nbits(&nbits, dy);
135 
136  mask = (1 << nbits) - 1;
137  put_bits(pb, 4, nbits - 2); /* 16 bits precision */
138  if (dx == 0) {
139  put_bits(pb, 1, 0);
140  put_bits(pb, 1, 1);
141  put_bits(pb, nbits, dy & mask);
142  } else if (dy == 0) {
143  put_bits(pb, 1, 0);
144  put_bits(pb, 1, 0);
145  put_bits(pb, nbits, dx & mask);
146  } else {
147  put_bits(pb, 1, 1);
148  put_bits(pb, nbits, dx & mask);
149  put_bits(pb, nbits, dy & mask);
150  }
151 }
152 
153 #define FRAC_BITS 16
154 
155 static void put_swf_matrix(AVIOContext *pb,
156  int a, int b, int c, int d, int tx, int ty)
157 {
158  PutBitContext p;
159  uint8_t buf[256];
160  int nbits;
161 
162  init_put_bits(&p, buf, sizeof(buf));
163 
164  put_bits(&p, 1, 1); /* a, d present */
165  nbits = 1;
166  max_nbits(&nbits, a);
167  max_nbits(&nbits, d);
168  put_bits(&p, 5, nbits); /* nb bits */
169  put_bits(&p, nbits, a);
170  put_bits(&p, nbits, d);
171 
172  put_bits(&p, 1, 1); /* b, c present */
173  nbits = 1;
174  max_nbits(&nbits, c);
175  max_nbits(&nbits, b);
176  put_bits(&p, 5, nbits); /* nb bits */
177  put_bits(&p, nbits, c);
178  put_bits(&p, nbits, b);
179 
180  nbits = 1;
181  max_nbits(&nbits, tx);
182  max_nbits(&nbits, ty);
183  put_bits(&p, 5, nbits); /* nb bits */
184  put_bits(&p, nbits, tx);
185  put_bits(&p, nbits, ty);
186 
187  flush_put_bits(&p);
188  avio_write(pb, buf, put_bits_ptr(&p) - p.buf);
189 }
190 
192 {
193  SWFEncContext *swf = s->priv_data;
194  AVIOContext *pb = s->pb;
195  PutBitContext p;
196  uint8_t buf1[256];
197  int i, width, height, rate, rate_base;
198  int version;
199 
200  swf->sound_samples = 0;
201  swf->swf_frame_number = 0;
202  swf->video_frame_number = 0;
203 
204  for(i=0;i<s->nb_streams;i++) {
205  AVCodecParameters *par = s->streams[i]->codecpar;
206  if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
207  if (swf->audio_par) {
208  av_log(s, AV_LOG_ERROR, "SWF muxer only supports 1 audio stream\n");
209  return AVERROR_INVALIDDATA;
210  }
211  if (par->codec_id == AV_CODEC_ID_MP3) {
212  swf->audio_par = par;
214  if (!swf->audio_fifo)
215  return AVERROR(ENOMEM);
216  } else {
217  av_log(s, AV_LOG_ERROR, "SWF muxer only supports MP3\n");
218  return -1;
219  }
220  } else {
221  if (swf->video_par) {
222  av_log(s, AV_LOG_ERROR, "SWF muxer only supports 1 video stream\n");
223  return AVERROR_INVALIDDATA;
224  }
225  if (par->codec_id == AV_CODEC_ID_VP6F ||
226  par->codec_id == AV_CODEC_ID_FLV1 ||
227  par->codec_id == AV_CODEC_ID_MJPEG) {
228  swf->video_st = s->streams[i];
229  swf->video_par = par;
230  } else {
231  av_log(s, AV_LOG_ERROR, "SWF muxer only supports VP6, FLV1 and MJPEG\n");
232  return -1;
233  }
234  }
235  }
236 
237  if (!swf->video_par) {
238  /* currently, cannot work correctly if audio only */
239  width = 320;
240  height = 200;
241  rate = 10;
242  rate_base= 1;
243  } else {
244  width = swf->video_par->width;
245  height = swf->video_par->height;
246  // TODO: should be avg_frame_rate
247  rate = swf->video_st->time_base.den;
248  rate_base = swf->video_st->time_base.num;
249  }
250 
251  if (!swf->audio_par)
252  swf->samples_per_frame = (44100LL * rate_base) / rate;
253  else
254  swf->samples_per_frame = (swf->audio_par->sample_rate * rate_base) / rate;
255 
256  avio_write(pb, "FWS", 3);
257 
258  if (!strcmp("avm2", s->oformat->name))
259  version = 9;
260  else if (swf->video_par && swf->video_par->codec_id == AV_CODEC_ID_VP6F)
261  version = 8; /* version 8 and above support VP6 codec */
262  else if (swf->video_par && swf->video_par->codec_id == AV_CODEC_ID_FLV1)
263  version = 6; /* version 6 and above support FLV1 codec */
264  else
265  version = 4; /* version 4 for mpeg audio support */
266  avio_w8(pb, version);
267 
268  avio_wl32(pb, DUMMY_FILE_SIZE); /* dummy size
269  (will be patched if not streamed) */
270 
271  put_swf_rect(pb, 0, width * 20, 0, height * 20);
272  if ((rate * 256LL) / rate_base >= (1<<16)) {
273  av_log(s, AV_LOG_ERROR, "Invalid (too large) frame rate %d/%d\n", rate, rate_base);
274  return AVERROR(EINVAL);
275  }
276  avio_wl16(pb, (rate * 256LL) / rate_base); /* frame rate */
277  swf->duration_pos = avio_tell(pb);
278  avio_wl16(pb, (uint16_t)(DUMMY_DURATION * (int64_t)rate / rate_base)); /* frame count */
279 
280  /* avm2/swf v9 (also v8?) files require a file attribute tag */
281  if (version == 9) {
283  avio_wl32(pb, 1<<3); /* set ActionScript v3/AVM2 flag */
284  put_swf_end_tag(s);
285  }
286 
287  /* define a shape with the jpeg inside */
288  if (swf->video_par && swf->video_par->codec_id == AV_CODEC_ID_MJPEG) {
290 
291  avio_wl16(pb, SHAPE_ID); /* ID of shape */
292  /* bounding rectangle */
293  put_swf_rect(pb, 0, width, 0, height);
294  /* style info */
295  avio_w8(pb, 1); /* one fill style */
296  avio_w8(pb, 0x41); /* clipped bitmap fill */
297  avio_wl16(pb, BITMAP_ID); /* bitmap ID */
298  /* position of the bitmap */
299  put_swf_matrix(pb, 1 << FRAC_BITS, 0,
300  0, 1 << FRAC_BITS, 0, 0);
301  avio_w8(pb, 0); /* no line style */
302 
303  /* shape drawing */
304  init_put_bits(&p, buf1, sizeof(buf1));
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 */
310  put_bits(&p, 5, 1); /* nbits */
311  put_bits(&p, 1, 0); /* X */
312  put_bits(&p, 1, 0); /* Y */
313  put_bits(&p, 1, 1); /* set fill style 1 */
314 
315  /* draw the rectangle ! */
316  put_swf_line_edge(&p, width, 0);
317  put_swf_line_edge(&p, 0, height);
318  put_swf_line_edge(&p, -width, 0);
319  put_swf_line_edge(&p, 0, -height);
320 
321  /* end of shape */
322  put_bits(&p, 1, 0); /* not an edge */
323  put_bits(&p, 5, 0);
324 
325  flush_put_bits(&p);
326  avio_write(pb, buf1, put_bits_ptr(&p) - p.buf);
327 
328  put_swf_end_tag(s);
329  }
330 
331  if (swf->audio_par && swf->audio_par->codec_id == AV_CODEC_ID_MP3) {
332  int v = 0;
333 
334  /* start sound */
336  switch(swf->audio_par->sample_rate) {
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 */
346  if (swf->audio_par->channels == 2)
347  v |= 0x01; /* stereo playback */
348  avio_w8(s->pb, v);
349  v |= 0x20; /* mp3 compressed */
350  avio_w8(s->pb, v);
351  avio_wl16(s->pb, swf->samples_per_frame); /* avg samples per frame */
352  avio_wl16(s->pb, 0);
353 
354  put_swf_end_tag(s);
355  }
356 
357  return 0;
358 }
359 
361  AVCodecParameters *par, const uint8_t *buf, int size)
362 {
363  SWFEncContext *swf = s->priv_data;
364  AVIOContext *pb = s->pb;
365 
366  /* Flash Player limit */
367  if (swf->swf_frame_number == 16000)
368  av_log(s, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
369 
370  if (par->codec_id == AV_CODEC_ID_VP6F ||
371  par->codec_id == AV_CODEC_ID_FLV1) {
372  if (swf->video_frame_number == 0) {
373  /* create a new video object */
375  avio_wl16(pb, VIDEO_ID);
376  swf->vframes_pos = avio_tell(pb);
377  avio_wl16(pb, 15000); /* hard flash player limit */
378  avio_wl16(pb, par->width);
379  avio_wl16(pb, par->height);
380  avio_w8(pb, 0);
382  put_swf_end_tag(s);
383 
384  /* place the video object for the first time */
386  avio_w8(pb, 0x36);
387  avio_wl16(pb, 1);
388  avio_wl16(pb, VIDEO_ID);
389  put_swf_matrix(pb, 1 << FRAC_BITS, 0, 0, 1 << FRAC_BITS, 0, 0);
390  avio_wl16(pb, swf->video_frame_number);
391  avio_write(pb, "video", 5);
392  avio_w8(pb, 0x00);
393  put_swf_end_tag(s);
394  } else {
395  /* mark the character for update */
397  avio_w8(pb, 0x11);
398  avio_wl16(pb, 1);
399  avio_wl16(pb, swf->video_frame_number);
400  put_swf_end_tag(s);
401  }
402 
403  /* set video frame data */
405  avio_wl16(pb, VIDEO_ID);
406  avio_wl16(pb, swf->video_frame_number++);
407  avio_write(pb, buf, size);
408  put_swf_end_tag(s);
409  } else if (par->codec_id == AV_CODEC_ID_MJPEG) {
410  if (swf->swf_frame_number > 0) {
411  /* remove the shape */
413  avio_wl16(pb, SHAPE_ID); /* shape ID */
414  avio_wl16(pb, 1); /* depth */
415  put_swf_end_tag(s);
416 
417  /* free the bitmap */
419  avio_wl16(pb, BITMAP_ID);
420  put_swf_end_tag(s);
421  }
422 
424 
425  avio_wl16(pb, BITMAP_ID); /* ID of the image */
426 
427  /* a dummy jpeg header seems to be required */
428  avio_wb32(pb, 0xffd8ffd9);
429  /* write the jpeg image */
430  avio_write(pb, buf, size);
431 
432  put_swf_end_tag(s);
433 
434  /* draw the shape */
435 
437  avio_wl16(pb, SHAPE_ID); /* shape ID */
438  avio_wl16(pb, 1); /* depth */
439  put_swf_matrix(pb, 20 << FRAC_BITS, 0, 0, 20 << FRAC_BITS, 0, 0);
440  put_swf_end_tag(s);
441  }
442 
443  swf->swf_frame_number++;
444 
445  /* streaming sound always should be placed just before showframe tags */
446  if (swf->audio_par && av_fifo_size(swf->audio_fifo)) {
447  int frame_size = av_fifo_size(swf->audio_fifo);
449  avio_wl16(pb, swf->sound_samples);
450  avio_wl16(pb, 0); // seek samples
451  av_fifo_generic_read(swf->audio_fifo, pb, frame_size, (void*)avio_write);
452  put_swf_end_tag(s);
453 
454  /* update FIFO */
455  swf->sound_samples = 0;
456  }
457 
458  /* output the frame */
460  put_swf_end_tag(s);
461 
462  return 0;
463 }
464 
466  AVCodecParameters *par, uint8_t *buf, int size)
467 {
468  SWFEncContext *swf = s->priv_data;
469 
470  /* Flash Player limit */
471  if (swf->swf_frame_number == 16000)
472  av_log(s, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
473 
474  if (av_fifo_size(swf->audio_fifo) + size > AUDIO_FIFO_SIZE) {
475  av_log(s, AV_LOG_ERROR, "audio fifo too small to mux audio essence\n");
476  return -1;
477  }
478 
479  av_fifo_generic_write(swf->audio_fifo, buf, size, NULL);
480  swf->sound_samples += av_get_audio_frame_duration2(par, size);
481 
482  /* if audio only stream make sure we add swf frames */
483  if (!swf->video_par)
484  swf_write_video(s, par, 0, 0);
485 
486  return 0;
487 }
488 
490 {
492  if (par->codec_type == AVMEDIA_TYPE_AUDIO)
493  return swf_write_audio(s, par, pkt->data, pkt->size);
494  else
495  return swf_write_video(s, par, pkt->data, pkt->size);
496 }
497 
499 {
500  SWFEncContext *swf = s->priv_data;
501  AVIOContext *pb = s->pb;
502  int file_size;
503 
504  put_swf_tag(s, TAG_END);
505  put_swf_end_tag(s);
506 
507  /* patch file size and number of frames if not streamed */
508  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && swf->video_par) {
509  file_size = avio_tell(pb);
510  avio_seek(pb, 4, SEEK_SET);
511  avio_wl32(pb, file_size);
512  avio_seek(pb, swf->duration_pos, SEEK_SET);
513  avio_wl16(pb, swf->video_frame_number);
514  if (swf->vframes_pos) {
515  avio_seek(pb, swf->vframes_pos, SEEK_SET);
516  avio_wl16(pb, swf->video_frame_number);
517  }
518  avio_seek(pb, file_size, SEEK_SET);
519  }
520  return 0;
521 }
522 
524 {
525  SWFEncContext *swf = s->priv_data;
526 
527  av_fifo_freep(&swf->audio_fifo);
528 }
529 
530 #if CONFIG_SWF_MUXER
532  .name = "swf",
533  .long_name = NULL_IF_CONFIG_SMALL("SWF (ShockWave Flash)"),
534  .mime_type = "application/x-shockwave-flash",
535  .extensions = "swf",
536  .priv_data_size = sizeof(SWFEncContext),
537  .audio_codec = AV_CODEC_ID_MP3,
538  .video_codec = AV_CODEC_ID_FLV1,
542  .deinit = swf_deinit,
544 };
545 #endif
546 #if CONFIG_AVM2_MUXER
548  .name = "avm2",
549  .long_name = NULL_IF_CONFIG_SMALL("SWF (ShockWave Flash) (AVM2)"),
550  .mime_type = "application/x-shockwave-flash",
551  .priv_data_size = sizeof(SWFEncContext),
552  .audio_codec = AV_CODEC_ID_MP3,
553  .video_codec = AV_CODEC_ID_FLV1,
557  .deinit = swf_deinit,
559 };
560 #endif
#define SHAPE_ID
Definition: swf.h:110
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:702
const AVCodecTag ff_swf_codec_tags[]
Definition: swf.c:25
#define NULL
Definition: coverity.c:32
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:459
Bytestream IO Context.
Definition: avio.h:161
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
version
Definition: libkvazaar.c:317
AVCodecParameters * audio_par
Definition: swfenc.c:41
int swf_frame_number
Definition: swfenc.c:37
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:218
int64_t duration_pos
Definition: swfenc.c:32
#define VIDEO_ID
Definition: mpeg.h:42
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
int num
Numerator.
Definition: rational.h:59
int size
Definition: packet.h:364
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:253
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:36
unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
Definition: utils.c:3086
static AVPacket pkt
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:472
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
#define DUMMY_DURATION
Definition: swf.h:30
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.
Definition: fifo.c:122
Definition: swf.h:33
Format I/O context.
Definition: avformat.h:1351
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:379
uint8_t
int width
Video only.
Definition: codec_par.h:126
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
AVFifoBuffer * audio_fifo
Definition: swfenc.c:40
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1419
#define height
static void put_swf_rect(AVIOContext *pb, int xmin, int xmax, int ymin, int ymax)
Definition: swfenc.c:99
uint8_t * data
Definition: packet.h:363
#define BITMAP_ID
Definition: swf.h:108
ptrdiff_t size
Definition: opengl_enc.c:100
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:225
#define av_log(a,...)
static void put_swf_line_edge(PutBitContext *pb, int dx, int dy)
Definition: swfenc.c:126
static void swf_deinit(AVFormatContext *s)
Definition: swfenc.c:523
Definition: swf.h:53
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
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:347
static const uint16_t mask[17]
Definition: lzw.c:38
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:153
unsigned int pos
Definition: spdifenc.c:410
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.
Definition: fifo.c:213
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:416
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
uint8_t * buf
Definition: put_bits.h:52
simple assert() macros that are a bit more flexible than ISO C assert().
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:1783
AVCodecParameters * video_par
Definition: swfenc.c:41
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1407
#define b
Definition: input.c:41
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:260
static int swf_write_audio(AVFormatContext *s, AVCodecParameters *par, uint8_t *buf, int size)
Definition: swfenc.c:465
static void put_swf_tag(AVFormatContext *s, int tag)
Definition: swfenc.c:45
static void max_nbits(int *nbits_ptr, int val)
Definition: swfenc.c:83
#define width
AVOutputFormat ff_swf_muxer
#define DUMMY_FILE_SIZE
Definition: swf.h:29
int samples_per_frame
Definition: swfenc.c:35
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:98
#define FLAG_SETFILL0
Definition: swf.h:104
const char * name
Definition: avformat.h:500
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define s(width, name)
Definition: cbs_vp9.c:257
static int swf_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: swfenc.c:489
ff_const59 struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1370
static int swf_write_video(AVFormatContext *s, AVCodecParameters *par, const uint8_t *buf, int size)
Definition: swfenc.c:360
int64_t vframes_pos
Definition: swfenc.c:34
AVOutputFormat ff_avm2_muxer
Stream structure.
Definition: avformat.h:876
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
static int swf_write_header(AVFormatContext *s)
Definition: swfenc.c:191
int frame_size
Definition: mxfenc.c:2166
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 ...
Definition: fifo.c:77
AVIOContext * pb
I/O context.
Definition: avformat.h:1393
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:203
AVStream * video_st
Definition: swfenc.c:42
a very simple circular buffer FIFO implementation
#define AUDIO_FIFO_SIZE
Definition: swfenc.c:29
int video_frame_number
Definition: swfenc.c:38
#define FRAC_BITS
Definition: swfenc.c:153
#define flags(name, subs,...)
Definition: cbs_av1.c:560
#define TAG_LONG
Definition: swf.h:100
int sample_rate
Audio only.
Definition: codec_par.h:170
Main libavformat public API header.
static void put_swf_end_tag(AVFormatContext *s)
Definition: swfenc.c:61
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:115
int64_t tag_pos
Definition: swfenc.c:33
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:62
int den
Denominator.
Definition: rational.h:60
int sound_samples
Definition: swfenc.c:36
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
Definition: fifo.c:43
void * priv_data
Format private data.
Definition: avformat.h:1379
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:346
int channels
Audio only.
Definition: codec_par.h:166
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:387
void av_fifo_freep(AVFifoBuffer **f)
Free an AVFifoBuffer and reset pointer to NULL.
Definition: fifo.c:63
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1023
int stream_index
Definition: packet.h:365
static int swf_write_trailer(AVFormatContext *s)
Definition: swfenc.c:498
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:905
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
static void put_swf_matrix(AVIOContext *pb, int a, int b, int c, int d, int tx, int ty)
Definition: swfenc.c:155
static double val(void *priv, double ch)
Definition: aeval.c:76
This structure stores compressed data.
Definition: packet.h:340
int i
Definition: input.c:407
#define FLAG_MOVETO
Definition: swf.h:103
bitstream writer API