From 8069b44ebfa2f9b86e900f35919f2caae105e25b Mon Sep 17 00:00:00 2001 From: Reinhard Tartler Date: Sun, 6 Jan 2013 15:45:51 +0100 Subject: [PATCH 01/16] Prepare 9.1 Release --- RELEASE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE b/RELEASE index ec635144f6..28a2186428 100644 --- a/RELEASE +++ b/RELEASE @@ -1 +1 @@ -9 +9.1 From a55700541756022043075975bca6a0b7376595b7 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 2 Jan 2013 13:34:48 -0500 Subject: [PATCH 02/16] x86: lavr: use the x86inc.asm automatic stack alignment in mixing functions CC:libav-stable@libav.org (cherry picked from commit 95d01c3f1c33c079db04e24133ba4a6b00d62d4a) Signed-off-by: Reinhard Tartler --- libavresample/x86/audio_mix.asm | 35 +++++++++------------------------ 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/libavresample/x86/audio_mix.asm b/libavresample/x86/audio_mix.asm index daf0a7b335..8a298e2081 100644 --- a/libavresample/x86/audio_mix.asm +++ b/libavresample/x86/audio_mix.asm @@ -260,29 +260,20 @@ MIX_1_TO_2_S16P_FLT %else %assign matrix_elements_stack 0 %endif +%assign matrix_stack_size matrix_elements_stack * mmsize -cglobal mix_%1_to_%2_%3_flt, 3,in_channels+2,needed_mmregs+matrix_elements_mm, src0, src1, len, src2, src3, src4, src5, src6, src7 +%assign needed_stack_size -1 * matrix_stack_size +%if ARCH_X86_32 && in_channels >= 7 +%assign needed_stack_size needed_stack_size - 16 +%endif -; get aligned stack space if needed -%if matrix_elements_stack > 0 - %if mmsize == 32 - %assign bkpreg %1 + 1 - %define bkpq r %+ bkpreg %+ q - mov bkpq, rsp - and rsp, ~(mmsize-1) - sub rsp, matrix_elements_stack * mmsize - %else - %assign matrix_stack_size matrix_elements_stack * mmsize - %assign pad matrix_stack_size + (mmsize - gprsize) - (stack_offset & (mmsize - gprsize)) - ; on x86-32 for 7 and 8 channels we need more stack space for src pointers - %if ARCH_X86_32 && in_channels >= 7 - %assign pad pad + 0x10 +cglobal mix_%1_to_%2_%3_flt, 3,in_channels+2,needed_mmregs+matrix_elements_mm, needed_stack_size, src0, src1, len, src2, src3, src4, src5, src6, src7 + +; define src pointers on stack if needed +%if matrix_elements_stack > 0 && ARCH_X86_32 && in_channels >= 7 %define src5m [rsp+matrix_stack_size+0] %define src6m [rsp+matrix_stack_size+4] %define src7m [rsp+matrix_stack_size+8] - %endif - SUB rsp, pad - %endif %endif ; load matrix pointers @@ -463,14 +454,6 @@ cglobal mix_%1_to_%2_%3_flt, 3,in_channels+2,needed_mmregs+matrix_elements_mm, s add lenq, mmsize jl .loop -; restore stack pointer -%if matrix_elements_stack > 0 - %if mmsize == 32 - mov rsp, bkpq - %else - ADD rsp, pad - %endif -%endif ; zero ymm high halves %if mmsize == 32 vzeroupper From c1555ae4b62a23addfe7265c29cb66cc7a0d886b Mon Sep 17 00:00:00 2001 From: Reinhard Tartler Date: Sun, 6 Jan 2013 18:04:10 +0100 Subject: [PATCH 03/16] update Changelog --- Changelog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Changelog b/Changelog index 92098cacd5..77e77a6371 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,11 @@ Entries are sorted chronologically from oldest to youngest within each release, releases are sorted from youngest to oldest. +version 9.1: +- Fix a crash on windows platforms related to automatic stack alignment + in libavresample + + version 9: - av_basename and av_dirname - adobe and limelight publisher authentication in RTMP From 42bd6d9cf681306d14c92af97a40116fe4eb2522 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Fri, 4 Jan 2013 15:44:02 +0100 Subject: [PATCH 04/16] oggdec: free the ogg streams on read_header failure Plug an annoying memory leak on broken files. (cherry picked from commit 89b51b570daa80e6e3790fcd449fe61fc5574e07) Signed-off-by: Luca Barbato --- libavformat/oggdec.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c index 07af5cf9d0..a6cd31c514 100644 --- a/libavformat/oggdec.c +++ b/libavformat/oggdec.c @@ -526,6 +526,19 @@ static int ogg_get_length(AVFormatContext *s) return 0; } +static int ogg_read_close(AVFormatContext *s) +{ + struct ogg *ogg = s->priv_data; + int i; + + for (i = 0; i < ogg->nstreams; i++) { + av_free(ogg->streams[i].buf); + av_free(ogg->streams[i].private); + } + av_free(ogg->streams); + return 0; +} + static int ogg_read_header(AVFormatContext *s) { struct ogg *ogg = s->priv_data; @@ -533,8 +546,10 @@ static int ogg_read_header(AVFormatContext *s) ogg->curidx = -1; //linear headers seek from start ret = ogg_get_headers(s); - if (ret < 0) + if (ret < 0) { + ogg_read_close(s); return ret; + } for (i = 0; i < ogg->nstreams; i++) if (ogg->streams[i].header < 0) @@ -619,19 +634,6 @@ retry: return psize; } -static int ogg_read_close(AVFormatContext *s) -{ - struct ogg *ogg = s->priv_data; - int i; - - for (i = 0; i < ogg->nstreams; i++) { - av_free(ogg->streams[i].buf); - av_free(ogg->streams[i].private); - } - av_free(ogg->streams); - return 0; -} - static int64_t ogg_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit) { From c01be297ce5ac244d79a7b287f7fa050de113a14 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Fri, 4 Jan 2013 16:05:51 +0100 Subject: [PATCH 05/16] oggdec: make sure the private parse data is cleaned up (cherry picked from commit d894f74762bc95310ba23f804b7ba8dffc8f6646) Signed-off-by: Luca Barbato --- libavformat/oggdec.c | 4 ++++ libavformat/oggdec.h | 1 + libavformat/oggparsevorbis.c | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c index a6cd31c514..d8f89b8f80 100644 --- a/libavformat/oggdec.c +++ b/libavformat/oggdec.c @@ -533,6 +533,10 @@ static int ogg_read_close(AVFormatContext *s) for (i = 0; i < ogg->nstreams; i++) { av_free(ogg->streams[i].buf); + if (ogg->streams[i].codec && + ogg->streams[i].codec->cleanup) { + ogg->streams[i].codec->cleanup(s, i); + } av_free(ogg->streams[i].private); } av_free(ogg->streams); diff --git a/libavformat/oggdec.h b/libavformat/oggdec.h index bb7b345934..d11ff9f591 100644 --- a/libavformat/oggdec.h +++ b/libavformat/oggdec.h @@ -55,6 +55,7 @@ struct ogg_codec { * Number of expected headers */ int nb_header; + void (*cleanup)(AVFormatContext *s, int idx); }; struct ogg_stream { diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c index 396a3e3ea7..fbe6c4fb41 100644 --- a/libavformat/oggparsevorbis.c +++ b/libavformat/oggparsevorbis.c @@ -192,6 +192,16 @@ fixup_vorbis_headers(AVFormatContext * as, struct oggvorbis_private *priv, return offset; } +static int vorbis_cleanup(AVFormatContext *s, int idx) +{ + struct ogg *ogg = s->priv_data; + struct ogg_stream *os = ogg->streams + idx; + struct oggvorbis_private *priv = os->private; + int i; + if (os->private) + for (i = 0; i < 3; i++) + av_freep(&priv->packet[i]); +} static int vorbis_header (AVFormatContext * s, int idx) @@ -359,5 +369,6 @@ const struct ogg_codec ff_vorbis_codec = { .magicsize = 7, .header = vorbis_header, .packet = vorbis_packet, + .cleanup= vorbis_cleanup, .nb_header = 3, }; From 0135dd73bb23060b896b06f2ecbb05435224f492 Mon Sep 17 00:00:00 2001 From: Reinhard Tartler Date: Sun, 6 Jan 2013 18:04:10 +0100 Subject: [PATCH 06/16] update Changelog --- Changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog b/Changelog index 77e77a6371..7f6249adfa 100644 --- a/Changelog +++ b/Changelog @@ -4,6 +4,7 @@ releases are sorted from youngest to oldest. version 9.1: - Fix a crash on windows platforms related to automatic stack alignment in libavresample +- Fix memleaks in the ogg demuxer. Related to CVE-2012-2882 version 9: From ebd3aa429c38d199f5ee9f578030a3bc6e50056b Mon Sep 17 00:00:00 2001 From: Ronald Bultje Date: Thu, 10 Jan 2013 11:02:57 -0800 Subject: [PATCH 07/16] vp3: Fix double free in vp3_decode_end() Signed-off-by: Dale Curtis Signed-off-by: Luca Barbato (cherry picked from commit ec86ba57312745fd7ad9771e3121e79c6aacba30) Signed-off-by: Luca Barbato --- libavcodec/vp3.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index 6e85b90964..bdd4289a49 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -281,15 +281,15 @@ static av_cold int vp3_decode_end(AVCodecContext *avctx) Vp3DecodeContext *s = avctx->priv_data; int i; - av_free(s->superblock_coding); - av_free(s->all_fragments); - av_free(s->coded_fragment_list[0]); - av_free(s->dct_tokens_base); - av_free(s->superblock_fragments); - av_free(s->macroblock_coding); - av_free(s->motion_val[0]); - av_free(s->motion_val[1]); - av_free(s->edge_emu_buffer); + av_freep(&s->superblock_coding); + av_freep(&s->all_fragments); + av_freep(&s->coded_fragment_list[0]); + av_freep(&s->dct_tokens_base); + av_freep(&s->superblock_fragments); + av_freep(&s->macroblock_coding); + av_freep(&s->motion_val[0]); + av_freep(&s->motion_val[1]); + av_freep(&s->edge_emu_buffer); if (avctx->internal->is_copy) return 0; From ca2e3f113188e5835533d54000c314721b8445db Mon Sep 17 00:00:00 2001 From: Dale Curtis Date: Thu, 10 Jan 2013 11:05:29 -0800 Subject: [PATCH 08/16] matroska: Fix use after free Signed-off-by: Dale Curtis Signed-off-by: Luca Barbato (cherry picked from commit ae3d41636942cbc0236bad21ad06c65f4eb0f096) Signed-off-by: Luca Barbato --- libavformat/matroskadec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index bf67253737..86ff477d85 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1744,6 +1744,7 @@ static int matroska_deliver_packet(MatroskaDemuxContext *matroska, */ static void matroska_clear_queue(MatroskaDemuxContext *matroska) { + matroska->prev_pkt = NULL; if (matroska->packets) { int n; for (n = 0; n < matroska->num_packets; n++) { @@ -2231,7 +2232,6 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, avio_seek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET); matroska->current_id = 0; while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) { - matroska->prev_pkt = NULL; matroska_clear_queue(matroska); if (matroska_parse_cluster(matroska) < 0) break; From 58baa367d696f206709a5eb195bbc514467ac82a Mon Sep 17 00:00:00 2001 From: Vladimir Pantelic Date: Wed, 9 Jan 2013 17:04:09 +0100 Subject: [PATCH 09/16] vc1dec: prevent a crash due missing pred_flag parameter Handle pred_flag parameter not given to get_mvdata_interlaced() Signed-off-by: Vladimir Pantelic Signed-off-by: Luca Barbato (cherry picked from commit 7b8c5b263bc680eff5710bee5994de39d47fc15e) Signed-off-by: Luca Barbato --- libavcodec/vc1dec.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index d5d6884a73..c29f91ce11 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -1133,8 +1133,12 @@ static av_always_inline void get_mvdata_interlaced(VC1Context *v, int *dmv_x, *dmv_x = get_bits(gb, v->k_x); *dmv_y = get_bits(gb, v->k_y); if (v->numref) { - *pred_flag = *dmv_y & 1; - *dmv_y = (*dmv_y + *pred_flag) >> 1; + if (pred_flag) { + *pred_flag = *dmv_y & 1; + *dmv_y = (*dmv_y + *pred_flag) >> 1; + } else { + *dmv_y = (*dmv_y + (*dmv_y & 1)) >> 1; + } } } else { @@ -1160,7 +1164,7 @@ static av_always_inline void get_mvdata_interlaced(VC1Context *v, int *dmv_x, *dmv_y = (sign ^ ((val >> 1) + offs_tab[index1 >> v->numref])) - sign; } else *dmv_y = 0; - if (v->numref) + if (v->numref && pred_flag) *pred_flag = index1 & 1; } } From fbde7b2d0aebf2b0123f6a19f871a904322a5b45 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Fri, 11 Jan 2013 05:07:42 +0100 Subject: [PATCH 10/16] zmbv: Reset the decoder on keyframe errors Prevent the crash on fuzzed files as reported in bug 63. (cherry picked from commit c1d1ef4ecd9c4f1ca01c8149c7e57c14968ca588) Signed-off-by: Luca Barbato --- libavcodec/zmbv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/zmbv.c b/libavcodec/zmbv.c index 0733fa70d4..c92e553f6d 100644 --- a/libavcodec/zmbv.c +++ b/libavcodec/zmbv.c @@ -428,6 +428,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac c->fmt = buf[3]; c->bw = buf[4]; c->bh = buf[5]; + c->decode_intra = NULL; + c->decode_xor = NULL; buf += 6; len -= 6; From bc182a6acaf8549fa335a90531c3533437d44c74 Mon Sep 17 00:00:00 2001 From: Marcin Juszkiewicz Date: Thu, 10 Jan 2013 12:22:53 +0000 Subject: [PATCH 11/16] configure: enable pic for shared libs on AArch64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Juszkiewicz Signed-off-by: Martin Storsjö (cherry picked from commit d11cb13b0ef02fb1c303b29805819f6e1c9dc61b) Signed-off-by: Luca Barbato --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index e87a3261de..8cc9cdc139 100755 --- a/configure +++ b/configure @@ -2788,7 +2788,7 @@ check_64bit(){ } case "$arch" in - alpha|ia64) + aarch64|alpha|ia64) spic=$shared ;; mips) From fadebd256e91b9dbfcc77af960696767c77d82d2 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sat, 12 Jan 2013 12:53:45 +0100 Subject: [PATCH 12/16] APIchanges: Fill in missing hashes and dates; fix a version number typo. --- doc/APIchanges | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index a5a0bea1fc..6e18ef652c 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,31 +13,31 @@ libavutil: 2012-10-22 API changes, most recent first: -2012-xx-xx - xxxxxxx - lavu 52.2.1 - avstring.h +2012-12-29 - d8fd06c - lavu 52.3.0 - avstring.h Add av_basename() and av_dirname(). -2012-xx-xx - xxxxxxx - lavu 52.2.0 - audioconvert.h +2012-11-11 - 5980f5d - lavu 52.2.0 - audioconvert.h Rename audioconvert.h to channel_layout.h. audioconvert.h is now deprecated. -2012-xx-xx - xxxxxxx - lavu 52.1.0 - intmath.h +2012-11-05 - dfde8a3 - lavu 52.1.0 - intmath.h Add av_ctz() for trailing zero bit count -2012-10-18 - xxxxxxx - lavu 51.45.0 - error.h +2012-10-21 - a893655 - lavu 51.45.0 - error.h Add AVERROR_EXPERIMENTAL -2012-10-12 - xxxxxxx - lavu 51.44.0 - pixdesc.h +2012-10-12 - d2fcb35 - lavu 51.44.0 - pixdesc.h Add functions for accessing pixel format descriptors. Accessing the av_pix_fmt_descriptors array directly is now deprecated. -2012-10-xx - xxxxxxx - lavu 51.43.0 - aes.h, md5.h, sha.h, tree.h +2012-10-11 - 9a92aea - lavu 51.43.0 - aes.h, md5.h, sha.h, tree.h Add functions for allocating the opaque contexts for the algorithms, deprecate the context size variables. -2012-10-xx - xxxxxxx - lavf 54.18.0 - avio.h +2012-10-10 - b522000 - lavf 54.18.0 - avio.h Add avio_closep to complement avio_close. -2012-10-xx - xxxxxxx - lavu 51.42.0 - pixfmt.h +2012-10-08 - 78071a1 - lavu 51.42.0 - pixfmt.h Rename PixelFormat to AVPixelFormat and all PIX_FMT_* to AV_PIX_FMT_*. To provide backwards compatibility, PixelFormat is now #defined as AVPixelFormat. From 7a2ee770f520ae4fd5f009cfc361a18e993dec91 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Sun, 13 Jan 2013 19:52:45 +0100 Subject: [PATCH 13/16] lavc: check for overflow in init_get_bits Fix an undefined behaviour and make the function return a proper error in case of overflow. CC: libav-stable@libav.org (cherry picked from commit d9cf5f516974c64e01846ca685301014b38cf224) Signed-off-by: Luca Barbato --- libavcodec/get_bits.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h index c56a2c2d10..16cfd5e0fd 100644 --- a/libavcodec/get_bits.h +++ b/libavcodec/get_bits.h @@ -362,20 +362,27 @@ static inline int check_marker(GetBitContext *s, const char *msg) } /** - * Inititalize GetBitContext. - * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger than the actual read bits - * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end + * Initialize GetBitContext. + * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes + * larger than the actual read bits because some optimized bitstream + * readers read 32 or 64 bit at once and could read over the end * @param bit_size the size of the buffer in bits + * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow. */ -static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer, - int bit_size) +static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer, + int bit_size) { - int buffer_size = (bit_size+7)>>3; - if (buffer_size < 0 || bit_size < 0) { + int buffer_size; + int ret = 0; + + if (bit_size > INT_MAX - 7 || bit_size <= 0) { buffer_size = bit_size = 0; buffer = NULL; + ret = AVERROR_INVALIDDATA; } + buffer_size = (bit_size + 7) >> 3; + s->buffer = buffer; s->size_in_bits = bit_size; #if !UNCHECKED_BITSTREAM_READER @@ -383,6 +390,7 @@ static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer, #endif s->buffer_end = buffer + buffer_size; s->index = 0; + return ret; } static inline void align_get_bits(GetBitContext *s) From 71e00caeab89d9beeef9c947673f72e992bd109c Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Sun, 13 Jan 2013 23:37:11 +0100 Subject: [PATCH 14/16] lavc: introduce the convenience function init_get_bits8 Accept the buffer size in bytes and check for overflow before passing the value in bits to init_get_bits. (cherry picked from commit e28ac6e5e27e64a206e399e958481c1e6f992189) Signed-off-by: Luca Barbato --- libavcodec/get_bits.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h index 16cfd5e0fd..12770a29a0 100644 --- a/libavcodec/get_bits.h +++ b/libavcodec/get_bits.h @@ -393,6 +393,22 @@ static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer, return ret; } +/** + * Initialize GetBitContext. + * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes + * larger than the actual read bits because some optimized bitstream + * readers read 32 or 64 bit at once and could read over the end + * @param byte_size the size of the buffer in bytes + * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow. + */ +static inline int init_get_bits8(GetBitContext *s, const uint8_t *buffer, + int byte_size) +{ + if (byte_size > INT_MAX / 8) + return AVERROR_INVALIDDATA; + return init_get_bits(s, buffer, byte_size * 8); +} + static inline void align_get_bits(GetBitContext *s) { int n = -get_bits_count(s) & 7; From e44d56b18d46957fceaefe7f8840263c5cd12d37 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Mon, 14 Jan 2013 05:32:38 +0100 Subject: [PATCH 15/16] lavc: set the default rc_initial_buffer_occupancy rc_buffer_size is not set before. Solve the initial the rate control underflow issue reported in bug 222. CC: libav-stable@libav.org Signed-off-by: Luca Barbato (cherry picked from commit bff3607547fdbb6e32b3830a351e6a33280c1e0d) Signed-off-by: Luca Barbato --- avconv_opt.c | 2 -- libavcodec/utils.c | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/avconv_opt.c b/avconv_opt.c index ce32df6b6b..e67abefd77 100644 --- a/avconv_opt.c +++ b/avconv_opt.c @@ -950,8 +950,6 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) if (p) p++; } video_enc->rc_override_count = i; - if (!video_enc->rc_initial_buffer_occupancy) - video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size * 3 / 4; video_enc->intra_dc_precision = intra_dc_precision - 8; /* two pass mode */ diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 23f2ac481a..19c8a99ff5 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -824,6 +824,9 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code } else if (avctx->channel_layout) { avctx->channels = av_get_channel_layout_nb_channels(avctx->channel_layout); } + + if (!avctx->rc_initial_buffer_occupancy) + avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3 / 4; } if (avctx->codec->init && !(avctx->active_thread_type & FF_THREAD_FRAME)) { From 72eca26bf95dd58ce05b9dbf9b1b3694f496daf6 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Mon, 14 Jan 2013 05:32:39 +0100 Subject: [PATCH 16/16] libx264: use the library specific default rc_initial_buffer_occupancy By default libav sets it to 3/4 while x264 sets it to 9/10. CC: libav-stable@libav.org Signed-off-by: Luca Barbato (cherry picked from commit 47812070a267cbdf74164e154d03d99bf8ced100) Signed-off-by: Luca Barbato --- libavcodec/libx264.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index f536f7f965..e9cbbad22a 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -272,7 +272,7 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.rc.f_rf_constant_max = x4->crf_max; } - if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy && + if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy > 0 && (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) { x4->params.rc.f_vbv_buffer_init = (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size; @@ -560,6 +560,7 @@ static const AVCodecDefault x264_defaults[] = { { "threads", AV_STRINGIFY(X264_THREADS_AUTO) }, { "thread_type", "0" }, { "flags", "+cgop" }, + { "rc_init_occupancy","-1" }, { NULL }, };