X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fmpegenc.c;h=1e119be10b27b9aef46a66c5d8e73b73a467fb61;hb=31dfe20dd2fe16c2a3a6816d140b8a32dbdc06ba;hp=098e076016720e02e02450cfc25519d1e6fc0bc1;hpb=15c6be8c7da7b94b5e131396e9a82ab6fe4a6b64;p=ffmpeg diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c index 098e0760167..1e119be10b2 100644 --- a/libavformat/mpegenc.c +++ b/libavformat/mpegenc.c @@ -65,6 +65,7 @@ typedef struct { int pack_header_freq; /* frequency (in packets^-1) at which we send pack headers */ int system_header_freq; int system_header_size; + int user_mux_rate; /* bitrate in units of bits/s */ int mux_rate; /* bitrate in units of 50 bytes/s */ /* stream info */ int audio_bound; @@ -318,6 +319,8 @@ static int mpeg_mux_init(AVFormatContext *ctx) s->packet_size = ctx->packet_size; } else s->packet_size = 2048; + if (ctx->max_delay < 0) /* Not set by the caller */ + ctx->max_delay = 0; s->vcd_padding_bytes_written = 0; s->vcd_padding_bitrate=0; @@ -421,7 +424,9 @@ static int mpeg_mux_init(AVFormatContext *ctx) video_bitrate += codec_rate; } - if (!s->mux_rate) { + if (s->user_mux_rate) { + s->mux_rate = (s->user_mux_rate + (8 * 50) - 1) / (8 * 50); + } else { /* we increase slightly the bitrate to take into account the headers. XXX: compute it exactly */ bitrate += bitrate / 20; @@ -830,6 +835,12 @@ static int flush_packet(AVFormatContext *ctx, int stream_index, if (stuffing_size < 0) stuffing_size = 0; + + if (startcode == PRIVATE_STREAM_1 && id >= 0xa0) { + if (payload_size < av_fifo_size(stream->fifo)) + stuffing_size += payload_size % stream->lpcm_align; + } + if (stuffing_size > 16) { /*<=16 for MPEG-1, <=32 for MPEG-2*/ pad_packet_bytes += stuffing_size; packet_size -= stuffing_size; @@ -1235,7 +1246,7 @@ static int mpeg_mux_end(AVFormatContext *ctx) #define OFFSET(x) offsetof(MpegMuxContext, x) #define E AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { - { "muxrate", NULL, OFFSET(mux_rate), AV_OPT_TYPE_INT, {0}, 0, INT_MAX, E }, + { "muxrate", NULL, OFFSET(user_mux_rate), AV_OPT_TYPE_INT, {0}, 0, INT_MAX, E }, { "preload", "Initial demux-decode delay in microseconds.", OFFSET(preload), AV_OPT_TYPE_INT, {500000}, 0, INT_MAX, E}, { NULL }, };