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