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  AVCPBProperties *props;
346 
347  st = ctx->streams[i];
348  stream = av_mallocz(sizeof(StreamInfo));
349  if (!stream)
350  return AVERROR(ENOMEM);
351  st->priv_data = stream;
352 
353  avpriv_set_pts_info(st, 64, 1, 90000);
354 
355  switch (st->codecpar->codec_type) {
356  case AVMEDIA_TYPE_AUDIO:
357  if (!s->is_mpeg2 &&
358  (st->codecpar->codec_id == AV_CODEC_ID_AC3 ||
363  "%s in MPEG-1 system streams is not widely supported, "
364  "consider using the vob or the dvd muxer "
365  "to force a MPEG-2 program stream.\n",
367  if (st->codecpar->codec_id == AV_CODEC_ID_AC3) {
368  stream->id = ac3_id++;
369  } else if (st->codecpar->codec_id == AV_CODEC_ID_DTS) {
370  stream->id = dts_id++;
371  } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE) {
372  stream->id = lpcm_id++;
373  for (j = 0; j < 4; j++) {
374  if (lpcm_freq_tab[j] == st->codecpar->sample_rate)
375  break;
376  }
377  if (j == 4) {
378  int sr;
379  av_log(ctx, AV_LOG_ERROR, "Invalid sampling rate for PCM stream.\n");
380  av_log(ctx, AV_LOG_INFO, "Allowed sampling rates:");
381  for (sr = 0; sr < 4; sr++)
382  av_log(ctx, AV_LOG_INFO, " %d", lpcm_freq_tab[sr]);
383  av_log(ctx, AV_LOG_INFO, "\n");
384  return AVERROR(EINVAL);
385  }
386  if (st->codecpar->ch_layout.nb_channels > 8) {
387  av_log(ctx, AV_LOG_ERROR, "At most 8 channels allowed for LPCM streams.\n");
388  return AVERROR(EINVAL);
389  }
390  stream->lpcm_header[0] = 0x0c;
391  stream->lpcm_header[1] = (st->codecpar->ch_layout.nb_channels - 1) | (j << 4);
392  stream->lpcm_header[2] = 0x80;
393  stream->lpcm_align = st->codecpar->ch_layout.nb_channels * 2;
394  } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) {
395  int freq;
396 
397  switch (st->codecpar->sample_rate) {
398  case 48000: freq = 0; break;
399  case 96000: freq = 1; break;
400  case 44100: freq = 2; break;
401  case 32000: freq = 3; break;
402  default:
403  av_log(ctx, AV_LOG_ERROR, "Unsupported sample rate.\n");
404  return AVERROR(EINVAL);
405  }
406 
407  stream->lpcm_header[0] = 0x0c;
408  stream->lpcm_header[1] = (freq << 4) |
409  (((st->codecpar->bits_per_coded_sample - 16) / 4) << 6) |
410  st->codecpar->ch_layout.nb_channels - 1;
411  stream->lpcm_header[2] = 0x80;
412  stream->id = lpcm_id++;
414  } else if (st->codecpar->codec_id == AV_CODEC_ID_MLP ||
416  av_log(ctx, AV_LOG_ERROR, "Support for muxing audio codec %s not implemented.\n",
418  return AVERROR_PATCHWELCOME;
419  } else if (st->codecpar->codec_id != AV_CODEC_ID_MP1 &&
422  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");
423  return AVERROR(EINVAL);
424  } else {
425  stream->id = mpa_id++;
426  }
427 
428  /* This value HAS to be used for VCD (see VCD standard, p. IV-7).
429  * Right now it is also used for everything else. */
430  stream->max_buffer_size = 4 * 1024;
431  s->audio_bound++;
432  break;
433  case AVMEDIA_TYPE_VIDEO:
434  if (st->codecpar->codec_id == AV_CODEC_ID_H264)
435  stream->id = h264_id++;
436  else
437  stream->id = mpv_id++;
438 
440  if (props && props->buffer_size)
441  stream->max_buffer_size = 6 * 1024 + props->buffer_size / 8;
442  else {
444  "VBV buffer size not set, using default size of 230KB\n"
445  "If you want the mpeg file to be compliant to some specification\n"
446  "Like DVD, VCD or others, make sure you set the correct buffer size\n");
447  // FIXME: this is probably too small as default
448  stream->max_buffer_size = 230 * 1024;
449  }
450  if (stream->max_buffer_size > 1024 * 8191) {
451  av_log(ctx, AV_LOG_WARNING, "buffer size %d, too large\n", stream->max_buffer_size);
452  stream->max_buffer_size = 1024 * 8191;
453  }
454  s->video_bound++;
455  break;
457  stream->id = mps_id++;
458  stream->max_buffer_size = 16 * 1024;
459  break;
460  default:
461  av_log(ctx, AV_LOG_ERROR, "Invalid media type %s for output stream #%d\n",
463  return AVERROR(EINVAL);
464  }
465  stream->fifo = av_fifo_alloc2(16, 1, 0);
466  if (!stream->fifo)
467  return AVERROR(ENOMEM);
468  }
469  bitrate = 0;
470  audio_bitrate = 0;
471  video_bitrate = 0;
472  for (i = 0; i < ctx->nb_streams; i++) {
473  AVCPBProperties *props;
474  int codec_rate;
475  st = ctx->streams[i];
476  stream = (StreamInfo *)st->priv_data;
477 
479  if (props)
480  codec_rate = props->max_bitrate;
481  else
482  codec_rate = st->codecpar->bit_rate;
483 
484  if (!codec_rate)
485  codec_rate = (1 << 21) * 8 * 50 / ctx->nb_streams;
486 
487  bitrate += codec_rate;
488 
489  if ((stream->id & 0xe0) == AUDIO_ID)
490  audio_bitrate += codec_rate;
491  else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
492  video_bitrate += codec_rate;
493  }
494 
495  if (s->user_mux_rate) {
496  s->mux_rate = (s->user_mux_rate + (8 * 50) - 1) / (8 * 50);
497  } else {
498  /* we increase slightly the bitrate to take into account the
499  * headers. XXX: compute it exactly */
500  bitrate += bitrate / 20;
501  bitrate += 10000;
502  s->mux_rate = (bitrate + (8 * 50) - 1) / (8 * 50);
503  if (s->mux_rate >= (1<<22)) {
504  av_log(ctx, AV_LOG_WARNING, "mux rate %d is too large\n", s->mux_rate);
505  s->mux_rate = (1<<22) - 1;
506  }
507  }
508 
509  if (s->is_vcd) {
510  int64_t overhead_rate;
511 
512  /* The VCD standard mandates that the mux_rate field is 3528
513  * (see standard p. IV-6).
514  * The value is actually "wrong", i.e. if you calculate
515  * it using the normal formula and the 75 sectors per second transfer
516  * rate you get a different value because the real pack size is 2324,
517  * not 2352. But the standard explicitly specifies that the mux_rate
518  * field in the header must have this value. */
519  // s->mux_rate = 2352 * 75 / 50; /* = 3528 */
520 
521  /* The VCD standard states that the muxed stream must be
522  * exactly 75 packs / second (the data rate of a single speed cdrom).
523  * Since the video bitrate (probably 1150000 bits/sec) will be below
524  * the theoretical maximum we have to add some padding packets
525  * to make up for the lower data rate.
526  * (cf. VCD standard p. IV-6 ) */
527 
528  /* Add the header overhead to the data rate.
529  * 2279 data bytes per audio pack, 2294 data bytes per video pack */
530  overhead_rate = audio_bitrate * 2294LL * (2324 - 2279);
531  overhead_rate += video_bitrate * 2279LL * (2324 - 2294);
532 
533  /* Add padding so that the full bitrate is 2324*75 bytes/sec */
534  s->vcd_padding_bitrate_num = (2324LL * 75 * 8 - bitrate) * 2279 * 2294 - overhead_rate;
535 #define VCD_PADDING_BITRATE_DEN (2279 * 2294)
536  }
537 
538  if (s->is_vcd || s->is_mpeg2)
539  /* every packet */
540  s->pack_header_freq = 1;
541  else
542  /* every 2 seconds */
543  s->pack_header_freq = 2 * bitrate / s->packet_size / 8;
544 
545  /* the above seems to make pack_header_freq zero sometimes */
546  if (s->pack_header_freq == 0)
547  s->pack_header_freq = 1;
548 
549  if (s->is_mpeg2)
550  /* every 200 packets. Need to look at the spec. */
551  s->system_header_freq = s->pack_header_freq * 40;
552  else if (s->is_vcd)
553  /* the standard mandates that there are only two system headers
554  * in the whole file: one in the first packet of each stream.
555  * (see standard p. IV-7 and IV-8) */
556  s->system_header_freq = 0x7fffffff;
557  else
558  s->system_header_freq = s->pack_header_freq * 5;
559 
560  for (i = 0; i < ctx->nb_streams; i++) {
561  stream = ctx->streams[i]->priv_data;
562  stream->packet_number = 0;
563  }
564  s->system_header_size = get_system_header_size(ctx);
565  s->last_scr = AV_NOPTS_VALUE;
566  return 0;
567 }
568 
569 static inline void put_timestamp(AVIOContext *pb, int id, int64_t timestamp)
570 {
571  avio_w8(pb, (id << 4) | (((timestamp >> 30) & 0x07) << 1) | 1);
572  avio_wb16(pb, (uint16_t)((((timestamp >> 15) & 0x7fff) << 1) | 1));
573  avio_wb16(pb, (uint16_t)((((timestamp) & 0x7fff) << 1) | 1));
574 }
575 
576 /* return the number of padding bytes that should be inserted into
577  * the multiplexed stream. */
579 {
581  int pad_bytes = 0;
582 
583  if (s->vcd_padding_bitrate_num > 0 && pts != AV_NOPTS_VALUE) {
584  int64_t full_pad_bytes;
585 
586  // FIXME: this is wrong
587  full_pad_bytes =
588  av_rescale(s->vcd_padding_bitrate_num, pts, 90000LL * 8 * VCD_PADDING_BITRATE_DEN);
589  pad_bytes = (int)(full_pad_bytes - s->vcd_padding_bytes_written);
590 
591  if (pad_bytes < 0)
592  /* might happen if we have already padded to a later timestamp. This
593  * can occur if another stream has already advanced further. */
594  pad_bytes = 0;
595  }
596 
597  return pad_bytes;
598 }
599 
600 /* Write an MPEG padding packet header. */
602  int packet_bytes)
603 {
605 
607  avio_wb16(pb, packet_bytes - 6);
608  if (!s->is_mpeg2) {
609  avio_w8(pb, 0x0f);
610  packet_bytes -= 7;
611  } else
612  packet_bytes -= 6;
613 
614  ffio_fill(pb, 0xff, packet_bytes);
615 }
616 
617 static int get_nb_frames(AVFormatContext *ctx, StreamInfo *stream, int len)
618 {
619  int nb_frames = 0;
620  PacketDesc *pkt_desc = stream->premux_packet;
621 
622  while (len > 0) {
623  if (pkt_desc->size == pkt_desc->unwritten_size)
624  nb_frames++;
625  len -= pkt_desc->unwritten_size;
626  pkt_desc = pkt_desc->next;
627  }
628 
629  return nb_frames;
630 }
631 
632 static int fifo_avio_wrapper(void *opaque, void *buf, size_t *nb_elems)
633 {
634  avio_write(opaque, buf, *nb_elems);
635  return 0;
636 }
637 
638 /* flush the packet on stream stream_index */
639 static int flush_packet(AVFormatContext *ctx, int stream_index,
640  int64_t pts, int64_t dts, int64_t scr, int trailer_size)
641 {
643  StreamInfo *stream = ctx->streams[stream_index]->priv_data;
644  uint8_t *buf_ptr;
645  int size, payload_size, startcode, id, stuffing_size, header_len;
646  int packet_size;
647  uint8_t buffer[128];
648  int zero_trail_bytes = 0;
649  int pad_packet_bytes = 0;
650  int pes_flags;
651  /* "general" pack without data specific to one stream? */
652  int general_pack = 0;
653  int nb_frames;
654 
655  id = stream->id;
656 
657  av_log(ctx, AV_LOG_TRACE, "packet ID=%2x PTS=%0.3f\n", id, pts / 90000.0);
658 
659  buf_ptr = buffer;
660 
661  if ((s->packet_number % s->pack_header_freq) == 0 || s->last_scr != scr) {
662  /* output pack and systems header if needed */
663  size = put_pack_header(ctx, buf_ptr, scr);
664  buf_ptr += size;
665  s->last_scr = scr;
666 
667  if (s->is_vcd) {
668  /* there is exactly one system header for each stream in a VCD MPEG,
669  * One in the very first video packet and one in the very first
670  * audio packet (see VCD standard p. IV-7 and IV-8). */
671 
672  if (stream->packet_number == 0) {
673  size = put_system_header(ctx, buf_ptr, id);
674  buf_ptr += size;
675  }
676  } else if (s->is_dvd) {
677  if (stream->align_iframe || s->packet_number == 0) {
678  int PES_bytes_to_fill = s->packet_size - size - 10;
679 
680  if (pts != AV_NOPTS_VALUE) {
681  if (dts != pts)
682  PES_bytes_to_fill -= 5 + 5;
683  else
684  PES_bytes_to_fill -= 5;
685  }
686 
687  if (stream->bytes_to_iframe == 0 || s->packet_number == 0) {
688  size = put_system_header(ctx, buf_ptr, 0);
689  buf_ptr += size;
690  size = buf_ptr - buffer;
692 
694  avio_wb16(ctx->pb, 0x03d4); // length
695  avio_w8(ctx->pb, 0x00); // substream ID, 00=PCI
696  ffio_fill(ctx->pb, 0x00, 979);
697 
699  avio_wb16(ctx->pb, 0x03fa); // length
700  avio_w8(ctx->pb, 0x01); // substream ID, 01=DSI
701  ffio_fill(ctx->pb, 0x00, 1017);
702 
703  memset(buffer, 0, 128);
704  buf_ptr = buffer;
705  s->packet_number++;
706  stream->align_iframe = 0;
707  // FIXME: rounding and first few bytes of each packet
708  scr += s->packet_size * 90000LL /
709  (s->mux_rate * 50LL);
710  size = put_pack_header(ctx, buf_ptr, scr);
711  s->last_scr = scr;
712  buf_ptr += size;
713  /* GOP Start */
714  } else if (stream->bytes_to_iframe < PES_bytes_to_fill) {
715  pad_packet_bytes = PES_bytes_to_fill -
716  stream->bytes_to_iframe;
717  }
718  }
719  } else {
720  if ((s->packet_number % s->system_header_freq) == 0) {
721  size = put_system_header(ctx, buf_ptr, 0);
722  buf_ptr += size;
723  }
724  }
725  }
726  size = buf_ptr - buffer;
728 
729  packet_size = s->packet_size - size;
730 
731  if (s->is_vcd && (id & 0xe0) == AUDIO_ID)
732  /* The VCD standard demands that 20 zero bytes follow
733  * each audio pack (see standard p. IV-8). */
734  zero_trail_bytes += 20;
735 
736  if ((s->is_vcd && stream->packet_number == 0) ||
737  (s->is_svcd && s->packet_number == 0)) {
738  /* for VCD the first pack of each stream contains only the pack header,
739  * the system header and lots of padding (see VCD standard p. IV-6).
740  * In the case of an audio pack, 20 zero bytes are also added at
741  * the end. */
742  /* For SVCD we fill the very first pack to increase compatibility with
743  * some DVD players. Not mandated by the standard. */
744  if (s->is_svcd)
745  /* the system header refers to both streams and no stream data */
746  general_pack = 1;
747  pad_packet_bytes = packet_size - zero_trail_bytes;
748  }
749 
750  packet_size -= pad_packet_bytes + zero_trail_bytes;
751 
752  if (packet_size > 0) {
753  size_t fifo_data;
754  /* packet header size */
755  packet_size -= 6;
756 
757  /* packet header */
758  if (s->is_mpeg2) {
759  header_len = 3;
760  if (stream->packet_number == 0)
761  header_len += 3; /* PES extension */
762  header_len += 1; /* obligatory stuffing byte */
763  } else {
764  header_len = 0;
765  }
766  if (pts != AV_NOPTS_VALUE) {
767  if (dts != pts)
768  header_len += 5 + 5;
769  else
770  header_len += 5;
771  } else {
772  if (!s->is_mpeg2)
773  header_len++;
774  }
775 
776  payload_size = packet_size - header_len;
777  if (id < 0xc0) {
778  startcode = PRIVATE_STREAM_1;
779  payload_size -= 1;
780  if (id >= 0x40) {
781  payload_size -= 3;
782  if (id >= 0xa0)
783  payload_size -= 3;
784  }
785  } else {
786  startcode = 0x100 + id;
787  }
788 
789  stuffing_size = payload_size - av_fifo_can_read(stream->fifo);
790 
791  // first byte does not fit -> reset pts/dts + stuffing
792  if (payload_size <= trailer_size && pts != AV_NOPTS_VALUE) {
793  int timestamp_len = 0;
794  if (dts != pts)
795  timestamp_len += 5;
796  if (pts != AV_NOPTS_VALUE)
797  timestamp_len += s->is_mpeg2 ? 5 : 4;
798  pts =
799  dts = AV_NOPTS_VALUE;
800  header_len -= timestamp_len;
801  if (s->is_dvd && stream->align_iframe) {
802  pad_packet_bytes += timestamp_len;
803  packet_size -= timestamp_len;
804  } else {
805  payload_size += timestamp_len;
806  }
807  stuffing_size += timestamp_len;
808  if (payload_size > trailer_size)
809  stuffing_size += payload_size - trailer_size;
810  }
811 
812  // can't use padding, so use stuffing
813  if (pad_packet_bytes > 0 && pad_packet_bytes <= 7) {
814  packet_size += pad_packet_bytes;
815  payload_size += pad_packet_bytes; // undo the previous adjustment
816  if (stuffing_size < 0)
817  stuffing_size = pad_packet_bytes;
818  else
819  stuffing_size += pad_packet_bytes;
820  pad_packet_bytes = 0;
821  }
822 
823  if (stuffing_size < 0)
824  stuffing_size = 0;
825 
826  if (startcode == PRIVATE_STREAM_1 && id >= 0xa0) {
827  if (payload_size < av_fifo_can_read(stream->fifo))
828  stuffing_size += payload_size % stream->lpcm_align;
829  }
830 
831  if (stuffing_size > 16) { /* <=16 for MPEG-1, <=32 for MPEG-2 */
832  pad_packet_bytes += stuffing_size;
833  packet_size -= stuffing_size;
834  payload_size -= stuffing_size;
835  stuffing_size = 0;
836  }
837 
838  nb_frames = get_nb_frames(ctx, stream, payload_size - stuffing_size);
839 
840  avio_wb32(ctx->pb, startcode);
841 
842  avio_wb16(ctx->pb, packet_size);
843 
844  if (!s->is_mpeg2)
845  ffio_fill(ctx->pb, 0xff, stuffing_size);
846 
847  if (s->is_mpeg2) {
848  avio_w8(ctx->pb, 0x80); /* mpeg2 id */
849 
850  pes_flags = 0;
851 
852  if (pts != AV_NOPTS_VALUE) {
853  pes_flags |= 0x80;
854  if (dts != pts)
855  pes_flags |= 0x40;
856  }
857 
858  /* Both the MPEG-2 and the SVCD standards demand that the
859  * P-STD_buffer_size field be included in the first packet of
860  * every stream. (see SVCD standard p. 26 V.2.3.1 and V.2.3.2
861  * and MPEG-2 standard 2.7.7) */
862  if (stream->packet_number == 0)
863  pes_flags |= 0x01;
864 
865  avio_w8(ctx->pb, pes_flags); /* flags */
866  avio_w8(ctx->pb, header_len - 3 + stuffing_size);
867 
868  if (pes_flags & 0x80) /* write pts */
869  put_timestamp(ctx->pb, (pes_flags & 0x40) ? 0x03 : 0x02, pts);
870  if (pes_flags & 0x40) /* write dts */
871  put_timestamp(ctx->pb, 0x01, dts);
872 
873  if (pes_flags & 0x01) { /* write pes extension */
874  avio_w8(ctx->pb, 0x10); /* flags */
875 
876  /* P-STD buffer info */
877  if ((id & 0xe0) == AUDIO_ID)
878  avio_wb16(ctx->pb, 0x4000 | stream->max_buffer_size / 128);
879  else
880  avio_wb16(ctx->pb, 0x6000 | stream->max_buffer_size / 1024);
881  }
882  } else {
883  if (pts != AV_NOPTS_VALUE) {
884  if (dts != pts) {
885  put_timestamp(ctx->pb, 0x03, pts);
886  put_timestamp(ctx->pb, 0x01, dts);
887  } else {
888  put_timestamp(ctx->pb, 0x02, pts);
889  }
890  } else {
891  avio_w8(ctx->pb, 0x0f);
892  }
893  }
894 
895  if (s->is_mpeg2) {
896  /* special stuffing byte that is always written
897  * to prevent accidental generation of start codes. */
898  avio_w8(ctx->pb, 0xff);
899 
900  ffio_fill(ctx->pb, 0xff, stuffing_size);
901  }
902 
903  if (startcode == PRIVATE_STREAM_1) {
904  avio_w8(ctx->pb, id);
905  if (id >= 0xa0) {
906  /* LPCM (XXX: check nb_frames) */
907  avio_w8(ctx->pb, 7);
908  avio_wb16(ctx->pb, 4); /* skip 3 header bytes */
909  avio_w8(ctx->pb, stream->lpcm_header[0]);
910  avio_w8(ctx->pb, stream->lpcm_header[1]);
911  avio_w8(ctx->pb, stream->lpcm_header[2]);
912  } else if (id >= 0x40) {
913  /* AC-3 */
914  avio_w8(ctx->pb, nb_frames);
915  avio_wb16(ctx->pb, trailer_size + 1);
916  }
917  }
918 
919  /* output data */
920  fifo_data = payload_size - stuffing_size;
921  av_assert0(fifo_data <= av_fifo_can_read(stream->fifo));
922  av_fifo_read_to_cb(stream->fifo, fifo_avio_wrapper, ctx->pb, &fifo_data);
923  stream->bytes_to_iframe -= fifo_data;
924  } else {
925  payload_size =
926  stuffing_size = 0;
927  }
928 
929  if (pad_packet_bytes > 0)
930  put_padding_packet(ctx, ctx->pb, pad_packet_bytes);
931 
932  ffio_fill(ctx->pb, 0x00, zero_trail_bytes);
933 
935 
936  s->packet_number++;
937 
938  /* only increase the stream packet number if this pack actually contains
939  * something that is specific to this stream! I.e. a dedicated header
940  * or some data. */
941  if (!general_pack)
942  stream->packet_number++;
943 
944  return payload_size - stuffing_size;
945 }
946 
948 {
949  /* There are two ways to do this padding: writing a sector/pack
950  * of 0 values, or writing an MPEG padding pack. Both seem to
951  * work with most decoders, BUT the VCD standard only allows a 0-sector
952  * (see standard p. IV-4, IV-5).
953  * So a 0-sector it is... */
954 
956 
957  ffio_fill(ctx->pb, 0, s->packet_size);
958 
959  s->vcd_padding_bytes_written += s->packet_size;
960 
962 
963  /* increasing the packet number is correct. The SCR of the following packs
964  * is calculated from the packet_number and it has to include the padding
965  * sector (it represents the sector index, not the MPEG pack index)
966  * (see VCD standard p. IV-6) */
967  s->packet_number++;
968 }
969 
970 static int remove_decoded_packets(AVFormatContext *ctx, int64_t scr)
971 {
972  int i;
973 
974  for (i = 0; i < ctx->nb_streams; i++) {
975  AVStream *st = ctx->streams[i];
976  StreamInfo *stream = st->priv_data;
977  PacketDesc *pkt_desc;
978 
979  while ((pkt_desc = stream->predecode_packet) &&
980  scr > pkt_desc->dts) { // FIXME: > vs >=
981  if (stream->buffer_index < pkt_desc->size ||
982  stream->predecode_packet == stream->premux_packet) {
984  "buffer underflow st=%d bufi=%d size=%d\n",
985  i, stream->buffer_index, pkt_desc->size);
986  break;
987  }
988  stream->buffer_index -= pkt_desc->size;
989  stream->predecode_packet = pkt_desc->next;
990  if (!stream->predecode_packet)
991  stream->last_packet = NULL;
992  av_freep(&pkt_desc);
993  }
994  }
995 
996  return 0;
997 }
998 
1000 {
1002  AVStream *st;
1003  StreamInfo *stream;
1004  int i, avail_space = 0, es_size, trailer_size;
1005  int best_i = -1;
1006  int best_score = INT_MIN;
1007  int ignore_constraints = 0;
1008  int ignore_delay = 0;
1009  int64_t scr = s->last_scr;
1010  PacketDesc *timestamp_packet;
1011  const int64_t max_delay = av_rescale(ctx->max_delay, 90000, AV_TIME_BASE);
1012 
1013 retry:
1014  for (i = 0; i < ctx->nb_streams; i++) {
1015  AVStream *st = ctx->streams[i];
1016  StreamInfo *stream = st->priv_data;
1017  const size_t avail_data = av_fifo_can_read(stream->fifo);
1018  const int space = stream->max_buffer_size - stream->buffer_index;
1019  int rel_space = 1024LL * space / stream->max_buffer_size;
1020  PacketDesc *next_pkt = stream->premux_packet;
1021 
1022  /* for subtitle, a single PES packet must be generated,
1023  * so we flush after every single subtitle packet */
1024  if (s->packet_size > avail_data && !flush
1026  return 0;
1027  if (avail_data == 0)
1028  continue;
1029  av_assert0(avail_data > 0);
1030 
1031  if (space < s->packet_size && !ignore_constraints)
1032  continue;
1033 
1034  if (next_pkt && next_pkt->dts - scr > max_delay && !ignore_delay)
1035  continue;
1036  if ( stream->predecode_packet
1037  && stream->predecode_packet->size > stream->buffer_index)
1038  rel_space += 1<<28;
1039  if (rel_space > best_score) {
1040  best_score = rel_space;
1041  best_i = i;
1042  avail_space = space;
1043  }
1044  }
1045 
1046  if (best_i < 0) {
1047  int64_t best_dts = INT64_MAX;
1048  int has_premux = 0;
1049 
1050  for (i = 0; i < ctx->nb_streams; i++) {
1051  AVStream *st = ctx->streams[i];
1052  StreamInfo *stream = st->priv_data;
1053  PacketDesc *pkt_desc = stream->predecode_packet;
1054  if (pkt_desc && pkt_desc->dts < best_dts)
1055  best_dts = pkt_desc->dts;
1056  has_premux |= !!stream->premux_packet;
1057  }
1058 
1059  if (best_dts < INT64_MAX) {
1060  av_log(ctx, AV_LOG_TRACE, "bumping scr, scr:%f, dts:%f\n",
1061  scr / 90000.0, best_dts / 90000.0);
1062 
1063  if (scr >= best_dts + 1 && !ignore_constraints) {
1065  "packet too large, ignoring buffer limits to mux it\n");
1066  ignore_constraints = 1;
1067  }
1068  scr = FFMAX(best_dts + 1, scr);
1069  if (remove_decoded_packets(ctx, scr) < 0)
1070  return -1;
1071  } else if (has_premux && flush) {
1073  "delay too large, ignoring ...\n");
1074  ignore_delay = 1;
1075  ignore_constraints = 1;
1076  } else
1077  return 0;
1078 
1079  goto retry;
1080  }
1081 
1082  av_assert0(best_i >= 0);
1083 
1084  st = ctx->streams[best_i];
1085  stream = st->priv_data;
1086 
1087  av_assert0(av_fifo_can_read(stream->fifo) > 0);
1088 
1089  av_assert0(avail_space >= s->packet_size || ignore_constraints);
1090 
1091  timestamp_packet = stream->premux_packet;
1092  if (timestamp_packet->unwritten_size == timestamp_packet->size) {
1093  trailer_size = 0;
1094  } else {
1095  trailer_size = timestamp_packet->unwritten_size;
1096  timestamp_packet = timestamp_packet->next;
1097  }
1098 
1099  if (timestamp_packet) {
1100  av_log(ctx, AV_LOG_TRACE, "dts:%f pts:%f scr:%f stream:%d\n",
1101  timestamp_packet->dts / 90000.0,
1102  timestamp_packet->pts / 90000.0,
1103  scr / 90000.0, best_i);
1104  es_size = flush_packet(ctx, best_i, timestamp_packet->pts,
1105  timestamp_packet->dts, scr, trailer_size);
1106  } else {
1107  av_assert0(av_fifo_can_read(stream->fifo) == trailer_size);
1108  es_size = flush_packet(ctx, best_i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, scr,
1109  trailer_size);
1110  }
1111 
1112  if (s->is_vcd) {
1113  /* Write one or more padding sectors, if necessary, to reach
1114  * the constant overall bitrate. */
1115  int vcd_pad_bytes;
1116 
1117  // FIXME: pts cannot be correct here
1118  while ((vcd_pad_bytes = get_vcd_padding_size(ctx, stream->premux_packet->pts)) >= s->packet_size) {
1120  // FIXME: rounding and first few bytes of each packet
1121  s->last_scr += s->packet_size * 90000LL / (s->mux_rate * 50LL);
1122  }
1123  }
1124 
1125  stream->buffer_index += es_size;
1126  // FIXME: rounding and first few bytes of each packet
1127  s->last_scr += s->packet_size * 90000LL / (s->mux_rate * 50LL);
1128 
1129  while (stream->premux_packet &&
1130  stream->premux_packet->unwritten_size <= es_size) {
1131  es_size -= stream->premux_packet->unwritten_size;
1132  stream->premux_packet = stream->premux_packet->next;
1133  }
1134  if (es_size) {
1135  av_assert0(stream->premux_packet);
1136  stream->premux_packet->unwritten_size -= es_size;
1137  }
1138 
1139  if (remove_decoded_packets(ctx, s->last_scr) < 0)
1140  return -1;
1141 
1142  return 1;
1143 }
1144 
1146 {
1147  int stream_index = pkt->stream_index;
1148  int size = pkt->size;
1149  const uint8_t *buf = pkt->data;
1151  AVStream *st = ctx->streams[stream_index];
1152  StreamInfo *stream = st->priv_data;
1153  int64_t pts, dts;
1154  PacketDesc *pkt_desc;
1155  int preload, ret;
1156  size_t can_write;
1157  const int is_iframe = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
1158  (pkt->flags & AV_PKT_FLAG_KEY);
1159 
1160  preload = av_rescale(s->preload, 90000, AV_TIME_BASE);
1161 
1162  pts = pkt->pts;
1163  dts = pkt->dts;
1164 
1165  if (s->last_scr == AV_NOPTS_VALUE) {
1166  if (dts == AV_NOPTS_VALUE || (dts < preload && ctx->avoid_negative_ts) || s->is_dvd) {
1167  if (dts != AV_NOPTS_VALUE)
1168  s->preload += av_rescale(-dts, AV_TIME_BASE, 90000);
1169  s->last_scr = 0;
1170  } else {
1171  s->last_scr = dts - preload;
1172  s->preload = 0;
1173  }
1174  preload = av_rescale(s->preload, 90000, AV_TIME_BASE);
1175  av_log(ctx, AV_LOG_DEBUG, "First SCR: %"PRId64" First DTS: %"PRId64"\n", s->last_scr, dts + preload);
1176  }
1177 
1178  if (dts != AV_NOPTS_VALUE) dts += preload;
1179  if (pts != AV_NOPTS_VALUE) pts += preload;
1180 
1181  av_log(ctx, AV_LOG_TRACE, "dts:%f pts:%f flags:%d stream:%d nopts:%d\n",
1182  dts / 90000.0, pts / 90000.0, pkt->flags,
1184 
1185  if (st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) {
1186  if (size < 3) {
1187  av_log(ctx, AV_LOG_ERROR, "Invalid packet size %d\n", size);
1188  return AVERROR(EINVAL);
1189  }
1190 
1191  /* Skip first 3 bytes of packet data, which comprise PCM header
1192  and will be written fresh by this muxer. */
1193  buf += 3;
1194  size -= 3;
1195  }
1196 
1197  /* Enlarge the FIFO before adding a new PacketDesc
1198  * in order to avoid inconsistencies on failure. */
1199  can_write = av_fifo_can_write(stream->fifo);
1200  if (can_write < size) {
1201  ret = av_fifo_grow2(stream->fifo, size - can_write);
1202  if (ret < 0)
1203  return ret;
1204  }
1205  pkt_desc = av_mallocz(sizeof(PacketDesc));
1206  if (!pkt_desc)
1207  return AVERROR(ENOMEM);
1208  if (!stream->predecode_packet) {
1209  stream->predecode_packet = pkt_desc;
1210  } else
1211  stream->last_packet->next = pkt_desc;
1212  stream->last_packet = pkt_desc;
1213  if (!stream->premux_packet)
1214  stream->premux_packet = pkt_desc;
1215  pkt_desc->pts = pts;
1216  pkt_desc->dts = dts;
1217  pkt_desc->unwritten_size =
1218  pkt_desc->size = size;
1219 
1220  if (s->is_dvd) {
1221  // min VOBU length 0.4 seconds (mpucoder)
1222  if (is_iframe &&
1223  (s->packet_number == 0 || pts != AV_NOPTS_VALUE &&
1224  (pts - stream->vobu_start_pts >= 36000))) {
1225  stream->bytes_to_iframe = av_fifo_can_read(stream->fifo);
1226  stream->align_iframe = 1;
1227  stream->vobu_start_pts = pts;
1228  }
1229  }
1230 
1231  av_fifo_write(stream->fifo, buf, size);
1232 
1233  for (;;) {
1234  int ret = output_packet(ctx, 0);
1235  if (ret <= 0)
1236  return ret;
1237  }
1238 }
1239 
1241 {
1242  StreamInfo *stream;
1243  int i;
1244 
1245  for (;;) {
1246  int ret = output_packet(ctx, 1);
1247  if (ret < 0)
1248  return ret;
1249  else if (ret == 0)
1250  break;
1251  }
1252 
1253  /* End header according to MPEG-1 systems standard. We do not write
1254  * it as it is usually not needed by decoders and because it
1255  * complicates MPEG stream concatenation. */
1256  // avio_wb32(ctx->pb, ISO_11172_END_CODE);
1257 
1258  for (i = 0; i < ctx->nb_streams; i++) {
1259  stream = ctx->streams[i]->priv_data;
1260 
1261  av_assert0(av_fifo_can_read(stream->fifo) == 0);
1262  }
1263  return 0;
1264 }
1265 
1267 {
1268  for (int i = 0; i < ctx->nb_streams; i++) {
1269  StreamInfo *stream = ctx->streams[i]->priv_data;
1270  if (!stream)
1271  continue;
1272  for (PacketDesc *pkt = stream->predecode_packet; pkt; ) {
1273  PacketDesc *tmp = pkt->next;
1274  av_free(pkt);
1275  pkt = tmp;
1276  }
1277  av_fifo_freep2(&stream->fifo);
1278  }
1279 }
1280 
1281 #define OFFSET(x) offsetof(MpegMuxContext, x)
1282 #define E AV_OPT_FLAG_ENCODING_PARAM
1283 static const AVOption options[] = {
1284  { "muxrate", NULL, OFFSET(user_mux_rate), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, ((1<<22) - 1) * (8 * 50), E },
1285  { "preload", "Initial demux-decode delay in microseconds.", OFFSET(preload), AV_OPT_TYPE_INT, { .i64 = 500000 }, 0, INT_MAX, E },
1286  { NULL },
1287 };
1288 
1289 static const AVClass mpeg_class = {
1290  .class_name = "mpeg/(s)vcd/vob/dvd muxer",
1291  .item_name = av_default_item_name,
1292  .version = LIBAVUTIL_VERSION_INT,
1293  .option = options,
1294 };
1295 
1296 #if CONFIG_MPEG1SYSTEM_MUXER
1298  .p.name = "mpeg",
1299  .p.long_name = NULL_IF_CONFIG_SMALL("MPEG-1 Systems / MPEG program stream"),
1300  .p.mime_type = "video/mpeg",
1301  .p.extensions = "mpg,mpeg",
1302  .priv_data_size = sizeof(MpegMuxContext),
1303  .p.audio_codec = AV_CODEC_ID_MP2,
1304  .p.video_codec = AV_CODEC_ID_MPEG1VIDEO,
1305  .write_header = mpeg_mux_init,
1306  .write_packet = mpeg_mux_write_packet,
1307  .write_trailer = mpeg_mux_end,
1308  .deinit = mpeg_mux_deinit,
1309  .p.priv_class = &mpeg_class,
1310 };
1311 #endif
1312 
1313 #if CONFIG_MPEG1VCD_MUXER
1315  .p.name = "vcd",
1316  .p.long_name = NULL_IF_CONFIG_SMALL("MPEG-1 Systems / MPEG program stream (VCD)"),
1317  .p.mime_type = "video/mpeg",
1318  .priv_data_size = sizeof(MpegMuxContext),
1319  .p.audio_codec = AV_CODEC_ID_MP2,
1320  .p.video_codec = AV_CODEC_ID_MPEG1VIDEO,
1321  .write_header = mpeg_mux_init,
1322  .write_packet = mpeg_mux_write_packet,
1323  .write_trailer = mpeg_mux_end,
1324  .deinit = mpeg_mux_deinit,
1325  .p.priv_class = &mpeg_class,
1326 };
1327 #endif
1328 
1329 #if CONFIG_MPEG2VOB_MUXER
1331  .p.name = "vob",
1332  .p.long_name = NULL_IF_CONFIG_SMALL("MPEG-2 PS (VOB)"),
1333  .p.mime_type = "video/mpeg",
1334  .p.extensions = "vob",
1335  .priv_data_size = sizeof(MpegMuxContext),
1336  .p.audio_codec = AV_CODEC_ID_MP2,
1337  .p.video_codec = AV_CODEC_ID_MPEG2VIDEO,
1338  .write_header = mpeg_mux_init,
1339  .write_packet = mpeg_mux_write_packet,
1340  .write_trailer = mpeg_mux_end,
1341  .deinit = mpeg_mux_deinit,
1342  .p.priv_class = &mpeg_class,
1343 };
1344 #endif
1345 
1346 /* Same as mpeg2vob_mux except that the pack size is 2324 */
1347 #if CONFIG_MPEG2SVCD_MUXER
1349  .p.name = "svcd",
1350  .p.long_name = NULL_IF_CONFIG_SMALL("MPEG-2 PS (SVCD)"),
1351  .p.mime_type = "video/mpeg",
1352  .p.extensions = "vob",
1353  .priv_data_size = sizeof(MpegMuxContext),
1354  .p.audio_codec = AV_CODEC_ID_MP2,
1355  .p.video_codec = AV_CODEC_ID_MPEG2VIDEO,
1356  .write_header = mpeg_mux_init,
1357  .write_packet = mpeg_mux_write_packet,
1358  .write_trailer = mpeg_mux_end,
1359  .deinit = mpeg_mux_deinit,
1360  .p.priv_class = &mpeg_class,
1361 };
1362 #endif
1363 
1364 /* Same as mpeg2vob_mux except the 'is_dvd' flag is set to produce NAV pkts */
1365 #if CONFIG_MPEG2DVD_MUXER
1367  .p.name = "dvd",
1368  .p.long_name = NULL_IF_CONFIG_SMALL("MPEG-2 PS (DVD VOB)"),
1369  .p.mime_type = "video/mpeg",
1370  .p.extensions = "dvd",
1371  .priv_data_size = sizeof(MpegMuxContext),
1372  .p.audio_codec = AV_CODEC_ID_MP2,
1373  .p.video_codec = AV_CODEC_ID_MPEG2VIDEO,
1374  .write_header = mpeg_mux_init,
1375  .write_packet = mpeg_mux_write_packet,
1376  .write_trailer = mpeg_mux_end,
1377  .deinit = mpeg_mux_deinit,
1378  .p.priv_class = &mpeg_class,
1379 };
1380 #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:441
SYSTEM_HEADER_START_CODE
#define SYSTEM_HEADER_START_CODE
Definition: mpeg.h:29
AVOutputFormat::name
const char * name
Definition: avformat.h:508
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:58
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:863
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:970
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:221
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1172
AVPacket::data
uint8_t * data
Definition: packet.h:374
AVOption
AVOption.
Definition: opt.h:251
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:639
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:617
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:311
MpegMuxContext::system_header_freq
int system_header_freq
Definition: mpegenc.c:71
AV_CODEC_ID_TRUEHD
@ AV_CODEC_ID_TRUEHD
Definition: codec_id.h:482
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:429
MpegMuxContext
Definition: mpegenc.c:66
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:34
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:482
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:771
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:327
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:999
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:653
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:439
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:578
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:256
MpegMuxContext::is_mpeg2
int is_mpeg2
Definition: mpegenc.c:78
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:438
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
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
ctx
AVFormatContext * ctx
Definition: movenc.c:48
lpcm_freq_tab
static const int lpcm_freq_tab[4]
Definition: mpeg.h:63
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:345
AVCPBProperties
This structure describes the bitrate properties of an encoded bitstream.
Definition: defs.h:126
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:1104
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:861
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:405
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:1146
av_fifo_can_read
size_t av_fifo_can_read(const AVFifo *f)
Definition: fifo.c:87
MpegMuxContext::system_header_size
int system_header_size
Definition: mpegenc.c:72
FFOutputFormat
Definition: mux.h:30
LPCM_ID
#define LPCM_ID
Definition: mpeg.h:46
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:200
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:601
ffio_fill
void ffio_fill(AVIOContext *s, int b, int64_t count)
Definition: aviobuf.c:208
PACK_START_CODE
#define PACK_START_CODE
Definition: mpeg.h:28
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:213
put_timestamp
static void put_timestamp(AVIOContext *pb, int id, int64_t timestamp)
Definition: mpegenc.c:569
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:178
AV_CODEC_ID_MPEG1VIDEO
@ AV_CODEC_ID_MPEG1VIDEO
Definition: codec_id.h:53
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1160
AVIOContext
Bytestream IO Context.
Definition: avio.h:166
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:375
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:115
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:947
AV_CODEC_ID_DTS
@ AV_CODEC_ID_DTS
Definition: codec_id.h:442
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:1289
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:373
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:222
avio_wb32
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:386
fifo_avio_wrapper
static int fifo_avio_wrapper(void *opaque, void *buf, size_t *nb_elems)
Definition: mpegenc.c:632
mpeg.h
attributes.h
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:380
bitrate
int64_t bitrate
Definition: h264_levels.c:131
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:442
E
#define E
Definition: mpegenc.c:1282
PRIVATE_STREAM_2
#define PRIVATE_STREAM_2
Definition: mpeg.h:39
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:269
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:367
avio_internal.h
mpeg_mux_end
static int mpeg_mux_end(AVFormatContext *ctx)
Definition: mpegenc.c:1240
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:131
AVFormatContext::max_delay
int max_delay
Definition: avformat.h:1216
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
AV_PKT_DATA_CPB_PROPERTIES
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
Definition: packet.h:146
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
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:838
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:1123
AVCPBProperties::buffer_size
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
Definition: defs.h:147
avformat.h
av_stream_get_side_data
uint8_t * av_stream_get_side_data(const AVStream *st, enum AVPacketSideDataType type, size_t *size)
Get side information from stream.
Definition: avformat.c:141
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
VIDEO_ID
#define VIDEO_ID
Definition: mpeg.h:42
id
enum AVCodecID id
Definition: dts2pts_bsf.c:364
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:1281
ff_mpeg2vob_muxer
const FFOutputFormat ff_mpeg2vob_muxer
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
SUB_ID
#define SUB_ID
Definition: mpeg.h:47
AVPacket::stream_index
int stream_index
Definition: packet.h:376
AVFormatContext::packet_size
unsigned int packet_size
Definition: avformat.h:1215
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:104
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:367
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:62
AVPacket
This structure stores compressed data.
Definition: packet.h:351
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
avio_wb16
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:464
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:91
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:156
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:1283
AV_CODEC_ID_MP1
@ AV_CODEC_ID_MP1
Definition: codec_id.h:480
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1132
mpeg_mux_deinit
static void mpeg_mux_deinit(AVFormatContext *ctx)
Definition: mpegenc.c:1266
mpeg_mux_write_packet
static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: mpegenc.c:1145
AV_CODEC_ID_MLP
@ AV_CODEC_ID_MLP
Definition: codec_id.h:467
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:151
mux.h