FFmpeg
mpegenc.c
Go to the documentation of this file.
1 /*
2  * MPEG-1/2 muxer
3  * Copyright (c) 2000, 2001, 2002 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 "config_components.h"
23 
24 #include <stdint.h>
25 
26 #include "libavutil/attributes.h"
27 #include "libavutil/fifo.h"
28 #include "libavutil/log.h"
29 #include "libavutil/mathematics.h"
30 #include "libavutil/opt.h"
31 
32 #include "libavcodec/put_bits.h"
33 
34 #include "avformat.h"
35 #include "avio_internal.h"
36 #include "internal.h"
37 #include "mpeg.h"
38 #include "mux.h"
39 
40 #define MAX_PAYLOAD_SIZE 4096
41 
42 typedef struct PacketDesc {
43  int64_t pts;
44  int64_t dts;
45  int size;
47  struct PacketDesc *next;
48 } PacketDesc;
49 
50 typedef struct StreamInfo {
52  uint8_t id;
53  int max_buffer_size; /* in bytes */
55  PacketDesc *predecode_packet; /* start of packet queue */
56  PacketDesc *last_packet; /* end of packet queue */
59  uint8_t lpcm_header[3];
63  int64_t vobu_start_pts;
64 } StreamInfo;
65 
66 typedef struct MpegMuxContext {
67  const AVClass *class;
68  int packet_size; /* required packet size */
70  int pack_header_freq; /* frequency (in packets^-1) at which we send pack headers */
73  int user_mux_rate; /* bitrate in units of bits/s */
74  int mux_rate; /* bitrate in units of 50 bytes/s */
75  /* stream info */
78  int is_mpeg2;
79  int is_vcd;
80  int is_svcd;
81  int is_dvd;
82  int64_t last_scr; /* current system clock */
83 
86 
87  int preload;
89 
94 
95 static int put_pack_header(AVFormatContext *ctx, uint8_t *buf,
96  int64_t timestamp)
97 {
99  PutBitContext pb;
100 
101  init_put_bits(&pb, buf, 128);
102 
104  if (s->is_mpeg2)
105  put_bits(&pb, 2, 0x1);
106  else
107  put_bits(&pb, 4, 0x2);
108  put_bits(&pb, 3, (uint32_t)((timestamp >> 30) & 0x07));
109  put_bits(&pb, 1, 1);
110  put_bits(&pb, 15, (uint32_t)((timestamp >> 15) & 0x7fff));
111  put_bits(&pb, 1, 1);
112  put_bits(&pb, 15, (uint32_t)((timestamp) & 0x7fff));
113  put_bits(&pb, 1, 1);
114  if (s->is_mpeg2)
115  /* clock extension */
116  put_bits(&pb, 9, 0);
117  put_bits(&pb, 1, 1);
118  put_bits(&pb, 22, s->mux_rate);
119  put_bits(&pb, 1, 1);
120  if (s->is_mpeg2) {
121  put_bits(&pb, 1, 1);
122  put_bits(&pb, 5, 0x1f); /* reserved */
123  put_bits(&pb, 3, 0); /* stuffing length */
124  }
125  flush_put_bits(&pb);
126  return put_bits_ptr(&pb) - pb.buf;
127 }
128 
129 static int put_system_header(AVFormatContext *ctx, uint8_t *buf,
130  int only_for_stream_id)
131 {
133  int size, i, private_stream_coded, id;
134  PutBitContext pb;
135 
136  init_put_bits(&pb, buf, 128);
137 
139  put_bits(&pb, 16, 0);
140  put_bits(&pb, 1, 1);
141 
142  /* maximum bit rate of the multiplexed stream */
143  put_bits(&pb, 22, s->mux_rate);
144  put_bits(&pb, 1, 1); /* marker */
145  if (s->is_vcd && only_for_stream_id == VIDEO_ID) {
146  /* This header applies only to the video stream
147  * (see VCD standard p. IV-7) */
148  put_bits(&pb, 6, 0);
149  } else
150  put_bits(&pb, 6, s->audio_bound);
151 
152  if (s->is_vcd) {
153  /* see VCD standard, p. IV-7 */
154  put_bits(&pb, 1, 0);
155  put_bits(&pb, 1, 1);
156  } else {
157  put_bits(&pb, 1, 0); /* variable bitrate */
158  put_bits(&pb, 1, 0); /* nonconstrained bitstream */
159  }
160 
161  if (s->is_vcd || s->is_dvd) {
162  /* see VCD standard p IV-7 */
163  put_bits(&pb, 1, 1); /* audio locked */
164  put_bits(&pb, 1, 1); /* video locked */
165  } else {
166  put_bits(&pb, 1, 0); /* audio locked */
167  put_bits(&pb, 1, 0); /* video locked */
168  }
169 
170  put_bits(&pb, 1, 1); /* marker */
171 
172  if (s->is_vcd && (only_for_stream_id & 0xe0) == AUDIO_ID) {
173  /* This header applies only to the audio stream
174  * (see VCD standard p. IV-7) */
175  put_bits(&pb, 5, 0);
176  } else
177  put_bits(&pb, 5, s->video_bound);
178 
179  if (s->is_dvd) {
180  put_bits(&pb, 1, 0); /* packet_rate_restriction_flag */
181  put_bits(&pb, 7, 0x7f); /* reserved byte */
182  } else
183  put_bits(&pb, 8, 0xff); /* reserved byte */
184 
185  /* DVD-Video Stream_bound entries
186  * id (0xB9) video, maximum P-STD for stream 0xE0. (P-STD_buffer_bound_scale = 1)
187  * id (0xB8) audio, maximum P-STD for any MPEG audio (0xC0 to 0xC7) streams. If there are none set to 4096 (32x128). (P-STD_buffer_bound_scale = 0)
188  * id (0xBD) private stream 1 (audio other than MPEG and subpictures). (P-STD_buffer_bound_scale = 1)
189  * id (0xBF) private stream 2, NAV packs, set to 2x1024. */
190  if (s->is_dvd) {
191 
192  int P_STD_max_video = 0;
193  int P_STD_max_mpeg_audio = 0;
194  int P_STD_max_mpeg_PS1 = 0;
195 
196  for (i = 0; i < ctx->nb_streams; i++) {
197  StreamInfo *stream = ctx->streams[i]->priv_data;
198 
199  id = stream->id;
200  if (id == 0xbd && stream->max_buffer_size > P_STD_max_mpeg_PS1) {
201  P_STD_max_mpeg_PS1 = stream->max_buffer_size;
202  } else if (id >= 0xc0 && id <= 0xc7 &&
203  stream->max_buffer_size > P_STD_max_mpeg_audio) {
204  P_STD_max_mpeg_audio = stream->max_buffer_size;
205  } else if (id == 0xe0 &&
206  stream->max_buffer_size > P_STD_max_video) {
207  P_STD_max_video = stream->max_buffer_size;
208  }
209  }
210 
211  /* video */
212  put_bits(&pb, 8, 0xb9); /* stream ID */
213  put_bits(&pb, 2, 3);
214  put_bits(&pb, 1, 1);
215  put_bits(&pb, 13, P_STD_max_video / 1024);
216 
217  /* audio */
218  if (P_STD_max_mpeg_audio == 0)
219  P_STD_max_mpeg_audio = 4096;
220  put_bits(&pb, 8, 0xb8); /* stream ID */
221  put_bits(&pb, 2, 3);
222  put_bits(&pb, 1, 0);
223  put_bits(&pb, 13, P_STD_max_mpeg_audio / 128);
224 
225  /* private stream 1 */
226  put_bits(&pb, 8, 0xbd); /* stream ID */
227  put_bits(&pb, 2, 3);
228  put_bits(&pb, 1, 0);
229  put_bits(&pb, 13, P_STD_max_mpeg_PS1 / 128);
230 
231  /* private stream 2 */
232  put_bits(&pb, 8, 0xbf); /* stream ID */
233  put_bits(&pb, 2, 3);
234  put_bits(&pb, 1, 1);
235  put_bits(&pb, 13, 2);
236  } else {
237  /* audio stream info */
238  private_stream_coded = 0;
239  for (i = 0; i < ctx->nb_streams; i++) {
240  StreamInfo *stream = ctx->streams[i]->priv_data;
241 
242  /* For VCDs, only include the stream info for the stream
243  * that the pack which contains this system belongs to.
244  * (see VCD standard p. IV-7) */
245  if (!s->is_vcd || stream->id == only_for_stream_id ||
246  only_for_stream_id == 0) {
247  id = stream->id;
248  if (id < 0xc0) {
249  /* special case for private streams (AC-3 uses that) */
250  if (private_stream_coded)
251  continue;
252  private_stream_coded = 1;
253  id = 0xbd;
254  }
255  put_bits(&pb, 8, id); /* stream ID */
256  put_bits(&pb, 2, 3);
257  if (id < 0xe0) {
258  /* audio */
259  put_bits(&pb, 1, 0);
260  put_bits(&pb, 13, stream->max_buffer_size / 128);
261  } else {
262  /* video */
263  put_bits(&pb, 1, 1);
264  put_bits(&pb, 13, stream->max_buffer_size / 1024);
265  }
266  }
267  }
268  }
269 
270  flush_put_bits(&pb);
271  size = put_bits_ptr(&pb) - pb.buf;
272  /* patch packet size */
273  AV_WB16(buf + 4, size - 6);
274 
275  return size;
276 }
277 
279 {
280  int buf_index, i, private_stream_coded;
281  StreamInfo *stream;
283 
284  if (s->is_dvd)
285  return 18; // DVD-Video system headers are 18 bytes fixed length.
286 
287  buf_index = 12;
288  private_stream_coded = 0;
289  for (i = 0; i < ctx->nb_streams; i++) {
290  stream = ctx->streams[i]->priv_data;
291  if (stream->id < 0xc0) {
292  if (private_stream_coded)
293  continue;
294  private_stream_coded = 1;
295  }
296  buf_index += 3;
297  }
298  return buf_index;
299 }
300 
302 {
304  int bitrate, i, mpa_id, mpv_id, h264_id, mps_id, ac3_id, dts_id, lpcm_id, j;
305  AVStream *st;
306  StreamInfo *stream;
307  int audio_bitrate;
308  int video_bitrate;
309 
310  s->packet_number = 0;
311  s->is_vcd = (CONFIG_MPEG1VCD_MUXER && ctx->oformat == &ff_mpeg1vcd_muxer.p);
312  s->is_svcd = (CONFIG_MPEG2SVCD_MUXER && ctx->oformat == &ff_mpeg2svcd_muxer.p);
313  s->is_mpeg2 = ((CONFIG_MPEG2VOB_MUXER && ctx->oformat == &ff_mpeg2vob_muxer.p) ||
314  (CONFIG_MPEG2DVD_MUXER && ctx->oformat == &ff_mpeg2dvd_muxer.p) ||
315  (CONFIG_MPEG2SVCD_MUXER && ctx->oformat == &ff_mpeg2svcd_muxer.p));
316  s->is_dvd = (CONFIG_MPEG2DVD_MUXER && ctx->oformat == &ff_mpeg2dvd_muxer.p);
317 
318  if (ctx->packet_size) {
319  if (ctx->packet_size < 20 || ctx->packet_size > (1 << 23) + 10) {
320  av_log(ctx, AV_LOG_ERROR, "Invalid packet size %d\n",
321  ctx->packet_size);
322  return AVERROR(EINVAL);
323  }
324  s->packet_size = ctx->packet_size;
325  } else
326  s->packet_size = 2048;
327  if (ctx->max_delay < 0) /* Not set by the caller */
328  ctx->max_delay = AV_TIME_BASE*7/10;
329 
330  s->vcd_padding_bytes_written = 0;
331  s->vcd_padding_bitrate_num = 0;
332 
333  s->audio_bound = 0;
334  s->video_bound = 0;
335 
336  mpa_id = AUDIO_ID;
337  ac3_id = AC3_ID;
338  dts_id = DTS_ID;
339  mpv_id = VIDEO_ID;
340  h264_id = H264_ID;
341  mps_id = SUB_ID;
342  lpcm_id = LPCM_ID;
343 
344  for (i = 0; i < ctx->nb_streams; i++) {
345  st = ctx->streams[i];
346  stream = av_mallocz(sizeof(StreamInfo));
347  if (!stream)
348  return AVERROR(ENOMEM);
349  st->priv_data = stream;
350 
351  avpriv_set_pts_info(st, 64, 1, 90000);
352 
353  switch (st->codecpar->codec_type) {
354  case AVMEDIA_TYPE_AUDIO:
355  if (!s->is_mpeg2 &&
356  (st->codecpar->codec_id == AV_CODEC_ID_AC3 ||
361  "%s in MPEG-1 system streams is not widely supported, "
362  "consider using the vob or the dvd muxer "
363  "to force a MPEG-2 program stream.\n",
365  if (st->codecpar->codec_id == AV_CODEC_ID_AC3) {
366  stream->id = ac3_id++;
367  } else if (st->codecpar->codec_id == AV_CODEC_ID_DTS) {
368  stream->id = dts_id++;
369  } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE) {
370  stream->id = lpcm_id++;
371  for (j = 0; j < 4; j++) {
372  if (lpcm_freq_tab[j] == st->codecpar->sample_rate)
373  break;
374  }
375  if (j == 4) {
376  int sr;
377  av_log(ctx, AV_LOG_ERROR, "Invalid sampling rate for PCM stream.\n");
378  av_log(ctx, AV_LOG_INFO, "Allowed sampling rates:");
379  for (sr = 0; sr < 4; sr++)
380  av_log(ctx, AV_LOG_INFO, " %d", lpcm_freq_tab[sr]);
381  av_log(ctx, AV_LOG_INFO, "\n");
382  return AVERROR(EINVAL);
383  }
384  if (st->codecpar->ch_layout.nb_channels > 8) {
385  av_log(ctx, AV_LOG_ERROR, "At most 8 channels allowed for LPCM streams.\n");
386  return AVERROR(EINVAL);
387  }
388  stream->lpcm_header[0] = 0x0c;
389  stream->lpcm_header[1] = (st->codecpar->ch_layout.nb_channels - 1) | (j << 4);
390  stream->lpcm_header[2] = 0x80;
391  stream->lpcm_align = st->codecpar->ch_layout.nb_channels * 2;
392  } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) {
393  int freq;
394 
395  switch (st->codecpar->sample_rate) {
396  case 48000: freq = 0; break;
397  case 96000: freq = 1; break;
398  case 44100: freq = 2; break;
399  case 32000: freq = 3; break;
400  default:
401  av_log(ctx, AV_LOG_ERROR, "Unsupported sample rate.\n");
402  return AVERROR(EINVAL);
403  }
404 
405  stream->lpcm_header[0] = 0x0c;
406  stream->lpcm_header[1] = (freq << 4) |
407  (((st->codecpar->bits_per_coded_sample - 16) / 4) << 6) |
408  st->codecpar->ch_layout.nb_channels - 1;
409  stream->lpcm_header[2] = 0x80;
410  stream->id = lpcm_id++;
412  } else if (st->codecpar->codec_id == AV_CODEC_ID_MLP ||
414  av_log(ctx, AV_LOG_ERROR, "Support for muxing audio codec %s not implemented.\n",
416  return AVERROR_PATCHWELCOME;
417  } else if (st->codecpar->codec_id != AV_CODEC_ID_MP1 &&
420  av_log(ctx, AV_LOG_ERROR, "Unsupported audio codec. Must be one of mp1, mp2, mp3, 16-bit pcm_dvd, pcm_s16be, ac3 or dts.\n");
421  return AVERROR(EINVAL);
422  } else {
423  stream->id = mpa_id++;
424  }
425 
426  /* This value HAS to be used for VCD (see VCD standard, p. IV-7).
427  * Right now it is also used for everything else. */
428  stream->max_buffer_size = 4 * 1024;
429  s->audio_bound++;
430  break;
431  case AVMEDIA_TYPE_VIDEO: {
432  const AVPacketSideData *sd;
433  AVCPBProperties *props = NULL;
434  if (st->codecpar->codec_id == AV_CODEC_ID_H264)
435  stream->id = h264_id++;
436  else
437  stream->id = mpv_id++;
438 
442  if (sd)
443  props = (AVCPBProperties*)sd->data;
444  if (props && props->buffer_size)
445  stream->max_buffer_size = 6 * 1024 + props->buffer_size / 8;
446  else {
448  "VBV buffer size not set, using default size of 230KB\n"
449  "If you want the mpeg file to be compliant to some specification\n"
450  "Like DVD, VCD or others, make sure you set the correct buffer size\n");
451  // FIXME: this is probably too small as default
452  stream->max_buffer_size = 230 * 1024;
453  }
454  if (stream->max_buffer_size > 1024 * 8191) {
455  av_log(ctx, AV_LOG_WARNING, "buffer size %d, too large\n", stream->max_buffer_size);
456  stream->max_buffer_size = 1024 * 8191;
457  }
458  s->video_bound++;
459  break;
460  }
462  stream->id = mps_id++;
463  stream->max_buffer_size = 16 * 1024;
464  break;
465  default:
466  av_log(ctx, AV_LOG_ERROR, "Invalid media type %s for output stream #%d\n",
468  return AVERROR(EINVAL);
469  }
470  stream->fifo = av_fifo_alloc2(16, 1, 0);
471  if (!stream->fifo)
472  return AVERROR(ENOMEM);
473  }
474  bitrate = 0;
475  audio_bitrate = 0;
476  video_bitrate = 0;
477  for (i = 0; i < ctx->nb_streams; i++) {
478  const AVPacketSideData *sd;
479  AVCPBProperties *props = NULL;
480  int codec_rate;
481  st = ctx->streams[i];
482  stream = (StreamInfo *)st->priv_data;
483 
487  if (sd)
488  props = (AVCPBProperties*)sd->data;
489  if (props)
490  codec_rate = props->max_bitrate;
491  else
492  codec_rate = st->codecpar->bit_rate;
493 
494  if (!codec_rate)
495  codec_rate = (1 << 21) * 8 * 50 / ctx->nb_streams;
496 
497  bitrate += codec_rate;
498 
499  if ((stream->id & 0xe0) == AUDIO_ID)
500  audio_bitrate += codec_rate;
501  else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
502  video_bitrate += codec_rate;
503  }
504 
505  if (s->user_mux_rate) {
506  s->mux_rate = (s->user_mux_rate + (8 * 50) - 1) / (8 * 50);
507  } else {
508  /* we increase slightly the bitrate to take into account the
509  * headers. XXX: compute it exactly */
510  bitrate += bitrate / 20;
511  bitrate += 10000;
512  s->mux_rate = (bitrate + (8 * 50) - 1) / (8 * 50);
513  if (s->mux_rate >= (1<<22)) {
514  av_log(ctx, AV_LOG_WARNING, "mux rate %d is too large\n", s->mux_rate);
515  s->mux_rate = (1<<22) - 1;
516  }
517  }
518 
519  if (s->is_vcd) {
520  int64_t overhead_rate;
521 
522  /* The VCD standard mandates that the mux_rate field is 3528
523  * (see standard p. IV-6).
524  * The value is actually "wrong", i.e. if you calculate
525  * it using the normal formula and the 75 sectors per second transfer
526  * rate you get a different value because the real pack size is 2324,
527  * not 2352. But the standard explicitly specifies that the mux_rate
528  * field in the header must have this value. */
529  // s->mux_rate = 2352 * 75 / 50; /* = 3528 */
530 
531  /* The VCD standard states that the muxed stream must be
532  * exactly 75 packs / second (the data rate of a single speed cdrom).
533  * Since the video bitrate (probably 1150000 bits/sec) will be below
534  * the theoretical maximum we have to add some padding packets
535  * to make up for the lower data rate.
536  * (cf. VCD standard p. IV-6 ) */
537 
538  /* Add the header overhead to the data rate.
539  * 2279 data bytes per audio pack, 2294 data bytes per video pack */
540  overhead_rate = audio_bitrate * 2294LL * (2324 - 2279);
541  overhead_rate += video_bitrate * 2279LL * (2324 - 2294);
542 
543  /* Add padding so that the full bitrate is 2324*75 bytes/sec */
544  s->vcd_padding_bitrate_num = (2324LL * 75 * 8 - bitrate) * 2279 * 2294 - overhead_rate;
545 #define VCD_PADDING_BITRATE_DEN (2279 * 2294)
546  }
547 
548  if (s->is_vcd || s->is_mpeg2)
549  /* every packet */
550  s->pack_header_freq = 1;
551  else
552  /* every 2 seconds */
553  s->pack_header_freq = 2 * bitrate / s->packet_size / 8;
554 
555  /* the above seems to make pack_header_freq zero sometimes */
556  if (s->pack_header_freq == 0)
557  s->pack_header_freq = 1;
558 
559  if (s->is_mpeg2)
560  /* every 200 packets. Need to look at the spec. */
561  s->system_header_freq = s->pack_header_freq * 40;
562  else if (s->is_vcd)
563  /* the standard mandates that there are only two system headers
564  * in the whole file: one in the first packet of each stream.
565  * (see standard p. IV-7 and IV-8) */
566  s->system_header_freq = 0x7fffffff;
567  else
568  s->system_header_freq = s->pack_header_freq * 5;
569 
570  for (i = 0; i < ctx->nb_streams; i++) {
571  stream = ctx->streams[i]->priv_data;
572  stream->packet_number = 0;
573  }
574  s->system_header_size = get_system_header_size(ctx);
575  s->last_scr = AV_NOPTS_VALUE;
576  return 0;
577 }
578 
579 static inline void put_timestamp(AVIOContext *pb, int id, int64_t timestamp)
580 {
581  avio_w8(pb, (id << 4) | (((timestamp >> 30) & 0x07) << 1) | 1);
582  avio_wb16(pb, (uint16_t)((((timestamp >> 15) & 0x7fff) << 1) | 1));
583  avio_wb16(pb, (uint16_t)((((timestamp) & 0x7fff) << 1) | 1));
584 }
585 
586 /* return the number of padding bytes that should be inserted into
587  * the multiplexed stream. */
589 {
591  int pad_bytes = 0;
592 
593  if (s->vcd_padding_bitrate_num > 0 && pts != AV_NOPTS_VALUE) {
594  int64_t full_pad_bytes;
595 
596  // FIXME: this is wrong
597  full_pad_bytes =
598  av_rescale(s->vcd_padding_bitrate_num, pts, 90000LL * 8 * VCD_PADDING_BITRATE_DEN);
599  pad_bytes = (int)(full_pad_bytes - s->vcd_padding_bytes_written);
600 
601  if (pad_bytes < 0)
602  /* might happen if we have already padded to a later timestamp. This
603  * can occur if another stream has already advanced further. */
604  pad_bytes = 0;
605  }
606 
607  return pad_bytes;
608 }
609 
610 /* Write an MPEG padding packet header. */
612  int packet_bytes)
613 {
615 
617  avio_wb16(pb, packet_bytes - 6);
618  if (!s->is_mpeg2) {
619  avio_w8(pb, 0x0f);
620  packet_bytes -= 7;
621  } else
622  packet_bytes -= 6;
623 
624  ffio_fill(pb, 0xff, packet_bytes);
625 }
626 
627 static int get_nb_frames(AVFormatContext *ctx, StreamInfo *stream, int len)
628 {
629  int nb_frames = 0;
630  PacketDesc *pkt_desc = stream->premux_packet;
631 
632  while (len > 0) {
633  if (pkt_desc->size == pkt_desc->unwritten_size)
634  nb_frames++;
635  len -= pkt_desc->unwritten_size;
636  pkt_desc = pkt_desc->next;
637  }
638 
639  return nb_frames;
640 }
641 
642 static int fifo_avio_wrapper(void *opaque, void *buf, size_t *nb_elems)
643 {
644  avio_write(opaque, buf, *nb_elems);
645  return 0;
646 }
647 
648 /* flush the packet on stream stream_index */
649 static int flush_packet(AVFormatContext *ctx, int stream_index,
650  int64_t pts, int64_t dts, int64_t scr, int trailer_size)
651 {
653  StreamInfo *stream = ctx->streams[stream_index]->priv_data;
654  uint8_t *buf_ptr;
655  int size, payload_size, startcode, id, stuffing_size, header_len;
656  int packet_size;
657  uint8_t buffer[128];
658  int zero_trail_bytes = 0;
659  int pad_packet_bytes = 0;
660  int pes_flags;
661  /* "general" pack without data specific to one stream? */
662  int general_pack = 0;
663  int nb_frames;
664 
665  id = stream->id;
666 
667  av_log(ctx, AV_LOG_TRACE, "packet ID=%2x PTS=%0.3f\n", id, pts / 90000.0);
668 
669  buf_ptr = buffer;
670 
671  if ((s->packet_number % s->pack_header_freq) == 0 || s->last_scr != scr) {
672  /* output pack and systems header if needed */
673  size = put_pack_header(ctx, buf_ptr, scr);
674  buf_ptr += size;
675  s->last_scr = scr;
676 
677  if (s->is_vcd) {
678  /* there is exactly one system header for each stream in a VCD MPEG,
679  * One in the very first video packet and one in the very first
680  * audio packet (see VCD standard p. IV-7 and IV-8). */
681 
682  if (stream->packet_number == 0) {
683  size = put_system_header(ctx, buf_ptr, id);
684  buf_ptr += size;
685  }
686  } else if (s->is_dvd) {
687  if (stream->align_iframe || s->packet_number == 0) {
688  int PES_bytes_to_fill = s->packet_size - size - 10;
689 
690  if (pts != AV_NOPTS_VALUE) {
691  if (dts != pts)
692  PES_bytes_to_fill -= 5 + 5;
693  else
694  PES_bytes_to_fill -= 5;
695  }
696 
697  if (stream->bytes_to_iframe == 0 || s->packet_number == 0) {
698  size = put_system_header(ctx, buf_ptr, 0);
699  buf_ptr += size;
700  size = buf_ptr - buffer;
702 
704  avio_wb16(ctx->pb, 0x03d4); // length
705  avio_w8(ctx->pb, 0x00); // substream ID, 00=PCI
706  ffio_fill(ctx->pb, 0x00, 979);
707 
709  avio_wb16(ctx->pb, 0x03fa); // length
710  avio_w8(ctx->pb, 0x01); // substream ID, 01=DSI
711  ffio_fill(ctx->pb, 0x00, 1017);
712 
713  memset(buffer, 0, 128);
714  buf_ptr = buffer;
715  s->packet_number++;
716  stream->align_iframe = 0;
717  // FIXME: rounding and first few bytes of each packet
718  scr += s->packet_size * 90000LL /
719  (s->mux_rate * 50LL);
720  size = put_pack_header(ctx, buf_ptr, scr);
721  s->last_scr = scr;
722  buf_ptr += size;
723  /* GOP Start */
724  } else if (stream->bytes_to_iframe < PES_bytes_to_fill) {
725  pad_packet_bytes = PES_bytes_to_fill -
726  stream->bytes_to_iframe;
727  }
728  }
729  } else {
730  if ((s->packet_number % s->system_header_freq) == 0) {
731  size = put_system_header(ctx, buf_ptr, 0);
732  buf_ptr += size;
733  }
734  }
735  }
736  size = buf_ptr - buffer;
738 
739  packet_size = s->packet_size - size;
740 
741  if (s->is_vcd && (id & 0xe0) == AUDIO_ID)
742  /* The VCD standard demands that 20 zero bytes follow
743  * each audio pack (see standard p. IV-8). */
744  zero_trail_bytes += 20;
745 
746  if ((s->is_vcd && stream->packet_number == 0) ||
747  (s->is_svcd && s->packet_number == 0)) {
748  /* for VCD the first pack of each stream contains only the pack header,
749  * the system header and lots of padding (see VCD standard p. IV-6).
750  * In the case of an audio pack, 20 zero bytes are also added at
751  * the end. */
752  /* For SVCD we fill the very first pack to increase compatibility with
753  * some DVD players. Not mandated by the standard. */
754  if (s->is_svcd)
755  /* the system header refers to both streams and no stream data */
756  general_pack = 1;
757  pad_packet_bytes = packet_size - zero_trail_bytes;
758  }
759 
760  packet_size -= pad_packet_bytes + zero_trail_bytes;
761 
762  if (packet_size > 0) {
763  size_t fifo_data;
764  /* packet header size */
765  packet_size -= 6;
766 
767  /* packet header */
768  if (s->is_mpeg2) {
769  header_len = 3;
770  if (stream->packet_number == 0)
771  header_len += 3; /* PES extension */
772  header_len += 1; /* obligatory stuffing byte */
773  } else {
774  header_len = 0;
775  }
776  if (pts != AV_NOPTS_VALUE) {
777  if (dts != pts)
778  header_len += 5 + 5;
779  else
780  header_len += 5;
781  } else {
782  if (!s->is_mpeg2)
783  header_len++;
784  }
785 
786  payload_size = packet_size - header_len;
787  if (id < 0xc0) {
788  startcode = PRIVATE_STREAM_1;
789  payload_size -= 1;
790  if (id >= 0x40) {
791  payload_size -= 3;
792  if (id >= 0xa0)
793  payload_size -= 3;
794  }
795  } else {
796  startcode = 0x100 + id;
797  }
798 
799  stuffing_size = payload_size - av_fifo_can_read(stream->fifo);
800 
801  // first byte does not fit -> reset pts/dts + stuffing
802  if (payload_size <= trailer_size && pts != AV_NOPTS_VALUE) {
803  int timestamp_len = 0;
804  if (dts != pts)
805  timestamp_len += 5;
806  if (pts != AV_NOPTS_VALUE)
807  timestamp_len += s->is_mpeg2 ? 5 : 4;
808  pts =
809  dts = AV_NOPTS_VALUE;
810  header_len -= timestamp_len;
811  if (s->is_dvd && stream->align_iframe) {
812  pad_packet_bytes += timestamp_len;
813  packet_size -= timestamp_len;
814  } else {
815  payload_size += timestamp_len;
816  }
817  stuffing_size += timestamp_len;
818  if (payload_size > trailer_size)
819  stuffing_size += payload_size - trailer_size;
820  }
821 
822  // can't use padding, so use stuffing
823  if (pad_packet_bytes > 0 && pad_packet_bytes <= 7) {
824  packet_size += pad_packet_bytes;
825  payload_size += pad_packet_bytes; // undo the previous adjustment
826  if (stuffing_size < 0)
827  stuffing_size = pad_packet_bytes;
828  else
829  stuffing_size += pad_packet_bytes;
830  pad_packet_bytes = 0;
831  }
832 
833  if (stuffing_size < 0)
834  stuffing_size = 0;
835 
836  if (startcode == PRIVATE_STREAM_1 && id >= 0xa0) {
837  if (payload_size < av_fifo_can_read(stream->fifo))
838  stuffing_size += payload_size % stream->lpcm_align;
839  }
840 
841  if (stuffing_size > 16) { /* <=16 for MPEG-1, <=32 for MPEG-2 */
842  pad_packet_bytes += stuffing_size;
843  packet_size -= stuffing_size;
844  payload_size -= stuffing_size;
845  stuffing_size = 0;
846  }
847 
848  nb_frames = get_nb_frames(ctx, stream, payload_size - stuffing_size);
849 
850  avio_wb32(ctx->pb, startcode);
851 
852  avio_wb16(ctx->pb, packet_size);
853 
854  if (!s->is_mpeg2)
855  ffio_fill(ctx->pb, 0xff, stuffing_size);
856 
857  if (s->is_mpeg2) {
858  avio_w8(ctx->pb, 0x80); /* mpeg2 id */
859 
860  pes_flags = 0;
861 
862  if (pts != AV_NOPTS_VALUE) {
863  pes_flags |= 0x80;
864  if (dts != pts)
865  pes_flags |= 0x40;
866  }
867 
868  /* Both the MPEG-2 and the SVCD standards demand that the
869  * P-STD_buffer_size field be included in the first packet of
870  * every stream. (see SVCD standard p. 26 V.2.3.1 and V.2.3.2
871  * and MPEG-2 standard 2.7.7) */
872  if (stream->packet_number == 0)
873  pes_flags |= 0x01;
874 
875  avio_w8(ctx->pb, pes_flags); /* flags */
876  avio_w8(ctx->pb, header_len - 3 + stuffing_size);
877 
878  if (pes_flags & 0x80) /* write pts */
879  put_timestamp(ctx->pb, (pes_flags & 0x40) ? 0x03 : 0x02, pts);
880  if (pes_flags & 0x40) /* write dts */
881  put_timestamp(ctx->pb, 0x01, dts);
882 
883  if (pes_flags & 0x01) { /* write pes extension */
884  avio_w8(ctx->pb, 0x10); /* flags */
885 
886  /* P-STD buffer info */
887  if ((id & 0xe0) == AUDIO_ID)
888  avio_wb16(ctx->pb, 0x4000 | stream->max_buffer_size / 128);
889  else
890  avio_wb16(ctx->pb, 0x6000 | stream->max_buffer_size / 1024);
891  }
892  } else {
893  if (pts != AV_NOPTS_VALUE) {
894  if (dts != pts) {
895  put_timestamp(ctx->pb, 0x03, pts);
896  put_timestamp(ctx->pb, 0x01, dts);
897  } else {
898  put_timestamp(ctx->pb, 0x02, pts);
899  }
900  } else {
901  avio_w8(ctx->pb, 0x0f);
902  }
903  }
904 
905  if (s->is_mpeg2) {
906  /* special stuffing byte that is always written
907  * to prevent accidental generation of start codes. */
908  avio_w8(ctx->pb, 0xff);
909 
910  ffio_fill(ctx->pb, 0xff, stuffing_size);
911  }
912 
913  if (startcode == PRIVATE_STREAM_1) {
914  avio_w8(ctx->pb, id);
915  if (id >= 0xa0) {
916  /* LPCM (XXX: check nb_frames) */
917  avio_w8(ctx->pb, 7);
918  avio_wb16(ctx->pb, 4); /* skip 3 header bytes */
919  avio_w8(ctx->pb, stream->lpcm_header[0]);
920  avio_w8(ctx->pb, stream->lpcm_header[1]);
921  avio_w8(ctx->pb, stream->lpcm_header[2]);
922  } else if (id >= 0x40) {
923  /* AC-3 */
924  avio_w8(ctx->pb, nb_frames);
925  avio_wb16(ctx->pb, trailer_size + 1);
926  }
927  }
928 
929  /* output data */
930  fifo_data = payload_size - stuffing_size;
931  av_assert0(fifo_data <= av_fifo_can_read(stream->fifo));
932  av_fifo_read_to_cb(stream->fifo, fifo_avio_wrapper, ctx->pb, &fifo_data);
933  stream->bytes_to_iframe -= fifo_data;
934  } else {
935  payload_size =
936  stuffing_size = 0;
937  }
938 
939  if (pad_packet_bytes > 0)
940  put_padding_packet(ctx, ctx->pb, pad_packet_bytes);
941 
942  ffio_fill(ctx->pb, 0x00, zero_trail_bytes);
943 
945 
946  s->packet_number++;
947 
948  /* only increase the stream packet number if this pack actually contains
949  * something that is specific to this stream! I.e. a dedicated header
950  * or some data. */
951  if (!general_pack)
952  stream->packet_number++;
953 
954  return payload_size - stuffing_size;
955 }
956 
958 {
959  /* There are two ways to do this padding: writing a sector/pack
960  * of 0 values, or writing an MPEG padding pack. Both seem to
961  * work with most decoders, BUT the VCD standard only allows a 0-sector
962  * (see standard p. IV-4, IV-5).
963  * So a 0-sector it is... */
964 
966 
967  ffio_fill(ctx->pb, 0, s->packet_size);
968 
969  s->vcd_padding_bytes_written += s->packet_size;
970 
972 
973  /* increasing the packet number is correct. The SCR of the following packs
974  * is calculated from the packet_number and it has to include the padding
975  * sector (it represents the sector index, not the MPEG pack index)
976  * (see VCD standard p. IV-6) */
977  s->packet_number++;
978 }
979 
980 static int remove_decoded_packets(AVFormatContext *ctx, int64_t scr)
981 {
982  int i;
983 
984  for (i = 0; i < ctx->nb_streams; i++) {
985  AVStream *st = ctx->streams[i];
986  StreamInfo *stream = st->priv_data;
987  PacketDesc *pkt_desc;
988 
989  while ((pkt_desc = stream->predecode_packet) &&
990  scr > pkt_desc->dts) { // FIXME: > vs >=
991  if (stream->buffer_index < pkt_desc->size ||
992  stream->predecode_packet == stream->premux_packet) {
994  "buffer underflow st=%d bufi=%d size=%d\n",
995  i, stream->buffer_index, pkt_desc->size);
996  break;
997  }
998  stream->buffer_index -= pkt_desc->size;
999  stream->predecode_packet = pkt_desc->next;
1000  if (!stream->predecode_packet)
1001  stream->last_packet = NULL;
1002  av_freep(&pkt_desc);
1003  }
1004  }
1005 
1006  return 0;
1007 }
1008 
1010 {
1012  AVStream *st;
1013  StreamInfo *stream;
1014  int i, avail_space = 0, es_size, trailer_size;
1015  int best_i = -1;
1016  int best_score = INT_MIN;
1017  int ignore_constraints = 0;
1018  int ignore_delay = 0;
1019  int64_t scr = s->last_scr;
1020  PacketDesc *timestamp_packet;
1021  const int64_t max_delay = av_rescale(ctx->max_delay, 90000, AV_TIME_BASE);
1022 
1023 retry:
1024  for (i = 0; i < ctx->nb_streams; i++) {
1025  AVStream *st = ctx->streams[i];
1026  StreamInfo *stream = st->priv_data;
1027  const size_t avail_data = av_fifo_can_read(stream->fifo);
1028  const int space = stream->max_buffer_size - stream->buffer_index;
1029  int rel_space = 1024LL * space / stream->max_buffer_size;
1030  PacketDesc *next_pkt = stream->premux_packet;
1031 
1032  /* for subtitle, a single PES packet must be generated,
1033  * so we flush after every single subtitle packet */
1034  if (s->packet_size > avail_data && !flush
1036  return 0;
1037  if (avail_data == 0)
1038  continue;
1039  av_assert0(avail_data > 0);
1040 
1041  if (space < s->packet_size && !ignore_constraints)
1042  continue;
1043 
1044  if (next_pkt && next_pkt->dts - scr > max_delay && !ignore_delay)
1045  continue;
1046  if ( stream->predecode_packet
1047  && stream->predecode_packet->size > stream->buffer_index)
1048  rel_space += 1<<28;
1049  if (rel_space > best_score) {
1050  best_score = rel_space;
1051  best_i = i;
1052  avail_space = space;
1053  }
1054  }
1055 
1056  if (best_i < 0) {
1057  int64_t best_dts = INT64_MAX;
1058  int has_premux = 0;
1059 
1060  for (i = 0; i < ctx->nb_streams; i++) {
1061  AVStream *st = ctx->streams[i];
1062  StreamInfo *stream = st->priv_data;
1063  PacketDesc *pkt_desc = stream->predecode_packet;
1064  if (pkt_desc && pkt_desc->dts < best_dts)
1065  best_dts = pkt_desc->dts;
1066  has_premux |= !!stream->premux_packet;
1067  }
1068 
1069  if (best_dts < INT64_MAX) {
1070  av_log(ctx, AV_LOG_TRACE, "bumping scr, scr:%f, dts:%f\n",
1071  scr / 90000.0, best_dts / 90000.0);
1072 
1073  if (scr >= best_dts + 1 && !ignore_constraints) {
1075  "packet too large, ignoring buffer limits to mux it\n");
1076  ignore_constraints = 1;
1077  }
1078  scr = FFMAX(best_dts + 1, scr);
1079  if (remove_decoded_packets(ctx, scr) < 0)
1080  return -1;
1081  } else if (has_premux && flush) {
1083  "delay too large, ignoring ...\n");
1084  ignore_delay = 1;
1085  ignore_constraints = 1;
1086  } else
1087  return 0;
1088 
1089  goto retry;
1090  }
1091 
1092  av_assert0(best_i >= 0);
1093 
1094  st = ctx->streams[best_i];
1095  stream = st->priv_data;
1096 
1097  av_assert0(av_fifo_can_read(stream->fifo) > 0);
1098 
1099  av_assert0(avail_space >= s->packet_size || ignore_constraints);
1100 
1101  timestamp_packet = stream->premux_packet;
1102  if (timestamp_packet->unwritten_size == timestamp_packet->size) {
1103  trailer_size = 0;
1104  } else {
1105  trailer_size = timestamp_packet->unwritten_size;
1106  timestamp_packet = timestamp_packet->next;
1107  }
1108 
1109  if (timestamp_packet) {
1110  av_log(ctx, AV_LOG_TRACE, "dts:%f pts:%f scr:%f stream:%d\n",
1111  timestamp_packet->dts / 90000.0,
1112  timestamp_packet->pts / 90000.0,
1113  scr / 90000.0, best_i);
1114  es_size = flush_packet(ctx, best_i, timestamp_packet->pts,
1115  timestamp_packet->dts, scr, trailer_size);
1116  } else {
1117  av_assert0(av_fifo_can_read(stream->fifo) == trailer_size);
1118  es_size = flush_packet(ctx, best_i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, scr,
1119  trailer_size);
1120  }
1121 
1122  if (s->is_vcd) {
1123  /* Write one or more padding sectors, if necessary, to reach
1124  * the constant overall bitrate. */
1125  int vcd_pad_bytes;
1126 
1127  // FIXME: pts cannot be correct here
1128  while ((vcd_pad_bytes = get_vcd_padding_size(ctx, stream->premux_packet->pts)) >= s->packet_size) {
1130  // FIXME: rounding and first few bytes of each packet
1131  s->last_scr += s->packet_size * 90000LL / (s->mux_rate * 50LL);
1132  }
1133  }
1134 
1135  stream->buffer_index += es_size;
1136  // FIXME: rounding and first few bytes of each packet
1137  s->last_scr += s->packet_size * 90000LL / (s->mux_rate * 50LL);
1138 
1139  while (stream->premux_packet &&
1140  stream->premux_packet->unwritten_size <= es_size) {
1141  es_size -= stream->premux_packet->unwritten_size;
1142  stream->premux_packet = stream->premux_packet->next;
1143  }
1144  if (es_size) {
1145  av_assert0(stream->premux_packet);
1146  stream->premux_packet->unwritten_size -= es_size;
1147  }
1148 
1149  if (remove_decoded_packets(ctx, s->last_scr) < 0)
1150  return -1;
1151 
1152  return 1;
1153 }
1154 
1156 {
1157  int stream_index = pkt->stream_index;
1158  int size = pkt->size;
1159  const uint8_t *buf = pkt->data;
1161  AVStream *st = ctx->streams[stream_index];
1162  StreamInfo *stream = st->priv_data;
1163  int64_t pts, dts;
1164  PacketDesc *pkt_desc;
1165  int preload, ret;
1166  size_t can_write;
1167  const int is_iframe = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
1168  (pkt->flags & AV_PKT_FLAG_KEY);
1169 
1170  preload = av_rescale(s->preload, 90000, AV_TIME_BASE);
1171 
1172  pts = pkt->pts;
1173  dts = pkt->dts;
1174 
1175  if (s->last_scr == AV_NOPTS_VALUE) {
1176  if (dts == AV_NOPTS_VALUE || (dts < preload && ctx->avoid_negative_ts) || s->is_dvd) {
1177  if (dts != AV_NOPTS_VALUE)
1178  s->preload += av_rescale(-dts, AV_TIME_BASE, 90000);
1179  s->last_scr = 0;
1180  } else {
1181  s->last_scr = dts - preload;
1182  s->preload = 0;
1183  }
1184  preload = av_rescale(s->preload, 90000, AV_TIME_BASE);
1185  av_log(ctx, AV_LOG_DEBUG, "First SCR: %"PRId64" First DTS: %"PRId64"\n", s->last_scr, dts + preload);
1186  }
1187 
1188  if (dts != AV_NOPTS_VALUE) dts += preload;
1189  if (pts != AV_NOPTS_VALUE) pts += preload;
1190 
1191  av_log(ctx, AV_LOG_TRACE, "dts:%f pts:%f flags:%d stream:%d nopts:%d\n",
1192  dts / 90000.0, pts / 90000.0, pkt->flags,
1194 
1195  if (st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) {
1196  if (size < 3) {
1197  av_log(ctx, AV_LOG_ERROR, "Invalid packet size %d\n", size);
1198  return AVERROR(EINVAL);
1199  }
1200 
1201  /* Skip first 3 bytes of packet data, which comprise PCM header
1202  and will be written fresh by this muxer. */
1203  buf += 3;
1204  size -= 3;
1205  }
1206 
1207  /* Enlarge the FIFO before adding a new PacketDesc
1208  * in order to avoid inconsistencies on failure. */
1209  can_write = av_fifo_can_write(stream->fifo);
1210  if (can_write < size) {
1211  ret = av_fifo_grow2(stream->fifo, size - can_write);
1212  if (ret < 0)
1213  return ret;
1214  }
1215  pkt_desc = av_mallocz(sizeof(PacketDesc));
1216  if (!pkt_desc)
1217  return AVERROR(ENOMEM);
1218  if (!stream->predecode_packet) {
1219  stream->predecode_packet = pkt_desc;
1220  } else
1221  stream->last_packet->next = pkt_desc;
1222  stream->last_packet = pkt_desc;
1223  if (!stream->premux_packet)
1224  stream->premux_packet = pkt_desc;
1225  pkt_desc->pts = pts;
1226  pkt_desc->dts = dts;
1227  pkt_desc->unwritten_size =
1228  pkt_desc->size = size;
1229 
1230  if (s->is_dvd) {
1231  // min VOBU length 0.4 seconds (mpucoder)
1232  if (is_iframe &&
1233  (s->packet_number == 0 || pts != AV_NOPTS_VALUE &&
1234  (pts - stream->vobu_start_pts >= 36000))) {
1235  stream->bytes_to_iframe = av_fifo_can_read(stream->fifo);
1236  stream->align_iframe = 1;
1237  stream->vobu_start_pts = pts;
1238  }
1239  }
1240 
1241  av_fifo_write(stream->fifo, buf, size);
1242 
1243  for (;;) {
1244  int ret = output_packet(ctx, 0);
1245  if (ret <= 0)
1246  return ret;
1247  }
1248 }
1249 
1251 {
1252  StreamInfo *stream;
1253  int i;
1254 
1255  for (;;) {
1256  int ret = output_packet(ctx, 1);
1257  if (ret < 0)
1258  return ret;
1259  else if (ret == 0)
1260  break;
1261  }
1262 
1263  /* End header according to MPEG-1 systems standard. We do not write
1264  * it as it is usually not needed by decoders and because it
1265  * complicates MPEG stream concatenation. */
1266  // avio_wb32(ctx->pb, ISO_11172_END_CODE);
1267 
1268  for (i = 0; i < ctx->nb_streams; i++) {
1269  stream = ctx->streams[i]->priv_data;
1270 
1271  av_assert0(av_fifo_can_read(stream->fifo) == 0);
1272  }
1273  return 0;
1274 }
1275 
1277 {
1278  for (int i = 0; i < ctx->nb_streams; i++) {
1279  StreamInfo *stream = ctx->streams[i]->priv_data;
1280  if (!stream)
1281  continue;
1282  for (PacketDesc *pkt = stream->predecode_packet; pkt; ) {
1283  PacketDesc *tmp = pkt->next;
1284  av_free(pkt);
1285  pkt = tmp;
1286  }
1287  av_fifo_freep2(&stream->fifo);
1288  }
1289 }
1290 
1291 #define OFFSET(x) offsetof(MpegMuxContext, x)
1292 #define E AV_OPT_FLAG_ENCODING_PARAM
1293 static const AVOption options[] = {
1294  { "muxrate", "mux rate as bits/s", OFFSET(user_mux_rate), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, ((1<<22) - 1) * (8 * 50), E },
1295  { "preload", "initial demux-decode delay in microseconds", OFFSET(preload), AV_OPT_TYPE_INT, { .i64 = 500000 }, 0, INT_MAX, E },
1296  { NULL },
1297 };
1298 
1299 static const AVClass mpeg_class = {
1300  .class_name = "mpeg/(s)vcd/vob/dvd muxer",
1301  .item_name = av_default_item_name,
1302  .version = LIBAVUTIL_VERSION_INT,
1303  .option = options,
1304 };
1305 
1306 #if CONFIG_MPEG1SYSTEM_MUXER
1308  .p.name = "mpeg",
1309  .p.long_name = NULL_IF_CONFIG_SMALL("MPEG-1 Systems / MPEG program stream"),
1310  .p.mime_type = "video/mpeg",
1311  .p.extensions = "mpg,mpeg",
1312  .priv_data_size = sizeof(MpegMuxContext),
1313  .p.audio_codec = AV_CODEC_ID_MP2,
1314  .p.video_codec = AV_CODEC_ID_MPEG1VIDEO,
1315  .write_header = mpeg_mux_init,
1316  .write_packet = mpeg_mux_write_packet,
1317  .write_trailer = mpeg_mux_end,
1318  .deinit = mpeg_mux_deinit,
1319  .p.priv_class = &mpeg_class,
1320 };
1321 #endif
1322 
1323 #if CONFIG_MPEG1VCD_MUXER
1325  .p.name = "vcd",
1326  .p.long_name = NULL_IF_CONFIG_SMALL("MPEG-1 Systems / MPEG program stream (VCD)"),
1327  .p.mime_type = "video/mpeg",
1328  .priv_data_size = sizeof(MpegMuxContext),
1329  .p.audio_codec = AV_CODEC_ID_MP2,
1330  .p.video_codec = AV_CODEC_ID_MPEG1VIDEO,
1331  .write_header = mpeg_mux_init,
1332  .write_packet = mpeg_mux_write_packet,
1333  .write_trailer = mpeg_mux_end,
1334  .deinit = mpeg_mux_deinit,
1335  .p.priv_class = &mpeg_class,
1336 };
1337 #endif
1338 
1339 #if CONFIG_MPEG2VOB_MUXER
1341  .p.name = "vob",
1342  .p.long_name = NULL_IF_CONFIG_SMALL("MPEG-2 PS (VOB)"),
1343  .p.mime_type = "video/mpeg",
1344  .p.extensions = "vob",
1345  .priv_data_size = sizeof(MpegMuxContext),
1346  .p.audio_codec = AV_CODEC_ID_MP2,
1347  .p.video_codec = AV_CODEC_ID_MPEG2VIDEO,
1348  .write_header = mpeg_mux_init,
1349  .write_packet = mpeg_mux_write_packet,
1350  .write_trailer = mpeg_mux_end,
1351  .deinit = mpeg_mux_deinit,
1352  .p.priv_class = &mpeg_class,
1353 };
1354 #endif
1355 
1356 /* Same as mpeg2vob_mux except that the pack size is 2324 */
1357 #if CONFIG_MPEG2SVCD_MUXER
1359  .p.name = "svcd",
1360  .p.long_name = NULL_IF_CONFIG_SMALL("MPEG-2 PS (SVCD)"),
1361  .p.mime_type = "video/mpeg",
1362  .p.extensions = "vob",
1363  .priv_data_size = sizeof(MpegMuxContext),
1364  .p.audio_codec = AV_CODEC_ID_MP2,
1365  .p.video_codec = AV_CODEC_ID_MPEG2VIDEO,
1366  .write_header = mpeg_mux_init,
1367  .write_packet = mpeg_mux_write_packet,
1368  .write_trailer = mpeg_mux_end,
1369  .deinit = mpeg_mux_deinit,
1370  .p.priv_class = &mpeg_class,
1371 };
1372 #endif
1373 
1374 /* Same as mpeg2vob_mux except the 'is_dvd' flag is set to produce NAV pkts */
1375 #if CONFIG_MPEG2DVD_MUXER
1377  .p.name = "dvd",
1378  .p.long_name = NULL_IF_CONFIG_SMALL("MPEG-2 PS (DVD VOB)"),
1379  .p.mime_type = "video/mpeg",
1380  .p.extensions = "dvd",
1381  .priv_data_size = sizeof(MpegMuxContext),
1382  .p.audio_codec = AV_CODEC_ID_MP2,
1383  .p.video_codec = AV_CODEC_ID_MPEG2VIDEO,
1384  .write_header = mpeg_mux_init,
1385  .write_packet = mpeg_mux_write_packet,
1386  .write_trailer = mpeg_mux_end,
1387  .deinit = mpeg_mux_deinit,
1388  .p.priv_class = &mpeg_class,
1389 };
1390 #endif
PacketDesc::pts
int64_t pts
Definition: mpegenc.c:43
StreamInfo::vobu_start_pts
int64_t vobu_start_pts
Definition: mpegenc.c:63
StreamInfo::last_packet
PacketDesc * last_packet
Definition: mpegenc.c:56
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
StreamInfo::lpcm_align
int lpcm_align
Definition: mpegenc.c:60
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
ff_mpeg1system_muxer
const FFOutputFormat ff_mpeg1system_muxer
av_fifo_can_write
size_t av_fifo_can_write(const AVFifo *f)
Definition: fifo.c:94
AV_CODEC_ID_AC3
@ AV_CODEC_ID_AC3
Definition: codec_id.h:443
SYSTEM_HEADER_START_CODE
#define SYSTEM_HEADER_START_CODE
Definition: mpeg.h:29
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
opt.h
StreamInfo::align_iframe
int align_iframe
Definition: mpegenc.c:62
put_bits32
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition: put_bits.h:291
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
space
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated space
Definition: undefined.txt:4
MpegMuxContext::last_scr
int64_t last_scr
Definition: mpegenc.c:82
get_system_header_size
static int get_system_header_size(AVFormatContext *ctx)
Definition: mpegenc.c:278
VCD_PADDING_BITRATE_DEN
#define VCD_PADDING_BITRATE_DEN
AVStream::priv_data
void * priv_data
Definition: avformat.h:768
ff_mpeg2dvd_muxer
const FFOutputFormat ff_mpeg2dvd_muxer
MpegMuxContext::preload
int preload
Definition: mpegenc.c:87
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
mpeg_mux_init
static av_cold int mpeg_mux_init(AVFormatContext *ctx)
Definition: mpegenc.c:301
remove_decoded_packets
static int remove_decoded_packets(AVFormatContext *ctx, int64_t scr)
Definition: mpegenc.c:980
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:222
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1323
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:373
AVPacket::data
uint8_t * data
Definition: packet.h:522
AVOption
AVOption.
Definition: opt.h:346
flush_packet
static int flush_packet(AVFormatContext *ctx, int stream_index, int64_t pts, int64_t dts, int64_t scr, int trailer_size)
Definition: mpegenc.c:649
AUDIO_ID
#define AUDIO_ID
Definition: mpeg.h:41
StreamInfo::lpcm_header
uint8_t lpcm_header[3]
Definition: mpegenc.c:59
mathematics.h
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
get_nb_frames
static int get_nb_frames(AVFormatContext *ctx, StreamInfo *stream, int len)
Definition: mpegenc.c:627
PacketDesc::next
struct PacketDesc * next
Definition: mpegenc.c:47
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:313
MpegMuxContext::system_header_freq
int system_header_freq
Definition: mpegenc.c:71
AV_CODEC_ID_TRUEHD
@ AV_CODEC_ID_TRUEHD
Definition: codec_id.h:484
StreamInfo::packet_number
int packet_number
Definition: mpegenc.c:58
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:577
MpegMuxContext
Definition: mpegenc.c:66
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:36
avio_write_marker
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
Definition: aviobuf.c:460
fifo.h
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: avformat.c:853
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:329
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
MpegMuxContext::is_dvd
int is_dvd
Definition: mpegenc.c:81
output_packet
static int output_packet(AVFormatContext *ctx, int flush)
Definition: mpegenc.c:1009
av_fifo_grow2
int av_fifo_grow2(AVFifo *f, size_t inc)
Enlarge an AVFifo.
Definition: fifo.c:99
MpegMuxContext::audio_bound
int audio_bound
Definition: mpegenc.c:76
pts
static int64_t pts
Definition: transcode_aac.c:643
PacketDesc
Definition: mpegenc.c:42
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:441
StreamInfo::max_buffer_size
int max_buffer_size
Definition: mpegenc.c:53
StreamInfo::id
uint8_t id
Definition: mpegenc.c:52
get_vcd_padding_size
static int get_vcd_padding_size(AVFormatContext *ctx, int64_t pts)
Definition: mpegenc.c:588
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
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
av_cold
#define av_cold
Definition: attributes.h:90
StreamInfo::predecode_packet
PacketDesc * predecode_packet
Definition: mpegenc.c:55
s
#define s(width, name)
Definition: cbs_vp9.c:198
MpegMuxContext::is_mpeg2
int is_mpeg2
Definition: mpegenc.c:78
bitrate
int64_t bitrate
Definition: av1_levels.c:47
H264_ID
#define H264_ID
Definition: mpeg.h:43
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CODEC_ID_MP2
@ AV_CODEC_ID_MP2
Definition: codec_id.h:440
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
StreamInfo::fifo
AVFifo * fifo
Definition: mpegenc.c:51
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AVPacketSideData::data
uint8_t * data
Definition: packet.h:374
ctx
AVFormatContext * ctx
Definition: movenc.c:48
lpcm_freq_tab
static const int lpcm_freq_tab[4]
Definition: mpeg.h:64
MpegMuxContext::mux_rate
int mux_rate
Definition: mpegenc.c:74
MpegMuxContext::user_mux_rate
int user_mux_rate
Definition: mpegenc.c:73
AV_CODEC_ID_PCM_DVD
@ AV_CODEC_ID_PCM_DVD
Definition: codec_id.h:347
AVCodecParameters::nb_coded_side_data
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition: codec_par.h:86
AVCPBProperties
This structure describes the bitrate properties of an encoded bitstream.
Definition: defs.h:269
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
PutBitContext
Definition: put_bits.h:50
MpegMuxContext::is_svcd
int is_svcd
Definition: mpegenc.c:80
PacketDesc::size
int size
Definition: mpegenc.c:45
MpegMuxContext::pack_header_freq
int pack_header_freq
Definition: mpegenc.c:70
if
if(ret)
Definition: filter_design.txt:179
AVFormatContext
Format I/O context.
Definition: avformat.h:1255
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:766
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
PutBitContext::buf
uint8_t * buf
Definition: put_bits.h:53
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
AV_WB16
#define AV_WB16(p, v)
Definition: intreadwrite.h:403
AC3_ID
#define AC3_ID
Definition: mpeg.h:44
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1297
av_fifo_can_read
size_t av_fifo_can_read(const AVFifo *f)
Definition: fifo.c:87
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:367
MpegMuxContext::system_header_size
int system_header_size
Definition: mpegenc.c:72
FFOutputFormat
Definition: mux.h:32
LPCM_ID
#define LPCM_ID
Definition: mpeg.h:46
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:178
StreamInfo::bytes_to_iframe
int bytes_to_iframe
Definition: mpegenc.c:61
put_padding_packet
static void put_padding_packet(AVFormatContext *ctx, AVIOContext *pb, int packet_bytes)
Definition: mpegenc.c:611
ffio_fill
void ffio_fill(AVIOContext *s, int b, int64_t count)
Definition: aviobuf.c:186
PACK_START_CODE
#define PACK_START_CODE
Definition: mpeg.h:28
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
put_timestamp
static void put_timestamp(AVIOContext *pb, int id, int64_t timestamp)
Definition: mpegenc.c:579
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
AV_CODEC_ID_MPEG1VIDEO
@ AV_CODEC_ID_MPEG1VIDEO
Definition: codec_id.h:53
av_packet_side_data_get
const AVPacketSideData * av_packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Get side information from a side data array.
Definition: avpacket.c:654
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1311
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
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
StreamInfo
Definition: mpegenc.c:50
AVPacket::size
int size
Definition: packet.h:523
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:106
PRIVATE_STREAM_1
#define PRIVATE_STREAM_1
Definition: mpeg.h:37
put_vcd_padding_sector
static void put_vcd_padding_sector(AVFormatContext *ctx)
Definition: mpegenc.c:957
AV_CODEC_ID_DTS
@ AV_CODEC_ID_DTS
Definition: codec_id.h:444
size
int size
Definition: twinvq_data.h:10344
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
mpeg_class
static const AVClass mpeg_class
Definition: mpegenc.c:1299
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:521
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:200
avio_wb32
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:364
fifo_avio_wrapper
static int fifo_avio_wrapper(void *opaque, void *buf, size_t *nb_elems)
Definition: mpegenc.c:642
mpeg.h
attributes.h
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:528
StreamInfo::buffer_index
int buffer_index
Definition: mpegenc.c:54
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:406
E
#define E
Definition: mpegenc.c:1292
PRIVATE_STREAM_2
#define PRIVATE_STREAM_2
Definition: mpeg.h:39
AV_PKT_DATA_CPB_PROPERTIES
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
Definition: packet.h:146
StreamInfo::premux_packet
PacketDesc * premux_packet
Definition: mpegenc.c:57
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:515
avio_internal.h
mpeg_mux_end
static int mpeg_mux_end(AVFormatContext *ctx)
Definition: mpegenc.c:1250
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
AVCPBProperties::max_bitrate
int64_t max_bitrate
Maximum bitrate of the stream, in bits per second.
Definition: defs.h:274
AVFormatContext::max_delay
int max_delay
Definition: avformat.h:1400
DTS_ID
#define DTS_ID
Definition: mpeg.h:45
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
ff_mpeg2svcd_muxer
const FFOutputFormat ff_mpeg2svcd_muxer
len
int len
Definition: vorbis_enc_data.h:426
PacketDesc::dts
int64_t dts
Definition: mpegenc.c:44
av_rescale
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:129
MpegMuxContext::vcd_padding_bytes_written
int64_t vcd_padding_bytes_written
Definition: mpegenc.c:85
AVCodecParameters::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
Definition: codec_par.h:81
MpegMuxContext::is_vcd
int is_vcd
Definition: mpegenc.c:79
ff_mpeg1vcd_muxer
const FFOutputFormat ff_mpeg1vcd_muxer
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:743
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
AVFormatContext::oformat
const struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1274
AVCPBProperties::buffer_size
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
Definition: defs.h:290
avformat.h
av_fifo_alloc2
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
Definition: fifo.c:47
id
enum AVCodecID id
Definition: dts2pts.c:364
VIDEO_ID
#define VIDEO_ID
Definition: mpeg.h:42
av_get_media_type_string
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:28
MpegMuxContext::video_bound
int video_bound
Definition: mpegenc.c:77
put_bits_ptr
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
Definition: put_bits.h:377
PADDING_STREAM
#define PADDING_STREAM
Definition: mpeg.h:38
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
OFFSET
#define OFFSET(x)
Definition: mpegenc.c:1291
ff_mpeg2vob_muxer
const FFOutputFormat ff_mpeg2vob_muxer
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
SUB_ID
#define SUB_ID
Definition: mpeg.h:47
AVPacket::stream_index
int stream_index
Definition: packet.h:524
AVFormatContext::packet_size
unsigned int packet_size
Definition: avformat.h:1399
MpegMuxContext::packet_size
int packet_size
Definition: mpegenc.c:68
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: codec_par.h:110
put_system_header
static int put_system_header(AVFormatContext *ctx, uint8_t *buf, int only_for_stream_id)
Definition: mpegenc.c:129
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:143
MpegMuxContext::vcd_padding_bitrate_num
int64_t vcd_padding_bitrate_num
Definition: mpegenc.c:84
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:499
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
avio_wb16
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:442
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:97
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
MpegMuxContext::packet_number
int packet_number
Definition: mpegenc.c:69
av_fifo_freep2
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
Definition: fifo.c:286
int
int
Definition: ffmpeg_filter.c:425
put_bits.h
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:54
options
static const AVOption options[]
Definition: mpegenc.c:1293
AV_CODEC_ID_MP1
@ AV_CODEC_ID_MP1
Definition: codec_id.h:482
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1283
mpeg_mux_deinit
static void mpeg_mux_deinit(AVFormatContext *ctx)
Definition: mpegenc.c:1276
mpeg_mux_write_packet
static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: mpegenc.c:1155
AV_CODEC_ID_MLP
@ AV_CODEC_ID_MLP
Definition: codec_id.h:469
PacketDesc::unwritten_size
int unwritten_size
Definition: mpegenc.c:46
put_pack_header
static int put_pack_header(AVFormatContext *ctx, uint8_t *buf, int64_t timestamp)
Definition: mpegenc.c:95
AVIO_DATA_MARKER_FLUSH_POINT
@ AVIO_DATA_MARKER_FLUSH_POINT
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
Definition: avio.h:145
mux.h