Libav
flvenc.c
Go to the documentation of this file.
1 /*
2  * FLV muxer
3  * Copyright (c) 2003 The Libav Project
4  *
5  * This file is part of Libav.
6  *
7  * Libav 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  * Libav 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 Libav; 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/dict.h"
23 #include "libavutil/intfloat.h"
24 #include "libavutil/mathematics.h"
25 #include "avc.h"
26 #include "avformat.h"
27 #include "flv.h"
28 #include "internal.h"
29 #include "metadata.h"
30 
31 #undef NDEBUG
32 #include <assert.h>
33 
34 static const AVCodecTag flv_video_codec_ids[] = {
41  { AV_CODEC_ID_NONE, 0 }
42 };
43 
44 static const AVCodecTag flv_audio_codec_ids[] = {
46  { AV_CODEC_ID_PCM_U8, FLV_CODECID_PCM >> FLV_AUDIO_CODECID_OFFSET },
47  { AV_CODEC_ID_PCM_S16BE, FLV_CODECID_PCM >> FLV_AUDIO_CODECID_OFFSET },
48  { AV_CODEC_ID_PCM_S16LE, FLV_CODECID_PCM_LE >> FLV_AUDIO_CODECID_OFFSET },
49  { AV_CODEC_ID_ADPCM_SWF, FLV_CODECID_ADPCM >> FLV_AUDIO_CODECID_OFFSET },
50  { AV_CODEC_ID_AAC, FLV_CODECID_AAC >> FLV_AUDIO_CODECID_OFFSET },
51  { AV_CODEC_ID_NELLYMOSER, FLV_CODECID_NELLYMOSER >> FLV_AUDIO_CODECID_OFFSET },
52  { AV_CODEC_ID_PCM_MULAW, FLV_CODECID_PCM_MULAW >> FLV_AUDIO_CODECID_OFFSET },
53  { AV_CODEC_ID_PCM_ALAW, FLV_CODECID_PCM_ALAW >> FLV_AUDIO_CODECID_OFFSET },
54  { AV_CODEC_ID_SPEEX, FLV_CODECID_SPEEX >> FLV_AUDIO_CODECID_OFFSET },
55  { AV_CODEC_ID_NONE, 0 }
56 };
57 
58 typedef struct FLVContext {
59  int reserved;
60  int64_t duration_offset;
61  int64_t filesize_offset;
62  int64_t duration;
63  int64_t delay;
64 
67  double framerate;
69 } FLVContext;
70 
71 typedef struct FLVStreamContext {
72  int64_t last_ts;
74 
76 {
79 
80  if (par->codec_id == AV_CODEC_ID_AAC) // specs force these parameters
83  else if (par->codec_id == AV_CODEC_ID_SPEEX) {
84  if (par->sample_rate != 16000) {
86  "flv only supports wideband (16kHz) Speex audio\n");
87  return -1;
88  }
89  if (par->channels != 1) {
90  av_log(s, AV_LOG_ERROR, "flv only supports mono Speex audio\n");
91  return -1;
92  }
94  } else {
95  switch (par->sample_rate) {
96  case 44100:
97  flags |= FLV_SAMPLERATE_44100HZ;
98  break;
99  case 22050:
100  flags |= FLV_SAMPLERATE_22050HZ;
101  break;
102  case 11025:
103  flags |= FLV_SAMPLERATE_11025HZ;
104  break;
105  case 16000: // nellymoser only
106  case 8000: // nellymoser only
107  case 5512: // not MP3
108  if (par->codec_id != AV_CODEC_ID_MP3) {
109  flags |= FLV_SAMPLERATE_SPECIAL;
110  break;
111  }
112  default:
113  av_log(s, AV_LOG_ERROR,
114  "flv does not support that sample rate, "
115  "choose from (44100, 22050, 11025).\n");
116  return -1;
117  }
118  }
119 
120  if (par->channels > 1)
121  flags |= FLV_STEREO;
122 
123  switch (par->codec_id) {
124  case AV_CODEC_ID_MP3:
126  break;
127  case AV_CODEC_ID_PCM_U8:
129  break;
132  break;
135  break;
138  break;
140  if (par->sample_rate == 8000)
142  else if (par->sample_rate == 16000)
144  else
146  break;
149  break;
152  break;
153  case 0:
154  flags |= par->codec_tag << 4;
155  break;
156  default:
157  av_log(s, AV_LOG_ERROR, "codec not compatible with flv\n");
158  return -1;
159  }
160 
161  return flags;
162 }
163 
164 static void put_amf_string(AVIOContext *pb, const char *str)
165 {
166  size_t len = strlen(str);
167  avio_wb16(pb, len);
168  avio_write(pb, str, len);
169 }
170 
171 static void put_avc_eos_tag(AVIOContext *pb, unsigned ts)
172 {
174  avio_wb24(pb, 5); /* Tag Data Size */
175  avio_wb24(pb, ts); /* lower 24 bits of timestamp in ms */
176  avio_w8(pb, (ts >> 24) & 0x7F); /* MSB of ts in ms */
177  avio_wb24(pb, 0); /* StreamId = 0 */
178  avio_w8(pb, 23); /* ub[4] FrameType = 1, ub[4] CodecId = 7 */
179  avio_w8(pb, 2); /* AVC end of sequence */
180  avio_wb24(pb, 0); /* Always 0 for AVC EOS. */
181  avio_wb32(pb, 16); /* Size of FLV tag */
182 }
183 
184 static void put_amf_double(AVIOContext *pb, double d)
185 {
187  avio_wb64(pb, av_double2int(d));
188 }
189 
190 static void put_amf_bool(AVIOContext *pb, int b)
191 {
193  avio_w8(pb, !!b);
194 }
195 
196 static void write_metadata(AVFormatContext *s, unsigned int ts)
197 {
198  AVIOContext *pb = s->pb;
199  FLVContext *flv = s->priv_data;
200  int metadata_count = 0;
201  int64_t metadata_size_pos, data_size, metadata_count_pos;
203 
204  /* write meta_tag */
205  avio_w8(pb, 18); // tag type META
206  metadata_size_pos = avio_tell(pb);
207  avio_wb24(pb, 0); // size of data part (sum of all parts below)
208  avio_wb24(pb, ts); // timestamp
209  avio_wb32(pb, 0); // reserved
210 
211  /* now data of data_size size */
212 
213  /* first event name as a string */
215  put_amf_string(pb, "onMetaData"); // 12 bytes
216 
217  /* mixed array (hash) with size and string/type/data tuples */
219  metadata_count_pos = avio_tell(pb);
220  metadata_count = 4 * !!flv->video_par +
221  5 * !!flv->audio_par +
222  1 * !!flv->data_par +
223  2; // +2 for duration and file size
224 
225  avio_wb32(pb, metadata_count);
226 
227  put_amf_string(pb, "duration");
228  flv->duration_offset = avio_tell(pb);
229 
230  // fill in the guessed duration, it'll be corrected later if incorrect
232 
233  if (flv->video_par) {
234  put_amf_string(pb, "width");
235  put_amf_double(pb, flv->video_par->width);
236 
237  put_amf_string(pb, "height");
238  put_amf_double(pb, flv->video_par->height);
239 
240  put_amf_string(pb, "videodatarate");
241  put_amf_double(pb, flv->video_par->bit_rate / 1024.0);
242 
243  if (flv->framerate != 0.0) {
244  put_amf_string(pb, "framerate");
245  put_amf_double(pb, flv->framerate);
246  metadata_count++;
247  }
248 
249  put_amf_string(pb, "videocodecid");
251  }
252 
253  if (flv->audio_par) {
254  put_amf_string(pb, "audiodatarate");
255  put_amf_double(pb, flv->audio_par->bit_rate / 1024.0);
256 
257  put_amf_string(pb, "audiosamplerate");
259 
260  put_amf_string(pb, "audiosamplesize");
261  put_amf_double(pb, flv->audio_par->codec_id == AV_CODEC_ID_PCM_U8 ? 8 : 16);
262 
263  put_amf_string(pb, "stereo");
264  put_amf_bool(pb, flv->audio_par->channels == 2);
265 
266  put_amf_string(pb, "audiocodecid");
268  }
269 
270  if (flv->data_par) {
271  put_amf_string(pb, "datastream");
272  put_amf_double(pb, 0.0);
273  }
274 
275  while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
276  put_amf_string(pb, tag->key);
278  put_amf_string(pb, tag->value);
279  metadata_count++;
280  }
281 
282  put_amf_string(pb, "filesize");
283  flv->filesize_offset = avio_tell(pb);
284  put_amf_double(pb, 0); // delayed write
285 
286  put_amf_string(pb, "");
288 
289  /* write total size of tag */
290  data_size = avio_tell(pb) - metadata_size_pos - 10;
291 
292  avio_seek(pb, metadata_count_pos, SEEK_SET);
293  avio_wb32(pb, metadata_count);
294 
295  avio_seek(pb, metadata_size_pos, SEEK_SET);
296  avio_wb24(pb, data_size);
297  avio_skip(pb, data_size + 10 - 3);
298  avio_wb32(pb, data_size + 11);
299 }
300 
302  const char* type, int codec_id)
303 {
304  const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
305  av_log(s, AV_LOG_ERROR,
306  "%s codec %s not compatible with flv\n",
307  type,
308  desc ? desc->name : "unknown");
309  return AVERROR(ENOSYS);
310 }
311 
313 {
314  int i;
315  AVIOContext *pb = s->pb;
316  FLVContext *flv = s->priv_data;
317  int64_t data_size;
318 
319  for (i = 0; i < s->nb_streams; i++) {
320  AVCodecParameters *par = s->streams[i]->codecpar;
321  FLVStreamContext *sc;
322  switch (par->codec_type) {
323  case AVMEDIA_TYPE_VIDEO:
324  if (s->streams[i]->avg_frame_rate.den &&
325  s->streams[i]->avg_frame_rate.num) {
326  flv->framerate = av_q2d(s->streams[i]->avg_frame_rate);
327  }
328  if (flv->video_par) {
329  av_log(s, AV_LOG_ERROR,
330  "at most one video stream is supported in flv\n");
331  return AVERROR(EINVAL);
332  }
333  flv->video_par = par;
334  if (!ff_codec_get_tag(flv_video_codec_ids, par->codec_id))
335  return unsupported_codec(s, "Video", par->codec_id);
336  break;
337  case AVMEDIA_TYPE_AUDIO:
338  if (flv->audio_par) {
339  av_log(s, AV_LOG_ERROR,
340  "at most one audio stream is supported in flv\n");
341  return AVERROR(EINVAL);
342  }
343  flv->audio_par = par;
344  if (get_audio_flags(s, par) < 0)
345  return unsupported_codec(s, "Audio", par->codec_id);
346  break;
347  case AVMEDIA_TYPE_DATA:
348  if (par->codec_id != AV_CODEC_ID_TEXT)
349  return unsupported_codec(s, "Data", par->codec_id);
350  flv->data_par = par;
351  break;
352  default:
353  av_log(s, AV_LOG_ERROR, "codec not compatible with flv\n");
354  return -1;
355  }
356  avpriv_set_pts_info(s->streams[i], 32, 1, 1000); /* 32 bit pts in ms */
357 
358  sc = av_mallocz(sizeof(FLVStreamContext));
359  if (!sc)
360  return AVERROR(ENOMEM);
361  s->streams[i]->priv_data = sc;
362  sc->last_ts = -1;
363  }
364 
365  flv->delay = AV_NOPTS_VALUE;
366 
367  avio_write(pb, "FLV", 3);
368  avio_w8(pb, 1);
371  avio_wb32(pb, 9);
372  avio_wb32(pb, 0);
373 
374  for (i = 0; i < s->nb_streams; i++)
375  if (s->streams[i]->codecpar->codec_tag == 5) {
376  avio_w8(pb, 8); // message type
377  avio_wb24(pb, 0); // include flags
378  avio_wb24(pb, 0); // time stamp
379  avio_wb32(pb, 0); // reserved
380  avio_wb32(pb, 11); // size
381  flv->reserved = 5;
382  }
383 
384  write_metadata(s, 0);
385 
386  for (i = 0; i < s->nb_streams; i++) {
387  AVCodecParameters *par = s->streams[i]->codecpar;
388  if (par->codec_id == AV_CODEC_ID_AAC || par->codec_id == AV_CODEC_ID_H264) {
389  int64_t pos;
392  avio_wb24(pb, 0); // size patched later
393  avio_wb24(pb, 0); // ts
394  avio_w8(pb, 0); // ts ext
395  avio_wb24(pb, 0); // streamid
396  pos = avio_tell(pb);
397  if (par->codec_id == AV_CODEC_ID_AAC) {
398  avio_w8(pb, get_audio_flags(s, par));
399  avio_w8(pb, 0); // AAC sequence header
400  avio_write(pb, par->extradata, par->extradata_size);
401  } else {
402  avio_w8(pb, par->codec_tag | FLV_FRAME_KEY); // flags
403  avio_w8(pb, 0); // AVC sequence header
404  avio_wb24(pb, 0); // composition time
406  }
407  data_size = avio_tell(pb) - pos;
408  avio_seek(pb, -data_size - 10, SEEK_CUR);
409  avio_wb24(pb, data_size);
410  avio_skip(pb, data_size + 10 - 3);
411  avio_wb32(pb, data_size + 11); // previous tag size
412  }
413  }
414 
415  return 0;
416 }
417 
419 {
420  int64_t file_size;
421 
422  AVIOContext *pb = s->pb;
423  FLVContext *flv = s->priv_data;
424  int i;
425 
426  /* Add EOS tag */
427  for (i = 0; i < s->nb_streams; i++) {
428  AVCodecParameters *par = s->streams[i]->codecpar;
429  FLVStreamContext *sc = s->streams[i]->priv_data;
430  if (par->codec_type == AVMEDIA_TYPE_VIDEO &&
431  par->codec_id == AV_CODEC_ID_H264)
432  put_avc_eos_tag(pb, sc->last_ts);
433  }
434 
435  file_size = avio_tell(pb);
436 
437  /* update information */
438  if (avio_seek(pb, flv->duration_offset, SEEK_SET) < 0)
439  av_log(s, AV_LOG_WARNING, "Failed to update header with correct duration.\n");
440  else
441  put_amf_double(pb, flv->duration / (double)1000);
442  if (avio_seek(pb, flv->filesize_offset, SEEK_SET) < 0)
443  av_log(s, AV_LOG_WARNING, "Failed to update header with correct filesize.\n");
444  else
445  put_amf_double(pb, file_size);
446 
447  avio_seek(pb, file_size, SEEK_SET);
448  return 0;
449 }
450 
452 {
453  AVIOContext *pb = s->pb;
455  FLVContext *flv = s->priv_data;
457  unsigned ts;
458  int size = pkt->size;
459  uint8_t *data = NULL;
460  int flags = 0, flags_size;
461 
462  if (par->codec_id == AV_CODEC_ID_VP6F || par->codec_id == AV_CODEC_ID_VP6A ||
463  par->codec_id == AV_CODEC_ID_AAC)
464  flags_size = 2;
465  else if (par->codec_id == AV_CODEC_ID_H264)
466  flags_size = 5;
467  else
468  flags_size = 1;
469 
470  if (flv->delay == AV_NOPTS_VALUE)
471  flv->delay = -pkt->dts;
472 
473  if (pkt->dts < -flv->delay) {
475  "Packets are not in the proper order with respect to DTS\n");
476  return AVERROR(EINVAL);
477  }
478 
479  ts = pkt->dts + flv->delay; // add delay to force positive dts
480 
482  write_metadata(s, ts);
484  }
485 
488 
489  switch (par->codec_type) {
490  case AVMEDIA_TYPE_VIDEO:
492 
493  flags = ff_codec_get_tag(flv_video_codec_ids, par->codec_id);
494 
496  break;
497  case AVMEDIA_TYPE_AUDIO:
498  flags = get_audio_flags(s, par);
499 
500  assert(size);
501 
503  break;
504  case AVMEDIA_TYPE_DATA:
506  break;
507  default:
508  return AVERROR(EINVAL);
509  }
510 
511  if (par->codec_id == AV_CODEC_ID_H264)
512  /* check if extradata looks like MP4 */
513  if (par->extradata_size > 0 && *(uint8_t*)par->extradata != 1)
514  if (ff_avc_parse_nal_units_buf(pkt->data, &data, &size) < 0)
515  return -1;
516 
517  /* check Speex packet duration */
518  if (par->codec_id == AV_CODEC_ID_SPEEX && ts - sc->last_ts > 160)
519  av_log(s, AV_LOG_WARNING, "Warning: Speex stream has more than "
520  "8 frames per packet. Adobe Flash "
521  "Player cannot handle this!\n");
522 
523  if (sc->last_ts < ts)
524  sc->last_ts = ts;
525 
526  avio_wb24(pb, size + flags_size);
527  avio_wb24(pb, ts);
528  avio_w8(pb, (ts >> 24) & 0x7F); // timestamps are 32 bits _signed_
529  avio_wb24(pb, flv->reserved);
530 
531  if (par->codec_type == AVMEDIA_TYPE_DATA) {
532  int data_size;
533  int64_t metadata_size_pos = avio_tell(pb);
535  put_amf_string(pb, "onTextData");
537  avio_wb32(pb, 2);
538  put_amf_string(pb, "type");
540  put_amf_string(pb, "Text");
541  put_amf_string(pb, "text");
543  put_amf_string(pb, pkt->data);
544  put_amf_string(pb, "");
546  /* write total size of tag */
547  data_size = avio_tell(pb) - metadata_size_pos;
548  avio_seek(pb, metadata_size_pos - 10, SEEK_SET);
549  avio_wb24(pb, data_size);
550  avio_seek(pb, data_size + 10 - 3, SEEK_CUR);
551  avio_wb32(pb, data_size + 11);
552  } else {
553  avio_w8(pb,flags);
554  if (par->codec_id == AV_CODEC_ID_VP6F || par->codec_id == AV_CODEC_ID_VP6A) {
555  if (par->extradata_size)
556  avio_w8(pb, par->extradata[0]);
557  else
558  avio_w8(pb, ((FFALIGN(par->width, 16) - par->width) << 4) |
559  (FFALIGN(par->height, 16) - par->height));
560  } else if (par->codec_id == AV_CODEC_ID_AAC)
561  avio_w8(pb, 1); // AAC raw
562  else if (par->codec_id == AV_CODEC_ID_H264) {
563  avio_w8(pb, 1); // AVC NALU
564  avio_wb24(pb, pkt->pts - pkt->dts);
565  }
566 
567  avio_write(pb, data ? data : pkt->data, size);
568 
569  avio_wb32(pb, size + flags_size + 11); // previous tag size
570  flv->duration = FFMAX(flv->duration,
571  pkt->pts + flv->delay + pkt->duration);
572  }
573 
574  av_free(data);
575 
576  return pb->error;
577 }
578 
580  .name = "flv",
581  .long_name = NULL_IF_CONFIG_SMALL("FLV (Flash Video)"),
582  .mime_type = "video/x-flv",
583  .extensions = "flv",
584  .priv_data_size = sizeof(FLVContext),
586  .video_codec = AV_CODEC_ID_FLV1,
590  .codec_tag = (const AVCodecTag* const []) {
592  },
595 };
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:392
static const AVCodecTag flv_audio_codec_ids[]
Definition: flvenc.c:44
#define CONFIG_LIBMP3LAME
Definition: config.h:368
Bytestream IO Context.
Definition: avio.h:104
#define AVSTREAM_EVENT_FLAG_METADATA_UPDATED
The call resulted in updated metadata.
Definition: avformat.h:820
int size
AVOutputFormat ff_flv_muxer
Definition: flvenc.c:579
double framerate
Definition: flvenc.c:67
int64_t delay
first dts delay (needed for AVC & Speex)
Definition: flvenc.c:63
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:130
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.
Definition: utils.c:2986
const char * desc
Definition: nvenc.c:101
int64_t duration
Definition: flvenc.c:62
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3483
int num
numerator
Definition: rational.h:44
int size
Definition: avcodec.h:1347
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:242
static int unsupported_codec(AVFormatContext *s, const char *type, int codec_id)
Definition: flvenc.c:301
static av_always_inline uint64_t av_double2int(double f)
Reinterpret a double as a 64-bit integer.
Definition: intfloat.h:70
int event_flags
Flags for the user to detect events happening on the file.
Definition: avformat.h:1218
void * priv_data
Definition: avformat.h:720
unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
Definition: utils.c:1973
static int get_audio_flags(AVFormatContext *s, AVCodecParameters *par)
Definition: flvenc.c:75
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:430
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3475
static const AVCodecTag flv_video_codec_ids[]
Definition: flvenc.c:34
Format I/O context.
Definition: avformat.h:940
internal metadata API header see avformat.h or the public API!
Public dictionary API.
uint8_t
Opaque data information usually continuous.
Definition: avutil.h:196
int width
Video only.
Definition: avcodec.h:3525
AVCodecParameters * video_par
Definition: flvenc.c:66
int64_t pos
Definition: flvdec.c:56
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1364
#define b
Definition: input.c:52
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
Definition: aviobuf.c:422
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1008
A point in the output bytestream where a demuxer can start parsing (for non self synchronizing bytest...
Definition: avio.h:77
const char data[16]
Definition: mxf.c:70
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:38
uint8_t * data
Definition: avcodec.h:1346
static int flags
Definition: log.c:50
uint32_t tag
Definition: movenc.c:854
AVCodecParameters * audio_par
Definition: flvenc.c:65
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:295
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:221
#define FFALIGN(x, a)
Definition: macros.h:48
static int write_trailer(AVFormatContext *s)
Definition: assenc.c:64
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1378
static int flv_write_trailer(AVFormatContext *s)
Definition: flvenc.c:418
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1148
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:190
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:479
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3479
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:781
#define FFMAX(a, b)
Definition: common.h:64
int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size)
Definition: avc.c:92
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1352
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:2462
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3501
int bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:3512
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:996
#define FLV_AUDIO_CODECID_OFFSET
Definition: flv.h:34
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:86
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:241
static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: flvenc.c:451
enum AVCodecID codec_id
Definition: avconv_vaapi.c:149
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:419
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:416
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: avio.h:286
const char * name
Definition: avformat.h:450
int reserved
Definition: flvenc.c:59
NULL
Definition: eval.c:55
FLV common header.
AVIOContext * pb
I/O context.
Definition: avformat.h:982
static int flv_write_header(AVFormatContext *s)
Definition: flvenc.c:312
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:200
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
Definition: avconv.c:278
static void put_amf_string(AVIOContext *pb, const char *str)
Definition: flvenc.c:164
static void put_amf_double(AVIOContext *pb, double d)
Definition: flvenc.c:184
AVCodecParameters * data_par
Definition: flvenc.c:68
const char * name
Name of the codec described by this descriptor.
Definition: avcodec.h:588
int error
contains the error code or 0 if no error happened
Definition: avio.h:138
This struct describes the properties of a single codec described by an AVCodecID. ...
Definition: avcodec.h:580
#define AMF_END_OF_OBJECT
Definition: flv.h:47
Definition: flv.h:62
static void put_amf_bool(AVIOContext *pb, int b)
Definition: flvenc.c:190
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:404
int sample_rate
Audio only.
Definition: avcodec.h:3564
Main libavformat public API header.
int64_t duration_offset
Definition: flvenc.c:60
raw UTF-8 text
Definition: avcodec.h:553
static void write_metadata(AVFormatContext *s, unsigned int ts)
Definition: flvenc.c:196
char * key
Definition: dict.h:73
int den
denominator
Definition: rational.h:45
static void put_avc_eos_tag(AVIOContext *pb, unsigned ts)
Definition: flvenc.c:171
A point in the output bytestream where a decoder can start decoding (i.e.
Definition: avio.h:71
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:423
char * value
Definition: dict.h:74
signifies 5512Hz and 8000Hz in the case of NELLYMOSER
Definition: flv.h:71
int len
void * priv_data
Format private data.
Definition: avformat.h:968
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:373
int bits_per_coded_sample
Definition: avcodec.h:3514
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3497
int channels
Audio only.
Definition: avcodec.h:3560
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1345
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:324
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1035
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:60
AVCodecParameters * codecpar
Definition: avformat.h:831
int64_t filesize_offset
Definition: flvenc.c:61
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:3487
int stream_index
Definition: avcodec.h:1348
This structure stores compressed data.
Definition: avcodec.h:1323
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:211
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1339
int64_t last_ts
last timestamp for each stream
Definition: flvenc.c:72
int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
Definition: avc.c:106
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:235