asfenc.c
Go to the documentation of this file.
1 /*
2  * ASF muxer
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/avassert.h"
23 #include "libavutil/dict.h"
24 #include "avformat.h"
25 #include "avio_internal.h"
26 #include "internal.h"
27 #include "riff.h"
28 #include "asf.h"
29 
30 #undef NDEBUG
31 #include <assert.h>
32 
33 
34 #define ASF_INDEXED_INTERVAL 10000000
35 #define ASF_INDEX_BLOCK (1<<9)
36 
37 #define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE 0x2
38 #define ASF_PACKET_ERROR_CORRECTION_FLAGS \
39  (ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT | \
40  ASF_PACKET_ERROR_CORRECTION_DATA_SIZE)
41 
42 #if (ASF_PACKET_ERROR_CORRECTION_FLAGS != 0)
43 # define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 1
44 #else
45 # define ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE 0
46 #endif
47 
48 #define ASF_PPI_PROPERTY_FLAGS \
49  (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE | \
50  ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD | \
51  ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE | \
52  ASF_PL_FLAG_STREAM_NUMBER_LENGTH_FIELD_IS_BYTE)
53 
54 #define ASF_PPI_LENGTH_TYPE_FLAGS 0
55 
56 #define ASF_PAYLOAD_FLAGS ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_WORD
57 
58 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
59 # define ASF_PPI_SEQUENCE_FIELD_SIZE 1
60 #endif
61 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
62 # define ASF_PPI_SEQUENCE_FIELD_SIZE 2
63 #endif
64 #if (ASF_PPI_FLAG_SEQUENCE_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_SEQUENCE_FIELD_SIZE))
65 # define ASF_PPI_SEQUENCE_FIELD_SIZE 4
66 #endif
67 #ifndef ASF_PPI_SEQUENCE_FIELD_SIZE
68 # define ASF_PPI_SEQUENCE_FIELD_SIZE 0
69 #endif
70 
71 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
72 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 1
73 #endif
74 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
75 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 2
76 #endif
77 #if (ASF_PPI_FLAG_PACKET_LENGTH_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PACKET_LENGTH_FIELD_SIZE))
78 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 4
79 #endif
80 #ifndef ASF_PPI_PACKET_LENGTH_FIELD_SIZE
81 # define ASF_PPI_PACKET_LENGTH_FIELD_SIZE 0
82 #endif
83 
84 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
85 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 1
86 #endif
87 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
88 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 2
89 #endif
90 #if (ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_DWORD == (ASF_PPI_LENGTH_TYPE_FLAGS & ASF_PPI_MASK_PADDING_LENGTH_FIELD_SIZE))
91 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 4
92 #endif
93 #ifndef ASF_PPI_PADDING_LENGTH_FIELD_SIZE
94 # define ASF_PPI_PADDING_LENGTH_FIELD_SIZE 0
95 #endif
96 
97 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
98 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 1
99 #endif
100 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
101 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 2
102 #endif
103 #if (ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE))
104 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 4
105 #endif
106 #ifndef ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE
107 # define ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE 0
108 #endif
109 
110 #if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
111 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 1
112 #endif
113 #if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
114 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 2
115 #endif
116 #if (ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE))
117 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 4
118 #endif
119 #ifndef ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE
120 # define ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE 0
121 #endif
122 
123 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_BYTE == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
124 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 1
125 #endif
126 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_WORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
127 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 2
128 #endif
129 #if (ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_IS_DWORD == (ASF_PPI_PROPERTY_FLAGS & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE))
130 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 4
131 #endif
132 #ifndef ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE
133 # define ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE 0
134 #endif
135 
136 #if (ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_BYTE == (ASF_PAYLOAD_FLAGS & ASF_PL_MASK_PAYLOAD_LENGTH_FIELD_SIZE))
137 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 1
138 #endif
139 #if (ASF_PL_FLAG_PAYLOAD_LENGTH_FIELD_IS_WORD == (ASF_PAYLOAD_FLAGS & ASF_PL_MASK_PAYLOAD_LENGTH_FIELD_SIZE))
140 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 2
141 #endif
142 #ifndef ASF_PAYLOAD_LENGTH_FIELD_SIZE
143 # define ASF_PAYLOAD_LENGTH_FIELD_SIZE 0
144 #endif
145 
146 #define PACKET_HEADER_MIN_SIZE \
147  (ASF_PACKET_ERROR_CORRECTION_FLAGS_FIELD_SIZE + \
148  ASF_PACKET_ERROR_CORRECTION_DATA_SIZE + \
149  1 + /* Length Type Flags */ \
150  1 + /* Property Flags */ \
151  ASF_PPI_PACKET_LENGTH_FIELD_SIZE + \
152  ASF_PPI_SEQUENCE_FIELD_SIZE + \
153  ASF_PPI_PADDING_LENGTH_FIELD_SIZE + \
154  4 + /* Send Time Field */ \
155  2) /* Duration Field */
156 
157 // Replicated Data shall be at least 8 bytes long.
158 #define ASF_PAYLOAD_REPLICATED_DATA_LENGTH 0x08
159 
160 #define PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD \
161  (1 + /* Stream Number */ \
162  ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
163  ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
164  ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
165  ASF_PAYLOAD_REPLICATED_DATA_LENGTH)
166 
167 #define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS \
168  (1 + /* Stream Number */ \
169  ASF_PAYLOAD_MEDIA_OBJECT_NUMBER_FIELD_SIZE + \
170  ASF_PAYLOAD_OFFSET_INTO_MEDIA_OBJECT_FIELD_SIZE + \
171  ASF_PAYLOAD_REPLICATED_DATA_LENGTH_FIELD_SIZE + \
172  ASF_PAYLOAD_REPLICATED_DATA_LENGTH + \
173  ASF_PAYLOAD_LENGTH_FIELD_SIZE)
174 
175 #define SINGLE_PAYLOAD_DATA_LENGTH \
176  (PACKET_SIZE - \
177  PACKET_HEADER_MIN_SIZE - \
178  PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD)
179 
180 #define MULTI_PAYLOAD_CONSTANT \
181  (PACKET_SIZE - \
182  PACKET_HEADER_MIN_SIZE - \
183  1 - /* Payload Flags */ \
184  2 * PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS)
185 
186 typedef struct {
187  uint32_t seqno;
189  ASFStream streams[128]; ///< it's max number and it's not that big
190  /* non streamed additonnal info */
191  uint64_t nb_packets; ///< how many packets are there in the file, invalid if broadcasting
192  int64_t duration; ///< in 100ns units
193  /* packet filling */
194  unsigned char multi_payloads_present;
195  int packet_size_left;
198  unsigned int packet_nb_payloads;
199  uint8_t packet_buf[PACKET_SIZE];
201  /* only for reading */
202  uint64_t data_offset; ///< beginning of the first data packet
203 
206  uint16_t maximum_packet;
210  int end_sec;
211 } ASFContext;
212 
213 static const AVCodecTag codec_asf_bmp_tags[] = {
214  { AV_CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
215  { AV_CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
216  { AV_CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
217  { AV_CODEC_ID_NONE, 0 },
218 };
219 
220 #define PREROLL_TIME 3100
221 
223 {
224  av_assert0(sizeof(*g) == 16);
225  avio_write(s, *g, sizeof(*g));
226 }
227 
228 static void put_str16(AVIOContext *s, const char *tag)
229 {
230  int len;
231  uint8_t *pb;
232  AVIOContext *dyn_buf;
233  if (avio_open_dyn_buf(&dyn_buf) < 0)
234  return;
235 
236  avio_put_str16le(dyn_buf, tag);
237  len = avio_close_dyn_buf(dyn_buf, &pb);
238  avio_wl16(s, len);
239  avio_write(s, pb, len);
240  av_freep(&pb);
241 }
242 
243 static int64_t put_header(AVIOContext *pb, const ff_asf_guid *g)
244 {
245  int64_t pos;
246 
247  pos = avio_tell(pb);
248  ff_put_guid(pb, g);
249  avio_wl64(pb, 24);
250  return pos;
251 }
252 
253 /* update header size */
254 static void end_header(AVIOContext *pb, int64_t pos)
255 {
256  int64_t pos1;
257 
258  pos1 = avio_tell(pb);
259  avio_seek(pb, pos + 16, SEEK_SET);
260  avio_wl64(pb, pos1 - pos);
261  avio_seek(pb, pos1, SEEK_SET);
262 }
263 
264 /* write an asf chunk (only used in streaming case) */
265 static void put_chunk(AVFormatContext *s, int type,
266  int payload_length, int flags)
267 {
268  ASFContext *asf = s->priv_data;
269  AVIOContext *pb = s->pb;
270  int length;
271 
272  length = payload_length + 8;
273  avio_wl16(pb, type);
274  avio_wl16(pb, length); // size
275  avio_wl32(pb, asf->seqno); // sequence number
276  avio_wl16(pb, flags); // unknown bytes
277  avio_wl16(pb, length); // size_confirm
278  asf->seqno++;
279 }
280 
281 /* convert from unix to windows time */
282 static int64_t unix_to_file_time(int ti)
283 {
284  int64_t t;
285 
286  t = ti * INT64_C(10000000);
287  t += INT64_C(116444736000000000);
288  return t;
289 }
290 
291 /* write the header (used two times if non streamed) */
292 static int asf_write_header1(AVFormatContext *s, int64_t file_size,
293  int64_t data_chunk_size)
294 {
295  ASFContext *asf = s->priv_data;
296  AVIOContext *pb = s->pb;
298  int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
299  int has_title;
300  int metadata_count;
301  AVCodecContext *enc;
302  int64_t header_offset, cur_pos, hpos;
303  int bit_rate;
304  int64_t duration;
305 
307 
308  tags[0] = av_dict_get(s->metadata, "title", NULL, 0);
309  tags[1] = av_dict_get(s->metadata, "author", NULL, 0);
310  tags[2] = av_dict_get(s->metadata, "copyright", NULL, 0);
311  tags[3] = av_dict_get(s->metadata, "comment", NULL, 0);
312  tags[4] = av_dict_get(s->metadata, "rating", NULL, 0);
313 
314  duration = asf->duration + PREROLL_TIME * 10000;
315  has_title = tags[0] || tags[1] || tags[2] || tags[3] || tags[4];
316  metadata_count = av_dict_count(s->metadata);
317 
318  bit_rate = 0;
319  for (n = 0; n < s->nb_streams; n++) {
320  enc = s->streams[n]->codec;
321 
322  avpriv_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */
323 
324  bit_rate += enc->bit_rate;
325  }
326 
327  if (asf->is_streamed) {
328  put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
329  }
330 
332  avio_wl64(pb, -1); /* header length, will be patched after */
333  avio_wl32(pb, 3 + has_title + !!metadata_count + s->nb_streams); /* number of chunks in header */
334  avio_w8(pb, 1); /* ??? */
335  avio_w8(pb, 2); /* ??? */
336 
337  /* file header */
338  header_offset = avio_tell(pb);
339  hpos = put_header(pb, &ff_asf_file_header);
341  avio_wl64(pb, file_size);
342  file_time = 0;
343  avio_wl64(pb, unix_to_file_time(file_time));
344  avio_wl64(pb, asf->nb_packets); /* number of packets */
345  avio_wl64(pb, duration); /* end time stamp (in 100ns units) */
346  avio_wl64(pb, asf->duration); /* duration (in 100ns units) */
347  avio_wl64(pb, PREROLL_TIME); /* start time stamp */
348  avio_wl32(pb, (asf->is_streamed || !pb->seekable) ? 3 : 2); /* ??? */
349  avio_wl32(pb, s->packet_size); /* packet size */
350  avio_wl32(pb, s->packet_size); /* packet size */
351  avio_wl32(pb, bit_rate); /* Nominal data rate in bps */
352  end_header(pb, hpos);
353 
354  /* unknown headers */
355  hpos = put_header(pb, &ff_asf_head1_guid);
357  avio_wl32(pb, 6);
358  avio_wl16(pb, 0);
359  end_header(pb, hpos);
360 
361  /* title and other infos */
362  if (has_title) {
363  int len;
364  uint8_t *buf;
365  AVIOContext *dyn_buf;
366 
367  if (avio_open_dyn_buf(&dyn_buf) < 0)
368  return AVERROR(ENOMEM);
369 
370  hpos = put_header(pb, &ff_asf_comment_header);
371 
372  for (n = 0; n < FF_ARRAY_ELEMS(tags); n++) {
373  len = tags[n] ? avio_put_str16le(dyn_buf, tags[n]->value) : 0;
374  avio_wl16(pb, len);
375  }
376  len = avio_close_dyn_buf(dyn_buf, &buf);
377  avio_write(pb, buf, len);
378  av_freep(&buf);
379  end_header(pb, hpos);
380  }
381  if (metadata_count) {
384  avio_wl16(pb, metadata_count);
385  while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
386  put_str16(pb, tag->key);
387  avio_wl16(pb, 0);
388  put_str16(pb, tag->value);
389  }
390  end_header(pb, hpos);
391  }
392 
393  /* stream headers */
394  for (n = 0; n < s->nb_streams; n++) {
395  int64_t es_pos;
396  // ASFStream *stream = &asf->streams[n];
397 
398  enc = s->streams[n]->codec;
399  asf->streams[n].num = n + 1;
400  asf->streams[n].seq = 1;
401 
402  switch (enc->codec_type) {
403  case AVMEDIA_TYPE_AUDIO:
404  wav_extra_size = 0;
405  extra_size = 18 + wav_extra_size;
406  extra_size2 = 8;
407  break;
408  default:
409  case AVMEDIA_TYPE_VIDEO:
410  wav_extra_size = enc->extradata_size;
411  extra_size = 0x33 + wav_extra_size;
412  extra_size2 = 0;
413  break;
414  }
415 
416  hpos = put_header(pb, &ff_asf_stream_header);
417  if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
420  } else {
423  }
424  avio_wl64(pb, 0); /* ??? */
425  es_pos = avio_tell(pb);
426  avio_wl32(pb, extra_size); /* wav header len */
427  avio_wl32(pb, extra_size2); /* additional data len */
428  avio_wl16(pb, n + 1); /* stream number */
429  avio_wl32(pb, 0); /* ??? */
430 
431  if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
432  /* WAVEFORMATEX header */
433  int wavsize = ff_put_wav_header(pb, enc);
434 
435  if (wavsize < 0)
436  return -1;
437  if (wavsize != extra_size) {
438  cur_pos = avio_tell(pb);
439  avio_seek(pb, es_pos, SEEK_SET);
440  avio_wl32(pb, wavsize); /* wav header len */
441  avio_seek(pb, cur_pos, SEEK_SET);
442  }
443  /* ERROR Correction */
444  avio_w8(pb, 0x01);
445  if (enc->codec_id == AV_CODEC_ID_ADPCM_G726 || !enc->block_align) {
446  avio_wl16(pb, 0x0190);
447  avio_wl16(pb, 0x0190);
448  } else {
449  avio_wl16(pb, enc->block_align);
450  avio_wl16(pb, enc->block_align);
451  }
452  avio_wl16(pb, 0x01);
453  avio_w8(pb, 0x00);
454  } else {
455  avio_wl32(pb, enc->width);
456  avio_wl32(pb, enc->height);
457  avio_w8(pb, 2); /* ??? */
458  avio_wl16(pb, 40 + enc->extradata_size); /* size */
459 
460  /* BITMAPINFOHEADER header */
462  }
463  end_header(pb, hpos);
464  }
465 
466  /* media comments */
467 
470  avio_wl32(pb, s->nb_streams);
471  for (n = 0; n < s->nb_streams; n++) {
472  AVCodec *p;
473  const char *desc;
474  int len;
475  uint8_t *buf;
476  AVIOContext *dyn_buf;
477 
478  enc = s->streams[n]->codec;
479  p = avcodec_find_encoder(enc->codec_id);
480 
481  if (enc->codec_type == AVMEDIA_TYPE_AUDIO)
482  avio_wl16(pb, 2);
483  else if (enc->codec_type == AVMEDIA_TYPE_VIDEO)
484  avio_wl16(pb, 1);
485  else
486  avio_wl16(pb, -1);
487 
488  if (enc->codec_id == AV_CODEC_ID_WMAV2)
489  desc = "Windows Media Audio V8";
490  else
491  desc = p ? p->name : enc->codec_name;
492 
493  if (avio_open_dyn_buf(&dyn_buf) < 0)
494  return AVERROR(ENOMEM);
495 
496  avio_put_str16le(dyn_buf, desc);
497  len = avio_close_dyn_buf(dyn_buf, &buf);
498  avio_wl16(pb, len / 2); // "number of characters" = length in bytes / 2
499 
500  avio_write(pb, buf, len);
501  av_freep(&buf);
502 
503  avio_wl16(pb, 0); /* no parameters */
504 
505  /* id */
506  if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
507  avio_wl16(pb, 2);
508  avio_wl16(pb, enc->codec_tag);
509  } else {
510  avio_wl16(pb, 4);
511  avio_wl32(pb, enc->codec_tag);
512  }
513  if (!enc->codec_tag)
514  return -1;
515  }
516  end_header(pb, hpos);
517 
518  /* patch the header size fields */
519 
520  cur_pos = avio_tell(pb);
521  header_size = cur_pos - header_offset;
522  if (asf->is_streamed) {
523  header_size += 8 + 30 + 50;
524 
525  avio_seek(pb, header_offset - 10 - 30, SEEK_SET);
526  avio_wl16(pb, header_size);
527  avio_seek(pb, header_offset - 2 - 30, SEEK_SET);
528  avio_wl16(pb, header_size);
529 
530  header_size -= 8 + 30 + 50;
531  }
532  header_size += 24 + 6;
533  avio_seek(pb, header_offset - 14, SEEK_SET);
534  avio_wl64(pb, header_size);
535  avio_seek(pb, cur_pos, SEEK_SET);
536 
537  /* movie chunk, followed by packets of packet_size */
538  asf->data_offset = cur_pos;
540  avio_wl64(pb, data_chunk_size);
542  avio_wl64(pb, asf->nb_packets); /* nb packets */
543  avio_w8(pb, 1); /* ??? */
544  avio_w8(pb, 1); /* ??? */
545  return 0;
546 }
547 
549 {
550  ASFContext *asf = s->priv_data;
551 
553  asf->nb_packets = 0;
554 
555  asf->index_ptr = av_malloc(sizeof(ASFIndex) * ASF_INDEX_BLOCK);
557  asf->maximum_packet = 0;
558 
559  /* the data-chunk-size has to be 50, which is data_size - asf->data_offset
560  * at the moment this function is done. It is needed to use asf as
561  * streamable format. */
562  if (asf_write_header1(s, 0, 50) < 0) {
563  //av_free(asf);
564  return -1;
565  }
566 
567  avio_flush(s->pb);
568 
569  asf->packet_nb_payloads = 0;
570  asf->packet_timestamp_start = -1;
571  asf->packet_timestamp_end = -1;
572  ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
573  NULL, NULL, NULL, NULL);
574 
575  if (s->avoid_negative_ts < 0)
576  s->avoid_negative_ts = 1;
577 
578  return 0;
579 }
580 
582 {
583  ASFContext *asf = s->priv_data;
584 
585  asf->is_streamed = 1;
586 
587  return asf_write_header(s);
588 }
589 
591  unsigned sendtime, unsigned duration,
592  int nb_payloads, int padsize)
593 {
594  ASFContext *asf = s->priv_data;
595  AVIOContext *pb = s->pb;
596  int ppi_size, i;
597  int64_t start = avio_tell(pb);
598 
599  int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS;
600 
601  padsize -= PACKET_HEADER_MIN_SIZE;
602  if (asf->multi_payloads_present)
603  padsize--;
604  av_assert0(padsize >= 0);
605 
607  for (i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++)
608  avio_w8(pb, 0x0);
609 
610  if (asf->multi_payloads_present)
611  iLengthTypeFlags |= ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT;
612 
613  if (padsize > 0) {
614  if (padsize < 256)
615  iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE;
616  else
617  iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD;
618  }
619  avio_w8(pb, iLengthTypeFlags);
620 
622 
623  if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD)
624  avio_wl16(pb, padsize - 2);
625  if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE)
626  avio_w8(pb, padsize - 1);
627 
628  avio_wl32(pb, sendtime);
629  avio_wl16(pb, duration);
630  if (asf->multi_payloads_present)
631  avio_w8(pb, nb_payloads | ASF_PAYLOAD_FLAGS);
632 
633  ppi_size = avio_tell(pb) - start;
634 
635  return ppi_size;
636 }
637 
639 {
640  ASFContext *asf = s->priv_data;
641  int packet_hdr_size, packet_filled_size;
642 
644 
645  if (asf->is_streamed)
646  put_chunk(s, 0x4424, s->packet_size, 0);
647 
648  packet_hdr_size = put_payload_parsing_info(s,
651  asf->packet_nb_payloads,
652  asf->packet_size_left);
653 
654  packet_filled_size = PACKET_SIZE - asf->packet_size_left;
655  av_assert0(packet_hdr_size <= asf->packet_size_left);
656  memset(asf->packet_buf + packet_filled_size, 0, asf->packet_size_left);
657 
658  avio_write(s->pb, asf->packet_buf, s->packet_size - packet_hdr_size);
659 
660  avio_flush(s->pb);
661  asf->nb_packets++;
662  asf->packet_nb_payloads = 0;
663  asf->packet_timestamp_start = -1;
664  asf->packet_timestamp_end = -1;
665  ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1,
666  NULL, NULL, NULL, NULL);
667 }
668 
670  int64_t presentation_time, int m_obj_size,
671  int m_obj_offset, int payload_len, int flags)
672 {
673  ASFContext *asf = s->priv_data;
674  AVIOContext *pb = &asf->pb;
675  int val;
676 
677  val = stream->num;
678  if (flags & AV_PKT_FLAG_KEY)
679  val |= ASF_PL_FLAG_KEY_FRAME;
680  avio_w8(pb, val);
681 
682  avio_w8(pb, stream->seq); // Media object number
683  avio_wl32(pb, m_obj_offset); // Offset Into Media Object
684 
685  // Replicated Data shall be at least 8 bytes long.
686  // The first 4 bytes of data shall contain the
687  // Size of the Media Object that the payload belongs to.
688  // The next 4 bytes of data shall contain the
689  // Presentation Time for the media object that the payload belongs to.
691 
692  avio_wl32(pb, m_obj_size); // Replicated Data - Media Object Size
693  avio_wl32(pb, (uint32_t) presentation_time); // Replicated Data - Presentation Time
694 
695  if (asf->multi_payloads_present) {
696  avio_wl16(pb, payload_len); // payload length
697  }
698 }
699 
700 static void put_frame(AVFormatContext *s, ASFStream *stream, AVStream *avst,
701  int64_t timestamp, const uint8_t *buf,
702  int m_obj_size, int flags)
703 {
704  ASFContext *asf = s->priv_data;
705  int m_obj_offset, payload_len, frag_len1;
706 
707  m_obj_offset = 0;
708  while (m_obj_offset < m_obj_size) {
709  payload_len = m_obj_size - m_obj_offset;
710  if (asf->packet_timestamp_start == -1) {
711  asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT);
712 
714  if (asf->multi_payloads_present) {
715  frag_len1 = MULTI_PAYLOAD_CONSTANT - 1;
716  } else {
717  frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH;
718  }
719  asf->packet_timestamp_start = timestamp;
720  } else {
721  // multi payloads
722  frag_len1 = asf->packet_size_left -
725 
726  if (frag_len1 < payload_len &&
727  avst->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
728  flush_packet(s);
729  continue;
730  }
731  }
732  if (frag_len1 > 0) {
733  if (payload_len > frag_len1)
734  payload_len = frag_len1;
735  else if (payload_len == (frag_len1 - 1))
736  payload_len = frag_len1 - 2; // additional byte need to put padding length
737 
738  put_payload_header(s, stream, timestamp + PREROLL_TIME,
739  m_obj_size, m_obj_offset, payload_len, flags);
740  avio_write(&asf->pb, buf, payload_len);
741 
742  if (asf->multi_payloads_present)
744  else
746  asf->packet_timestamp_end = timestamp;
747 
748  asf->packet_nb_payloads++;
749  } else {
750  payload_len = 0;
751  }
752  m_obj_offset += payload_len;
753  buf += payload_len;
754 
755  if (!asf->multi_payloads_present)
756  flush_packet(s);
758  flush_packet(s);
759  }
760  stream->seq++;
761 }
762 
763 static void update_index(AVFormatContext *s, int start_sec,
764  uint32_t packet_number, uint16_t packet_count)
765 {
766  ASFContext *asf = s->priv_data;
767 
768  if (start_sec > asf->next_start_sec) {
769  int i;
770 
771  if (!asf->next_start_sec) {
772  asf->next_packet_number = packet_number;
773  asf->next_packet_count = packet_count;
774  }
775 
776  if (start_sec > asf->nb_index_memory_alloc) {
777  asf->nb_index_memory_alloc = (start_sec + ASF_INDEX_BLOCK) & ~(ASF_INDEX_BLOCK - 1);
778  asf->index_ptr = av_realloc( asf->index_ptr, sizeof(ASFIndex) * asf->nb_index_memory_alloc );
779  }
780  for (i = asf->next_start_sec; i < start_sec; i++) {
783  }
784  }
785  asf->maximum_packet = FFMAX(asf->maximum_packet, packet_count);
786  asf->next_packet_number = packet_number;
787  asf->next_packet_count = packet_count;
788  asf->next_start_sec = start_sec;
789 }
790 
792 {
793  ASFContext *asf = s->priv_data;
794  ASFStream *stream;
795  AVCodecContext *codec;
796  uint32_t packet_number;
797  int64_t pts;
798  int start_sec;
799  int flags = pkt->flags;
800 
801  codec = s->streams[pkt->stream_index]->codec;
802  stream = &asf->streams[pkt->stream_index];
803 
804  if (codec->codec_type == AVMEDIA_TYPE_AUDIO)
805  flags &= ~AV_PKT_FLAG_KEY;
806 
807  pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts;
808  av_assert0(pts != AV_NOPTS_VALUE);
809  pts *= 10000;
810  asf->duration = FFMAX(asf->duration, pts + pkt->duration * 10000);
811 
812  packet_number = asf->nb_packets;
813  put_frame(s, stream, s->streams[pkt->stream_index],
814  pkt->dts, pkt->data, pkt->size, flags);
815 
816  start_sec = (int)((PREROLL_TIME * 10000 + pts + ASF_INDEXED_INTERVAL - 1)
818 
819  /* check index */
820  if ((!asf->is_streamed) && (flags & AV_PKT_FLAG_KEY)) {
821  uint16_t packet_count = asf->nb_packets - packet_number;
822  update_index(s, start_sec, packet_number, packet_count);
823  }
824  asf->end_sec = start_sec;
825 
826  return 0;
827 }
828 
830  uint16_t max, uint32_t count)
831 {
832  AVIOContext *pb = s->pb;
833  int i;
834 
836  avio_wl64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2) * count);
839  avio_wl32(pb, max);
840  avio_wl32(pb, count);
841  for (i = 0; i < count; i++) {
842  avio_wl32(pb, index[i].packet_number);
843  avio_wl16(pb, index[i].packet_count);
844  }
845 
846  return 0;
847 }
848 
850 {
851  ASFContext *asf = s->priv_data;
852  int64_t file_size, data_size;
853 
854  /* flush the current packet */
855  if (asf->pb.buf_ptr > asf->pb.buffer)
856  flush_packet(s);
857 
858  /* write index */
859  data_size = avio_tell(s->pb);
860  if (!asf->is_streamed && asf->next_start_sec) {
861  update_index(s, asf->end_sec + 1, 0, 0);
863  }
864  avio_flush(s->pb);
865 
866  if (asf->is_streamed || !s->pb->seekable) {
867  put_chunk(s, 0x4524, 0, 0); /* end of stream */
868  } else {
869  /* rewrite an updated header */
870  file_size = avio_tell(s->pb);
871  avio_seek(s->pb, 0, SEEK_SET);
872  asf_write_header1(s, file_size, data_size - asf->data_offset);
873  }
874 
875  av_free(asf->index_ptr);
876  return 0;
877 }
878 
879 #if CONFIG_ASF_MUXER
880 AVOutputFormat ff_asf_muxer = {
881  .name = "asf",
882  .long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
883  .mime_type = "video/x-ms-asf",
884  .extensions = "asf,wmv,wma",
885  .priv_data_size = sizeof(ASFContext),
886  .audio_codec = AV_CODEC_ID_WMAV2,
887  .video_codec = AV_CODEC_ID_MSMPEG4V3,
892  .codec_tag = (const AVCodecTag * const []) {
894  },
895 };
896 #endif /* CONFIG_ASF_MUXER */
897 
898 #if CONFIG_ASF_STREAM_MUXER
899 AVOutputFormat ff_asf_stream_muxer = {
900  .name = "asf_stream",
901  .long_name = NULL_IF_CONFIG_SMALL("ASF (Advanced / Active Streaming Format)"),
902  .mime_type = "video/x-ms-asf",
903  .extensions = "asf,wmv,wma",
904  .priv_data_size = sizeof(ASFContext),
905  .audio_codec = AV_CODEC_ID_WMAV2,
906  .video_codec = AV_CODEC_ID_MSMPEG4V3,
911  .codec_tag = (const AVCodecTag * const []) {
913  },
914 };
915 #endif /* CONFIG_ASF_STREAM_MUXER */
const ff_asf_guid ff_asf_header
Definition: asf.c:23
Definition: start.py:1
unsigned int packet_size
Definition: avformat.h:1018
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:367
const char * s
Definition: avisynth_c.h:668
Bytestream IO Context.
Definition: avio.h:68
#define ASF_PAYLOAD_FLAGS
Definition: asfenc.c:56
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:988
const ff_asf_guid ff_asf_codec_comment_header
Definition: asf.c:73
#define PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD
Definition: asfenc.c:160
unsigned char * buf_ptr
Current position in the buffer.
Definition: avio.h:84
unsigned int packet_nb_payloads
Definition: asfenc.c:198
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
static int64_t unix_to_file_time(int ti)
Definition: asfenc.c:282
if max(w)>1 w=0.9 *w/max(w)
int is_streamed
Definition: asfenc.c:188
#define PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS
Definition: asfenc.c:167
int num
Definition: asf.h:37
Definition: asf.h:86
static int write_packet(AVFormatContext *s, AVPacket *pkt)
static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: asfenc.c:791
uint64_t data_offset
beginning of the first data packet
Definition: asfdec.c:52
uint32_t next_packet_number
Definition: asfenc.c:207
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
Definition: dict.c:33
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:199
unsigned char * buffer
Start of the buffer.
Definition: avio.h:82
static int put_payload_parsing_info(AVFormatContext *s, unsigned sendtime, unsigned duration, int nb_payloads, int padsize)
Definition: asfenc.c:590
uint16_t maximum_packet
Definition: asfenc.c:206
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:141
#define FF_ARRAY_ELEMS(a)
static int asf_write_trailer(AVFormatContext *s)
Definition: asfenc.c:849
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:39
uint16_t next_packet_count
Definition: asfenc.c:208
uint32_t packet_number
Definition: asf.h:87
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:976
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
Format I/O context.
Definition: avformat.h:944
const ff_asf_guid ff_asf_data_header
Definition: asf.c:80
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Public dictionary API.
#define ASF_INDEX_BLOCK
Definition: asfenc.c:35
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:291
AVIOContext pb
Definition: asfenc.c:200
uint8_t
const ff_asf_guid ff_asf_audio_stream
Definition: asf.c:39
static AVPacket pkt
Definition: demuxing.c:56
static int asf_write_header(AVFormatContext *s)
Definition: asfenc.c:548
ASFStream streams[128]
it&#39;s max number and it&#39;s not that big
Definition: asfdec.c:44
AVStream ** streams
Definition: avformat.h:992
int packet_size_left
Definition: asfdec.c:50
uint8_t * data
uint32_t tag
Definition: movenc.c:894
#define ASF_PPI_LENGTH_TYPE_FLAGS
Definition: asfenc.c:54
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:248
static int64_t duration
Definition: ffplay.c:294
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:173
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static int write_trailer(AVFormatContext *s)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:355
uint32_t seqno
Definition: asfenc.c:187
static int asf_write_index(AVFormatContext *s, ASFIndex *index, uint16_t max, uint32_t count)
Definition: asfenc.c:829
AVDictionary * metadata
Definition: avformat.h:1092
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
#define PREROLL_TIME
Definition: asfenc.c:220
const ff_asf_guid ff_asf_head1_guid
Definition: asf.c:84
const ff_asf_guid ff_asf_simple_index_header
Definition: asf.c:96
const ff_asf_guid ff_asf_head2_guid
Definition: asf.c:88
static void put_payload_header(AVFormatContext *s, ASFStream *stream, int64_t presentation_time, int m_obj_size, int m_obj_offset, int payload_len, int flags)
Definition: asfenc.c:669
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int64_t packet_timestamp_start
Definition: asfenc.c:196
const ff_asf_guid ff_asf_video_conceal_none
Definition: asf.c:61
simple assert() macros that are a bit more flexible than ISO C assert().
#define ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD
Definition: asf.h:150
const char * name
Name of the codec implementation.
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:334
#define FFMAX(a, b)
Definition: common.h:56
int flags
A combination of AV_PKT_FLAG values.
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
#define ASF_PPI_FLAG_MULTIPLE_PAYLOADS_PRESENT
Definition: asf.h:142
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:991
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:117
FFT buffer for g
Definition: stft_peak.m:17
int bit_rate
the average bitrate
int void avio_flush(AVIOContext *s)
Force flushing of buffered data to the output s.
Definition: aviobuf.c:193
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:35
int width
picture width / height.
static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
Definition: asfenc.c:265
#define ASF_PACKET_ERROR_CORRECTION_FLAGS
Definition: asfenc.c:38
const ff_asf_guid ff_asf_extended_content_header
Definition: asf.c:92
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:351
t
Definition: genspecsines3.m:6
const char * name
Definition: avformat.h:378
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
#define ASF_PAYLOAD_REPLICATED_DATA_LENGTH
Definition: asfenc.c:158
int next_start_sec
Definition: asfenc.c:209
int avoid_negative_ts
Avoid negative timestamps during muxing.
Definition: avformat.h:1180
const ff_asf_guid ff_asf_my_guid
Definition: asf.c:122
#define ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE
Definition: asf.h:149
uint8_t ff_asf_guid[16]
Definition: riff.h:59
Stream structure.
Definition: avformat.h:643
NULL
Definition: eval.c:55
#define ASF_PACKET_ERROR_CORRECTION_DATA_SIZE
Definition: asfenc.c:37
uint8_t packet_buf[PACKET_SIZE]
Definition: asfenc.c:199
#define ASF_PPI_PROPERTY_FLAGS
Definition: asfenc.c:48
enum AVMediaType codec_type
const ff_asf_guid ff_asf_file_header
Definition: asf.c:27
#define SINGLE_PAYLOAD_DATA_LENGTH
Definition: asfenc.c:175
enum AVCodecID codec_id
static int64_t extra_size
Definition: ffmpeg.c:128
AVIOContext * pb
I/O context.
Definition: avformat.h:977
const ff_asf_guid ff_asf_video_stream
Definition: asf.c:53
Definition: asf.h:36
int64_t packet_timestamp_end
Definition: asfenc.c:197
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:151
main external API structure.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
void * buf
Definition: avisynth_c.h:594
static void flush_packet(AVFormatContext *s)
Definition: asfenc.c:638
double value
Definition: eval.c:82
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
int index
Definition: gxfenc.c:89
synthesis window for stochastic i
const ff_asf_guid ff_asf_stream_header
Definition: asf.c:31
static const AVCodecTag codec_asf_bmp_tags[]
Definition: asfenc.c:213
int avio_put_str16le(AVIOContext *s, const char *str)
Convert an UTF-8 string to UTF-16LE and write it.
Definition: aviobuf.c:318
const AVMetadataConv ff_asf_metadata_conv[]
Definition: asf.c:143
static int64_t put_header(AVIOContext *pb, const ff_asf_guid *g)
Definition: asfenc.c:243
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
int64_t duration
in 100ns units
Definition: asfenc.c:192
#define type
void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf)
void ff_put_guid(AVIOContext *s, const ff_asf_guid *g)
Definition: asfenc.c:222
#define ASF_INDEXED_INTERVAL
Definition: asfenc.c:34
const ff_asf_guid ff_asf_comment_header
Definition: asf.c:69
static void put_frame(AVFormatContext *s, ASFStream *stream, AVStream *avst, int64_t timestamp, const uint8_t *buf, int m_obj_size, int flags)
Definition: asfenc.c:700
static int flags
Definition: cpu.c:23
static void update_index(AVFormatContext *s, int start_sec, uint32_t packet_number, uint16_t packet_count)
Definition: asfenc.c:763
ASFIndex * index_ptr
Definition: asfenc.c:204
#define MULTI_PAYLOAD_CONSTANT
Definition: asfenc.c:180
Main libavformat public API header.
static void end_header(AVIOContext *pb, int64_t pos)
Definition: asfenc.c:254
#define ASF_PL_FLAG_KEY_FRAME
Definition: asf.h:182
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Definition: aviobuf.c:71
uint64_t nb_packets
how many packets are there in the file, invalid if broadcasting
Definition: asfenc.c:191
unsigned char seq
Definition: asf.h:38
int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
const ff_asf_guid ff_asf_audio_conceal_spread
Definition: asf.c:49
const ff_asf_guid ff_asf_codec_comment1_header
Definition: asf.c:76
char * key
Definition: dict.h:81
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size)
Definition: asfenc.c:292
char * value
Definition: dict.h:82
int len
void * priv_data
Format private data.
Definition: avformat.h:964
uint32_t nb_index_memory_alloc
Definition: asfenc.c:205
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:470
#define PACKET_SIZE
Definition: asf.h:29
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static int asf_write_stream_header(AVFormatContext *s)
Definition: asfenc.c:581
void INT64 INT64 count
Definition: avisynth_c.h:594
static void put_str16(AVIOContext *s, const char *tag)
Definition: asfenc.c:228
void INT64 start
Definition: avisynth_c.h:594
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:68
uint16_t packet_count
Definition: asf.h:88
#define PACKET_HEADER_MIN_SIZE
Definition: asfenc.c:146
const char int length
Definition: avisynth_c.h:668
int end_sec
Definition: asfenc.c:210
unsigned char multi_payloads_present
Definition: asfenc.c:194
#define MKTAG(a, b, c, d)
Definition: common.h:282
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:190